This project has moved. For the latest updates, please go here.

Process audio data without saving a file

Feb 23, 2015 at 6:12 PM
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
Coordinator
Feb 23, 2015 at 7:00 PM
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.
Mar 5, 2015 at 5:11 PM
thank you very much