Timing issues with Realtime MIDI via Virtual MIDI Port
Timing issues with Realtime MIDI via Virtual MIDI Port
- Subject: Timing issues with Realtime MIDI via Virtual MIDI Port
- From: Robert Jonkman <email@hidden>
- Date: Tue, 04 Oct 2011 15:19:54 +0800
Hello,
I'm producing an AU plugin for doing drum replacement. The program
detects transients and outputs MIDI via a virtual MIDI port. The
program was originally written for the VST format and I'm in the
process of porting it to AU.
The only problem I'm experiencing has to do with recording the MIDI
output from the plugin. The MIDI is recorded to the MIDI track
early--i.e the MIDI notes are recorded to the MIDI track before the
transient even occurs! What's even more baffling is that the notes
'sound' perfectly in time during recording, but visually they are
being recorded about 150 ms early.
I've played around with scheduling my notes with timestamps that are
slightly in the future. While this does allow them to be recorded in
the right position, the notes 'sound' late and it makes realtime
performance impossible.
I've been scouring the web for a week looking for the answer to my
problems but nothing has come up.
Here is some of my relevant code from the end of my render method.
delta frames represent the number of frames that should go by before
the event is heard. CurrentTime is calculated at the beginning of
each render() call. It's probably also worth noting that I tried
setting the timestamp to 0 and still had the same issue.
for (int z = 0; z < queuedEvents; z++) {
Byte buffer[1024];
MIDIPacketList *packetlist = (MIDIPacketList*)buffer;
MIDIPacket *currentpacket = MIDIPacketListInit(packetlist);
Byte data[3];
data[0] = eventQueue[z].midiData[0];
data[1] = eventQueue[z].midiData[1];
data[2] = eventQueue[z].midiData[2];
currentpacket = MIDIPacketListAdd(packetlist, sizeof(buffer),
currentpacket, currentTime +
AudioConvertNanosToHostTime((float)(eventQueue[z].deltaFrames /
framesPerMilliSecond) * 1000000), 3, data);
MIDIReceived((MIDIEndpointRef)*midi_source, packetlist);
}
Thank-you in advance for any help you can offer me.
Robert.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden