我需要一些嵌套类的帮助。这源于我在这里问的一个问题
基本上我有一个类'myPlugin'。这个类是我程序的主体,包括“processReplace”功能。
在 processReplacing 中,我需要使用 DSP 过滤信号,目前我正在使用 11 个过滤器,这导致 11 个过滤器(和所有缓冲区)被硬编码到 processReplacing 中。
但是,现在我决定创建一个过滤器类,这样我就可以为每个过滤器创建一个新实例,根据需要调用并提高我的代码效率。
到目前为止,我几乎没有成功。但是现在我正在使用嵌套类,如果我可以开始工作,应该意味着所有其他人都应该效仿。
标题中的类定义是:
class myPlugin : public AudioEffectX
{
public: myPlugin (audioMasterCallback audioMaster); ~myPlugin();
// Processing
virtual void processReplacing (float** inputs, float** outputs, VstInt32 sampleFrames);
virtual void processDoubleReplacing (double** inputs, double** outputs, VstInt32 sampleFrames);
virtual void midiOutNoteOn (int iKey, int iVel);
virtual void midiOutNoteOff (int iKey, int iVel);
// Program
virtual void setProgramName (char* name);
virtual void getProgramName (char* name);
// Parameters
virtual void setParameter (VstInt32 index, float value);
virtual float getParameter (VstInt32 index);
virtual void getParameterLabel (VstInt32 index, char* label);
virtual void getParameterDisplay (VstInt32 index, char* text);
virtual void getParameterName (VstInt32 index, char* text);
virtual bool getEffectName (char* name);
virtual bool getVendorString (char* text);
virtual bool getProductString (char* text);
virtual VstInt32 getVendorVersion ();
virtual VstInt32 canDo (char* text);
class aFilterL
{
friend class myPlugin;
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 myPlugin;
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;
}
};
};#万一
然后我的问题是我无法正确初始化过滤器类。'myPlugin' 的构造函数看起来像这样(请记住,这是实际构造函数的一个非常简化的版本)
myPlugin::myPlugin (audioMasterCallback audioMaster)
: AudioEffectX (audioMaster, 1, 1) // 1 个程序,仅 1 个参数 {
setNumInputs (2); // stereo in
setNumOutputs (2); // stereo out
setUniqueID ('Gain'); // identify
canProcessReplacing (); // supports replacing output
canDoubleReplacing (); // supports double precision processing
myPlugin *my_aFilter1L = new aFilterL();
myPlugin *my_aFilter1R = new aFilterR();
}
myPlugin::~myPlugin ()
{ }
然后,当我尝试在 processReplacing 中使用 my_aFilter1L 等时,它会引发错误:“错误 C2065:'my_aFilter1L':未声明的标识符”和“错误 C2227:'->aFilterMethodL' 的左侧必须指向类/结构/联合/通用类型”
我已经尝试初始化存储在 myPlugin 构造函数中的过滤器类中的值。我曾尝试创建过滤器构造函数,即 myPlugin::aFilter1L()或aFilter1L::aFilter1L() 但这些导致了更多错误。
不太确定我能做什么。我以前使用过类/函数,但从来没有嵌套过这么多的类。我在网上看过很多帖子,但每个答案都不太适用;或者我已经尝试了我找到的解决方案,但它们没有奏效。