This code works in every DAWs except FL Studio

Hi, I am struggling with a little distortion plugin.

I have this function called at render :

bool FXTriodeClassA::render(ProcessData& buffers)
{
	auto numSamples = buffers.getSamplesInBlock();
	auto chanL = buffers.getOutputBuffer(0);
	auto chanR = buffers.getOutputBuffer(1);

	// create an updated TriodeClassAParameters
	TriodeClassAParameters newTriodeParams;
	newTriodeParams.waveshaper = (distortionModel)mParams[eTriodeA_Waveshaper].getLastValue();
	newTriodeParams.saturation = mParams[eTriodeA_Saturation].getValue();
	newTriodeParams.asymmetry = mParams[eTriodeA_Asymmetry].getValue();
	newTriodeParams.outputGain = mParams[eTriodeA_OutputGain].getValue();
	newTriodeParams.invertOutput = mParams[eTriodeA_InvertOutput].getLastValue();;
	newTriodeParams.enableHPF = true;
	newTriodeParams.enableLSF = true;
	newTriodeParams.hpf_Fc = mParams[eTriodeA_HpfFC].getValue();
	newTriodeParams.lsf_Fshelf = mParams[eTriodeA_LsfFShelf].getValue();
	newTriodeParams.lsf_BoostCut_dB = mParams[eTriodeA_LsfBoostCutDb].getValue();

	// call setParams
	mTriodeClassA[0].setParameters(newTriodeParams);
	mTriodeClassA[1].setParameters(newTriodeParams);
	for (uint32_t i = 0; i < numSamples; i++) {

		auto drywet = mParams[eTriodeA_DryWet].getValue();
		auto sampleL = chanL[i];
		auto sampleR = chanR[i];
		auto processedSampleL = sampleL * (float)newTriodeParams.outputGain;
		auto processedSampleR = sampleR * (float)newTriodeParams.outputGain;
		chanL[i] = doLinearInterpolation(sampleL, processedSampleL, drywet);
		chanR[i] = doLinearInterpolation(sampleR, processedSampleR, drywet);
	}
    return true;
}

The only computing I’m doing is here :

		auto processedSampleL = sampleL * (float)newTriodeParams.outputGain;
		auto processedSampleR = sampleR * (float)newTriodeParams.outputGain;

If I run this code in FL it makes the sound awful but it works perfectly fine on Reaper, Ableton and Bitwig.

If I simply remove the multiplication, no processing is happening and it’s a dry FX, but it sounds as expected in FL Studio.

Anybody knows if FL Studio has a different behavior than the others ?

Thx !

ah… I just found out that FL is sending me buffers with randoms sizes, that explains everything :cry:

Note that other hosts may vary the processing buffer size too, for example at transport loop boundaries or in other spurious situations. Your code should never assume the buffer size stays the same at each processBlock call, but you do get the maximum buffer size that is going to be used in the prepareToPlay call.

1 Like

This should probably be an FAQ somewhere. :wink:

3 Likes