AAX Plugin looking ahead? *,*


G’day folks, I’m making a drum replacement plugin that plays a sample when triggered by a certain threshold level from the input.
The funny thing is that the plugin seems to be “looking ahead” from the actual playback in pro tools, so the sample ends up playing earlier than the actual transient from the input. However, when the plugin is listening to a real-time input from the microphone, the bug is gone (the sample is played after the input detection, as it was meant to be).

When I run these tests, there are no other plugins introducing any delay compensation. And my plugin is also not delay compensated yet, so it is set to zero.

Any thoughts?

Thanks in advance.

Here’s my process block:

void TriggerAudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiMessages)

	auto mainIO = getBusBuffer (buffer, true, 0);
	auto scInput = getBusBuffer (buffer, true, 0);

	double sampleRate = getSampleRate();
	int bufferSize = buffer.getNumSamples();
	int numChannels = buffer.getNumChannels();
	int midiEvent = midiMessages.getFirstEventTime();

	float detectorThresholdValue = *parameters.getRawParameterValue("threshold");

	int timeBetweenNotes = 60; //ms

	for (int j = 0; j < bufferSize; ++j) //for each sample
		if (midiEvent == 0 || j != midiEvent)
		if (t==0)
   if (detect (scInput,numChannels, detectorThresholdValue, sampleRate, j))
	   if (!midiEnable)
		   midiMessages.clear(); // no midi input
	   //samplerSynth.noteOff(1, 60, 0, false);
	   samplerSynth.noteOn(1, 60, 1);  // it plays
	   t = sampleRate*timeBetweenNotes*0.001;

		} //t=0
		if (t>0) //time countdown
	}//unique sample handle


	scInput.clear(); //
	mainIO.clear(); // clears both buffers for now

	samplerSynth.renderNextBlock(mainIO, midiMessages, 0, bufferSize); // renders output

	midiMessages.clear(); //clears midi buffer;