Hello,
I tried to create inside a SynthNote type additive synth a classical low pass filter.
I created 2 arrays for the output values like this : left = (float*)inBufferList.mBuffers[0].mData; right = numChans == 2 ? (float*)inBufferList.mBuffers[1].mData : 0; leftB = (float*)inBufferList.mBuffers[0].mData; //the second array rightB = numChans == 2 ? (float*)inBufferList.mBuffers[1].mData : 0;
I calculate alpha, beta and gamma belong a code source that I have : float theta = Theta(cutOf, sampleRate); //values of cutOf from 0 to 20 000 Hz. float theSin = Qval / (2.0 * sin(theta)); //value for Q from 0 to 1 float beta = 0.5 * ((1.0 - theSin) / (1.0 + theSin)); float gamma = (0.5 + beta) * cos(theta); float alpha = (0.5 + beta - gamma)/4.0;
//leftB[frame]+= the additive synth result
Then, inside the "case kNoteState_ReleasedButSustained" : if (leftB[frame - 1] && leftB[frame-2]){ UInt32 j = frame-2; UInt32 z = 0; if (j < z) j+=3;
UInt32 k = frame-1; if (k < z) k+=3;
left[frame] += 2*(alpha*(leftB[frame] + 2*leftB[k] + leftB[j]) + gamma*leftB[k] - beta*leftB[j]); if (right) right[frame] += 2*(alpha*(rightB[frame] + 2*rightB[k] + rightB[j]) + gamma*rightB[k] - beta*rightB[j]); }
The result is just noisy : when the cutOf is in the middle, no effect, but when I want to filter the additive synth, it sounds like a BitCrunch effect. When Qval is too high, it crashes... Would you have an idea?
Thanks!
|