.VST plugin error


#1

is this okay to do

void DiddyBop_AudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
const int totalNumInputChannels = getTotalNumInputChannels();
const int totalNumOutputChannels = getTotalNumOutputChannels();
const int numSamples = buffer.getNumSamples(); // How many samples in the buffer for this block?
int channel;

if (bassBoost)
{
	setParameterNotifyingHost(DiddyBop_AudioProcessor::kCentreFrequencyParam, 73);
	setParameterNotifyingHost(DiddyBop_AudioProcessor::kQParam, 1.75);
}
else
{
	setParameterNotifyingHost(DiddyBop_AudioProcessor::kCentreFrequencyParam, 10);
	setParameterNotifyingHost(DiddyBop_AudioProcessor::kQParam, 0.1);
}


{

	inputBuffer[0].setSize(M, bufferSize);
	inputBuffer[0].clear();
    inputBuffer[1].setSize(M, bufferSize);
	
	for (int m = 0; m < M; ++m)
	{
		if (getThreshold() < 0)
		{
			inputBuffer[0].clear(m, 0, bufferSize);
			// Mix down left-right to analyse the input		
			inputBuffer[0].addFrom(m, 0, buffer, m * 2, 0, bufferSize, 0.5);
			inputBuffer[0].addFrom(m, 0, buffer, m * 2 + 1, 0, bufferSize, 0.5);
			// compression : calculates the control voltage
			//compressor(inputBuffer[0], m);
			
			//inputBuffer[1].makeCopyOf(inputBuffer[0]);
			
			compressor_[0]->setRatio(2);
			compressor_[0]->setAttackTime(14);
			compressor_[0]->setReleaseTime(41);
			compressor_[0]->setThreshold(getThreshold());
			compressor_[0]->setGain(0);


			//gain if compression is less than -12
			if (compressor_[0]->getThreshold() < (-15))
			{
				compressor_[0]->setGain(abs(3));
			}
			else
				compressor_[0]->setGain(0);
				//
			//Compress Buffer 0
			compressor_[0]->Compress(inputBuffer[0], m);


			//Make a copy of buffer 0
			

			//InputBuffer1 copy

			compressor_[1]->setRatio(2);
			compressor_[1]->setAttackTime(50);
			compressor_[1]->setReleaseTime(80);
			if (compressor_[0]->getThreshold() < (-10))
			{
				compressor_[1]->setThreshold(compressor_[0]->getThreshold());
			}
			else
			{
				compressor_[1]->setThreshold(-10);
			}
			compressor_[1]->setGain(0);
		    compressor_[1]->Compress(inputBuffer[1], m);



			compressor_[2]->setRatio(40);
			compressor_[2]->setAttackTime(20);
			compressor_[2]->setReleaseTime(90);
			compressor_[2]->setThreshold(-20);
			compressor_[2]->setGain(0);
			compressor_[2]->Compress(inputBuffer[1], m);

			for (int i = 0; i < bufferSize; ++i)
			{
	     		compressor_[0]->c[i] *= compressor_[1]->c[i]*compressor_[2]->c[i];
			}

			// apply control voltage to the audio signal
			for (int i = 0; i < bufferSize; ++i)
			{
				buffer.getWritePointer(2 * m + 0)[i] *= compressor_[0]->c[i];
				buffer.getWritePointer(2 * m + 1)[i] *= compressor_[0]->c[i];
			}

			inputBuffer[0].clear(m, 0, bufferSize);
			// Mix down left-right to analyse the output
			inputBuffer[0].addFrom(m, 0, buffer, m * 2, 0, bufferSize, 0.5);
			inputBuffer[0].addFrom(m, 0, buffer, m * 2 + 1, 0, bufferSize, 0.5);
		}
	}

}

//if (onOff)
//{
	for (channel = 0; channel < totalNumInputChannels; ++channel)
	{
		// channelData is an array of length numSamples which contains the audio for one channel
		float* channelData = buffer.getWritePointer(channel);

		// Run the samples through the IIR filter whose coefficients define the parametric
		// equaliser. See juce_IIRFilter.cpp for the implementation.
		eqFilters_[channel]->processSamples(channelData, numSamples);
		
		//buffer.applyGain((getThreshold()));
	}


//========================================================================

// Go through the remaining channels. In case we have more outputs
// than inputs, or there aren't enough filters, we'll clear any
// remaining output channels (which could otherwise contain garbage)
while (channel < totalNumOutputChannels)
{
	buffer.clear(channel++, 0, buffer.getNumSamples());
}

//// 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 (int 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...
//for (int channel = 0; channel < totalNumInputChannels; ++channel)
//{
//    float* channelData = buffer.getWritePointer (channel);

//    // ..do something to the data...
//}

}


#2

You might want to make your post a bit more readable if you’re asking people to spend timing looking at it. Indent code blocks by 4 spaces for markdown to handle it correctly, and don’t use tabs!


#3

The first thing that jumps out to me is that it appears that you are setting the size of your buffers in the processBlock. This is a big no no, you must not allocate memory inside of processBlock. Instead do this work in prepareToPlay(). Just keep in mind that you will not be able to reliably set your working buffer size to that of the number of samples of each block as this number can and will change from time to time.