AUv3 wrapper bug report: midi output incorrect timestamp

Hello. Our AUv3 plugins had timing issues reported on Audiobus forum. The reason is wrong sample-offset for midi messages. I’ve created some testing projects in AUM with midi monitor and was surprised that sample offset information is lost, and all midi messages reach midi monitor at start of the buffer. This causes audible sync issues when buffer size is 1024 or 2048.

After some research, I came to conclusion that this line is incorrect juce_AUv3_Wrapper.mm::1612:

midiOut (metadata.samplePosition, 0, metadata.numBytes, metadata.data);

and should be:

midiOut (timestamp->mSampleTime + metadata.samplePosition, 0, metadata.numBytes, metadata.data);

This topic for example mention that AUEventSampleTime is not just sample position inside buffer, but seems to be timestamp. Moreover, for midi input messages from host to plugin Juce is doing this reverse conversion (line 1459):

midiMessages.addEvent (midiEvent.data, midiEvent.length, static_cast<int> (midiEvent.eventSampleTime - timestamp->mSampleTime));

After the correction I can see that sample offset is applied to midi messages and playback is in sync. I had tested this only with iOS, so I wonder if same issue occurs on macOS.
I’m building my plugins now with hacked juce module, so is it a bug or what is proper way to pass midi message sample position without having access to AudioTimeStamp object in processor’s callbacks?

Thanks

Thanks for reporting this issue. I’ve pushed a fix here:

I’ve also updated the MIDILogger demo to print message timestamps, which should make it easier to test similar problems in the future:

1 Like