Translate the MIDI key number in semitones with middle C = 60 to linear octaves with middle C = 8, and translate the MIDI velocity number to range from 0 to 84 (roughly the dynamic range in decibels of a compact disc): instr 1 ikey = p4 ivelocity = p5 ioctave = ikey / 12 + 3 idb = ivelocity / 127 * 84 endin