将值存储在缓冲区中,在类函数方法中

时间:2022-08-08 16:59:26

I am programming a VST DSP plugin in c++.

我正在用c++编写VST DSP插件。

I am creating a series of band pass filters in a 'filterbank'. I have implemented a filter class in my header (including function) and built constructor/destructor correctly in .cpp.

我正在“过滤库”中创建一系列带通过滤器。我在头(包括函数)中实现了一个filter类,并在.cpp中正确地构建了构造函数/析构函数。

I can pass values to the method and return them also. However, the issues lays in the area of storing data in buffers in the function. It seems that every time the function method is called that the values stored in the buffer are reset (or alternatively, are not stored correctly in the first place). Therefore, what is passed back is not 'complete'.

我可以将值传递给该方法并返回它们。但是,问题在于将数据存储在函数的缓冲区中。似乎每次调用函数方法时,存储在缓冲区中的值都被重置(或者,一开始没有正确地存储)。因此,传回来的信息并不“完整”。

Any advice greatly appreciated!

任何的建议深表感谢!

n.b. This post has been update with new code:

注意:这篇文章已经更新了新代码:

Here's the classes:

这是类:

class aFilterL

{

{

friend class Beat_to_Midi;

朋友类Beat_to_Midi;

public: aFilterL(); ~aFilterL();

公众:aFilterL();~ aFilterL();

float fOut1_l;
float filterOut1_l;
float Out_1_l;
float Out_2_l;
float* buffer_Out_1_l;
float* buffer_Out_2_l;

virtual float aFilterMethodL (float a0, float a1, float a2, float b1, float b2, float inputL, float prevInput1L, float prevInput2L) {

虚浮动aFilterMethodL (float a0, float a1, float a2, float b1, float b2, float inputL, float prevInput1L, float prevInput2L)

Out_1_l = buffer_Out_1_l[0];
Out_2_l = buffer_Out_2_l[0];

filterOut1_l = (a0 * inputL) + (a1 * prevInput1L) + (a2 * prevInput2L) - (b1 * Out_1_l) - (b2 * Out_2_l) + 1.0E-25;

fOut1_l = filterOut1_l;
buffer_Out_2_l[0] = buffer_Out_1_l[0];
buffer_Out_1_l[0] = fOut1_l;  
return fOut1_l;

}

}

};

};

class aFilterR {

类aFilterR {

friend class Beat_to_Midi;

朋友类Beat_to_Midi;

public: aFilterR(); ~aFilterR();

公众:aFilterR();~ aFilterR();

float fOut1_r;
float filterOut1_r;
float Out_1_r;
float Out_2_r;
float* buffer_Out_1_r;
float* buffer_Out_2_r;

virtual float aFilterMethodR (float a0, float a1, float a2, float b1, float b2, float inputR, float prevInput1R, float prevInput2R) {

虚浮动aFilterMethodR (float a0, float a1, float a2, float b1, float b2, float inputR, float prevInput1R, float prevInput2R)

Out_1_r = buffer_Out_1_r[0];
Out_2_r = buffer_Out_2_r[0];

filterOut1_r = (a0 * inputR) + (a1 * prevInput1R) + (a2 * prevInput2R) - (b1 * Out_1_r) - (b2 * Out_2_r) + 1.0E-25;

fOut1_r = filterOut1_r;
buffer_Out_2_r[0] = buffer_Out_1_r[0];
buffer_Out_1_r[0] = fOut1_r;
return fOut1_r;

} };

} };

This is then constructed/destructed in the cpp as follows:

然后在cpp中构建/销毁如下:

aFilterL::aFilterL()

{ fOut1_l = 0.f; filterOut1_l = 0.f;

{ fOut1_l f = 0.;filterOut1_l f = 0.;

Out_1_l = 0.f;
Out_2_l = 0.f;

buffer_Out_1_l = new float [1];
buffer_Out_2_l = new float [1];

buffer_Out_1_l[0] = 0.f;
buffer_Out_2_l[0] = 0.f;

}

}

aFilterL::~aFilterL() {

aFilterL::~ aFilterL(){

if (buffer_Out_1_l)
    delete[] buffer_Out_1_l;
if (buffer_Out_2_l)
    delete[] buffer_Out_2_l;

}

}

aFilterR::aFilterR() { fOut1_r = 0.f;

aFilterR::aFilterR() {fOut1_r = 0.f;

filterOut1_r = 0.f;

Out_1_r = 0.f;
Out_2_r = 0.f;

buffer_Out_1_r = new float [1];
buffer_Out_2_r = new float [1];

buffer_Out_1_r[0] = 0.f;
buffer_Out_2_r[0] = 0.f;

}

}

aFilterR::~aFilterR() {

aFilterR::~ aFilterR(){

if (buffer_Out_1_r)
    delete[] buffer_Out_1_r;
if (buffer_Out_2_r)
    delete [] buffer_Out_2_r;

}

}

Finally it is implemented in the processReplacing function as:

最后在processreplace函数中实现:

void myPlugin::processReplacing (float** inputs, float** outputs, VstInt32 sampleFrames) {

void myPlugin: processreplace (float** input, float* output, VstInt32 sampleframe)

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

    aFilterL *my_aFilter1L = new aFilterL;
aFilterR *my_aFilter1R = new aFilterR;

while (--sampleFrames >= 0) {

而(——sampleFrames >= 0)

// Filter Input

/ /过滤输入

In_1_l = buffer_In_1_l[0];

In_1_l = buffer_In_1_l[0];

In_1_r = buffer_In_1_r[0];

In_1_r = buffer_In_1_r[0];

In_2_l = buffer_In_2_l[0];

In_2_l = buffer_In_2_l[0];

In_2_r = buffer_In_2_r[0];

In_2_r = buffer_In_2_r[0];

// Filter in management

/ /过滤管理

buffer_In_2_l[0] = buffer_In_1_l[0];

buffer_In_2_l[0]= buffer_In_1_l[0];

buffer_In_2_r[0] = buffer_In_1_r[0];

buffer_In_2_r[0]= buffer_In_1_r[0];

buffer_In_1_l[0] = *in1;

buffer_In_1_l[0]= *三机一体;

buffer_In_1_r[0] = *in2;

buffer_In_1_r[0]= * in2;

// send to function for processing

//发送至处理功能。

returnedL = my_aFilter1L->aFilterMethodL(0.000171f, 0.0f, -0.000171f, -1.999911f, 0.999943f, *in1, In_1_l, In_2_l);

returnedL = my_aFilter1L->aFilterMethodL(0.000171f, 0.0f, -0.000171f, -1.999911f, 0.999943f, *in1, In_1_l, In_2_l);

returnedR = my_aFilter1R->aFilterMethodR(0.000171f, 0.0f, -0.000171f, -1.999911f, 0.999943f, *in2, In_1_r, In_2_r);

returnedR = my_aFilter1R->aFilterMethodR(0.000171f, 0.0f, -0.000171f, -1.999911f, 0.999943f, *in2, In_1_r, In_2_r);

// Send filter output to out

//将过滤器输出发送出去

*out1 = returnedL;

*着干活= returnedL;

*out2 = returnedR;

* out2 = returnedR;

*in1++;

* in1 + +;

*in2++;

* in2 + +;

*out1++;

*着干活+ +;

*out2++; }}

* out2 + +;} }

2 个解决方案

#1


3  

Are you aware of the fact that return exits the function immediately? So the code after that which stores values to your buffers, is never executed.

您是否意识到return立即退出函数?因此,在将值存储到缓冲区之后的代码永远不会被执行。

Instead, you should place the return call at the end of the function.

相反,应该将返回调用放在函数的末尾。

Some other notes:

一些其他的笔记:

  • It is unclear to me why you need pointers to buffers if you only ever use the first element.
  • 我不清楚如果只使用第一个元素,为什么需要指针指向缓冲区。
  • You have duplicate code in the -L and -R functions. Instead, use two instances of a 'mono' class, so you only store data for a single channel per class.
  • 在-L和-R函数中有重复的代码。相反,使用“mono”类的两个实例,因此每个类只能存储单个通道的数据。
  • You (almost) never need to use this->. Just leave it out.
  • 您(几乎)不需要使用这个->。就让它出来。

#2


1  

After creating my new question on nested classes found here the solution has been found.

在这里创建了我的新问题之后,在这里找到了解决方案。

The filter classes are declared within the myPlugin class.

过滤器类在myPlugin类中声明。

From here constructors and destructors are built as:

从这里构造函数和析构函数被构建为:

myPlugin::aFilterL::aFilterL()
myPlugin::aFilterL::~aFilterL()

in the myPlugin constructor the new instances are created:

在myPlugin构造函数中,创建了新的实例:

aFilterL *my_aFilter1L = new aFilterL();

and the final piece in the puzzle is then to make sure they are added as an instance to the myPlugin effect:

最后一个问题是确保它们作为myPlugin效果的一个实例:

aFilterL my_aFilter1L;
aFilterR my_aFilter1R;

my_aFilter1L etc can now be accessed via processReplacing and seems to be functioning correctly.

my_aFilter1L等现在可以通过processreplace访问,并且看起来运行正常。

Many thanks to everyone for all your help in this matter.

非常感谢大家在这件事上的帮助。

#1


3  

Are you aware of the fact that return exits the function immediately? So the code after that which stores values to your buffers, is never executed.

您是否意识到return立即退出函数?因此,在将值存储到缓冲区之后的代码永远不会被执行。

Instead, you should place the return call at the end of the function.

相反,应该将返回调用放在函数的末尾。

Some other notes:

一些其他的笔记:

  • It is unclear to me why you need pointers to buffers if you only ever use the first element.
  • 我不清楚如果只使用第一个元素,为什么需要指针指向缓冲区。
  • You have duplicate code in the -L and -R functions. Instead, use two instances of a 'mono' class, so you only store data for a single channel per class.
  • 在-L和-R函数中有重复的代码。相反,使用“mono”类的两个实例,因此每个类只能存储单个通道的数据。
  • You (almost) never need to use this->. Just leave it out.
  • 您(几乎)不需要使用这个->。就让它出来。

#2


1  

After creating my new question on nested classes found here the solution has been found.

在这里创建了我的新问题之后,在这里找到了解决方案。

The filter classes are declared within the myPlugin class.

过滤器类在myPlugin类中声明。

From here constructors and destructors are built as:

从这里构造函数和析构函数被构建为:

myPlugin::aFilterL::aFilterL()
myPlugin::aFilterL::~aFilterL()

in the myPlugin constructor the new instances are created:

在myPlugin构造函数中,创建了新的实例:

aFilterL *my_aFilter1L = new aFilterL();

and the final piece in the puzzle is then to make sure they are added as an instance to the myPlugin effect:

最后一个问题是确保它们作为myPlugin效果的一个实例:

aFilterL my_aFilter1L;
aFilterR my_aFilter1R;

my_aFilter1L etc can now be accessed via processReplacing and seems to be functioning correctly.

my_aFilter1L等现在可以通过processreplace访问,并且看起来运行正常。

Many thanks to everyone for all your help in this matter.

非常感谢大家在这件事上的帮助。