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


Topics: Audio, Getting Started, Newbie, Plugin Development
Mar 19, 2016 at 12:45 AM
Does anyone know of an example of panning in c#?

Particularly, taking a stereo signal and panning it - or taking two mono signals and panning those...

Failing that, a generic algorithm in pseudo code, or some other language would be good.
Mar 19, 2016 at 7:58 AM
Panning a stereo signal is controlling the other channel's volume.
So panning to the right means lowering the volume on the left.
You could add a little boost in volume (right channel) also but watch your unity gain.

Mar 19, 2016 at 8:08 AM
Well, that seems like the obvious answer, but I'm sure it's not that simple. It never is with DSP.

All of the algorithms I've seen on the net talk about "pan law" and give complex equations with angles.
Mar 19, 2016 at 7:34 PM
Edited Mar 19, 2016 at 7:46 PM
Simplest way is to decrease gain (attenuator). Increasing gain (amplificator) is not practical as you'll need to workaround clipping issues with samples values getting higher than 1.

Panning in analog equipment is usually done with a linear control (pot, fader...) sending voltage signal to VCA (voltage controlled attenuator).

See how the voltage signal (Y vol axis) is linear (V shaped) in this mono pan law graph:

The green signal is not a final gain value that you can easily apply to the samples values in DSP. The VCA here operates on a dB logarithmic scale, think exponential. The way to get out of the complex equations is to begin by converting the dB gain value to a linear gain value.

For a typical pan law you convert ranges from [0, -3] dB to [1, 0] linear. You then apply that converted gain value to each sample with a linear convolution, fancy way of saying multiply sample value by constant value.

Stereo and other multi-channel pan laws brings summing operation in the mix, fancy way of saying add two sample values together. The only thing to watch out for is to never go over unity gain. If you sum two mono tracks to a single mono track without attenuation you'll effectively create an amplificator and therefore risk clipping.

In this 2 tracks mixed to 1 scenario with a potential maximum sample value of 1 on each track, clipping happens because 1 + 1 > 1 so you can do 1 * 0.5 + 1 * 0.5 <= 1 to prevent clipping easily. The panning and mixing operations are done independently in series on each sample value.
Mar 20, 2016 at 8:34 AM
Mar 21, 2016 at 12:18 AM
Thanks to the both of you!