在类函数方法内将值存储在缓冲区中
我正在用 C++ 编写 VST DSP 插件。
我正在“滤波器组”中创建一系列带通滤波器。我已经在标头(包括函数)中实现了一个过滤器类,并在 .cpp 中正确构建了构造函数/析构函数。
我可以将值传递给该方法并返回它们。然而,问题在于函数缓冲区中存储数据的区域。似乎每次调用函数方法时,存储在缓冲区中的值都会被重置(或者,一开始就没有正确存储)。因此,传回的内容并不“完整”。
任何建议都非常感谢!
注:这篇文章已更新为新代码:
这是课程:
class aFilterL
{
friend class Beat_to_Midi;
民众: 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;
虚拟浮点aFilterMethodL(浮点a0,浮点a1,浮点a2,浮点b1,浮点b2,浮点inputL,浮点prevInput1L,浮点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;
}
};
aFilterR类 {
朋友类 Beat_to_Midi;
民众: 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;
虚拟浮点aFilterMethodR(浮点a0,浮点a1,浮点a2,浮点b1,浮点b2,浮点inputR,浮点prevInput1R,浮点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;
} };
然后在 cpp 中构造/销毁它,如下所示:
aFilterL::aFilterL()
{ fOut1_l = 0.f; 过滤输出1_l = 0.f;
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() {
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;
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() {
if (buffer_Out_1_r)
delete[] buffer_Out_1_r;
if (buffer_Out_2_r)
delete [] buffer_Out_2_r;
}
最后在 processReplacing 函数中实现为:
void myPlugin::processReplacing (float**inputs, float**outputs, VstInt32sampleFrames) {
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) {
// 过滤器输入
In_1_l = buffer_In_1_l[0];
In_1_r = buffer_In_1_r[0];
In_2_l = buffer_In_2_l[0];
In_2_r = buffer_In_2_r[0];
// 管理中的过滤器
buffer_In_2_l[0] = buffer_In_1_l[0];
buffer_In_2_r[0] = buffer_In_1_r[0];
buffer_In_1_l[0] = *in1;
buffer_In_1_r[0] = *in2;
// 发送到函数进行处理
returnedL = my_aFilter1L->aFilterMethodL(0.000171f, 0.0f, -0.000171f, -1.999911f, 0.999943f, *in1, In_1_l, In_2_l);
返回R = my_aFilter1R->aFilterMethodR(0.000171f, 0.0f, -0.000171f, -1.999911f, 0.999943f, *in2, In_1_r, In_2_r);
// 将过滤器输出发送到 out
*out1 = returnedL;
*out2=返回R;
*in1++;
*in2++;
*输出1++;
*输出2++; }}
I am programming a VST DSP plugin in c++.
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.
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;
public:
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)
{
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
{
friend class Beat_to_Midi;
public:
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)
{
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:
aFilterL::aFilterL()
{
fOut1_l = 0.f;
filterOut1_l = 0.f;
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()
{
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;
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()
{
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:
void myPlugin::processReplacing (float** inputs, float** outputs, VstInt32 sampleFrames)
{
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)
{
// Filter Input
In_1_l = buffer_In_1_l[0];
In_1_r = buffer_In_1_r[0];
In_2_l = buffer_In_2_l[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_r[0] = buffer_In_1_r[0];
buffer_In_1_l[0] = *in1;
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);
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;
*out2 = returnedR;
*in1++;
*in2++;
*out1++;
*out2++;
}}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否知道
return
会立即退出该函数?因此,之后将值存储到缓冲区的代码永远不会执行。相反,您应该将返回调用放在函数的末尾。
其他一些注意事项:
this->
。把它留下吧。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.Instead, you should place the return call at the end of the function.
Some other notes:
this->
. Just leave it out.在此处找到关于嵌套类的新问题后,解决方案是成立。
过滤器类在 myPlugin 类中声明。
从这里构建构造函数和析构函数如下:
在 myPlugin 构造函数中创建新实例:
然后难题的最后一部分是确保它们作为实例添加到 myPlugin 效果中:
现在可以通过 processReplacing 访问 my_aFilter1L 等并且似乎运行正常。
非常感谢大家在此事上提供的所有帮助。
After creating my new question on nested classes found here the solution has been found.
The filter classes are declared within the myPlugin class.
From here constructors and destructors are built as:
in the myPlugin constructor the new instances are created:
and the final piece in the puzzle is then to make sure they are added as an instance to the myPlugin effect:
my_aFilter1L etc can now be accessed via processReplacing and seems to be functioning correctly.
Many thanks to everyone for all your help in this matter.