Understanding MIDI A Painless Tutorial On Midi For
Understanding MIDI A Painless Tutorial On Midi For
net/publication/316955785
CITATIONS READS
0 7,711
2 authors:
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Hélio Magalhães de Oliveira on 18 May 2017.
H. M. de Oliveira1
Departamento de Estatı́stica, Universidade Federal de Pernambuco, UFPE, Recife, PE
R. C. de Oliveira2
Depto de Engenharia da Computação, Universidade Estadual do Amazonas, UEA, Manaus, AM
arXiv:1705.05322v1 [cs.SD] 15 May 2017
Abstract. A short overview demystifying the midi audio format is presented. The goal is
to explain the file structure and how the instructions are used to produce a music signal,
both in the case of monophonic signals as for polyphonic signals.
keywords. Midi files, Computer Music, Monophonic and Polyphonic.
1 Introduction
Digital music is a broad and fascinating subject [2], [3], [12]. The Musical Instrument
Digital Interface (MIDI) protocol is an industry-standard defined in early 80’s to repre-
sent musical information [7], [9]. Even dealing with an old subject, it does not seem to
be available on the Internet enlightening texts (most shows only tables, commands and
technicalities). It is a the most spread binary protocol for communicating intended to
connect electronic musical instruments such as synthesizers, in computer for the purpose
of recording, editing and programming, and electronic music equipment in the electronic
home studios [10], [6]. MIDI System appeared for the need for standardization of the media
between the synthesizers. This standard was created when electronic music was developed
by a consortium of Japanese and American manufacturers Synthesizers (Sequential Sys-
tems, Roland Corporation, Yamaha, Kurzweil...). You can make free download millions
of popular songs in MIDI versions. It transmits data using serial ports. For many peo-
ple, still remains somewhat nebulous how to assemble a midi file from a music as well as
the interpretation of a file previously generated. Unlike other formats (such as .wav and
.mp3), a MIDI file does not contain audio itself, but the instructions to produce it, i.e. it
is basically a digitized score. That is to say that MIDI is not audio signal: it just con-
tains musical instruction. MIDI messages are comparable with those piano rolls, in which
data control are represented as opposed to audio waveforms. The MIDI protocol allows
sending messages over 16 independent channels, allowing 16 hearing instruments. MIDI
consists of both a simple hardware interface, and a more elaborate transmission protocol.
What MIDI specifies? Here is a list: hardware; driver; communication channels; messages;
modes; controllers; files standard MIDI; visual control (MIDI show control) among other
things. In this note we are just concerned with midi protocol [4], [7].
1
[email protected] also https://arxiv.org/a/deoliveira_h_1.atom
2
[email protected]
2
Standard MIDI Files contain at the top level things called events. Each event consists
of two components: a MIDI time, and a MIDI message. These time/message pairs follow
each other one in a MIDI file as illustrated in Fig. 1. The time value is a measurement of
the time to wait before playing the next message in the stream of MIDI file data. This
method of specifying the time is called delta time that specifies the duration between
two events (Table 1). MIDI commands and data are distinguished according to the most
significant bit of the byte. If there is a zero in the top bit, then the byte is a data byte,
otherwise the byte is a command byte.
The MIDI messages are sent as a sequence of one or more bytes. The first byte is a com-
mand (STATUS) byte, often followed by data (DATA) bytes with additional parameters.
The command byte determines the type of the command. The number of DATA bytes
that follow depend on the type of the message. For instance, the following two commands
have different number of data bytes: FF 58 04 04 02 30 08 and 90 3C 28. The main com-
mands in midi files are Note-on (0×90) and Note-off (0×80) that allows starting/stopping
playing a single musical note. There are at least two playing modes, namely mono and
poly. Monophonic: the start of a new “note-on” command implies the termination of the
previous note. Polyphonic: multiple notes may be sounding at once, until the notes reach
the end of their decay envelope, or when explicit “note-off” commands are received.
3
9 0 3 c 2 8
1001 0000 0011 1011 0010 1000
The velocity value normally goes from 1 to 127, covering the range from a practically
inaudible note up to the maximum note level. It basically corresponds to the scale of
nuances found in music notation, as follows. Figure 3 shows different standard note level.
In the beginning of the file, it is quite common to use the following commands:
Another command used in the beginning encompasses the definition of the metronome:
FF 51 03 tt tt tt set number microseconds per quarter note. For instance: FF 51 03 07
A1 20 for 120 bpm; FF 51 03 0f 42 40 for 60 bpm.
End of Track: FF 2F 00. This event is not optional. It is included so that an exact ending
point may be specified for the track, so that an exact length is defined, which is necessary
for tracks which are looped or concatenated. For looking inside a midi file, we suggest [11].
For example, here is initial data from a monophonic MIDI file (in hex): 00 FF 58 04 04
02 30 08 00 FF 59 02 00 00 00 90 3C 28 81 00 90 3C 00 00 90 3C 1E 81 00 90 3C 00 00 90 43
2D 81 00 90 43 00 00 90 43 32 81 00 90 43 00 00 90 45 2D 81 00 90 45 · · · The way of reading
this file is separating {time/message} pairs as {00 FF 58 04 04 02 30 08} {00 FF 59 02 00
00} {00 90 3C 28} {81 00 90 3C 00} {00 90 3C 1E} {81 00 90 3C 00} {00 90 43 2D} {81 00 90
43 00} {00 90 43 32} {81 00 90 43 00} {00 90 45 2D} {81 00 90 45 00} · · · Black characters
are delta time information, and blue characters are messages. Blue boldface type part is
command and ordinary blue characters are data associated with the previous command.
Final remark: many times the command note-off 80 nn 00 is replaced by the command
90 nn 00 (note-on, pitch nn, null intensity), which is equivalent.
The sequence of played notes is C4 1/4, C4 1/4, G4 1/4, G4 1/4, A4 1/4, A4 1/4, G4 1/4, F4
1/4, F4 1/4, E4 1/8, E4 1/8, D4 1/8, D4 1/8, C4 1/2.
5
The MIDI message used to specify the instrument is a “program change” message:
command byte=1100 CCCC (MIDI channel 0 to 15); Data byte 1=0XXX XXXX (instru-
ment number from 0 to 127). The sax, piano and bass drum will use channels 1, 2 and
10, respectively. An illustrative example of MIDI sequence is shown in the sequel. First
send the program changes to specify the instruments on each channel. In Fig. 7 there is
a score example with three instruments. Suppose that the sax, piano and bass drum will
use respectively channels 1, 2 and 10. The MIDI message sequence is the following.
Specifying the instruments to use on each channel: 00 C0 41 (Alto Sax=66 ⇒
coded 65 =0×41), 00 C1 00 (Piano=1 ⇒ coded 0), 00 C9 00 (Standard Drums Kit=1 ⇒
coded 0)
Notes inserting: 00 90 48 40 (Start sax C4, pitch=72=0×48), 00 91 3C 40 (Start piano
C3, pitch=60=0×3C), 00 91 43 40 (Start piano G3, pitch=67=0×43), 00 91 4C 40 (Start
piano E4, pitch=76=0×4C), 00 99 23 40 (Start Bass Drum=35=0×23), 81 00 90 48 00
(Stop sax C4, pitch=72=0×48), 00 99 23 00 (Stop Bass Drum=35=0×23), 00 90 4A 40
(Start sax D4, pitch=74=0×4A), 81 00 90 4A 00 (Stop sax D4, pitch=74=0×4A), 00 90
4C 40 (Start sax E4, pitch=76= 0×4C), 00 99 23 40 (Start Bass Drum =35=0×23), 81 00
90 4C 00 (Stop sax E4, pitch=76=0×4C), 00 99 23 00 (Stop Bass Drum=35=0×23), 00 90
4F 40 (Start sax G4, pitch=79=0×4F), 81 00 90 4F 00 (Stop sax G4, pitch=79=0×4F), 00
91 3C 00 (Stop piano C3, pitch=60=0×3C), 00 91 43 00 (Stop piano G3, pitch=67=0×43),
00 91 4C 00 (Stop piano E4, pitch=76=0×4C). Therefore, the midi sequence correspond-
ing to the score of Figure 7 is 00 C0 41 00 C1 00 00 C9 00 00 90 48 40 00 91 3C 40 00 91 43
40 00 91 4C 40 00 99 23 40 81 00 90 48 00 00 99 23 00 00 90 4A 40 81 00 90 4A 00 00 90 4C 40 00
99 23 40 81 00 90 4C 00 00 99 23 00 00 90 4F 40 81 00 90 4F 00 00 91 3C 00 00 91 43 00 00 91 4C 00
7
6 Summary
This brief explanatory report revises one of the representations of discrete mathemati-
cal structures used in music. It is intended for midi beginners. The motivation for writing
it came from the difficulty finding a simple text that allows understanding midi files. The
presentation tries to throw some light in the way as a midi is built from a musical score.
It also allows to understand the commands of a hex file (midi) generated to build the
corresponding score. Fig. 6 provides insight into the way the time events are defined. It is
hoped that this note help ordinary users who deal with digital music. A final remark (just
for readers who have never attempted to understand midi): “when trying to learn midi
by Internet, the reader could get a feel of the hardship in having clarity on the subject.
Nevertheless, after reading this paper he may find it a trivial matter. Is that The mind
that opens to a new idea never returns to its original size (A. Einstein).”
References
[1] S. Airy, and J. M. Parr. MIDI, music and me: Students’ perspectives on compos-
ing with MIDI, Music Education Res., Vol.3,N.1, 41-49, 2001 http://dx.doi.org/10.
1080/14613800020029941
[2] B. Arnell. McScope: System. Music, Computers, and Software, April 58-60, 1988.
[3] Z. Cataltepe, Y. Yaslan, and A. Sonmez. Music genre classification using MIDI and
audio features. EURASIP J. on Adv. in Signal Processing Dec. 036409, 1-8, 2007.
http://dx.doi.org/10.1155/2007/36409
[4] J. Cooper, Mind over MIDI: Information sources and system-exclusive data formats.
Keyboard October, 110-111, 1986.
[5] B. Enders, and W. Klemme. MIDI and Sound Book for the Atari ST. Redwood: M&T
Books, 1989. ISBN:155851043.
[6] R. Guérin. Midi power- The comprehensive guide, Thompson Course Tech., 2001.
[7] J. Heckroth, A tutorial on MIDI and wavetable music synthesis. Application Note,
Crystal division of Cirrus Logic, 1998.
[8] T. Holman. Surround Sound: Up and Running, CRC Press, 2014. ISBN:0240808290
[9] J. Matzkin. A MIDI musical offering. PC Magazine 29 Nov.229+, 1988.
[10] MIDI 1.0 Detailed specification, document version 4.2, revised 1995.
[11] online hex editor at http://www.onlinehexeditor.com
[12] K. Pohlman. Principles of Digital Audio, McGraw-Hill, 2011. ISBN:9780071663465