Philip,
I have to admit, the variable-length quantities in MIDI are very
confusing. Let me see if I can explain what's going on by way of
example.
Suppose we have the number 8192 decimal that we want to convert to a
MIDI variable-length quantity. In hex, this is 20 00.
Usually, the bits in a two-byte binary numbers are counted this way in
decimal:
(32768 16384 8192 4096 2048 1024 512 256) (128 64 32 16 8 4 2 1)
So, normally you would convert 8192 to binary by setting the bit
representing 8192 like this:
00100000 00000000
Now, in the MIDI variable-length system, binary bits are represented
this way:
(skip 8192 4096 2048 1024 512 256 128) (skip 64 32 16 8 4 2 1)
where the skipped bits are flags that tell you when you're at the last
byte.
In our example, we would set the bit representing 8192, and also set
the bit labeled "skip" in the leftmost byte, signifying that this is
the last byte.
This gives, in binary:
11000000 00000000
In hex this becomes C0 00
From the web page that you've taken you're examples from, you'll see
that they say that 2000h converts to C000h in the variable-length
system. Hopefully what I've written here shows why that is the case.
Ron Benditt
Alien Apparatus Company, Inc.
http://www.alienapparatus.com
_______________________________________________
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>
|