Source code: | vlv.cpp |
vlv is a command-line program that calculates/converts variable length values which are used for storing timing values in midifiles.
Convert/Create Variable Length Values. Usage: vlv [-d|-2] [-x|-c|-b] number(s) Options: -d = input numbers are given in decimal notation (hex is default) -2 = input numbers are given in binary notation (hex is default) -b = output numbers are given in binary notation -c = output numbers are given in decimal notation -x = output numbers are given in hexadecimal notation --options = list all options, default values, and aliases
Example usage of the vlv program:
> # convert a hex number to VLV bytes: > vlv 3fff ff 7f > # convert a hex number to VLV bytes in decimal notation: > vlv -c 3fff 255 127 > # convert a decimal number to VLV bytes in decimal notation: > vlv -d -c 54632 131 170 104 > # convert hex VLV bytes into a hexadecimal number: > vlv 81 80 F4 00 203a00 > # convert hex VLV bytes into a decimal number: > vlv -c 81 80 F4 00 2112000 > # convert hex VLV bytes into a binary number: > vlv -b 81 80 F4 00 1000000011101000000000
Several different values in standard MIDI file events are expressed as variable length quantities (e.g. delta time values). A variable length value uses a minimum number of bytes to hold the value, and in most circumstances this leads to some degree of data compresssion.
A variable length value uses the low order 7 bits of a byte to represent the value or part of the value. The high order bit is an "escape" or "continuation" bit. All but the last byte of a variable length value have the high order bit set. The last byte has the high order bit cleared. The bytes always appear most significant byte first. Here are some examples:
Variable length Real value 0x7F 127 (0x7F) 0x81 0x7F 255 (0xFF) 0x82 0x80 0x00 32768 (0x8000)