I took an existing mono (non-stereo) NAudio example for Visual Studio 2010 from:
http://mark-dot-net.blogspot.com/2009/10/playback-of-sine-wave-in-naudio.html
and changed it to have two channel stereo audio as shown below:
public abstract class WaveProvider32 : IWaveProvider
{
public WaveProvider32() : this(44100, 2) // Was 44100, 1
{
}
.
.
.
}
When I try to place the correct sample value in the first float in buffer and a zero in the second float in buffer, I was expecting to get a sine wave on the right channel and no audio on the left.
I'm seeing the same frequency 10x lower amplitude out of phase sine wave on the left channel vs. the right channel.
Is that from some kind of signal bleed through or am I not understanding how the code should work?
Here is a sample of how I changed WaveProvider32:
public class SineWaveProvider32 : WaveProvider32
{
.
.
.
public override int Read(float[] buffer, int offset, int sampleCount)
{
int sampleRate = WaveFormat.SampleRate;
for (int n = 0; n < sampleCount; n += 1)
{
buffer[n+offset] = (float)(Amplitude * Math.Sin((2 * Math.PI * sample * Frequency) / sampleRate));
buffer[n+offset+1] = (float)(0);
sample++;
if (sample >= sampleRate)
{
sample = 0;
}
}
return sampleCount;
}
}
Any advice on what I'm doing wrong?
Regards
Note: The NAudio project is located at:
http://naudio.codeplex.com/
Your for loop should have += 2, not += 1.
for (int n = 0; n < sampleCount; n += 2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With