如何访问缓冲区中的上一个术语?

时间:2016-01-18 06:05:44

标签: c++ buffer term

致力于转型:

yl(n) = F1yb(n) + yl(n − 1)

yb(n) = F1yh(n) + yb(n − 1)

yh(n) = x(n) − yl(n − 1) − Q1yb(n − 1)

在C ++中我试图访问缓冲区中的前一个术语以便使用它,但是这个等式本身似乎相当成问题。有任何想法吗?如果有人愿意通读它当然,我也可以提交代码。 亲切的问候!

代码本身:

{
fSamplingFreq = getSampleRate(); /*Get system sample rate*/
N = (int)fSamplingFreq; /*Size of buffer - 1 second of audio*/
inputBuffer = new float[N]; /*Create a new buffer for input of size N*/
cutOffBuffer = new float[N]; /*Create a new buffer for values of cut off frequency of size N*/
yhBuffer = new float[N];
ybBuffer = new float[N];
ylBuffer = new float[N];
ridx = widx = 0; /*Read and write indices*/
fCutOff = 30; /*Initialises parameters*/
fGain = 0.5;

setCutOff(fCutOff); /*Set cut off frequency to initial value*/

setNumInputs(1); /*Mono in*/
setNumOutputs(1); /*Mono out*/

//setNumInputs(2); /*Stereo in*/
//setNumOutputs(2); /*Stereo out*/

resume(); /*Flush buffer*/
}

Wobble :: ~Wobble()
{
/*delete buffer memory*/
delete inputBuffer;
delete cutOffBuffer;
delete yhBuffer;
delete ybBuffer;
delete ylBuffer;
}

/*Called every time the plug-in is switched on (in this case to reset the memory to zero)*/
void Wobble::resume()
{
/*Flush the buffers*/
memset(inputBuffer, 0, N * sizeof(float));
memset(cutOffBuffer, 0, N * sizeof(float));
memset(yhBuffer, 0, N * sizeof(float));
memset(ybBuffer, 0, N * sizeof(float));
memset(ylBuffer, 0, N * sizeof(float));
AudioEffectX::resume();
}

/*This sets the cut off frequency of low-pass*/
void Wobble::setCutOff(int widx)
{
int fw = 500;
float centre = fw / fSamplingFreq;

do
{
    if (fLFOFreqMin = 30, fCutOff <= fLFOFreqMax, fLFOFreqMin + centre)
    {
        fCutOff = fLFOFreqMin + centre;
        cutOffBuffer[widx] = fCutOff;
    }
    if (fLFOFreqMax = 180, fCutOff >= fLFOFreqMin, fLFOFreqMax - centre)
    {
        fCutOff = fLFOFreqMax - centre;
        cutOffBuffer[widx] = fCutOff;
    }
} while (cutOffBuffer[N] < inputBuffer[N]);
}

/*Main processing loop, DSP code goes here*/
void Wobble::processReplacing(float** inputs, float** outputs, VstInt32 sampleFrames)
{
/*Pointers to input and output sampleframe*/
float *in = inputs[0];
float *out = outputs[0];

/*Variables used within processing loop*/
float x, y, xM, cutM, yh, yhM, yb, ybM, yl, ylM, F1, Q1, d, fc, fs, pi;

/*Processing Loop*/
while (--sampleFrames >= 0)
{
    d = 0.01;
    Q1 = 2 * d;
    pi = 3.14;

    setCutOff(widx);

    x = *in; /*Get current sample*/
    inputBuffer[widx] = x; /*write current sample into buffer at position*/

    xM = inputBuffer[ridx] * fGain; /*Get sample from buffer at position ridx*/
    cutM = cutOffBuffer[ridx];

    if (ridx == 0)
    {
        F1 = 2 * sin((pi * cutM) / fs);

        yh = x;
        yhBuffer[widx] = yh;
        yhM = yhBuffer[ridx];

        yb = F1 * yh;
        ybBuffer[widx] = yb;
        ybM = ybBuffer[ridx];

        yl = F1 * yb;
        ylBuffer[widx] = yl;
        ylM = ylBuffer[ridx];
    }
    if (ridx != 0)
    {
        yhM = x - yl(n - 1) - Q1 * yb(n - 1);
        ybM = F1 * yhM + yb(n - 1);
        ylM = F1 * ybM + yl(n - 1);

        F1 = 2 * sin((pi * cutM) / fs);
    }

    *out = ylM + xM; /*Output the sample*/

    in++; /*Increase input sample by one*/
    out++; /*Increase output sample by one*/
    ridx++; /*Increase read pointer by one*/
    widx++; /*Increase write pointer by one*/

    if (widx >= N)
        widx -= N; /*Wrap write index*/
    if (ridx >= N)
        ridx -= N; /*Wrap read index*/
}
}

0 个答案:

没有答案