Naudio panning is not working

426 views Asked by At

I can't get the panning to work in Naudio.
here is my code:

void Play(double Amp, double Left, double Right)
{
    BBeats = new binaural_beats();
    BBeats.Amplitude = Amp;
    BBeats.Amplitude2 = Amp;
    BBeats.Frequency = Left;
    BBeats.Frequency2 = Right;

    BBeats.Bufferlength = 44100 * 2 * 3; // will play for 3 sec

    waveout = new WaveOut();
    WaveChannel32 temp = new WaveChannel32(BBeats);

    temp.PadWithZeroes = false;
    temp.Pan = 0.0f;

    waveout.Init(temp);
    waveout.Play();
}

I tried 0.0F, 1.0F and 100F but it is not working.

I want it to play completely from one speaker and not from the other one. or from one channel and not the other channel.

3

There are 3 answers

1
Mark Heath On

The Pan setting on WaveChannel32 goes from -1 (left only) to 1 (right only)

Or for more control over panning strategies, look at the PanningSampleProvider class.

0
Frank On

I just spent the entire night with same problem.

AND the solution was a whole different place than expected. I tried using pan and PanningSampleProvider, and MultiplexingWaveProvider, to obtain control over the pan, but I could only hear a minor change in sound, not really a pan. On my output meters, I could see maybe 10% variation.

Now I must translate from Danish, so it might not be 100% accurate. But under your sound device in windows, select the play device you are using, press properties, press extensions, and tick the "Deactivate all sound effects". BAM, 100% control over pan.

Guess windows have some kind of auto-level algorithm between stereo channels selected as default - don't know why and what it should do.

0
ngoctrambui On

I had the same problem. I tried to use PanningSampleProvider (NAudio) but it didn't work. I found out the cause was window system setting. Just turn off mono audio from Audio Setting. Turn off mono audio

Here is my source code:

var _audioFile = new AudioFileReader("E://CShap/Test/speaker.wav");
var monofile = new StereoToMonoSampleProvider(_audioFile);
var panner = new PanningSampleProvider(monofile);
panner.PanStrategy = new SquareRootPanStrategy();
panner.Pan = -1.0f; // pan fully left
WaveFileWriter.CreateWaveFile16("E://CShap/Test/speaker_resampler_L.wav", panner);