Problem inserting tempo event (for a simple php script)
[email protected] ("Alex") Fri, 15 Aug 2003 19:44:56 -0700
| Newsgroups | perl.midi |
|---|---|
| Message-ID | <[email protected]> |
Hi. I am trying to create MIDI using PHP.
Here is what I have so far:
----------------------------------------------------------------------------
--------
$file = "\x4D\x54\x68\x64"; // MThd
$file .= pack("N", 6); // header length
$file .= pack("n", 1); // format
$file .= pack("n", 1); // # of track
$file .= pack("n", $TPQ); // TPQ
$file .= "\x4D\x54\x72\x6B"; // MTrk
$file .= pack("N", $length); // length
$file .= $data; // the data
----------------------------------------------------------------------------
--------
where $TPQ, $length, and $data are already defined.
The problem I have is, how do I add a TEMPO event to this MIDI?
Tempo structure:
FF 51 03 tt tt tt
where tttttt = New tempo, in us/quarter-note, in 24-bit binary
Let's say I want to add a tempo of 500000 to the beginning of the track,
what should I do?
I tried to include the lines (below) right before "$file .= $data; // the
data", and increased $length by 6, but the MIDI doesn't seem to be valid....
$file .= "\xFF\x51\x03"; // tempo
$file .= pack("a*",substr(pack("N",500000),1,3)); // speed
What should have been done instead?
I am very confused with the conversion of strings and numbers and binary.
Any help or suggestion is greatly appreciated. Thank you.
Alex