MIDI file format

xiaoxiao2021-03-06  51

The MIDI file consists of Chunks:

Composition of each Chunk:

Type length data 4 bytes 4 bytes (previously specified) length

A 4- Byte Chunk Type (ASCII) A 4-Byte Length (32-bit, MSB First) (previously specified) length data

There are two types of Chunks:

HEADER CHUNKS

There is a chunk sign "mthd"

TRACK CHUNKS

There is a chunk sign "mtrk"

A MIDI file consists of a header chunk and a close one or more TRACK CHUNKS.

In the chunks structure, it is strictly regulated since the length zone. It may be contained in CHUNKS to be ignored in addition to "MTHD" or "MTRK". The MIDI manual requires that the software can handle unexpected Chunk and ignore the entire CHUNK.

<--- chunk --->

Type length data MIDI file:

MTHD 6 Mtrn ...: mtrk ...

Numerical representation

In the MIDI file, in addition to basic MIDI data, there is also a variable data (type). Such as: Delta-Times and Meta-Events.

Here are some information about such numbers, they usually have 1 to 2 formats below:

Differential number variable length

Binary number

Storage of the binary:

Each byte 8-bit MSB first (the leftmost byte power (or digit)

(Unless other description)

Variable length number

This variable length is for convenience of representing any extensive integers without having to create an integer of a fixed width.

A variable length number is represented as a continuous 7-bit data. From the highest bit to the lowest position, the last byte bit7 is equal to 0, the previous byte bit7 is equal to 1.

example:

Number variable length

Decimal Hex Binary Binary Hex - abcd aaaabbbbccccdddd 100000aa 1aabbbbc 0cccdddd - 0: 127 00: 7F 0000 0000: 0111 1111 0000 0000: 0111 1111 00: 7F 128: 16383 80: 3FFF 00000000 10000000: 00111111 11111111 10000001 00000000 : 11111111 011111118100: FF 7F 1000 03E8 11 1110 1000 10000111 01101000 87 68 100000 010 0100 10111101 10000100 01000000 BD 84 40

Thus, you can find from the above example: small number (0 ~ 127) can be represented by one byte. And (compared) large numbers can also be expressed.

In the MIDI file, the maximum number is 0FFF, FFFF. This specified variable length allows for the use of 32-bit integers.

HEADER CHUNKS

The HEADER CHUNK data section includes three 16-bit (data) regions. This area description: (MIDI file) format, the number of TRACK and the time setting of MIDI.

The length of Header Chunk is 6 bytes. No matter how software must follow this principle. Even if it is greater than expected, any unexpected data is ignored. HEADER CHUNK

CHUNK Type Length Data 4 byte (ASCII) 4 bytes (32-bit binary) <- Length (= 6 bytes) -> 16-bit 16-bit 16-bit MTHD

The length of the CHUNK data section. This is a 32-bit binary number, MSB first. This is set to 6 in the MIDI 1.0 file manual. However, taking into account the future expansion, (Hope) Any of the author of any MIDI file can cope with large Header Chunks.

MIDI file format. This is a 16-bit binary number, MSB first. Effective formats are: 0, 1 and 2.

The number of TRACK Chunk in the MIDI file. This is a 16-bit binary number, MSB first.

This defines the number of Delta-TIMEs in the MIDI file (one) unit. This is a 16-bit binary number, MSB first.

There are two formats of the following, depend on the highest bit value.

Bit:

15 14 ... 8 7 ... 0

0 1/4 Musical Notes Tick 1 - Frame / Second Ticks / Frame

Bit 15 = 0:

BITS 0-14

The number of DELTA-TIMEs per 1/4 note.

Bit 15 = 1:

BITS 0-7

The number of Delta-TIMEs for each SMTPE frame.

BITS 8-14

Negative numbers, indicate the number of SMTPE frames per second. The effective number meets the MTC Quarter Frame message.

-24 = 24 frames per second

-25 = 25 frames / sec

-29 = 30 frames / sec, DROP FRAME

-30 = 30 frames / sec, Non-Drop Frame

MIDI file formats

There are three changes in the MIDI file:

Format 0 ... accommodate a single Track. Format 1 ... accommodate one and multiple synchronous tracks (all Track simultaneously play). Format 2 ... accommodate one and multiple independent Tracks (all TRACK stand-alone play).

MIDI file format 0

Format 0 MIDI file includes a header-chunk and a track-chunk.

This Track-Chunk includes all notes and beats messages.

MIDI file format 1

Format 1 MIDI file includes a Header-Chunk and multiple track-chunks, all TRACK play simultaneously.

The first Track in format 1 is dedicated. It looks "Tempo Map". It includes all Meta-Event: a beam marks, tape, tag / track name, tone number, tag, and SMTPE offset. In format 1 (these) will be placed in the first TRACK.

MIDI file format 2

The format 2 MIDI file includes a Header-Chunk and multiple track-chunks, each of which exhibits an independent order.

TRACK CHUNKS

The data part of the Track Chunk is composed of a pair of . is a must, 0 is a valid Delta-Time.

TRACK CHUNK

Type length data 4 byte (ASCII) 4 bytes (32-bit binary number) <- length -> (binary number) mtrk ...

"Tick" relative to the previous event is a variable length number.

One of the following:

·

·

·

event

Note: There is no clear separator between and . This is because Delta-Times and Event have a length definition.

Delta-Time defines the highest bit of the last byte equal to 0. The MIDI CHANNEL message has a length definition. Sysex-Events and Meta-Events have a clear length zone.

MIDI event

MIDI CHANNEL message contains:

Channel Voice Messages Channel Mode Messages

Running Status is typically represented by the same state in the MIDI file. Running status can also be canceled.

SYSEX event

(Detailed Description of System Advanced Messages) is satisfactory and relative to MIDI Channel messages. can be used.

SYSEX-Events popular two styles:

SYSEX Events F0 F0 SYSEX EVENT

This result in the F0 (the beginning of the message) being sent. Next, it is .

A variable length number, indicating the length of

f0 is sent as a MIDI message. F7 f7 sysex evenet (or 'escape ")

This causes to be sent, without other additional numbers.

A variable length number, indicating the length of

is sent as a MIDI message.

In the case above, the end F7 of the message is not automatically sent. It must be explicitly included in or .

Most system advanced messages are very simple, and as a single package is sent. Started at F0, ending in F7. This is very easy to apply to the F0 form of .

However, some system advanced messages are accustomed to real-time control devices. How to synthesize a system advanced message composed of a series of 'part' with an appropriate delay. Because, it is possible to interrupt one message in an event, there is a certain delay. This is a F7 form that can apply .

In fact, F7 Sysex Event is accustomed to incorporating any_data in the MIDI stream. For example, a MIDI system real-time message (although it is not satisfactory).

example 1:

General Message: F0 7e 09 03 01 01 F7 (Sample Dump Request - Device 9, Sample Number 257) Yes: F0 06 7e 09 03 01 01 F7 or Alternating: F7 07 F0 7e 09 03 01 01 F7 Example 2 :

The MIDI system real-time message "stop" uses F7 01 FC when "continues" with F7 01 FB.

Suppose: You want to stop an external device - drum, send a "stop", then "Continue" after 48 Delta-Time units. The complete DELTA-TEM event sequence is like this:

00 F7 01 FC 30 F7 01 FB

Meta event

Meta Events is used to represent track names, lyrics, prompts, etc., which are not sent as a MIDI message, but it is still a (useful) component of the MIDI file.

The basic form of Meta Events:

FF

One byte describes the type of meta-event. Possible range is 00-7f. Not all values ​​are in this range, but the program can cope with unexpected values ​​and diagnose this length and ignore the expected data part.

The length of the stressed data. This is a variable length (number). 0 is a valid

0 or more byte data.

META EVENTS FF 00 02 SS SS Voice

This is an optional event that can only be generated in the first TRACK and before non-zero. In the format 2 file, this is used to identify each Track, if ignored, this serial number is represented by the order of TRACK. .

In format 1 file, this event can only be generated in the first track.

SS SS SEQUENCE NUMBER, 16 BIT BINARY FF 01 Text Event

This event is used to comment TRACK text. Independent 8-bit data (other ASCII text) is also allowed.

Length (Variable Length)

One byte ASCII Text or 8-Bit Binary FF 02 Version Notice

This event is a copyright notice expressed by ASCII text. This is the form of formula "(c) 1850 J.strauss" This event is used for the first Track, the first event.

FF 03 Quotes / TRACK Name

Voice or TRACK name. FF 04 Musical Instrument Name

Describe the instrument used by this Track. This detailed description (this) MIDI CHANNEL is in (this) the instrument used in Track. FF 05 lyrics

Song lyrics. Usually every syllable has its own lyrics, at this time, the lyrics will be sang. FF 06 Tag

Usually used in the first TRACK of format 0 or format 1. Mark meaningful points (such as "Psalm 1") FF 07

It is used to show what happened on the stage. Such as: "The curtain is rising", "exits, stand left", etc. FF 201 CC MIDI CHANNEL Prefix Associated MIDI CHANNEL with Meta-Events and Sysex-Events. Until the next (must contain MIDI CHANNEL information)

CC MIDI CHANNEL 1-16 Range: 00-0F FF 2F 00 TRACK End

This event is necessary. It is used to sweep out the defined length. Its essential information is this track is a loop or connects to another track. FF 51 03 TT TT TT Terminal

This setting of the 1/4 note is indicated by subtle. This means changing a unit length of Delta-Time. (Note 1) If it is not pointed, the default speed is 120 shots / points. This is equivalent to TTTTTT = 500,000.

TT TT TT new beat, represents 1/4 note 24-bit binary number FF 54 05 HH mm SS FR FF SMTPE offset

An optional event describes the SMTPE time at which TRACK begins. This event must occur before non-zero delta-time and before the first event. In format 1, this event must be in the first Track (The Tempo Map).

HH MM SS FR Hour / minute / sec / frame with SMTPE format. This must be consistent with the message MIDI TIME Code Quarter Frame (details, time coding must be introduced)

FF FRACTIONAL FRAME, IN HUNDRETH'S OF A FRAME

FF 58 04 NN DD CC BB Terminal

The form of a beam marker: NN / 2 ^ DD as: 6/8 with nn = 6, DD = 3 is represented. This parameter CC is the number of Ticks representing the metronome of each MIDI clock.

Typically 24 MIDI clocks are one 1/4 note. However, some software allows users to set this value themselves. Parameter BB Definition: 24 MIDI Clock (This "General" (indicated) 1/4 note) number of 1/32 notes.

Nn beat mark, molecule

DD beam marks, denominates (DD times) of 2 (DD). Example: A denominator 4 is represented by DD = 2.

CC's number of Ticks per MIDI clock beam.

The number of 1/32 notes in 24 MIDI clocks (8 is standard).

FF 59 02 SF Mi Tone Symbol

Tone symbols, indicating the sign of the upgrade or decaying value, high-key or minor. 0 indicates that C is adjusted, the negative number indicates "decline", and the positive number indicates "promotion".

SF upgrade or decision value -7 = 7 promotion 0 = C adjustment 7 = 7

Mi 0 = high-key 1 = small adjustment

FF 7F Sequencer Description Meta-Event

This is in the MIDI file with system advanced events. This event is used in the MIDI file to represent the description of the manufacturer sequencer.

Length of (Variable Length)

1 or 3 bytes represent manufacturing vendors. This value is also used as MIDI SYSTEM EXCLUSIVE MESSAGES.

8-bit binary

FootNotes

Note 1

In this case is defined as the unit DELTA-TIME number "1/4 note" (msbit = 0), a variable beat speed represents a change in Delta-Time length. In this case Msbit = 1, "Ticks" indicates an absolute term (Ticks / Frames / Second), and he has no explanation in the instructions and will affect a new TEMPO application. .

转载请注明原文地址:https://www.9cbs.com/read-115832.html

New Post(0)