Why am I getting such wierd audio output?

I’m working on a plugin which adds noise to an audio signal in input. Here is the code I use:

void PluginTest1AudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiMessages)
    ScopedNoDenormals noDenormals;
    auto totalNumInputChannels  = getTotalNumInputChannels();
    auto totalNumOutputChannels = getTotalNumOutputChannels();
	//Temporary buffer for DSP processing.
	juce::AudioBuffer<float> tmpBuffer = *new juce::AudioBuffer<float>(buffer.getNumChannels() ,buffer.getNumSamples());
	//resault of randomization
	double randRes = rand.nextDouble();
	// counter to check if recalculation is nessacary.
	double factorCount = 0;

    // In case we have more outputs than inputs, this code clears any output
    // channels that didn't contain input data, (because these aren't
    // guaranteed to be empty - they may contain garbage).
    // This is here to avoid people getting screaming feedback
    // when they first compile a plugin, but obviously you don't need to keep
    // this code if your algorithm always overwrites all the output channels.
    for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
        buffer.clear (i, 0, buffer.getNumSamples());

    // This is the place where you'd normally do the guts of your plugin's
    // audio processing...
    // Make sure to reset the state if your inner loop is processing
    // the samples and the outer loop is handling the channels.
    // Alternatively, you can process the samples with the channels
    // interleaved by keeping the same state.
	for (int channel = 0; channel < totalNumInputChannels; ++channel)
		//get channel data

		// loop through each sample
		for (int sample = 0; sample < buffer.getNumSamples(); sample++)
			// validate if recalculation is needed
			if (factorCount == (int)*treeState.getRawParameterValue(RRF_ID))
				// get a value for the noise;
				randRes = rand.nextDouble();
				// set counter back to 0;
				factorCount = 0;
			// apply 0 gating
			if (buffer.getSample(channel, sample) == 0.0f && zeroGate)
				//the change in amplitude is 0.
				staticChange = 0;
				// add the noise as static
				staticChange = ((randRes * 2.0f) - 1.0f) * *treeState.getRawParameterValue(AMT_ID);

			//check if dynamicFollow mode is activated
			if (dynamicFollow)
				// multiply static change by the sample value * DFF
				dynamicChange = staticChange + *treeState.getRawParameterValue(DFF_ID) * (staticChange * buffer.getSample(channel, sample) - staticChange);
				// dynamicchange is equal to the static change value.
				dynamicChange = staticChange;

			// Add noise sample to the audio buffer
			tmpBuffer.addSample(channel, sample, dynamicChange);

			//TMP Disabled
			//// apply the change value to the sample
			//channelData[sample] = buffer.getSample(channel, sample) + dynamicChange;

			// increment factor counter
		// filter in channel
		//lowPass->processSamples(tmpBuffer.getWritePointer(channel), buffer.getNumSamples());

		//highPass->processSamples(tmpBuffer.getWritePointer(channel), buffer.getNumSamples());
	//Add input to the tmpBuffer.
	for (int channel = 0; channel < totalNumInputChannels; ++channel)
		auto* channelData = buffer.getWritePointer(channel);

		for (int sample = 0; sample < buffer.getNumSamples(); sample++)
			channelData[sample] = buffer.getSample(channel, sample) + tmpBuffer.getSample(channel, sample);
	//Set output buffer equal to tmpBuffer.

both zeroGate and DynamicFollow are turned on.

As you can see I generate a random value every X amount of samples determined by treeState.getRawParameterValue(RRF_ID) and then do some dynamic processing to get a dynamicChange value.

After that I want to filter the noise signal so I add each value to a buffer and filter it. (For debugging I turned off the filters). After filtering I add the filtered noise buffer back to the original buffer.

Whenever i add the plugin to a new track on ableton to test it I get a wierd output. Even if I don’t provide an input signal. Here is an example of the output I get: Glitchy FX 3.zip (194.0 KB)

Turning the sliders for RRF_ID, AMT_ID and DFF_ID doesn’t change the effect.

What is going on here? what am I doing wrong?


And you don’t want to do a lookup per sample. The automation data is updated only once per processBlock call, so you should prefer to put that into a stack variable.

Thanks for the replies. As I understand it I need to seperate processing for each channel and I don’t need to call the getRawParameterValue function everytime?

I hope that I’m not annoying you with these post…

Thanks anyway.