View Full Version : Where should my variables be declared?
RRokkenAudio
01-17-2010, 10:40 AM
I'm usually putting my variables here: Does that eat up cpu at all? I have only seen schwa's sample code with iplug, not sure what you guys are doing..
void SomePlug::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
{
double* in1 = inputs[0];
double* in2 = inputs[1];
double* out1 = outputs[0];
double* out2 = outputs[1];
double SR = this->GetSampleRate();
double inputgain = GetParam(finputgain)->DBToAmp();
double hipass = GetParam(fhipass)->Value();
double mixcntrl = GetParam(fmix)->Value();
double outputgain = GetParam(foutputgain)->DBToAmp();
int listenswitch = GetParam(flisten)->Value();
int bypassswitch = GetParam(fbypass)->Value();
~Rob.
Astralp
01-17-2010, 02:24 PM
See my other post on onParamChange, do as much as you can in there.
Also something like setting the samplerate you can do in the constructor ie; where you have set up all your parameters and graphics etc... In the header of your project in the private: section you can define global variables that will be visible in the whole class so:
<yourprojectname>.h
....
private:
double samplerate;
The idea is to have as little as possible in the processing part, so anything that can be calculated outside of it, should be :)
RRokkenAudio
01-17-2010, 02:31 PM
Well, i just tried this:
//Optional methods
void Reset() {}
void OnParamChange(int paramIdx) {
double peakL = 0.0, peakR = 0.0;
}
And it gives the error: undeclared identifier.... ?? It is public, i dont see why its not working... something i'm missing. That is in the .h file
Astralp
01-17-2010, 02:47 PM
You can't assign the value in the header, you would assign the value in the constructor, in the header it would just be:
double peakL;
Although with the peaks, they are ok in the main process, and probably more efficient too as they change at block or sample rate. The samplerate only needs setting once and so could use the above method.
double hipass = GetParam(fhipass)->Value();
This is an example of how this is being executed on every block, if you defined a private variable in the header:
double hipass;
Then
void onParamChange(int paramIdx)
{
if (paramIdx)
hipass = GetParam(fhipass)->Value();
.....
This would only be set when the fhipass parameter changes so that you can just use hipass variable in your processing function.
Incidentally, the samplerate is perhaps not the best example because the host could change it if the user changes samplerate, I am not 100% sure if the plug is re-initialized when that happens, perhaps adding it to the reset() function will be necesary. But the what i was trying to demonstrate is that any variable that only needs setting once, can be declared in the hearer and then set in the constructor.
hehe It is hard to describe all of this, hope I'm doing ok and not confusing you even more.
RRokkenAudio
01-17-2010, 04:19 PM
lol, i'll just keep doing it the way i was lol, I tried this way and got the error: error C3861: 'GetParam': identifier not found
Astralp
01-17-2010, 04:22 PM
In OnParamChange() Use:
IParam* val = GetParam(paramIdx); // get the current value
EDIT:
then:
hipass = val->Value();
Astralp
01-17-2010, 04:27 PM
Just edited the above just in case you didn't see, the Iparam val bit is generic and can be used at the top to get the value of any parameter, then either using switches or if statements you decide what param it is :)
RRokkenAudio
01-17-2010, 04:33 PM
i'll try to make some of this, i have no clue what any of that means.
"int paramIdx" ?? no clue
"IParam* val " ?? nope, still no clue
lol.
Using this: void onParamChange(int paramIdx)
{
IParam* val = GetParam(paramIdx); // get the current value
}
I get error : getparam identifier not found.
Astralp
01-17-2010, 04:46 PM
sorry that top bit was just to lazily show you where to put it, onParamChange should already be defined in your project you don't need to add it, you asked in the other thread what it was for.
So find the existing function:
void VSTproject::OnParamChange(int paramIdx)
{
// then add here:
IParam* val = GetParam(paramIdx); // get the current value
switch (paramIdx)
{
case fhipass:
{
hipass = val->Value();
} break;
}
Then you can simply add new cases for as many parameters as you need:
IParam* val = GetParam(paramIdx); // get the current value
switch (paramIdx)
{
case fhipass: // declared parameter name
{
hipass = val->Value();
} break;
case anotherparam:
{
// do something with this one
double newparam = val->Value();
} break;
}
hopefully I didn't typo anything, but that should get you going i hope!
RRokkenAudio
01-17-2010, 05:17 PM
I thought I would see some cpu usage drop by changing to this structure, didn't drop any lol, oh well, at least its more structured.
BTW: when using IParam* inputgain = GetParam(paramIdx); that is almost like a direct replacement for :inputgain = GetParam(finputgain)->DBToAmp(); ??
~Rob.
Astralp
01-17-2010, 05:31 PM
yes, you would use the created val structure to access it like this:
IParam* val = GetParam(paramIdx); // get the current value
switch (paramIdx)
{
case fhipass: // declared parameter name
{
hipass = val->Value();
} break;
case finputgain:
{
inputgain = val->DBToAmp(); // should work but untested!
} break;
}
RRokkenAudio
01-17-2010, 11:51 PM
Thanks! Got it all squared away! :)
We need a wiki on this...
~Rob.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.