Table of Contents:
Panning is the process of using left and right channels separately.
Assuming we have a value P0 which represents the value of the panning knob (-1 to 1) we can get coeficients that act as a gain value for each channel.
$$ LeftCoeficient = 0.5 - (P_0/2) $$
$$ RightCoeficient = 0.5 + (P_0/2) $$
See Desmos example below for visual:
https://www.desmos.com/calculator/ieqrzoiqm8
We can use the example from last section to build a panning function.
float[] PanningCalc( float Panning ) {
Panning = (Panning * 2.f) - 1.f; //change 1 - 0 to -1 - 1
float LeftVal = 0.5f - (Panning / 2);
float RightVal = 0.5f + (Panning / 2);
float[] Values[2] = [LeftVal, RightVal];
return Values;
}
And then in our processing we can use this to add gain to our samples accordingly.
Vst::Sample32* LeftIn = data.inputs[0].channelBuffers32[0];
Vst::Sample32* RightIn = data.inputs[0].channelBuffers32[1];
Vst::Sample32* LeftOut = data.outputs[0].channelBuffers32[0];
Vst::Sample32* RightOut = data.outputs[0].channelBuffers32[1];
for (int i = 0; i < data.numSamples; i++) {
float[] PanningValues = PanningCalc( mPan );
LeftOut[i] = LeftIn[i] * PanningValues[0];
RightOut[i] = RightIn[i] * PanningValues[1];
}