Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring values in buffer, within class function method
    primarykey
    data
    text
    <p>I am programming a VST DSP plugin in c++.</p> <p>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.</p> <p>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'.</p> <p>Any advice greatly appreciated!</p> <p>n.b. This post has been update with new code:</p> <p><strong>Here's the classes:</strong></p> <pre><code>class aFilterL </code></pre> <p>{</p> <p>friend class Beat_to_Midi;</p> <p>public: aFilterL(); ~aFilterL();</p> <pre><code>float fOut1_l; float filterOut1_l; float Out_1_l; float Out_2_l; float* buffer_Out_1_l; float* buffer_Out_2_l; </code></pre> <p>virtual float aFilterMethodL (float a0, float a1, float a2, float b1, float b2, float inputL, float prevInput1L, float prevInput2L) {</p> <pre><code>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; </code></pre> <p>}</p> <p>};</p> <p>class aFilterR {</p> <p>friend class Beat_to_Midi;</p> <p>public: aFilterR(); ~aFilterR();</p> <pre><code>float fOut1_r; float filterOut1_r; float Out_1_r; float Out_2_r; float* buffer_Out_1_r; float* buffer_Out_2_r; </code></pre> <p>virtual float aFilterMethodR (float a0, float a1, float a2, float b1, float b2, float inputR, float prevInput1R, float prevInput2R) { </p> <pre><code>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; </code></pre> <p>} };</p> <p><strong>This is then constructed/destructed in the cpp as follows:</strong></p> <pre><code>aFilterL::aFilterL() </code></pre> <p>{ fOut1_l = 0.f; filterOut1_l = 0.f;</p> <pre><code>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; </code></pre> <p>}</p> <p>aFilterL::~aFilterL() { </p> <pre><code>if (buffer_Out_1_l) delete[] buffer_Out_1_l; if (buffer_Out_2_l) delete[] buffer_Out_2_l; </code></pre> <p>}</p> <p>aFilterR::aFilterR() { fOut1_r = 0.f;</p> <pre><code>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; </code></pre> <p>}</p> <p>aFilterR::~aFilterR() { </p> <pre><code>if (buffer_Out_1_r) delete[] buffer_Out_1_r; if (buffer_Out_2_r) delete [] buffer_Out_2_r; </code></pre> <p>}</p> <p><strong>Finally it is implemented in the processReplacing function as:</strong></p> <p>void myPlugin::processReplacing (float** inputs, float** outputs, VstInt32 sampleFrames) { </p> <pre><code>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; </code></pre> <p>while (--sampleFrames >= 0) { </p> <p>// Filter Input </p> <p>In_1_l = buffer_In_1_l[0]; </p> <p>In_1_r = buffer_In_1_r[0]; </p> <p>In_2_l = buffer_In_2_l[0]; </p> <p>In_2_r = buffer_In_2_r[0]; </p> <p>// Filter in management </p> <p>buffer_In_2_l[0] = buffer_In_1_l[0];</p> <p>buffer_In_2_r[0] = buffer_In_1_r[0]; </p> <p>buffer_In_1_l[0] = *in1; </p> <p>buffer_In_1_r[0] = *in2; </p> <p>// send to function for processing</p> <p>returnedL = my_aFilter1L->aFilterMethodL(0.000171f, 0.0f, -0.000171f, -1.999911f, 0.999943f, *in1, In_1_l, In_2_l);</p> <p>returnedR = my_aFilter1R->aFilterMethodR(0.000171f, 0.0f, -0.000171f, -1.999911f, 0.999943f, *in2, In_1_r, In_2_r);</p> <p>// Send filter output to out </p> <p>*out1 = returnedL; </p> <p>*out2 = returnedR; </p> <p>*in1++; </p> <p>*in2++; </p> <p>*out1++; </p> <p>*out2++; }}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload