Howdy--
I'm writing an application that will write Standard MIDI files as part
of its feature set. While the MIDI spec overall is pretty
straightforward, I'm completely and totally stuck on one part of it,
and that is variable-length quantities. Here's what it says in the
spec:
[quote]
Some numbers in MIDI files are represented in a form called a
"variable-length quantity". These are represented as 7 bits per byte,
most significant bits first. All bytes except the last have bit 7 set,
and the last byte has bit 7 clear. If the number if between 0 and 127,
it is thus represented exactly as one byte. Here are some examples of
numbers represented as variable-length quantities:
Number (Hex) Variable Quantity (Hex)
00000000 00
00000040 40
0000007F 7F
00000080 81 00
00002000 C0 00
00003FFF FF 7F
00004000 81 80 00
00100000 C0 80 00
001FFFFF FF FF 7F
00200000 81 80 80 00
08000000 C0 80 80 00
0FFFFFFF FF FF FF 7F
[/quote]
The MIDI has a couple of routines in C to write and read the values,
but I don't know any C. Here is the MIDI code in C that I'm attempting
to port:
[code]
WriteVarLen (value)
register long value;
{
register long buffer;
buffer = value 0x7f;
while ((value >>= 7) >0)
{
buffer <<= 8;
buffer |= 0x80;
buffer += (value & 0x7f);
}
while (TRUE)
{
putc(buffer, outfile);
if (buffer & 0x80)
buffer >>= 8;
else
break;
}
}
doubleword ReadVarLen ()
{
register doubleword value;
register byte c;
if ((vaklue = getc(infile)) & 0x80)
{
value &= 0x7f;
do
{
value = (value << 7) + ((c = getc(infile)) & 0x7f);
} while (c & 0x80);
}
return (value);
}
[/code]
So, here are my questions about this:
1. What exactly are these routines doing? Not just step-by-step, but
what are the underlying concepts and principles behind them? What am I
programming towards (if that makes any sense)?
2. If, even after being told this and I still can't port it properly,
would someone be interested in porting them to REALbasic for me? Or at
least take a look at the code I just started for writing them and fix
it? I'm more than willing to pay for someone's time who can get me a
working routine to use in my app. (I would like to have an NDA signed
in case they need to see my app's source code. One never knows what
will be The Next Big Thing. ;-) )
Just y'all know, I've been on Google every freakin' day for the past
two weeks and I couldn't find anything that brought me any closer to a
solution. I'm just not "getting it", I think.
BTW, massive thanks to Ron Benditt over at Alien Apparatus for giving
me what he had on reading MIDI files. It was a huge leap forward. When
I get this sussed out, I'll send you the solution. I know you haven't
responded to my last question yet; I'm just widening the search now.
Thanks...
Thanks! And I really hope to hear from someone soon.
--
Philip Regan
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
|