COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :

Go Back   Cockos Incorporated Forums > Other Software Discussion > WDL users forum

Reply
 
Thread Tools Display Modes
Old 06-07-2015, 01:09 PM   #1
Youlean
Human being with feelings
 
Youlean's Avatar
 
Join Date: May 2015
Location: Serbia
Posts: 654
Default Problem with using multiple instances of the plugin

Hi, I have edited IPlugEffect project so that left channel has simple low pass filter. The problem is that everything works normal util I duplicate the plugin in FL Studio, then in left channel I get some weird noise, and if I disable one of the plugin everything works OK. Does somebody have some clue?

Here is the code:

Code:
void IPlugEffect::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
{
  // Mutex is already locked for us.

  double* in1 = inputs[0];
  double* in2 = inputs[1];
  double* out1 = outputs[0];
  double* out2 = outputs[1];

  for (int s = 0; s < nFrames; ++s, ++in1, ++in2, ++out1, ++out2)
  {
	  static double pout = 0.0; //Declaration for previous output value
	  *out1 = 0.99 * (pout - *in1) + *in1; //Set the simple filter

	  //*out1 = *in1 * mGain;
            *out2 = *in2 * mGain;

	   pout = *out1; //Sets previous value
  }
}
Youlean is offline   Reply With Quote
Old 06-07-2015, 01:31 PM   #2
olilarkin
Human being with feelings
 
Join Date: Apr 2009
Location: Berlin, Germany
Posts: 1,248
Default

don't use a static loal variable for the previous output value, make a (non static) member variable in your class and use that to store the state. I think the static value will be shared across your plugin instances causing conflict.
__________________
VirtualCZ | Endless Series | iPlug2 | Linkedin | Facebook

Last edited by olilarkin; 06-07-2015 at 04:00 PM.
olilarkin is offline   Reply With Quote
Old 06-07-2015, 02:13 PM   #3
stw
Human being with feelings
 
stw's Avatar
 
Join Date: Apr 2012
Posts: 279
Default

static variables are definitely shared across all plugin instances.
Only use i can think of is to store DAW conditions like samplerate etc, or if you want to share some data on purpose between them.
However i wonder why your code works at all because pout is declared inside your processing loop and therefore its value should always be 0?
stw is offline   Reply With Quote
Old 06-07-2015, 02:29 PM   #4
jack461
Human being with feelings
 
jack461's Avatar
 
Join Date: Nov 2013
Location: France
Posts: 181
Default

I think static variables are initialized only once, at load time. So the code should be working, except pout is shared with any other plugin...
jack461 is offline   Reply With Quote
Old 06-07-2015, 11:28 PM   #5
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,646
Default

Quote:
Originally Posted by stw View Post
Only use i can think of is to store DAW conditions like samplerate etc, or if you want to share some data on purpose between them.
Slightly off-topic, but I wouldn't make the sample rate static, because I wouldn't be surprised if there are hosts out there that will load multilple instances of your plug-in at different sample rates.
Tale is offline   Reply With Quote
Old 06-08-2015, 01:56 AM   #6
Youlean
Human being with feelings
 
Youlean's Avatar
 
Join Date: May 2015
Location: Serbia
Posts: 654
Default

Thanks for all suggestions! I will check this out.
Youlean is offline   Reply With Quote
Old 06-08-2015, 04:37 AM   #7
stw
Human being with feelings
 
stw's Avatar
 
Join Date: Apr 2012
Posts: 279
Default

Quote:
Originally Posted by Tale View Post
Slightly off-topic, but I wouldn't make the sample rate static, because I wouldn't be surprised if there are hosts out there that will load multilple instances of your plug-in at different sample rates.
come to think of it, you're right - always expect the unexpected. Thanks for the hint...
stw is offline   Reply With Quote
Old 06-08-2015, 04:47 AM   #8
Mink99
Human being with feelings
 
Mink99's Avatar
 
Join Date: Jan 2011
Location: Zürich
Posts: 1,008
Default

A plugin is loaded only once into the memory, even when several instances are "initialised"

The code and the static data therefore exists for all instances.


This means that the assignment pout = *out is executed whenever any instance of the plugin is running through that code, thus overwriting the value of pout for all other instances.

The previous assignment *out1 = 0.99 .... Will then not use the pout of the last execution of the own instance, but the the value of the last run of any instance. And this value therefore will not be correct.
Mink99 is offline   Reply With Quote
Old 06-11-2015, 10:29 PM   #9
Tired_Joe
Human being with feelings
 
Join Date: Apr 2015
Posts: 55
Default

I´ve the same problem, but without using "static" variables.
I wanted to program a simple EQ to improve my C++, DSP and WDL skills. I build a class and a new file for a parametric EQ.
I think the class is the problem, but I´ve no clue how to fix it. Everything works very good as long as I don´t open a second instance.

I change the parameters of the EQ-object in the "void project::OnParamChange(int paramIdx)" function and it works very good.

Has someone a solution for my problem?

clEQ.h
Code:
class clParametric
{
private:
	int n; 
	double pi;
	double A;
	
	double x[3];
	double y[3];
	
	double w0; 
	double alpha;  
	
	double	b0; 
	double	b1; 
	double  b2; 
	double  a0; 
	double  a1; 
	double  a2; 
	
public:
	double dBGain;	// Cut or Boost in dB
	double Fs;		// SampleRate
	double Q;     	// Q
	double f0;		// Frequency
	
	void Initialize();
	double Process(double SampleIn);     
};
clEQ.cpp
Code:
// Calculate the EQ parameter
void clParametric::Initialize()
{
	pi = (2*acos(0.0));
	n = 2;  // xxx weis nicht ob das geil ist
	A = pow (10., dBGain/40.);
	
	w0 = 2.*pi*f0/Fs;
	alpha = sin(w0)/(2*Q);                                      
	
  	b0 =   1 + alpha * A;
  	b1 =  -2 * cos(w0);
    b2 =   1 - alpha * A;
    a0 =   1 + alpha / A;
    a1 =  -2 * cos(w0);
    a2 =   1 - alpha /A;
}

double clParametric::Process(double SamplesIn)
{			
	n = 2;
	x[n-2] = x[n-1];		x[n-1] = x[n];
	x[n]= SamplesIn; 
	y[n-2] = y[n-1];	y[n-1] = y[n];
	y[n] = (b0/a0)*x[n] + (b1/a0)*x[n-1] + (b2/a0)*x[n-2]- (a1/a0)*y[n-1] - (a2/a0)*y[n-2];
	
	return y[n];	
}
project.cpp
Code:
// Build a new object
clParametric EQ_parametric;

// processing
  for (int s=0; s<nFrames; s++)
  {
    out1[s] = EQ_parametric.Process(in1[s]);
  }

Last edited by Tired_Joe; 06-11-2015 at 11:00 PM.
Tired_Joe is offline   Reply With Quote
Old 06-11-2015, 11:11 PM   #10
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,646
Default

I think the problem might be that clParametric EQ_parametric is a local (or maybe global) variable, while it should be a member variable of your plug-in class.
Tale is offline   Reply With Quote
Old 06-12-2015, 02:34 AM   #11
Tired_Joe
Human being with feelings
 
Join Date: Apr 2015
Posts: 55
Default

Thanks Tale,

that was the problem
Tired_Joe is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 08:33 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.