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

NAudio sampleChannel issue - getting 2 streams of MaxSampleValues from a mono sampleChannel

Apr 3, 2014 at 3:38 PM
I am using NAudio in a windows forms application.

I want to have a meter display while the user is recording audio.

The problem I am getting is that every second MaxSampleValues from a mono sampleChannel_PreVolumeMeter is 0 (zero).

....
        sampleChannel = new SampleChannel(bufferedWaveProvider2, false);
        sampleChannel.PreVolumeMeter += sampleChannel_PreVolumeMeter;
        Trace.WriteLine(string.Format("sampleChannel.WaveFormat = {0}, {1}", sampleChannel.WaveFormat, sampleChannel.WaveFormat.Channels));
....
   void sampleChannel_PreVolumeMeter(object sender, StreamVolumeEventArgs e)
    {
        if (e.MaxSampleValues[0] != 0)
        {
            volumeMeterRecord.Amplitude = e.MaxSampleValues[0];
            wfPainterPreVolume.AddMax(e.MaxSampleValues[0]);
        }

            Trace.WriteLine(string.Format("sampleChannel_PreVolumeMeter {0}", e.MaxSampleValues[0].ToString()));

    }
Sample Output

Mode=Debug
sampleChannel.WaveFormat = IeeeFloat, 1
sampleChannel_PreVolumeMeter 0.06512451
sampleChannel_PreVolumeMeter 0
sampleChannel_PreVolumeMeter 0.04870605
sampleChannel_PreVolumeMeter 0
sampleChannel_PreVolumeMeter 0.1290894
sampleChannel_PreVolumeMeter 0
sampleChannel_PreVolumeMeter 1
sampleChannel_PreVolumeMeter 0

My work around is working - (ignore the 0 (zero) samples) but I don't understand why it is needed...
Apr 19, 2014 at 8:31 PM
I have pretty much the same problem.

It seems that AudioFileReader always turned mono into stereo...

In my case :
AudioFileReader newAudio = new AudioFileReader(path);
byte[] data = new byte[100];
int read =  newAudio.Read(data, 0, data.Length);
 for (int i = 0; i < read; i += 2)
{
System.Console.WriteLine(BitConverter.ToInt16(data,i));
}
and here is what I get :
0
0
-18432
0
14464
0
-18432
0
-18432
0
14528
0
-18176
0
14592
0
-18240
0
14464
0
-18432
0
14336
0
-18304
0
14528
0
...
So halft the time its zero...
Anyone know how to have an issue for this please ?