able (see Resources). Microchip also provides comprehensive datasheets – the PIC18F2550 document runs to 430
pages — so I had a lot of reading to do. A few months
later (after sketching out some different approaches), I
started serious work on the design.
Referring to Figure 1, the PIC18F2550 is the heart of
mistralXG. It manages data flowing between the MIDI
ports and the PC via its serial and USB ports, and provides
logic and control for the MIDI switches and the user interface (two pushbuttons and an LCD display).
The code offers the following features:
• Selecting which MIDI stream is sent to the synthesizer
• Running Status control for MIDI OUT
• MIDI data filtering
• MIDI OUT and MIDI THRU control
• Adjustment of LCD brightness
• Monitoring of MIDI IN and MIDI OUT activity
• Maintaining and displaying error information
Let’s take a brief look at some of the technologies that
are used in the design. If you really want to know how
mistralXG works, there’s no substitute for diving in and
reading up on this stuff. There are also copious comments
in the source code, which is available on the Nuts & Volts
website at www.nutsvolts.com.
MIDI: The Musical Instrument Digital Interface
MIDI is a serial protocol for passing messages
between controllers and music synthesizers. Commands
such as “Note on,” “Bend pitch,” “Note off,” and “Change
instrument” control the sounds a synthesizer makes.
Sixteen channels (1-16) — each mapped to a single instrument — are defined for a single MIDI connection, but
MIDI does not define which instrument each channel represents. MIDI composers have to decide the instrument-to
channel mapping for each tune.
A command might say, “Play Middle C on channel 5,
medium loud.” Three bytes are required to construct this
command. These are (in hexadecimal) 0x94, 0x3C, and
0x40. The first four bits of 0x94 (the “ 9”) indicate this
command is “Note on.” The “ 4” in 0x94 says that the note
should be played on channel 5 (counting starts at 0 for
channel 1). Byte 2 selects note number 60 (0x3C) which is
middle C. Notes 0-127 are defined (from low to high
pitch). The last byte gives the volume, with 0 being silent
and 127 (0x7F) being loudest.
Instruments are numbered 1-128 (0-127) and mappings are again arbitrary. The General MIDI specification,
however, defines a mapping most synthesizers can be set
to match. When playing a MIDI file, you have to make
sure that your synth uses the correct mapping to prevent
notes meant for one instrument being played by another
— perhaps even the drum kit! One synthesizer’s piano
may sound different from another’s, but at least they both
generate the right type of sound for the music.
MIDI hardware recognizes command bytes because
their most significant bit (MSB) is set to 1. Command
bytes are followed by 0, 1, or 2 data bytes which have
their MSB=0. Details of the commands and how to interpret them can be found in the Resource links.
MIDI is real-time
MIDI data are transmitted in real time. As soon as a
synthesizer receives a completed “Note on” message for a
particular note and channel, it starts to play the note. It
will continue to sound until a “Stop note” command for
the same note and channel is received. So, a synthesizer
connected to a MIDI keyboard will reproduce the exact
timing of the notes as they are played by the musician,
with a slight — usually indiscernible — delay to allow for
constructing, transmitting,and receiving the MIDI messages. If multiple MIDI devices are chained together, this
delay can become significant and must be kept in mind
when setting up complex MIDI systems.
MIDI was launched about 25 years ago, and the specification has changed little since then. The data or bit rate
of 31. 25 kHz seems very slow by today’s standards, but
MIDI’s wide adoption within the electronic music industry
has ensured its survival, and it is likely to be around for
many years to come.
Figure 2. mistralXG prototype.
Figure 3. mistralXG Home screen.
February 2009 45