Filter envelope problem


#1

Hello! I’ve been stuck with the filter envelope for a while now and I would like to finish my synthesiser. Everything else works really well, but when I try to update my own filter coefficients (calculated with Bilinear transform) inside SynthVoice::renderNextBlock(). My Voice process looks like this now:

void SynthVoice::renderNextBlock(AudioBuffer<float> &outputBuffer, int startSample, int numSamples)
{
	float val;
	for (int sample = 0; sample < numSamples; sample++)
	{
		val = setEnvelope()*level;
		for (int channel = 0; channel < outputBuffer.getNumChannels(); channel++)
		{
			outputBuffer.addSample(channel, startSample, val);
		}
		startSample++;
		cutmod=myVoiceEnv1.adsr2(trig);
	}
	updateCoeffs();
	processADSR_TEST(outputBuffer);
}

processADSR_TEST(outputBuffer) processes the filter and updatecoeffs() tries to update the cutoff frequency of the filter as follows:

void SynthVoice::updateCoeffs()
{
	// Updates biquad coefficient:"cutoff" with the "cutmod" factor
	//res = *Q / sqrt(2);
	float newCut = cut*(1 + cutmod);
	//float newCut = (1+testThingy)*cut;
	if (newCut >= 20000.0f) newCut = 20000.0f;
	float K = tan(M_PI*newCut / lastSampleRate);
	float Kdenom = (K / res) + K*K + 1.0;
	// Coeffs:
	b[0] = (K*K / Kdenom) / (res*1.4142);
	b[1] = 2 * b[0];
	b[2] = b[0];
	//a0 = 1.0f;
	a[1] = 2.0 * (K*K - 1.0) / Kdenom;
	a[2] = (1.0 - K / res + K*K) / Kdenom;
}

The filter is first given the parameters “cut” and “res” (or Q) from PluginProcessor.cpp and when I update or sweep the cutoff parameter by hand, the filter sounds really good and I would like it to sound like that but with the envelope. The envelope I use uses my own code but it should work fine because the volume envelope also uses the same code. I’ve tried to debug “cutmod” and “newCut” etc with Visual Studio and the values change but the only thing that happens is that the sound might become trapped inside a voice even if replaced, but cutoff frequency sweep is not heard.

I’ve also tried to update the coefficients of the filter when calculating every sample, and it doesn’t work either.
Any help is welcome.
Cheers.