Help with Plug n Script script [solved]

Official support for: bluecataudio.com
Post Reply New Topic
RELATED
PRODUCTS

Post

If anyone can suggest a solution I would appreciate it. I'm writing what should be a simple stereo panner script. The input is stereo and the left and right inputs can be panned independently across the left and right outputs from -100 (left) to 100 (right). The script I wrote compiles without error but the script does not do as desired. In fact, I'm not sure what it is doing. Mathematically, the functions work on paper but not in practice.

bool initialize()
{
if(audioInputsCount!=2)
{
print("Error: this script requires 2 audio channels, not "+audioInputsCount);
return false;
}
return true;
}

array<string> inputParametersNames={"Left Bal","Right Bal"};
array<string> inputParametersUnits={"",""};
array<double> inputParameters(inputParametersNames.length);
array<double> inputParametersMin={0,0};
array<double> inputParametersMax={90,90};
array<double> inputParametersDefault={0,90};

double lilo=0;
double liro=0;
double rilo=0;
double riro=0;

void processSample(array<double>& ioSample)
{
double left=ioSample[0];
double right=ioSample[1];
ioSample[0]=(left*lilo)+(right*rilo);
ioSample[1]=(left*liro)+(right*riro);
}

void updateInputParameters()
{
lilo=cos(inputParameters[0]);
liro=sin(inputParameters[0]);
rilo=cos(inputParameters[1]);
riro=sin(inputParameters[1]);
}
Last edited by Top Jimmy on Tue Feb 07, 2017 2:12 am, edited 2 times in total.

Post

Irrespective of the correctness/incorrectness of the code (I do not understand the business with 0.45 and 45 in the least), you are missing an important opportunity for efficiency. Variables leftbal and rightbal are set in updateInputParameters and do not otherwise change unless the user modifies the external parameter control. Yet you calculate the cos and sin of leftbal and rightbal for every single sample (in every call to processSample). Why not just calculate the sin and cos values in updateInputParameters and reuse those values in processSample?

Post

dmbaer wrote:Irrespective of the correctness/incorrectness of the code (I do not understand the business with 0.45 and 45 in the least), you are missing an important opportunity for efficiency. Variables leftbal and rightbal are set in updateInputParameters and do not otherwise change unless the user modifies the external parameter control. Yet you calculate the cos and sin of leftbal and rightbal for every single sample (in every call to processSample). Why not just calculate the sin and cos values in updateInputParameters and reuse those values in processSample?
Thanks for pointing out the inefficiency. I've updated the script above and removed the extraneous math. The script still does the same thing wrong.

I assumed that functions like sin & cos are available by default, but is there a higher order math function library that needs to be invoked?

Post

So I had to calculate on radians not degrees. ;)

Problem solved.

Post Reply

Return to “Blue Cat Audio”