an27 application note design by example/chapter11/miditut.pdfan27 application note a tutorial on...

24
1 Copyright Cirrus Logic, Inc. 1998 (All Rights Reserved) Cirrus Logic, Inc. Crystal Semiconductor Products Division P.O. Box 17847, Austin, Texas 78760 (512) 445 7222 FAX: (512) 445 7581 http://www.crystal.com AN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument Digital Interface (MIDI) protocol has been widely accepted and utilized by musicians and composers since its conception in the 1982/1983 time frame. MIDI data is a very ef- ficient method of representing musical perfor- mance information, and this makes MIDI an attractive protocol for computer applications which produce sound, such as multimedia presentations or computer games. However, the lack of standard- ization of synthesizer capabilities hindered appli- cations developers and presented MIDI users with a rather steep learning curve to overcome. Fortu- nately, thanks to the publication of the General MIDI System specification, wide acceptance of the most common PC/MIDI interfaces, support for MIDI in Microsoft WINDOWS, and the evolution of low-cost high-quality wavetable music synthe- sizers, the MIDI protocol is now seeing widespread use in a growing number of applications. This pa- per gives a brief overview of the standards and ter- minology associated with the generation of sound using the MIDI protocol and wavetable music syn- thesizers. USE OF MIDI IN MULTIMEDIA APPLICATIONS Originally developed to allow musicians to connect synthesizers together, the MIDI protocol is now finding widespread use in the generation of sound for games and multimedia applications. There are several advantages to generating sound with a MIDI synthesizer rather than using sampled audio from disk or CD-ROM. The first advantage is stor- age space. Data files used to store digitally sampled audio in PCM format (such as .WAV files) tend to be quite large. This is especially true for lengthy musical pieces captured in stereo using high sam- pling rates. MIDI data files, on the other hand, are extremely small when compared with sampled au- dio files. For instance, files containing high quality stereo sampled audio require about 10 MBytes of data per minute of sound, while a typical MIDI se- quence might consume less than 10 KBytes of data per minute of sound. This is because the MIDI file does not contain the sampled audio data, it contains only the instructions needed by a synthesizer to play the sounds. These instructions are in the form of MIDI messages, which instruct the synthesizer which sounds to use, which notes to play, and how loud to play each note. The actual sounds are then generated by the synthesizer. The smaller file size also means that less of the PCs bandwidth is utilized in spooling this data out to the peripheral which is generating sound. Other advan- tages of utilizing MIDI to generate sounds include the ability to easily edit the music, and the ability to change the playback speed and the pitch or key of the sounds independently. This last point is partic- ularly important in synthesis applications such as karaoke equipment, where the musical key and tempo of a song may be selected by the user. FEB ‘98 AN27REV4

Upload: others

Post on 25-Aug-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

1

Copyright Cirrus Logic, Inc. 1998(All Rights Reserved)

Cirrus Logic, Inc.Crystal Semiconductor Products DivisionP.O. Box 17847, Austin, Texas 78760(512) 445 7222 FAX: (512) 445 7581http://www.crystal.com

AN27

Application Note

A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESISBy Jim Heckroth

INTRODUCTION

The Musical Instrument Digital Interface (MIDI)protocol has been widely accepted and utilized bymusicians and composers since its conception inthe 1982/1983 time frame. MIDI data is a very ef-ficient method of representing musical perfor-mance information, and this makes MIDI anattractive protocol for computer applications whichproduce sound, such as multimedia presentationsor computer games. However, the lack of standard-ization of synthesizer capabilities hindered appli-cations developers and presented MIDI users witha rather steep learning curve to overcome. Fortu-nately, thanks to the publication of the GeneralMIDI System specification, wide acceptance of themost common PC/MIDI interfaces, support forMIDI in Microsoft WINDOWS, and the evolutionof low-cost high-quality wavetable music synthe-sizers, the MIDI protocol is now seeing widespreaduse in a growing number of applications. This pa-per gives a brief overview of the standards and ter-minology associated with the generation of soundusing the MIDI protocol and wavetable music syn-thesizers.

USE OF MIDI IN MULTIMEDIA APPLICATIONS

Originally developed to allow musicians to connectsynthesizers together, the MIDI protocol is nowfinding widespread use in the generation of soundfor games and multimedia applications. There areseveral advantages to generating sound with aMIDI synthesizer rather than using sampled audio

from disk or CD-ROM. The first advantage is stor-age space. Data files used to store digitally sampledaudio in PCM format (such as .WAV files) tend tobe quite large. This is especially true for lengthymusical pieces captured in stereo using high sam-pling rates. MIDI data files, on the other hand, areextremely small when compared with sampled au-dio files. For instance, files containing high qualitystereo sampled audio require about 10 MBytes ofdata per minute of sound, while a typical MIDI se-quence might consume less than 10 KBytes of dataper minute of sound. This is because the MIDI filedoes not contain the sampled audio data, it containsonly the instructions needed by a synthesizer toplay the sounds. These instructions are in the formof MIDI messages, which instruct the synthesizerwhich sounds to use, which notes to play, and howloud to play each note. The actual sounds are thengenerated by the synthesizer.

The smaller file size also means that less of the PCsbandwidth is utilized in spooling this data out to theperipheral which is generating sound. Other advan-tages of utilizing MIDI to generate sounds includethe ability to easily edit the music, and the ability tochange the playback speed and the pitch or key ofthe sounds independently. This last point is partic-ularly important in synthesis applications such askaraoke equipment, where the musical key andtempo of a song may be selected by the user.

FEB ‘98AN27REV4

Page 2: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

2 AN27REV4

MIDI SYSTEMS

The Musical Instrument Digital Interface (MIDI)protocol provides a standardized and efficientmeans of conveying musical performance informa-tion as electronic data. MIDI information is trans-mitted in "MIDI messages", which can be thoughtof as instructions which tell a music synthesizerhow to play a piece of music. The Synthesizer re-ceiving the MIDI data must generate the actualsounds. The MIDI 1.0 Detailed Specification, pub-lished by the International MIDI Association, pro-vides a complete description of the MIDI protocol.

The MIDI data stream is a unidirectional asynchro-nous bit stream at 31.25 kbits/sec. with 10 bitstransmitted per byte (a start bit, 8 data bits, and onestop bit). The MIDI interface on a MIDI instrumentwill generally include three different MIDI connec-tors, labeled IN, OUT, and THRU. The MIDI datastream is usually originated by a MIDI controller,such as a musical instrument keyboard, or by aMIDI sequencer. A MIDI controller is a devicewhich is played as an instrument, and it translatesthe performance into a MIDI data stream in realtime (as it is played). A MIDI sequencer is a devicewhich allows MIDI data sequences to be captured,stored, edited, combined, and replayed. The MIDIdata output from a MIDI controller or sequencer istransmitted via the devices’ MIDI OUT connector.

The recipient of this MIDI data stream is common-ly a MIDI sound generator or sound module, whichwill receive MIDI messages at its MIDI IN connec-tor, and respond to these messages by playingsounds. Figure 1 shows a simple MIDI system,consisting of a MIDI keyboard controller and aMIDI sound module. Note that many MIDI key-board instruments include both the keyboard con-troller and the MIDI sound module functionswithin the same unit. In these units, there is an in-ternal link between the keyboard and the soundmodule which may be enabled or disabled by set-ting the "local control" function of the instrumentto ON or OFF respectively.

The single physical MIDI channel is divided into16 logical channels by the inclusion of a 4-bit chan-nel number within many of the MIDI messages. Amusical instrument keyboard can generally be setto transmit on any one of the sixteen MIDI chan-nels. A MIDI sound source, or sound module, canbe set to receive on specific MIDI channel(s). In thesystem depicted in Figure 1, the sound modulewould have to be set to receive the channel whichthe keyboard controller is transmitting on in orderto play sounds.

Information received on the MIDI IN connector ofa MIDI device is transmitted back out (repeated) atthe devices’ MIDI THRU connector. Several MIDIsound modules can be daisy-chained by connectingthe THRU output of one device to the IN connectorof the next device downstream in the chain.

Figure 1. A Simple MIDI System

Page 3: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

AN27REV4 3

Figure 2 shows a more elaborate MIDI system. Inthis case, a MIDI keyboard controller is used as aninput device to a MIDI sequencer, and there areseveral sound modules connected to the sequenc-er’s MIDI OUT port. A composer might utilize asystem like this to write a piece of music consistingof several different parts, where each part is writtenfor a different instrument. The composer wouldplay the individual parts on the keyboard one at atime, and these individual parts would be capturedby the sequencer. The sequencer would then playthe parts back together through the sound modules.Each part would be played on a different MIDIchannel, and the sound modules would be set to re-ceive different channels. For example, Sound mod-ule number 1 might be set to play the part receivedon channel 1 using a piano sound, while module 2plays the information received on channel 5 usingan acoustic bass sound, and the drum machineplays the percussion part received on MIDIchannel 10.

In the last example, a different sound module isused to play each part. However, sound moduleswhich are "multi-timbral" are capable of playingseveral different parts simultaneously. A singlemulti-timbral sound module might be configured to

receive the piano part on channel 1, the bass part onchannel 5, and the drum part on channel 10, andwould play all three parts simultaneously.

Figure 3 depicts a PC-based MIDI system. In thissystem, the PC is equipped with an internal MIDIinterface card which sends MIDI data to an externalmulti-timbral MIDI synthesizer module. Applica-tion software, such as Multimedia presentationpackages, educational software, or games, send in-formation to the MIDI interface card over the PCbus. The MIDI interface converts this informationinto MIDI messages which are sent to the soundmodule. Since this is a multi-timbral module, it canplay many different musical parts, such as piano,bass and drums, at the same time. SophisticatedMIDI sequencer software packages are also avail-able for the PC. With this software running on thePC, a user could connect a MIDI keyboard control-ler to the MIDI IN port of the MIDI interface card,and have the same music composition capabilitiesdiscussed in the last paragraph.

There are a number of different configurations ofPC-based MIDI systems possible. For instance, theMIDI interface and the MIDI sound module mightbe combined on the PC add-in card. In fact, the Mi-crosoft Multimedia PC (MPC) Specification states

Figure 2. An Expanded MIDI System

Page 4: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

4 AN27REV4

that a PC add-in sound card must have an on-boardsynthesizer in order to be MPC compliant. Until re-cently, most MPC compliant sound cards includedFM synthesizers with limited capabilities and mar-ginal sound quality. With these systems, an exter-nal wavetable synthesizer module might be addedto get better sound quality. Recently, more ad-vanced sound cards have been appearing which in-clude high quality wavetable music synthesizerson-board, or as a daughter-card options. With theincreasing use of the MIDI protocol in PC applica-tions, this trend is sure to continue.

MIDI MESSAGES

A MIDI message is made up of an eight bit statusbyte which is generally followed by one or two databytes. There are a number of different types ofMIDI messages. At the highest level, MIDI mes-sages are classified as being either Channel Mes-sages or System Messages. Channel messages arethose which apply to a specific channel, and thechannel number is included in the status byte forthese messages. System messages are not channelspecific, and no channel number is indicated intheir status bytes. Channel Messages may be fur-ther classified as being either Channel Voice Mes-sages, or Mode Messages. Channel Voice

Messages carry musical performance data, andthese messages comprise most of the traffic in atypical MIDI data stream. Channel Mode messagesaffect the way a receiving instrument will respondto the Channel Voice messages. MIDI SystemMessages are classified as being System CommonMessages, System Real Time Messages, or SystemExclusive Messages. System Common messagesare intended for all receivers in the system. SystemReal Time messages are used for synchronizationbetween clock-based MIDI components. SystemExclusive messages include a Manufacturer’s Iden-tification (ID) code, and are used to transfer anynumber of data bytes in a format specified by thereferenced manufacturer. The various classes ofMIDI messages are discussed in more detail in thefollowing paragraphs.

Channel Voice Messages

Channel Voice Messages are used to send musicalperformance information. The messages in this cat-egory are the Note On, Note Off, Polyphonic KeyPressure, Channel Pressure, Pitch Bend Change,Program Change, and the Control Change message.

In MIDI systems, the activation of a particular noteand the release of the same note are considered astwo separate events. When a key is pressed on a

Figure 3. PC-Based MIDI System

Page 5: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

AN27REV4 5

MIDI keyboard instrument or MIDI keyboard con-troller, the keyboard sends a Note On message onthe MIDI OUT port. The keyboard may be set totransmit on any one of the sixteen logical MIDIchannels, and the status byte for the Note On mes-sage will indicate the selected channel number. TheNote On status byte is followed by two data bytes,which specify key number (indicating which keywas pressed) and velocity (how hard the key waspressed). The key number is used in the receivingsynthesizer to select which note should be played,and the velocity is normally used to control the am-plitude of the note. When the key is released, thekeyboard instrument or controller will send a NoteOff message. The Note Off message also includesdata bytes for the key number and for the velocitywith which the key was released. The Note Off ve-locity information is normally ignored.

Some MIDI keyboard instruments have the abilityto sense the amount of pressure which is being ap-plied to the keys while they are depressed. Thispressure information, commonly called "after-touch", may be used to control some aspects of thesound produced by the synthesizer (vibrato, for ex-ample). If the keyboard has a pressure sensor foreach key, then the resulting "polyphonic after-touch" information would be sent in the form ofPolyphonic Key Pressure messages. These messag-es include separate data bytes for key number andpressure amount. It is currently more common forkeyboard instruments to sense only a single pres-sure level for the entire keyboard. This "channel af-tertouch" information is sent using the ChannelPressure message, which needs only one data byteto specify the pressure value.

The Pitch Bend Change message is normally sentfrom a keyboard instrument in response to changesin position of the pitch bend wheel. The pitch bendinformation is used to modify the pitch of soundsbeing played on a given channel. The Pitch Bendmessage includes two data bytes to specify thepitch bend value. Two bytes are required to allow

fine enough resolution to make pitch changes re-sulting from movement of the pitch bend wheelseem to occur in a continuous manner rather than insteps.

The Program Change message is used to specifythe type of instrument which should be used to playsounds on a given channel. This message needsonly one data byte which specifies the new pro-gram number.

MIDI Control Change messages are used to controla wide variety of functions in a synthesizer. ControlChange messages, like other MIDI channel mes-sages, should only affect the channel number indi-cated in the status byte. The control change statusbyte is followed by one data byte indicating the"controller number", and a second byte which spec-ifies the "control value". The controller numberidentifies which function of the synthesizer is to becontrolled by the message.

Controller Numbers 0 - 31 are generally used forsending data from switches, wheels, faders, or ped-als on a MIDI controller device such as a musicalinstrument keyboard. Control numbers 32 - 63 areused to send an optional Least Significant Byte(LSB) for control numbers 0 through 31, respec-tively. Some examples of synthesizer functionswhich may be controlled are modulation (controllernumber 1), volume (controller number 7), and pan(controller number 10). Controller numbers 64through 67 are used for switched functions. theseare the sustain/damper pedal (controller number64), portamento (controller number 65), sostenutopedal (controller number 66), and soft pedal (con-troller number 67). Controller numbers 16-19 and80-83 are defined to be general purpose controllers,and controller numbers 48-51 may be used to sendan optional LSB for controller numbers 16-19. Sev-eral of the MIDI controllers merit more detailed de-scriptions, and these controllers are described in thefollowing paragraphs.

Page 6: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

6 AN27REV4

Controller number zero is defined as the bank se-lect. The bank select function is used in some syn-thesizers in conjunction with the MIDI ProgramChange message to expand the number of differentinstrument sounds which may be specified (theProgram Change message alone allows selection ofone of 128 possible program numbers). The addi-tional sounds are commonly organized as "varia-tions" of the 128 addressed by the Program Changemessage. Variations are selected by preceding theProgram Change message with a Control Changemessage which specifies a new value for controllerzero (see the Roland General Synthesizer Standardtopic covered later in this paper).

Controller numbers 91 through 95 may be used tocontrol the depth or level of special effects, such asreverb or chorus, in synthesizers which have thesecapabilities.

Controller number 6 (Data Entry), in conjunctionwith Controller numbers 96 (Data Increment), 97(Data Decrement), 98 (Registered Parameter Num-ber LSB), 99 (Registered Parameter NumberMSB), 100 (Non-Registered Parameter NumberLSB), and 101 (Non-Registered Parameter Num-ber MSB), may be used to send parameter data to asynthesizer in order to edit sound patches. Regis-tered parameters are those which have been as-signed some particular function by the MIDIManufacturers Association (MMA) and the JapanMIDI Standards Committee (JMSC). For example,there are Registered Parameter numbers assignedto control pitch bend sensitivity and master tuningfor a synthesizer. Non-Registered parameters havenot been assigned specific functions, and may beused for different functions by different manufac-turers. Parameter data is transferred by first select-ing the parameter number to be edited usingcontrollers 98 and 99 or 100 and 101, and then ad-justing the data value for that parameter using con-troller number 6, 96, or 97.

Controller Numbers 121 through 127 are used toimplement the MIDI "Channel Mode Messages".These messages are covered in the next section.

Channel Mode Messages

Channel Mode messages (MIDI controller num-bers 121 through 127) affect the way a synthesizerresponds to MIDI data. Controller number 121 isused to reset all controllers. Controller number 122is used to enable or disable Local Control (In aMIDI synthesizer which has it’s own keyboard, thefunctions of the keyboard controller and the syn-thesizer can be isolated by turning Local Controloff). Controller numbers 124 through 127 are usedto select between Omni Mode On or Off, and to se-lect between the Mono Mode or Poly Mode of op-eration.

When Omni mode is On, the synthesizer will re-spond to incoming MIDI data on all channels.When Omni mode is Off, the synthesizer will onlyrespond to MIDI messages on one channel. WhenPoly mode is selected, incoming Note On messagesare played polyphonically. This means that whenmultiple Note On messages are received, each noteis assigned its own voice (subject to the number ofvoices available in the synthesizer). The result isthat multiple notes are played at the same time.When Mono mode is selected, a single voice is as-signed per MIDI channel. This means that only onenote can be played on a given channel at a giventime. Most modern MIDI synthesizers will defaultto Omni On/Poly mode of operation. In this mode,the synthesizer will play note messages received onany MIDI channel, and notes received on eachchannel are played polyphonically. In the OmniOff/Poly mode of operation, the synthesizer will re-ceive on a single channel and play the notes re-ceived on this channel polyphonically. This modeis useful when several synthesizers are daisy-chained using MIDI THRU. In this case each syn-thesizer in the chain can be set to play one part (the

Page 7: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

AN27REV4 7

MIDI data on one channel), and ignore the infor-mation related to the other parts.

Note that a MIDI instrument has one MIDI channelwhich is designated as its "Basic Channel". The Ba-sic Channel assignment may be hard-wired, or itmay be selectable. Mode messages can only be re-ceived by an instrument on the Basic Channel.

System Common Messages

The System Common Messages which are current-ly defined include MTC Quarter Frame, Song Se-lect, Song Position Pointer, Tune Request, and EndOf Exclusive (EOX). The MTC Quarter Framemessage is part of the MIDI Time Code informa-tion used for synchronization of MIDI equipmentand other equipment, such as audio or video tapemachines.

The Song Select message is used with MIDI equip-ment, such as sequencers or drum machines, whichcan store and recall a number of different songs.The Song Position Pointer is used to set a sequenc-er to start playback of a song at some point otherthan at the beginning. The Song Position Pointervalue is related to the number of MIDI clockswhich would have elapsed between the beginningof the song and the desired point in the song. Thismessage can only be used with equipment whichrecognizes MIDI System Real Time Messages(MIDI Sync).

The Tune Request message is generally used to re-quest an analog synthesizer to retune its’ internaloscillators. This message is generally not neededwith digital synthesizers.

The EOX message is used to flag the end of a Sys-tem Exclusive message, which can include a vari-able number of data bytes.

System Real Time Messages

The MIDI System Real Time messages are used tosynchronize all of the MIDI clock-based equipmentwithin a system, such as sequencers and drum ma-

chines. Most of the System Real Time messagesare normally ignored by keyboard instruments andsynthesizers. To help ensure accurate timing, Sys-tem Real Time messages are given priority overother messages, and these single-byte messagesmay occur anywhere in the data stream (a RealTime message may appear between the status byteand data byte of some other MIDI message). TheSystem Real Time messages are the Timing Clock,Start, Continue, Stop, Active Sensing, and the Sys-tem Reset message. The Timing Clock message isthe master clock which sets the tempo for playbackof a sequence. The Timing Clock message is sent24 times per quarter note. The Start, Continue, andStop messages are used to control playback of thesequence.

The Active Sensing signal is used to help eliminate"stuck notes" which may occur if a MIDI cable isdisconnected during playback of a MIDI sequence.Without Active Sensing, if a cable is disconnectedduring playback, then some notes may be left play-ing indefinitely because they have been activatedby a Note On message, but will never receive theNote Off. In transmitters which utilize Active Sens-ing, the Active Sensing message is sent once every300 ms by the transmitting device when this devicehas no other MIDI data to send. If a receiver who ismonitoring Active Sensing does not receive anytype of MIDI messages for a period of time exceed-ing 300 ms, the receiver may assume that the MIDIcable has been disconnected, and it should there-fore turn off all of its’ active notes. Use of ActiveSensing in MIDI transmitters and receivers is op-tional.

The System Reset message, as the name implies, isused to reset and initialize any equipment which re-ceives the message. This message is generally notsent automatically by transmitting devices, andmust be initiated manually by a user.

Page 8: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

8 AN27REV4

System Exclusive Messages

System Exclusive messages may be used to senddata such as patch parameters or sample data be-tween MIDI devices. Manufacturers of MIDIequipment may define their own formats for Sys-tem Exclusive data. Manufacturers are grantedunique identification (ID) numbers by the MMA orthe JMSC, and the manufacturer ID number is in-cluded as the second byte of the System Exclusivemessage. The manufacturers ID byte is followed byany number of data bytes, and the data transmissionis terminated with the EOX message. Manufactur-ers are required to publish the details of their Sys-tem Exclusive data formats, and othermanufacturers may freely utilize these formats,provided that they do not alter or utilize the formatin a way which conflicts with the original manufac-turers specifications.

There is also a MIDI Sample Dump Standard,which is a System Exclusive data format defined inthe MIDI specification for the transmission of sam-ple data between MIDI devices.

Running Status

MIDI data is transmitted serially. Musical eventswhich originally occurred at the same time must besent one at a time in the MIDI data stream, andtherefore these events will not actually be played atexactly the same time. However, the resulting de-lays are generally short enough that the events areperceived as having occurred simultaneously. TheMIDI data transmission rate is 31.35 kbit/s with10 bits transmitted per byte of MIDI data. Thus, a3 byte Note On or Note Off message takes about1 ms to be sent. For a person playing a MIDI instru-ment keyboard, the time skew between playback ofnotes when 10 keys are pressed simultaneouslyshould not exceed 10 ms, and this would not be per-ceptible. However, MIDI data being sent from a se-quencer can include a number of different parts. Ona given beat, there may be a large number of musi-cal events which should occur simultaneously, and

the delays introduced by serialization of this infor-mation might be noticeable.

To help reduce the amount of data transmitted inthe MIDI data stream, a technique called "runningstatus" may be employed. It is very common for astring of consecutive messages to be of the samemessage type. For instance, when a chord is playedon a keyboard, 10 successive Note On messagesmay be generated, followed by 10 Note Off mes-sages. When running status is used, a status byte issent for a message only when the message is not ofthe same type as the last message sent on the samechannel. The status byte for subsequent messagesof the same type may be omitted (only the databytes are sent for these subsequent messages). Theeffectiveness of running status can be enhanced bysending Note On messages with a velocity of zeroin place of Note Off messages. In this case, longstrings of Note On messages will often occur.Changes in some of the the MIDI controllers ormovement of the pitch bend wheel on a musical in-strument can produce a staggering number of MIDIchannel voice messages, and running status canalso help a great deal in these instances.

MIDI SEQUENCERS AND STANDARD MIDI FILES

MIDI messages are received and processed by aMIDI synthesizer in real time. When the synthesiz-er receives a MIDI "note on" message it plays theappropriate sound. When the corresponding "noteoff" message is received, the synthesizer turns thenote off. If the source of the MIDI data is a musicalinstrument keyboard, then this data is being gener-ated in real time. When a key is pressed on the key-board, a "note on" message is generated in realtime. In these real time applications, there is noneed for timing information to be sent along withthe MIDI messages. However, if the MIDI data isto be stored as a data file, and/or edited using a se-quencer, then some form of "time-stamping" forthe MIDI messages is required.

Page 9: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

AN27REV4 9

The International MIDI Association publishes aStandard MIDI Files specification, which providesa standardized method for handling time-stampedMIDI data. This standardized file format for time-stamped MIDI data allows different applications,such as sequencers, scoring packages, and multi-media presentation software, to share MIDI datafiles.

The specification for Standard MIDI Files definesthree formats for MIDI files. MIDI sequencers cangenerally manage multiple MIDI data streams, or"tracks". MIDI files having Format 0 must store allof the MIDI sequence data on a single track. This isgenerally useful only for simple "single track" de-vices. Format 1 files, which are the most commonlyused, store data as a collection of tracks. Format 2files can store several independent patterns.

SYNTHESIZER POLYPHONY AND TIMBRES

The polyphony of a sound generator refers to itsability to play more than one note at a time. Polyph-ony is generally measured or specified as a numberof notes or voices. Most of the early music synthe-sizers were monophonic, meaning that they couldonly play one note at a time. If you pressed fivekeys simultaneously on the keyboard of a mono-phonic synthesizer, you would only hear one note.Pressing five keys on the keyboard of a synthesizerwhich was polyphonic with four voices of polyph-ony would, in general, produce four notes. If thekeyboard had more voices (many modern soundmodules have 16, 24, or 32 note polyphony), thenyou would hear all five of the notes.

The different sounds that a synthesizer or soundgenerator can produce are often referred to as"patches", "programs", "algorithms", sounds, or"timbres". Modern synthesizers commonly useprogram numbers to represent different soundsthey produce. Sounds may then be selected byspecifying the program numbers (or patch num-bers) for the desired sound. For instance, a sound

module might use patch number 1 for its acousticpiano sound, and patch number 36 for its fretlessbass sound. The association of patch numbers tosounds is often referred to as a patch map. A MIDIProgram Change message is used to tell a devicereceiving on a given channel to change the instru-ment sound being used. For example, a sequencercould set up devices on channel 4 to play fretlessbass sounds by sending a Program Change messagefor channel four with a data byte value of 36 (this isthe General MIDI program number for the fretlessbass patch).

A synthesizer or sound generator is said to bemulti-timbral if it is capable of producing two ormore different instrument sounds simultaneously.Again, if a synthesizer can play five notes simulta-neously, then it is polyphonic. If it can produce apiano sound and an acoustic bass sound at the sametime, then it is also multi-timbral. A synthesizer orsound module which has 24 notes of polyphonyand which is 6 part multi-timbral (capable of pro-ducing 6 different timbres simultaneously) couldsynthesize the sound of a 6 piece band or orchestra.A sequencer could send MIDI messages for a pianopart on channel 1, bass on channel 2, saxophone onchannel 3, drums on channel 10, etc. A 16 partmulti-timbral synthesizer could receive a differentpart on each of MIDI’s 16 logical channels.

The polyphony of a multi-timbral synthesizer isusually allocated dynamically among the differentparts (timbres) being used. In our example, at a giv-en instant five voices might be used for the pianopart, two voices for the bass, one for the saxophone,and 6 voices for the drums, leaving 10 voices free.Note that some sounds utilize more than one voice,so the number of notes which may be produced si-multaneously may be less than the stated polypho-ny of the synthesizer, depending on which soundsare being utilized.

Page 10: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

10 AN27REV4

THE GENERAL MIDI (GM) SYSTEM

At the beginning of a MIDI sequence, a ProgramChange message is usually sent on each channelused in the piece in order to set up the appropriateinstrument sound for each part. The ProgramChange message tells the synthesizer which patchnumber should be used for a particular MIDI chan-nel. If the synthesizer receiving the MIDI sequenceuses the same patch map (the assignment of patchnumbers to sounds) that was used in the composi-tion of the sequence, then the sounds will be as-signed as intended. Unfortunately, prior to GeneralMIDI, there was no standard for the relationship ofpatch numbers to specific sounds for synthesizers.Thus, a MIDI sequence might produce differentsounds when played on different synthesizers, eventhough the synthesizers had comparable types ofsounds. For example, if the composer had selectedpatch number 5 for channel 1, intending this to bean electric piano sound, but the synthesizer playingthe MIDI data had a tuba sound mapped at patchnumber 5, then the notes intended for the pianowould be played on the tuba when using this syn-thesizer (even though this synthesizer may have afine electric piano sound available at some otherpatch number).

The General MIDI (GM) Specification, publishedby the International MIDI Association, defines aset of general capabilities for General MIDI Instru-ments. The General MIDI Specification includesthe definition of a General MIDI Sound Set (apatch map), a General MIDI Percussion map (map-ping of percussion sounds to note numbers), and aset of General MIDI Performance capabilities(number of voices, types of MIDI messages recog-nized, etc.). A MIDI sequence which has been gen-erated for use on a General MIDI Instrumentshould play correctly on any General MIDI synthe-sizer or sound module.

The General MIDI system utilizes MIDI channels1-9 and 11-16 for chromatic instrument sounds,

while channel number 10 is utilized for "key-based" percussion sounds. The General MIDISound set for channels 1-9 and 11-16 is given inTable 1. These instrument sounds are grouped into"sets" of related sounds. For example, programnumbers 1-8 are piano sounds, 6-16 are chromaticpercussion sounds, 17-24 are organ sounds, 25-32are guitar sounds, etc.

For the instrument sounds on channels 1-9 and 11-16, the note number in a Note On message is usedto select the pitch of the sound which will beplayed. For example if the Vibraphone instrument(program number 12) has been selected on channel3, then playing note number 60 on channel 3 wouldplay the middle C note (this would be the defaultnote to pitch assignment on most instruments), andnote number 59 on channel 3 would play B belowmiddle C. Both notes would be played using the Vi-braphone sound.

The General MIDI percussion map used for chan-nel 10 is given in Table 2. For these "key-based"sounds, the note number data in a Note On messageis used differently. Note numbers on channel 10 areused to select which drum sound will be played.For example, a Note On message on channel 10with note number 60 will play a Hi Bongo drumsound. Note number 59 on channel 10 will play theRide Cymbal 2 sound.

It should be noted that the General MIDI systemspecifies sounds using program numbers 1 through128. The MIDI Program Change message used toselect these sounds uses an 8-bit byte, which corre-sponds to decimal numbering from 0 through 127,to specify the desired program number. Thus, to se-lect GM sound number 10, the Glockenspiel, theProgram Change message will have a data bytewith the decimal value 9.

The General MIDI system specifies which instru-ment or sound corresponds with each pro-gram/patch number, but General MIDI does notspecify how these sounds are produced. Thus, pro-

Page 11: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

AN27REV4 11

Prog # Instrument Name Prog # Instrument Name Prog # Instrument Name1 Acoustic Grand Piano 44 Contrabass 87 Lead 7 (fifths)2 Bright Acoustic Piano 45 Tremolo Strings 88 Lead 8 (bass + lead)3 Electric Grand Piano 46 Pizzicato Strings 89 Pad 1 (new age)4 Honky-tonk Piano 47 Orchestral Harp 90 Pad 2 (warm)5 Electric Piano 1 48 Timpani 91 Pad 3 (polysynth)6 Electric Piano 2 49 String Ensemble 1 92 Pad 4 (choir)7 Harpsichord 50 String Ensemble 2 93 Pad 5 (bowed)8 Clavi 51 SynthStrings 1 94 Pad 6 (metallic)9 Celesta 52 SynthStrings 2 95 Pad 7 (halo)10 Glockenspiel 53 Choir Aahs 96 Pad 8 (sweep)11 Music Box 54 Voice Oohs 97 FX 1 (rain)12 Vibraphone 55 Synth Voice 98 FX 2 (soundtrack)13 Marimba 56 Orchestra Hit 99 FX 3 (crystal)14 Xylophone 57 Trumpet 100 FX 4 (atmosphere)15 Tubular Bells 58 Trombone 101 FX 5 (brightness)16 Dulcimer 59 Tuba 102 FX 6 (goblins)17 Drawbar Organ 60 Muted Trumpet 103 FX 7 (echoes)18 Percussive Organ 61 French Horn 104 FX 8 (sci-fi)19 Rock Organ 62 Brass Section 105 Sita20 Church Organ 63 SynthBrass 1 106 Banjo21 Reed Organ 64 SynthBrass 2 107 Shamisen22 Accordion 65 Soprano Sax 108 Koto23 Harmonica 66 Alto Sax 109 Kalimba24 Tango Accordion 67 Tenor Sax 110 Bag pipe25 Acoustic Guitar (nylon) 68 Baritone Sax 111 Fiddle26 Acoustic Guitar (steel) 69 Oboe 112 Shanai27 Electric Guitar (jazz) 70 English Horn 113 Tinkle Bell28 Electric Guitar (clean) 71 Bassoon 114 Agogo29 Electric Guitar (muted) 72 Clarinet 115 Steel Drums30 Overdriven Guitar 73 Piccolo 116 Woodblock31 Distortion Guitar 74 Flute 117 Taiko Drum32 Guitar harmonics 75 Recorder 118 Melodic Tom33 Acoustic Bass 76 Pan Flute 119 Synth Drum34 Electric Bass (finger) 77 Blown Bottle 120 Reverse Cymbal35 Electric Bass (pick) 78 Shakuhachi 121 Guitar Fret Noise36 Fretless Bass 79 Whistle 122 Breath Noise37 Slap Bass 1 80 Ocarina 123 Seashore38 Slap Bass 2 81 Lead 1 (square) 124 Bird Tweet39 Synth Bass 1 82 Lead 2 (sawtooth) 125 Telephone Ring40 Synth Bass 2 83 Lead 3 (calliope) 126 Helicopter41 Violin 84 Lead 4 (chiff) 127 Applause42 Viola 85 Lead 5 (charang) 128 Gunshot43 Cello 86 Lead 6 (voice)

Table 1. General MIDI Sound Set (All Channels Except 10)

Page 12: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

12 AN27REV4

gram number 1 should select the Acoustic GrandPiano sound on any General MIDI instrument.However, the Acoustic Grand Piano sound on twoGeneral MIDI synthesizers which use differentsynthesis techniques may sound quite different.

THE ROLAND GENERAL SYNTHESIZER (GS) STANDARD

The Roland General Synthesizer (GS) functions area superset of those specified for General MIDI. TheGS system includes all of the GM sounds (whichare referred to as "capital instrument" sounds), andadds new sounds which are organized as variationsof the capital instruments.

Variations are selected using the MIDI ControlChange message in conjunction with the ProgramChange message. The Control Change message issent first, and it is used to set controller number 0to some specified nonzero value indicating the de-sired variation (some capital sounds have severaldifferent variations). The Control Change messageis followed by a MIDI Program Change message

which indicates the program number of the relatedcapital instrument. For example, Capital instru-ment number 25 is the Nylon String Guitar. TheUkulele is a variation of this instrument. The Uku-lele is selected by sending a Control Change mes-sage which sets controller number 0 to a value of 8,followed by a program change message on thesame channel which selects program number 25.Sending the Program change message alone wouldselect the capital instrument, the Nylon String Gui-tar. Note also that a Control Change of controllernumber 0 to a value of 0 followed by a ProgramChange message would also select the capital in-strument.

The GS system also includes adjustable reverbera-tion and chorus effects. The effects depth for bothreverb and chorus may be adjusted on an individualMIDI channel basis using Control Change messag-es. The type of reverb and chorus sounds employedmay also be selected using System Exclusive mes-sages.

Note # Drum Sound Note # Drum Sound Note # Drum Sound35 Acoustic Bass Drum 51 Ride Cymbal 1 67 High Agogo36 Bass Drum 1 52 Chinese Cymbal 68 Low Agogo37 Side Stick 53 Ride Bell 69 Cabasa38 Acoustic Snare 54 Tambourine 70 Maracas39 Hand Clap 55 Splash Cymbal 71 Short Whistle40 Electric Snare 56 Cowbell 72 Long Whistle41 Low Floor Tom 57 Crash Cymbal 2 73 Short Guiro42 Closed Hi-Hat 58 Vibraslap 74 Long Guiro43 High Floor Tom 59 Ride Cymbal 2 75 Claves44 Pedal Hi-Hat 60 Hi Bongo 76 Hi Wood Block45 Low Tom 61 Low Bongo 77 Low Wood Block46 Open Hi-Hat 62 Mute Hi Conga 78 Mute Cuica47 Low Mid Tom 63 Open Hi Conga 79 Open Cuica48 Hi Mid Tom 64 Low Conga 80 Mute Triangle49 Crash Cymbal 1 65 High Timbale 81 Open Triangle50 High Tom 66 Low Timbale

Table 2. General MIDI Percussion Map (Channel 10)

Page 13: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

AN27REV4 13

SYNTHESIZER IMPLEMENTATIONS: FM VS. WAVETABLE

There are a number of different technologies or al-gorithms used to create sounds in music synthesiz-ers. Two widely used techniques are FrequencyModulation (FM) synthesis and Wavetable synthe-sis. FM synthesis techniques generally use one pe-riodic signal (the modulator) to modulate thefrequency of another signal (the carrier). If themodulating signal is in the audible range, then theresult will be a significant change in the timbre ofthe carrier signal. Each FM voice requires a mini-mum of two signal generators. These generators arecommonly referred to as "operators", and differentFM synthesis implementations have varying de-grees of control over the operator parameters. So-phisticated FM systems may use 4 or 6 operatorsper voice, and the operators may have adjustableenvelopes which allow adjustment of the attack anddecay rates of the signal. Although FM systemswere implemented in the analog domain on earlysynthesizer keyboards, modern FM synthesis im-plementations are done digitally.

FM synthesis techniques are very useful for creat-ing expressive new synthesized sounds. However,if the goal of the synthesis system is to recreate thesound of some existing instrument, this can gener-ally be done more accurately with digital sample-based techniques. Digital sampling systems storehigh quality sound samples digitally, and then re-play these sounds on demand. Digital sample-based synthesis systems may employ a variety ofspecial techniques, such as sample looping, pitchshifting, mathematical interpolation, and poly-phonic digital filtering, in order to reduce theamount of memory required to store the sound sam-ples (or to get more types of sounds from a givenamount of memory). These sample-based synthesissystems are often called "wavetable" synthesizers(the sample memory in these systems contains alarge number of sampled sound segments, and canbe thought of as a "table" of sound waveforms

which may be looked up and utilized when need-ed). A number of the special techniques employedin this type of synthesis are discussed in the follow-ing paragraphs.

WAVETABLE SYNTHESIS TECHNIQUES

Looping and Envelope Generation

One of the primary techniques used in wavetablesynthesizers to conserve sample memory space isthe looping of sampled sound segments. For a largenumber of instrument sounds, the sound can bemodeled as consisting of two major sections, the at-tack section and the sustain section. The attack sec-tion is the initial part of the sound, where theamplitude and the spectral characteristics of thesound may be changing very rapidly. The sustainsection of the sound is that part of the sound follow-ing the attack, where the characteristics of thesound are changing less dynamically. Figure 4shows a waveform with portions which could beconsidered the attack and the sustain sections indi-cated. In this example, the spectral characteristicsof the waveform remain constant throughout thesustain section, while the amplitude is decreasing ata fairly constant rate. This is an exaggerated exam-ple, in most natural instrument sounds, both thespectral characteristics and the amplitude continueto change through the duration of the sound. Thesustain section, if one can be identified, is that sec-tion for which the characteristics of the sound arerelatively constant.

A great deal of memory can be saved in wave-tablesynthesis systems by storing only a short segmentof the sustain section of the waveform, and thenlooping this segment during playback. Figure 5shows a two period segment of the sustain sectionfrom the waveform in Figure 4, which has beenlooped to create a steady state signal. If the originalsound had a fairly constant spectral content andamplitude during the sustained section, then thesound resulting from this looping operation should

Page 14: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

14 AN27REV4

be a good approximation of the sustained section ofthe original.

For many acoustic string instruments, the spectralcharacteristics of the sound remain fairly constantduring the sustain section, while the amplitude of thesignal decays. This can be simulated with a loopedsegment by multiplying the looped samples by a de-creasing gain factor during playback to get the de-sired shape or envelope. The amplitude envelope ofa sound is commonly modeled as consisting of somenumber of linear segments. An example is the com-monly used four part piecewise-linear Attack-De-cay-Sustain-Release (ADSR) envelope model.Figure 6 depicts a typical ADSR envelope shape,and Figure 7 shows the result of applying this enve-lope to the looped waveform from Figure 5.

A typical wavetable synthesis system would storeseparate sample segments for the attack section andthe looped section of an instrument. These samplesegments might be referred to as the initial soundand the loop sound. The initial sound is played oncethrough, and then the loop sound is played repeti-tively until the note ends. An envelope generatorfunction is used to create an envelope which is ap-propriate for the particular instrument, and this en-velope is applied to the output samples duringplayback. Playback of the initial wave (with the theAttack portion of the envelope applied) beginswhen a Note On message is received. The length ofthe initial sound segment is fixed by the number ofsamples in the segment, and the length of the At-tack and Decay sections of the envelope are gener-

Figure 4. Attack and Sustain Portions of a waveform

Figure 5. Looping a Sound Segment

Page 15: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

AN27REV4 15

ally also fixed for a given instrument sound. Thesustain section will continue to repeat the loop sam-ples while applying the Sustain envelope slope(which decays slowly in our examples), until aNote Off message is applied. The Note Off mes-sage triggers the beginning of the Release portionof the envelope.

Loop Length

The loop length is measured as a number of sam-ples, and the length of the loop should be equal toan integral number of periods of the fundamentalpitch of the sound being played (if this is not true,then an undesirable "pitch shift" will occur duringplayback when the looping begins). Of course, thelength of the pitch period of a sampled instrument

sound will generally not work out to be an integralnumber of sample periods. Therefore, it is commonto perform a "resampling" process on the originalsampled sound, to get new a new sound sample forwhich the pitch period is an integral number ofsample periods.

In practice, the length of the loop segment for anacoustic instrument sample may be many periodswith respect to the fundamental pitch of the sound.If the sound has a natural vibrato or chorus effect,then it is generally desirable to have the loop seg-ment length be an integral multiple of the period ofthe vibrato or chorus.

One-Shot Sounds

Figure 6. A Typical ADSR Amplitufe Envelope

Figure 7. ADSR Envelope Applied to Looped Sound Segment

Page 16: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

16 AN27REV4

The previous paragraphs discussed dividing a sam-pled sound into an attack section and a sustain sec-tion, and then using looping techniques tominimize the storage requirements for the sustainportion. However, some sounds, particularlysounds of short duration or sounds whose charac-teristics change dynamically throughout their dura-tion, are not suitable for looped playbacktechniques. Short drum sounds often fit this de-scription. These sounds are stored as a single sam-ple segment which is played once through with nolooping. This class of sounds are referred to as"one-shot" sounds.

Sample Editing and Processing

There are a number of sample editing and process-ing steps involved in preparing sampled sounds foruse in a wave-table synthesis system. The require-ments for editing the original sample data to identi-fy and extract the initial and loop segments, and forresampling the data to get a pitch period lengthwhich is an integer multiple of the sampling period,have already been mentioned.

Editing may also be required to make the endpointsof the loop segment compatible. If the amplitudeand the slope of the waveform at the beginning ofthe loop segment do not match those at the end ofthe loop, then a repetitive "glitch" will be heardduring playback of the looped section. Additionalprocessing may be performed to "compress" thedynamic range of the sound to improve the sig-nal/quantizing noise ratio or to conserve samplememory. This topic is addressed next.

When all of the sample processing has been com-pleted, the resulting sampled sound segments forthe various instruments are tabulated to form thesample memory for the synthesizer.

Sample Data Compression

The signal-to-quantizing noise ratio for a digitallysampled signal is limited by sample word size (thenumber of bits per sample), and by the amplitude of

the digitized signal. Most acoustic instrumentsounds reach their peak amplitude very quickly,and the amplitude then slowly decays from thispeak. The ear’s sensitivity dynamically adjusts tosignal level. Even in systems utilizing a relativelysmall sample word size, the quantizing noise levelis generally not perceptible when the signal is nearmaximum amplitude. However, as the signal leveldecays, the ear becomes more sensitive, and thenoise level will appear to increase. Of course, usinga larger word size will reduce the quantizing noise,but there is a considerable price penalty paid if thenumber of samples is large.

Compression techniques may be used to improvethe signal-to-quantizing noise ratio for some sam-pled sounds. These techniques reduce the dynamicrange of the sound samples stored in the samplememory. The sample data is decompressed duringplayback to restore the dynamic range of the signal.This allows the use of sample memory with asmaller word size (smaller dynamic range) than isutilized in the rest of the system. There are a num-ber of different compression techniques which maybe used to compress the dynamic range of a signal.

For signals which begin at a high amplitude and de-cay in a fairly linear fashion, a simple compressiontechnique can be effective. If the slope of the decayenvelope of the signal is estimated, then an enve-lope with the complementary slope (the negative ofthe decay slope) can be constructed and applied tothe original sample data. The resulting sample data,which now has a flat envelope, can be stored in thesample memory, utilizing the full dynamic range ofthe memory. The decay envelope can then be ap-plied to the stored sample data during sound play-back to restore the envelope of the original sound.

Note that there is some compression effect inherentin the looping techniques described earlier. If theloop segment is stored at an amplitude level whichmakes full use of the dynamic range available inthe sample memory, and the processor and D/A

Page 17: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

AN27REV4 17

converters used for playback have a wider dynamicrange than the sample memory, then the applicationof a decay envelope during playback will have adecompression effect similar to that described inthe previous paragraph.

Pitch Shifting

In order to minimize sample memory requirements,wavetable synthesis systems utilize pitch shifting,or pitch transposition techniques, to generate anumber of different notes from a single sound sam-ple of a given instrument. For example, if the sam-ple memory contains a sample of a middle C noteon the acoustic piano, then this same sample datacould be used to generate the C# note or D noteabove middle C using pitch shifting.

Pitch shifting is accomplished by accessing thestored sample data at different rates during play-back. For example, if a pointer is used to addressthe sample memory for a sound, and the pointer isincremented by one after each access, then the sam-ples for this sound would be accessed sequentially,resulting in some particular pitch. If the pointer in-crement was two rather than one, then only everysecond sample would be played, and the resultingpitch would be shifted up by one octave (the fre-quency would be doubled).

Frequency Accuracy

In the previous example, the sample memory ad-dress pointer was incremented by an integer num-ber of samples. This allows only a limited set ofpitch shifts. In a more general case, the memorypointer would consist of an integer part and a frac-tional part, and the increment value could be a frac-tional number of samples. The integer part of theaddress pointer is used to address the sample mem-ory, the fractional part is used to maintain frequen-cy accuracy. For example if the increment valuewas equivalent to 1/2, then the pitch would be shift-ed down by one octave (the frequency would behalved). When non-integer increment values are

utilized, the frequency resolution for playback isdetermined by the number of bits used to representthe fractional part of the address pointer and the ad-dress increment parameter.

Interpolation

When the fractional part of the address pointer isnon-zero, then the "desired value" falls betweenavailable data samples. Figure 8 depicts a simpli-fied addressing scheme wherein the Address Point-er and the increment parameter each have a 4-bitinteger part and a 4-bit fractional part. In this case,the increment value is equal to 1 1/2 samples. Verysimple systems might simply ignore the fractionalpart of the address when determining the samplevalue to be sent to the D/A converter. The data val-ues sent to the D/A converter when using this ap-proach are indicated in the Figure 8, case I. Aslightly better approach would be to use the nearestavailable sample value. More sophisticated sys-tems would perform some type of mathematical in-terpolation between available data points in orderto get a value to be used for playback. Values whichmight be sent to the D/A when interpolation is em-ployed are shown as case II. Note that the overallfrequency accuracy would be the same for bothcases indicated, but the output is severely distortedin the case where interpolation is not used.

There are a number of different algorithms used forinterpolation between sample values. The simplestis linear interpolation. With linear interpolation, in-terpolated value is simply the weighted average ofthe two nearest samples, with the fractional addressused as a weighting constant. For example, if theaddress pointer indicated an address of (n+K),where n is the integer part of the address and K isthe fractional part, than the interpolated value canbe calculated as s(n+K) = (1-K)s(n) + (K)s(n+1),where s(n) is the sample data value at address n.More sophisticated interpolation techniques cancan be utilized to further reduce distortion, butthese techniques are computationally expensive.

Page 18: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

18 AN27REV4

Oversampling

Oversampling of the sound samples may also beused to improve distortion in wavetable synthesissystems. For example, if 4X oversampling wereutilized for a particular instrument sound sample,then an address increment value of 4 would be usedfor playback with no pitch shift. The data pointschosen during playback will be closer to the "de-sired values", on the average, than they would be ifno oversampling were utilized because of the in-creased number of data points used to represent thewaveform. Of course, oversampling has a high costin terms of sample memory requirements.

In many cases, the best approach may be to utilizelinear interpolation combined with varying degreesof oversampling where needed. The linear interpo-

lation technique provides reasonable accuracy formany sounds, without the high penalty in terms ofprocessing power required for more sophisticatedinterpolation methods. For those sounds whichneed better accuracy, oversampling is employed.With this approach, the additional memory re-quired for oversampling is only utilized where it ismost needed. The combined effect of linear inter-polation and selective oversampling can produceexcellent results.

Splits

When the pitch of a sampled sound is changed dur-ing playback, the timbre of the sound is changedsomewhat also. For small changes in pitch (up to afew semitones), the timbre change is generally notnoticed. However, if a large pitch shift is used, the

Figure 8. Sample Memory Addressing and Interpolation

Page 19: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

AN27REV4 19

resulting note will sound unnatural. Thus, a partic-ular sample of an instrument sound will be usefulfor recreating a limited range of notes using pitchshifting techniques. To get coverage of the entireinstrument range, a number of different samples ofthe instrument are used, and each of these samplesis used to synthesize a limited range of notes. Thistechnique can be thought of as splitting a musicalinstrument keyboard into a number of ranges ofnotes, with a different sound sample used for eachrange. Each of these ranges is referred to as a split,or key split.

Velocity splits refer to the use of different samplesfor different note velocities. Using velocity splits,one sample might be utilized if a particular note isplayed softly, where a different sample would beutilized for the same note of the same instrumentwhen played with a higher velocity.

Note that the explanations above refer to the use ofkey splits and velocity splits in the sound synthesisprocess. In this case, the different splits utilize dif-ferent samples of the same instrument sound. Keysplitting and velocity splitting techniques are alsoutilized in a performance context. In the perfor-mance context, different splits generally producedifferent instrument sounds. For instance, a key-board performer might want to set up a key splitwhich would play a fretless bass sound from thelower octaves of his keyboard, while the upper oc-taves play the vibraphone. Similarly, a velocitysplit might be set up to play the acoustic pianosound when keys are played with soft to moderatevelocity, but an orchestral string sound plays whenthe keys are pressed with higher velocity.

Aliasing Noise

The previous paragraph discussed the timbrechanges which result from pitch shifting. The resa-mpling techniques used to shift the pitch of a storedsound sample can also result in the introduction of

aliasing noise into an instrument sound. The gener-ation of aliasing noise can also limit the amount ofpitch shifting which may be effectively applied to asound sample. Sounds which are rich in upper har-monic content will generally have more of a prob-lem with aliasing noise. Low-pass filtering appliedafter interpolation can help eliminate the undesir-able effect of aliasing noise. The use of oversam-pling also helps eliminate aliasing noise.

LFOs for vibrato and tremolo

Vibrato and tremolo are effects which are oftenproduced by musicians playing acoustic instru-ments. Vibrato is basically a low-frequency modu-lation of the pitch of a note, while tremolo ismodulation of the amplitude of the sound. Theseeffects are simulated in synthesizers by implement-ing low-frequency oscillators (LFOs) which areused to modulate the pitch or amplitude of the syn-thesized sound being produced. Natural vibrato andtremolo effects tend to increase in strength as a noteis sustained. This is accomplished in synthesizersby applying an envelope generator to the LFO. Forexample, a flute sound might have a tremolo effectwhich begins at some point after the note hassounded, and the tremolo effect gradually increasesto some maximum level, where it remains until thenote stops sounding.

Layering

Layering refers to a technique in which multiplesounds are utilized for each note played. This tech-nique can be used to generate very rich sounds, andmay also be useful for increasing the number of in-strument patches which can be created from a lim-ited sample set. Note that layered sounds generallyutilize more than one voice of polyphony for eachnote played, and thus the number of voices avail-able is effectively reduced when these sounds arebeing used.

Page 20: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

20 AN27REV4

Polyphonic Digital Filtering for Timbre Enhancement

It was mentioned earlier that low-pass filtering maybe used to help eliminate noise which may be gen-erated during the pitch shifting process. There arealso a number of ways in which digital filtering isused in the timbre generation process to improvethe resulting instrument sound. In these applica-tions, the digital filter implementation is polyphon-ic, meaning that a separate filter is implemented foreach voice being generated, and the filter imple-mentation should have dynamically adjustable cut-off frequency and/or Q.

For many acoustic instruments, the character of thetone which is produced changes dramatically as afunction of the amplitude level at which the instru-ment is played. For example, the tone of an acous-tic piano may be very bright when the instrument isplayed forcefully, but much more mellow when itis played softly. Velocity splits, which utilize dif-ferent sample segments for different note veloci-ties, can be implemented to simulate thisphenomena. Another very powerful technique is toimplement a digital low-pass filter for each notewith a cutoff frequency which varies as a functionof the note velocity. This polyphonic digital filterdynamically adjusts the output frequency spectrumof the synthesized sound as a function of note ve-locity, allowing a very effective recreation of theacoustic instrument timbre.

Another important application of polyphonic digi-tal filtering is in smoothing out the transitions be-tween samples in key-based splits. At the borderbetween two splits, there will be two adjacent noteswhich are based on different samples. Normally,one of these samples will have been pitch shiftedup to create the required note, while the other willhave been shifted down in pitch. As a result, thetimbre of these two adjacent notes may be signifi-cantly different, making the split obvious. Thisproblem may be alleviated by employing a poly-

phonic digital filter which uses the note number tocontrol the filter characteristics. A table may beconstructed containing the filter characteristics foreach note number of a given instrument. The filtercharacteristics are chosen to compensate for thepitch shifting associated with the key splits used forthat instrument.

It is also common to control the characteristics ofthe digital filter using an envelope generator or anLFO. The result is an instrument timbre which hasa spectrum which changes as a function of time.For example, It is often desirable to generate a tim-bre which is very bright at the onset, but whichgradually becomes more mellow as the note de-cays. This can easily be done using a polyphonicdigital filter which is controlled by an envelopegenerator.

THE PC TO MIDI INTERFACE AND THE MPU-401

To use MIDI with a personal computer, a PC toMIDI interface product is generally required (thereare a few personal computers which comeequipped with built-in MIDI interfaces). There area number of MIDI interface products for PCs. Themost common types of MIDI interfaces for IBMcompatibles are add-in cards which plug into an ex-pansion slot on the PC bus, but there are also serialport MIDI interfaces (connects to a serial port onthe PC) and parallel port MIDI interfaces (connectsto the PC printer port). The fundamental functionof a MIDI interface for the PC is to convert paralleldata bytes from the PC data bus into the serialMIDI data format and vice versa (a UART func-tion). However, "smart" MIDI interfaces may pro-vide a number of more sophisticated functions,such as generation of MIDI timing data, MIDI databuffering, MIDI message filtering, synchronizationto external tape machines, and more.

The defacto standard for MIDI interface add-incards for the PC is the Roland MPU-401 interface.The MPU-401 is a smart MIDI interface, which

Page 21: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

AN27REV4 21

also supports a dumb mode of operation (often re-ferred to as "pass-through mode" or "UARTmode"). There are a number of MPU-401 compati-ble MIDI interfaces on the market. In addition,many add-in sound cards include built-in MIDI in-terfaces which implement the UART mode func-tions of the MPU-401.

COMPATIBILITY CONSIDERATIONS FOR MIDI APPLICATIONS ON THE PC

There are two levels of compatibility which mustbe considered for MIDI applications running on thePC. First is the compatibility of the applicationwith the MIDI interface being used. The second isthe compatibility of the application with the MIDIsynthesizer. Compatibility considerations underDOS and the Microsoft Windows operating systemare discussed in the following paragraphs.

DOS Applications

DOS applications which utilize MIDI synthesizersinclude MIDI sequencing software, music scoringapplications, and a variety of games. In terms ofMIDI interface compatibility, virtually all of theseapplications support the MPU-401 interface, andmost utilize only the UART mode. These applica-tions should work correctly if the PC is equippedwith a MPU-401, a full-featured MPU-401 com-patible, or a sound card with a MPU-401 UART-mode capability. Other MIDI interfaces, such as se-rial port or parallel port MIDI adapters, will onlywork if the application provides support for thatparticular model of MIDI interface.

A particular application may provide support for anumber of different models of synthesizers orsound modules. Prior to the General MIDI stan-dard, there was no widely accepted standard patchset for synthesizers, so applications generally need-ed to provide support for each of the most popularsynthesizers at the time. If the application did notsupport the particular model of synthesizer orsound module that was attached to the PC, then the

sounds produced by the application might not bethe sounds which were intended. Modern applica-tions can provide support for a General MIDI (GM)synthesizer, and any GM-compatible sound sourceshould produce the correct sounds. Some othermodels which are commonly supported are the Ro-land MT-32, the Roland LAPC-1, and the RolandSound Canvas. The Roland MT-32 was an externalMIDI sound module which utilized Roland’s Lin-ear Additive (LA) synthesis, and the MT-32 com-bined with an MPU-401 interface became apopular MIDI synthesis platform for the PC. TheLAPC-1 was a PC add-in card which combined theMT-32 synthesis function with the MPU-401 MIDIinterface. The Sound Canvas is Roland’s GeneralSynthesizer (GS) sound module, and this unit hasbecome an industry standard.

Microsoft Windows and the Multimedia PC (MPC)

The number of applications for high quality audiofunctions on the PC (including music synthesis)grew explosively after the introduction of Mi-crosoft Windows 3.0 with Multimedia Extensions("Windows with Multimedia") in 1991. The Multi-media PC (MPC) specification, originally pub-lished by Microsoft in 1991 and now published bythe Multimedia PC Marketing Council (a subsid-iary of the Software Publishers Association), spec-ifies minimum requirements for multimedia-capable Personal Computers. A system whichmeets these requirements will be able to take fulladvantage of Windows with Multimedia. Note thatmany of the functions originally included in theMultimedia Extensions have been incorporatedinto the Windows 3.1 operating system.

The audio capabilities utilized by Windows 3.1 orWindows with Multimedia include audio recordingand playback (linear PCM sampling), music syn-thesis, and audio mixing. In order to support the re-quired music synthesis functions, MPC-compliant

Page 22: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

22 AN27REV4

audio adapter cards must have on-board music syn-thesizers.

The MPC specification defines two types of syn-thesizers; a "Base Multitimbral Synthesizer", andan "Extended Multitimbral Synthesizer". Both theBase and the Extended synthesizer must supportthe General MIDI patch set. The difference be-tween the Base and the Extended synthesizer re-quirements is in the minimum number of notes ofpolyphony, and the minimum number of simulta-neous timbres which can be produced. Base Multi-timbral Synthesizers must be capable of playing 6"melodic notes" and "2 percussive" notes simulta-neously, using 3 "melodic timbres" and 2 "percus-sive timbres". The formal requirements for anExtended Multitimbral Synthesizer are only that itmust have capabilities which exceed those speci-fied for a Base Multitimbral Synthesizer. However,the "goals" for an Extended synthesizer include theability to play 16 melodic notes and 8 percussivenotes simultaneously, using 9 melodic timbres and8 percussive timbres.

The MPC specification also includes an authoringstandard for MIDI composition. This standard re-quires that each MIDI file contain two arrange-ments of the same song, one for Base synthesizersand one for Extended synthesizers. The MIDI datafor the Base synthesizer arrangement is sent onMIDI channels 13 - 16 (with the percussion trackon channel 16), and the Extended synthesizer ar-rangement utilizes channels 1 - 10 (percussion is onchannel 10). This technique allows a single MIDIfile to play on either type of synthesizer.

Windows applications generally address hardwaredevices such as MIDI interfaces or synthesizersthrough the use of drivers. The drivers provide ap-plications software with a common interfacethrough which hardware may be accessed, and thissimplifies the hardware compatibility issue. Beforea synthesizer is used, a suitable driver must be in-stalled using the Windows Driver applet within the

Control Panel. The device drivers supplied withWindows 3.1 include a driver for the MPU-401/LAPC-1 MIDI interface, and a driver for theoriginal AdLib FM synthesizer card. Most otherMIDI interfaces and/or synthesizers are shippedwith their own Windows drivers.

When a MIDI interface or synthesizer is installed inthe PC and a suitable device driver has been loaded,the Windows MIDI Mapper applet will appearwithin the Control Panel. MIDI messages are sentfrom an application to the MIDI Mapper, whichthen routes the messages to the appropriate devicedriver. The MIDI Mapper may be set to performsome filtering or translations of the MIDI messagesin route from the application to the driver. The pro-cessing to be performed by the MIDI Mapper is de-fined in the MIDI Mapper Setups, Patch Maps, andKey Maps.

MIDI Mapper Setups are used to assign MIDIchannels to device drivers. For instance, If youhave an MPU-401 interface with a General MIDIsynthesizer and you also have a Creative LabsSoundblaster card in your system, you might wishto assign channels 13 to 16 to the Ad Lib driver(which will drive the Base-level FM synthesizer onthe Soundblaster), and assign channels 1 - 10 to theMPU-401 driver. In this case, MPC compatibleMIDI files will play on both the General MIDI syn-thesizer and the FM synthesizer at the same time.The General MIDI synthesizer will play the Ex-tended arrangement on MIDI channels 1 - 10, andthe FM synthesizer will play the Base arrangementon channels 13-16. The MIDI Mapper Setups canalso be used to change the channel number of MIDImessages. If you have MIDI files which were com-posed for a General MIDI instrument, and you areplaying them on a Base Multitimbral Synthesizer,you would probably want to take the MIDI percus-sion data coming from your application on channel10 and send this information to the device driver onchannel 16.

Page 23: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument

AN27

AN27REV4 23

The MIDI Mapper patch maps are used to translatepatch numbers when playing MPC or GeneralMIDI files on synthesizers which do not use theGeneral MIDI patch numbers. Patch maps can alsobe used to play MIDI files which were arranged fornon-GM synthesizers on GM synthesizers. For ex-ample, the Windows-supplied MT-32 patch mapcan be used when playing GM-compatible .MIDfiles on the Roland MT-32 sound module or LAPC-1 sound card.

The MIDI Mapper key maps perform a similarfunction, translating the key numbers contained inMIDI Note On and Note Off messages. This capa-bility is useful for translating GM-compatible per-cussion parts for playback on non-GM synthesizersor vice-versa. The Windows-supplied MT-32 keymap changes the key-to-drum sound assignmentsused for General MIDI to those used by the MT-32and LAPC-1.

Some MIDI applications, such as MIDI sequencersoftware packages, can be set to make use of the

MIDI Mapper, or to address the device driver di-rectly (bypassing the MIDI Mapper). Other Win-dows applications always utilize the MIDI Mapper.

SUMMARY

The MIDI protocol provides an efficient format forconveying musical performance data, and the Stan-dard MIDI Files specification ensures that differentapplications can share time-stamped MIDI data.The storage efficiency of the MIDI file formatmakes MIDI an attractive vehicle for generation ofsounds in multimedia applications, computergames, or high-end karaoke equipment. The Gener-al MIDI system provides a common set of capabil-ities and a common patch map for high polyphony,multi-timbral synthesizers. General MIDI-compat-ible Synthesizers employing high quality wavet-able synthesis techniques provide an ideal MIDIsound generation facility for multimedia applica-tions.

Page 24: AN27 Application Note Design By Example/chapter11/miditut.pdfAN27 Application Note A TUTORIAL ON MIDI AND WAVETABLE MUSIC SYNTHESIS By Jim Heckroth INTRODUCTION The Musical Instrument