Quantcast
Channel: NAudio
Viewing all 5831 articles
Browse latest View live

New Post: Process audio data without saving a file

$
0
0
To begin tell them that my English is not very good but try to explain my problem.

I'm working with NAudio library to process audio in C # .Net.

I'm recording an audio file (WAV) and then process the data without any problem this way.
        WaveChannel32 wave = new WaveChannel32(new WaveFileReader(rutaWav));
        arch = new StreamWriter(rutaCsv);

        byte[] buffer = new byte[16384];

        int read = 0;

        objS.iniTiempo();
        while (wave.Position < wave.Length)
        {
            read = wave.Read(buffer, 0, 16384);

            for (int i = 0; i < read / 4; i++)
            {
                double val = BitConverter.ToSingle(buffer, i * 4);
               objS.Escenario(val);
               arch.WriteLine(val); // CSV file just to check the data
            }
        }
        arch.Close();

My problem is that I need to do the same but instead of reading a WAV file I read the same data directly from the microphone.

Then edit the code when I write the wav file in the following way.
    ficheroOndaSalidaEscenario.Write(e.Buffer, 0, e.BytesRecorded);
    for (int i = 0; i < e.BytesRecorded/4 ; i++)
    {
           double val = BitConverter.ToSingle(e.Buffer, i*4);
           arch_dinamico.WriteLine(val); // // CSV file just to check the data
    }
But the result is not the same as reading the WAV file, I searched for information for many days and still not find the answer please if anyone knows how to solve my problem appreciate your help


Sorry for my bad English

New Post: Bug report: WaveFileReader - Argument out of range exception

$
0
0
Hello Mark, I tried to Play a 2GB wav file that I recorded using your wavefilewriter.

Waveformat: IEEE float, 32bit, 44100Hz.

The WaveFileReader throws an exception on playback start, "Argument out of range exception".
Seems, it sets a negative Position in underlying filestream.
Filesize can´t be a Problem, ~6GB is allowed for wave files at least.

Ideas Mark?


Message:
System.ArgumentOutOfRangeException wurde nicht behandelt.
Message="Nicht negative Zahl erforderlich. Parametername: value"
ParamName="value"
Source="mscorlib"
Stack Trace:
bei System.IO.FileStream.set_Position(Int64 value) bei NAudio.FileFormats.Wav.WaveFileChunkReader.ReadWaveHeader(Stream stream) bei NAudio.Wave.WaveFileReader..ctor(Stream inputStream) bei NAudio.Wave.WaveFileReader..ctor(String waveFile)[...]

New Post: Bug report: WaveFileReader - Argument out of range exception

$
0
0
The maximum standard WAV file size is 4GB, although if you are making large files (>2GB), I'd recommend making RF64 files

If you can create some example test code that reproduces this issue, then we can look into getting it fixed.

New Post: Process audio data without saving a file

$
0
0
What WaveFormat are you recording in? If it's 16 bit then you can't use BitConverter.ToSingle - you'll need to use ToInt16 as the samples will be shorts.

New Post: Kinect Audio Stream With NAudio

$
0
0
Sorry, I don't have a kinnect so I can't answer questions 1-3.
The answer to question 4 depends on what output device you are using - WaveOut? WasapiOut?

New Post: Asio under NAudio: Problem with passing audio in to audio out on same AsioOut instance

$
0
0
you are not copying over the output buffers. You are copying the array of output buffer pointers, which will have no effect.
This option is only advised for people who are comfortable for working with pointers. You need to go through each InputBuffer pointer, and copy the number of bytes available from that pointer to the pointer in the corresponding output buffer pointer.

New Post: Getting unspecified error while executing simple command line app

$
0
0
That error is usually related to the soundcard driver. What sound device is it using? What WaveFormat are you trying to open with?

New Post: Asio under NAudio: Problem with passing audio in to audio out on same AsioOut instance

$
0
0
Hi Mark,

Thanks for the response.

At this point in time, our project is only focused on bringing in data over ASIO, and is working like a champ.

I had experiemented with the scheme you have proposed below, where pointers are used to transfer the data, and I was running into some sort of syntax/compilation error at about the point in time where we no longer had the requirement to play back audio we had received, and the effort was abandoned.

Eventually we may revisit the feature to be able to pass Input Audio right back out, using the ASIO object, and I will post any successful code at that time.

FWIW, pointers are no big deal here, I am really a low level C/assembler HW/FW/SW engineer temporarily wearing my C# hat.

Thanks,
John Waygan




On 2/23/2015 3:03 PM, markheath wrote:

From: markheath

you are not copying over the output buffers. You are copying the array of output buffer pointers, which will have no effect.
This option is only advised for people who are comfortable for working with pointers. You need to go through each InputBuffer pointer, and copy the number of bytes available from that pointer to the pointer in the corresponding output buffer pointer.


New Post: Bug report: WaveFileReader - Argument out of range exception

$
0
0
VB .NET (shortened) sample code, that produces the issue:
Imports NAudio.Wave

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim waveOut = New WaveOut() With {.DeviceNumber = 0, .DesiredLatency = 225}
        Dim fileName As String = "C:\Users\Martin\Desktop\Record3.wav"

        Dim waveReader As IWaveProvider = New WaveFileReader(fileName)

        waveOut.Init(waveReader)
        waveOut.Play()
    End Sub
End Class
Concerning bwf, I don´t like that Format as it is not supported by most other Players. Alternative Format: "Sony Pictures Digital Wave 64", in short "Wave64" with "*.w64" Extension. Also not widely supported though.

New Post: Asio under NAudio: Problem with passing audio in to audio out on same AsioOut instance

$
0
0
yeah, I've got some code kicking around somewhere that can do this which I made for carl franklin. I keep meaning to turn it into a blog post.

New Post: Bug report: WaveFileReader - Argument out of range exception

$
0
0
for >4GB you have to go the RF64 route. What I mean is, what do you do to make a WAV file that has this issue? Can you make one with some calls to WAV file writer that will exhibit this issue when you play it. I have no idea what is in Record3.wav.

New Post: Bug report: WaveFileReader - Argument out of range exception

$
0
0
The "Record3.wav" file has the issue described above. Any bigger record had this issue, although None was >4GB.

So again, Record3 has the WaveFormat: IEEE float, 32bit, 44100Hz.

I can upload it, but 2GB is a lot for my slow Connection.


Edit: I´ve tested more records and the "Magic" border seems to be somewhere between 1 and 2GB file size.

New Post: Managed to sqeeze a beep on Windows Phone 8.1 with NAudio WasapiOutRT

$
0
0
Most interesting!

On my Emulator, I kept getting the "A first chance exception of type 'System.InvalidOperationException' occurred in NAudio.Win8.DLL" exception. No throws, no debug stops - just this in the Debug Output console. No matter UnhandledException and Debug Native and Managed combinations, I was always getting one beep and a line in the output.

My Lumia 830, though, was completely different story - it worked :) Yes, a simple monotonous tone it was, but it was playing and for far more than a second :) It was so eager at playing, that while debugging if I brought the test app in the background, sound would pause and then continue to play from the background.

So, since I will be dealing with Windows Phone and sound in the coming 1-2 months, I will try to push a Windows Phone NAudio port test some more :)

BTW, I discovered an error in my code - CloseHandle is in "api-ms-win-core-handle-l1-1-0.dll".

New Comment on "MP3"

$
0
0
You can use MediaFoundationDecoder for decoding mp4/m4a etc. https://msdn.microsoft.com/de-de/library/windows/desktop/dd757927%28v=vs.85%29.aspx Supported from Win 7 on I think.

New Post: NAudio read a .wav and send to socket

$
0
0
I use this code but it send too fast sample to the listener, I want send to listener sample how is comming when I recording

      using (WaveFileReader reader = new WaveFileReader(fileName))
      {
        try
        {
          int sampleRate = reader.WaveFormat.SampleRate;
          while (reader.Position < reader.Length)
          {
            byte[] bytes = new byte[sampleRate];
            int bytesRead = reader.Read(bytes, 0, sampleRate);
            audiosocket.Send(bytes, 0, bytesRead, SocketFlags.None);
            
          }
        }
        catch (Exception ex)
        {
          
   
        }  
      }

New Post: Audio Sample Position

$
0
0
Hi,

What is the most efficient way to get position/timing data for each audio sample? Any help is appreciated!

Brandon

New Post: Implemented Loopback capturing for NAudio

$
0
0
I have lot of problem brohter pls help me. i add all above code in class and recieve build time error. pls guid me how i can start and stop recording from window form in c#???

Error 1 'NAudio.CoreAudioApi.WasapiLoopbackCapture' does not implement interface member 'NAudio.Wave.IWaveIn.RecordingStopped'. 'NAudio.CoreAudioApi.WasapiLoopbackCapture.RecordingStopped' cannot implement 'NAudio.Wave.IWaveIn.RecordingStopped' because it does not have the matching return type of 'System.EventHandler<NAudio.Wave.StoppedEventArgs>'. E:\Student\std\proj\WMP\WMP\WMP\WasapiLoopbackCapture.cs 17 18 WMP

New Post: Mp3 streaming problem using NAudio - C#

$
0
0
I am working on streaming mp3 from url source for a few days.It almost works good except a small problem. The problem is that there is some momentary interruptions while playing mp3. I couldnt figure out why this happening. I need help and my code is like that. Sorry it's too long but maybe you want to try.
private void buttonPlay_Click(object sender, EventArgs e)
        {
           
 
            string url = "http://freedownloads.last.fm/download/569264057/Get%2BGot.mp3";
            bool playingStarted = false;
 
            WaveStream str;
            WaveFormat format = GetWaveFormat(url);
 
            HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest;
            HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
 
            int contentLength=(int)resp.ContentLength;
 
            Stream stream = resp.GetResponseStream();
 
            BufferedWaveProvider provider = new BufferedWaveProvider(format);
            provider.BufferDuration = TimeSpan.FromMinutes(20);
            
            byte[] buffer = new byte[format.SampleRate];
            byte[] totalBuffer = new byte[contentLength];
            byte[] mp3StreamBuffer = new byte[format.SampleRate];
            
            int bytesRead = 0, totalBytes=0;
            int decBytes = 0;
            long skipTo = 0;
           
            Task.Factory.StartNew(() =>
            {
                while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    Buffer.BlockCopy(buffer, 0, totalBuffer, totalBytes, bytesRead);
 
                    totalBytes += bytesRead;
 
                    this.Invoke((MethodInvoker)delegate { progressBar2.Value = (int)(totalBytes * 100.0 / contentLength); });
 
                    if (totalBytes < format.AverageBytesPerSecond) 
                        continue;
 
                    str = new Mp3FileReader(new MemoryStream(totalBuffer));
 
                    str.Position = skipTo;
 
                    while ((decBytes = str.Read(mp3StreamBuffer, 0, mp3StreamBuffer.Length)) > 0) 
                    {
                        provider.AddSamples(mp3StreamBuffer, 0, decBytes);
                    }
 
                    skipTo = str.Position;
 
                    if (playingStarted)
                    {
                        playingStarted = false;
                        Task.Factory.StartNew(() =>
                        {
                            
                            play.Init(provider);
                            play.Play();
                        });
                    }
                }
            });
 
        }
 
        
 
        WaveFormat GetWaveFormat(string url)
        {
            HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest;
            HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
            Stream stream = resp.GetResponseStream();
            byte[] buffer = new byte[2048];
            int readBytes = 0, bytesReceived = 0;
 
            MemoryStream ms = new MemoryStream();
 
            while ((readBytes = stream.Read(buffer, 0, buffer.Length)) > 0)
            {
                ms.Write(buffer, 0, readBytes);
                bytesReceived += readBytes;
                if (bytesReceived >= 10000) break;
            }
            req.Abort();
            resp.Close(); ms.Position = 0;
            WaveStream tempStream = new Mp3FileReader(ms);
            return tempStream.WaveFormat;
        }

New Post: Audio Sample Position

$
0
0
in what context? are you playing / recording audio / examining a file?

New Post: How can I position an mp3 streaming?

$
0
0
I am working on mp3 streaming and using WaveOut and BufferedWaveProvider to play mp3.How can I specify position of mp3?
Viewing all 5831 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>