This project has moved and is read-only. For the latest updates, please go here.

Using WasapiLoopbackCapture to do a sound visualizer

Apr 16, 2013 at 6:27 PM
Edited Apr 17, 2013 at 12:18 AM
hello

i'm trying to do a visualizer using Naudio wasapi loop back capture feature, but i have a problem using samples.

NAudio.Wave.WasapiLoopbackCapture wasapi = new NAudio.Wave.WasapiLoopbackCapture();
wasapi.StartRecording();
wasapi.DataAvailable += InputBufferToFileCallback;

Now i use the event InputBufferToFileCallback to get the e.buffer and then extracting from the byte array the samples
        byte[] buffer = e.Buffer;
        int bytesRecorded = e.BytesRecorded;
        int bufferIncrement = (int)(wasapi.WaveFormat.BlockAlign / wasapi.WaveFormat.Channels);
        int bitsPerSample = wasapi.WaveFormat.BitsPerSample;

        for (int index = 0; index < e.BytesRecorded; index += bufferIncrement)
        {
            float sample32left = 0;
            float sample32right = 0;
            sample32right = BitConverter.ToSingle(buffer, index);
            sample32left = BitConverter.ToSingle(buffer, index + 4);
            sampleAggregator.Add(sample32left, sample32right);
        }
My question is if the samples for the right and left channels are right or if is it possible to use the wavechannel32 class to get the left and right samples in relation to the wasapiloopbackCapture.

thanks

EDIT: resolved, the problem was the bufferIncrement that is equal to wasapi.WaveFormat.BlockAlign , no division.