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

Understanding DataAvailable event WaveInEventArgs

Mar 2, 2015 at 7:10 AM
I just started using NAudio and I have following code:
        capture = new WasapiCapture(SelectedDevice);
        capture.ShareMode = AudioClientShareMode.Shared;
        capture.WaveFormat = new WaveFormat(48000,32,2);
        SelectedDevice.AudioEndpointVolume.MasterVolumeLevelScalar = 1.0f;//Max
        capture.RecordingStopped += OnRecordingStopped;
        capture.DataAvailable += CaptureOnDataAvailable;
and following function to handle DataAvailable event
        private void CaptureOnDataAvailable(object sender, WaveInEventArgs e)

I want to know what will be contents of e.Buffer will be like if my bit depth is 32, sample rate 48000Hz and channel 2?

Is it like this:
         e.Buffer[0] will contain least significant byte of channel 1
         e.Buffer[3] will contain most significant byte of channel 1
         e.Buffer[4] will contain least significant byte of channel 2
         e.Buffer[7] will contain most significant byte of channel 2
         and so on
If not, please explain its format.
Mar 2, 2015 at 12:20 PM
Yes, it will be little endian, with interleaved samples. You can use BitConverter to help read samples out.
32 bit PCM is a bit unusual. More common to use IEEE float (use WaveFormat.CreateIEEEFloat ... static method)
In fact with WASAPI, I'd recommend leaving the WaveFormat alone. You can't change the sample rate in shared mode anyway. By default you'll get a WAVEFORMATEXTENSIBLE containing 32 bit floating point (IEEE float). You can use BitConverter.ToSingle to read them out
Marked as answer by Talha5389 on 3/2/2015 at 5:29 AM