MIDI Clock with MIDIPacketList parsing
MIDI Clock with MIDIPacketList parsing
- Subject: MIDI Clock with MIDIPacketList parsing
- From: "Dan Callaway" <email@hidden>
- Date: Wed, 30 Jul 2003 10:16:57 -0700
Hello,
I have a program that synchronizes a MIDI file to incoming System Realtime
(0xF8) Messages. Every 0xF8 pulse represents 1/24 of a beat.
My approach has been to parse the MIDI file into a sequence of
MIDIPacketLists. Each MIDIPacketList represents 1/24 of one beat. I leave
all MIDITimeStamps in terms of 'ticks.' When my MIDIReadProc sees a 0xF8, it
multiplies these ticks by a time factor and then sends the entire
MIDIPacketList at once. The result is good synchronization, with some
'gotchas.'
I can't determine the appropriate amount of memory to allocate for a given
MIDIPacketList. My original logic was this:
4 Bytes for MIDIPacketList UInt32 length
+
numPackets * (8 Bytes for MIDITimeStamp + 2 Bytes for UInt16 packet
length)
+
Total number of data Bytes
When I malloc'd this amount of memory for my MIDIPacketLists, though, I had
problems. I added a 40 byte 'slop factor,' and things got better, but not
perfect. I then did a sizeof(MIDIPacketList) and saw something like '256.' I
upped my slop factor to 256 and things got really good. Does this mean that
every MIDIPacketList, even if it only has 1 byte of data, needs 256 bytes?
Maybe this is part of the problem: I'm using MIDIPacketListAdd to build up
each MIDIPacketList in a buffer, and then doing a byte-by-byte copy of the
buffer into a malloc'd pointer. The size of this malloc() is what I'm fuzzy
on. Perhaps something happens in the course of MIDIPacketListInit and
MIDIPacketListAdd that I'm not accounting for?
I know this isn't the best way to do this kind of sync, but I'm kind of a
newbie and my perception is that any other approach will require much more
run-time processing, necessitating a custom thread. Right now I do all the
sweating during my parse function, and MIDIReadProc can handle all run-time
duties. The problem is that with my slop factor for every MIDIPacketList
(multiply the number of beats in a long MIDI file by 24. . .!!!!) my memory
usage is hideous and frightening.
Any assistance on this would be hugely appreciated.
Thanks,
Dan Callaway
digitalconductor.com
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.