What is the MIDI?

Definition of MIDI

MIDI(Musical Instrument Digital Interface) Musical Instrument Digital Interface is proposed in the early 1980s to solve the communication problem between electroacoustic instruments. MIDI is the most widely used standard music format in the music editing world. It can be called “computer readable sheet music”. It uses digital control signals of musical notes to record music. A complete MIDI music is only a few tens of kilobytes in size and can contain dozens of music tracks. Almost all modern music is synthesized using MIDI plus a sound library. MIDI transmits not sound signals, but notes, control parameters and other instructions, which tell the MIDI device what to do and how to do it, such as which note to play, how loud and so on. They are represented collectively as MIDI messages. The transmission adopts asynchronous serial communication, and the baud rate of standard communication is 31.25×(1±0.01) KBaud. — From Baidu Encyclopedia

MIDI standard protocols GM, GS, and XG

  • GS:MIDI this play instruction sequence file is the instrument digital interface shorthand, is by Japan and the United States several famous electronic instrument manufacturers jointly developed in 1983 digital music/electronic synthesizer unified international standard, its emergence to solve the problem of digital music instrument compatibility between different manufacturers! Japanese Roland company in 1984 put forward the GS standard, greatly enhanced the performance of music.
  • GM: In order to facilitate musicians to widely use different synthesizer equipment and facilitate the exchange of MIDI files, the International MIDI Producers Association (MMA) developed the general MIDI standard – GM in 1991, which is based on the General synthesizer GS standard by Roland Corporation of Japan
  • XG:YAMAHA launched its OWN XG MIDI format on GM standard in 1994, increasing the number of instrument groups, expanding the scope of MIDI standard definition, in the range of professional music has been widely used!

General MIDI standard

The piano

Acoustic Grand Piano Grand piano
Bright Acoustic Piano Bright grand piano

The MIDI jack

Traditional interfaces

Type B interface. –

The above lists only two common interfaces

MIDI data parsing

The head of data

Audio track block

The MIDI events

MIDI file composition

< header block > + < track block data >Copy the code

1. File header block

< identifier string >(4 bytes) + < header data area length >(4 bytes) + < header data area >(6 bytes)Copy the code
  • A string of flags that refers to “MThd” or “MTrk”, where MThd is the header block type and MTrk is the track type. So the header flag is the ASCII code of MThd, which in hexadecimal notation is 4D 54 68 64.

  • The length of the header data area refers to the length of the following header data area. Because the length is 6 bytes, the value is fixed as 00 00 00 06.

  • The first block data area, consisting of 6 bytes, is ff ff NN NN DD DD.

    • The first two bytes ff ff specify the MIDI file format
    00 00 indicates that there is only one track. 00 01 indicates that there are multiple synchronous tracks. 00 10 indicates that there are multiple independent tracksCopy the code
    • Nn nn specifies the number of tracks, usually greater than 1, because there are global tracks in addition to the main track.
    • Dd Dd Specifies the basic time format
    Dd The highest bit of DD is the marker bit. 0 is used for timing with ticks and the following data is a quaver ticks. 1 is used to time the SMPTE format. The following value defines the number of SMTPE frames per second and the TICK of each SMTPE frame. Using MIDI as our example, dd dd data is 01 E0, indicating that ticks are used for timing. 1E0 in decimal is 480, that is, each quaver contains 480ticks. The later event times are all in ticks.Copy the code

2. The audio track

< flag string >(4 bytes) + < track block data area length >(4 bytes) + < track block data area >(multiple MIDI events)Copy the code
  • As mentioned above, the track block identifier string is “MTrk”, also recording ASCII code, expressed in hexadecimal is 4D 54 72 6b. The length of the track block data area is also fixed at 4 bytes, specifying the length of the following data area.

  • Composition of MIDI events

    <delta time> + <MIDI message >Copy the code
    • Delta time is expressed in dynamic bytes, in tick.
    • MIDI message, consisting of one status byte + multiple data bytes. The status byte can be read asmethodsThe data bytes can be understood as the values of this methodparameter.
    • The highest byte of the status byte is always 1, because it ranges from 128 to 255, and the highest byte of the data byte is always 0, so it ranges from 0 to 127.
    • Messages can be divided into channel messages and system messages according to their properties. Channel messages operate on a single MIDI Channel, whose Channel is represented by the lower 4 bits of the status byte, from 0F there are 16. The following table shows the class of channel messages, where X is 016.
Status byte Functional description Data byte description
8X Release notes. 1 byte: note sign (007F / 2 bytes: force (007F)
9X Press the notes. 1 byte: note sign (007F / 2 bytes: force (007F)
AX After touching the notes 1 byte: note sign (007F / 2 bytes: force (007F)
BX Controller change 1 byte: controller number (00)79) / 2 bytes: controller parameter (00)7F)
CX Change the musical instrument 1 byte: instrument number (00~7F)
DX Channel trigger pressure 1 byte: Pressure (00~7F)
EX Bend the sound wheel 1 byte: low byte of the voice wheel change value / 2 byte: high byte of the voice wheel change value
  • There is also a special status byte FF that represents non-MIDI events, also known as meta-events. The syntax for meta-events is as follows:

    FF + < type bytes >(1 byte) + < data bytes length > + < data bytes >Copy the code

    If the number of bytes of data is not fixed, but has the previous dynamic bytes specified, it is represented by —

    species Functional description Data byte length Data byte description
    00 Set the track sequence 2 The sequence sign 00 00-FF FF
    01 Text event Text information
    02 Copyright notice Copyright information
    03 Specifies the name of the song/track Song name (when used for a global track)/ name of the track
    04 Specify the musical instrument Name of the instrument
    05 The lyrics The lyrics
    06 tag Tag (usually in a format 0 track, or the first track in format 1.)
    07 annotation Describe some of the actions or events that occur at this point
    2F Audio tracks to terminate End of track sign (mandatory)
    51 The specified speed Set speed, measured in subtlety, is the time of a quarter note
    58 Specify the beat slightly

The soft sound source

Data formats supported by iOS

IOS supports sf2 data format (SoundFont V2.0)

Timbre store

SoundFont is a sound library, also known as soft sound source

Composition of timbre

Samples -> Instruments -> Presents

Detects the type of sound source in the sound library

There is a software called Polyphone that can open soft audio sources and check the number of monophonic notes in sf2 files. Some sf2 files have only one monophonic note, piano files, and some contain 128 (standard MIDI,GM specified 128) + medium audio sources, so that the tone can be switched

Midi

Midi connection test tool Midi Wrench

Next chapter: iOS device development of a MIDI file player, switch music source, and do the operation of response