Standard MIDI file format

xiaoxiao2021-03-06  41

Standard MIDI file format

The standard MIDI file format is like a strange beast. Overall, it is so that you can't resist. Of course, how do you see it irrelevant, but use a sufficiently descriptor to describe a piece of music and make it reproduced, not very little work. However, although it is complicated, the structure of the MIDI file format is still very straightforward.

Here I have to give up some things, because after all, I am not MIDI is not MIDI file expert! Recently, I prepared a Gravis ultrasonic sound card for my PC. After listening to several MIDI files (.mid), I thought: "Oh, if I can make my own MIDI (.mid) file, how is it? ! "Well, after a few hours of annoying, I found that those don't have no value. However, I will not let a lengthy file format can stop (in addition, I told my wife, the computer is not very difficult, and I hate as a false gentle). So, if you find anything in this article, please let me know, I will modify it. At the same time, the scope of this document does not provide all types of MIDI commands and any possible file configuration! This basic guide will enable readers to make MIDI types (in moderate time investment).

1 Overview:

A MIDI file is basically consisting of two parts, heads and track blocks. The second section describes the head block, and the third quarter tells the track block. A MIDI file has a header to describe the format of the file, and many track blocks. A track can imagine that you can assign a track for some kind of sound, a score, a musical instrument or anything you need.

2. Head:

The head block appears in the beginning of the file, there are three ways to describe the file. The head looks like this:   4D 54 68 64 00 00 00 06 FF FF NN NN DD DD

The first 4 bytes are equivalent to the ASCII code MTHD, then 4 bytes after MTHD are the size of the head. It will always be 00 00 00 00 06 because the current header information will always be 6 bytes.

  FF FF is the format of the document, there are 3 formats: 0-monorail 1- multi-regulation, synchronization   2-multi-regular, asynchronous

Monorail, it is obvious that there is only one track. Synchronous multi-track means that all tracks are vertical synchronization, or other wording begins at the same time, and can express a different part of a song. The asynchronous multi-track is not necessary to start at the same time, and can be completely disagreeable.

  nn is the number of orbits in the MIDI file. DD DD is the number of rhythm of each 4-cenon DELTA-TIME (this will be described in detail later).

3. Orbital block:

The remaining file part after the head is the track block. Each track contains a head and can contain many MIDI commands you want. Track heads and file heads and similar:

4D 54 72 6B XX XX XX XX

In line with the head, the first 4 bytes are ASCII, this is MTRK, which is followed by 4 bytes of MTRK, gives the length of the track in bytes (excluding track heads).

Under Head is the MIDI event, these events are the same as data that can be accepted and transmitted with accumulated MIDI synthesizer ports. A MIDI event is preceded in a delta-time. A delta-time is the number of rhythm after the MIDI event is executed, and the number of rhythm of each quarter note has previously defined in the header of the file. This delta-time is a variable length encoded value. Although this format is confusing, it allows you to use a large number of numerals as needed, which will not waste some bytes due to the numerical case of small demand! The value is converted to a 7-bit byte, and in addition to the last byte, the most meaningful one of each byte is 1, in addition to the maximum active bit. This allows a value to be read by one byte, if you find the highest valid bit is 0, this is the last bit of this value (smaller than the meaning). According to MIDI, all Delta-Time has up to 4 bytes. Delta-Time is the MIDI event, each MIDI event (except for the running event) with a command byte of the highest valid bit, always 1 (value will be> 128). The list of most commands is in Appendix A. Each command has different parameters and lengths, but the next data will be the highest valid bit zero (value will <128). There is an exception here that Meta-Event, the highest effective bit can be 1. However, Meta-Events requires a long parameter to distinguish.

  minor mistakes can cause confusion that is running mode, which is where the current MIDI command is ignored, and the final version of the MIDI command is assumed. This means that if the command is included, the MIDI event is converted by Delta-Time and the parameter.

4. Summary:

If this note is just more confusion, the examples provided below may help clarify the problem! At the same time, two utilities and a diagram file are included in this document:

Dec.exe - This public process is a text file that converts binary files (such as .mid) into a tagged boundary that corresponds to each byte in decimal.

    ec.exe - This public program converts each byte of the decimal text file with the tag boundary to binary files.

Midinote.ps - this is a note page for the keyboard and the five-tarant spectrum.

Appendix A

1.MIDI event command

Each command byte has two parts, left Nybble (4 digits) contains the current command, and right Nybble contains the channel number of the command to be executed. There are 16 MIDI channels 8 MIDI commands (command Nybble must be maximum. The bit is 1). In the following table, x represents the MIDI channel number. All notes are data bytes <128 (the highest valid bit is 0).

Hexadecimal binary data description

8X 1000XXXX NN VV note close (release keyboard) nn = audio symbol VV = speed

9x 1001xxxx NN VV note open (press keyboard) nn = audio symbol vv = speed

AX 1010XXXX NN VV Touch the keyboard NN = 音 符 VV = speed

BX 1011xxxx CC VV Convert Control CC = Control No. VV = New Value CX 1100XXXX PP Change Program (Pieces) PP = New Server number

DX 1101xxxx CC contact after passage   CC = pipeline number

EX 1110XXXX BB TT changes mutual bite and gears (2000h indicates the default or no change) (what does not understand :) BB = value low 7 (Least Sig) TT = value of 7 (Most Sig) The table below is a list of Meta-Events without channels, and their format is:

  inffx xx nn dd

 All meta-events is command (XX), length, or byte (NN) in data, current data (DD)

Hexadecimal binary data description 00 00000000 NN SSSS setting track No. NN = 02 (serial number of two bytes) SSSS = serial number

01 00000001 nn tt .. All text events you need  nn = text length tt = text characters in bytes

02 00000010 NN TT .. The same text, but used for copyright information NN TT = the same text event

03 00000011 nn tt .. sequence or track name NN TT = the same text event

04 00000100 nn Tt .. Track Musical Inn Nn TT = Text Event

05 00000101 nn tt .. lyrics NN TT = the same text event

06 00000110 NN TT .. Tag NN TT = Top Text Event

07 00000111 NN TT .. floating point note NN TT = the same text event

2F 00101111 00 This event must appear at the end of each track

51 01010001 03 TTTTTT Settings TTTTTT = Microsecond / Quarantin

58 01011000 04 NN DD CC BB Terminal NN = Team Number Molecular DD = Termary Item 3 = 8 Shot, etc .. CC = Bebrace Rhythm BB = Two-quarter note marked No. 32 Digital 59 01011001 02 SF Mi Tone Symbol SF = Challenge / Dressance (-7 = 7 Dressance, 0 = Benchmark C Tone, 7 = 7) Mi = High Stress / Small (0 = Motor, 1 = small adjustment)

7f 01111111 xx dd .. Detailed information of the sequencer XX = byte number DD = data

The following table lists the system messages that control the entire system. There is no number of MIDI channels here (these are generally applied to the MIDI keyboard.)

Hexadecimal binary data description

F8 11111000 Synchronization The timer FA 11111010 begins the current queue FB 11111011 Continued a queue Fc 11111100 from the stopped place to stop a queue

The following table lists the command tags corresponding to the note. Octagon || 音 符 # || || C | C # | D | D # | e | f | f # | g | g # | a | a # | b --------------- -------------------------------------------------- ------------ 0 || 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 1 || 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 || 48 | 49 | 50 | 51 | 52 | 56 | 57 | 58 | 59 5 || 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 6 || 72 | 73 | 74 | 75 | 76 | 80 | 81 | 82 | 83 7 || 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | || 96 | 97 | 98 | 99 || | 101 | 102 | 106 | 107 9 || 108 | 109 | 110 | 111 | 112 | 113 | 117 | 118 | 119 10 || 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | Reference: "MID I Systems and Control "Francis Rumsey 1990 Focal Press" MIDI and Sound Book for the Atari ST "Bernd Enders and Wolfgang Klem 1989 M & T Publishing, Inc.MIDI file specs and general MIDI specs were a" o obtained by sending e-mail to LISTSERV @ Auvm.american.edu with the phrase get midispec package in the message.

**** Table 1 - General Midi Instrument Patch Map **** (Groups Sounds INTO SIXTEEN FAMILIES, W / 8 Instruments in Each Family)

PROG # instruction pop # instructionnt

(1-8 piano) (9-16 chrom percussion) 1 acoustic grand 9 celesta2 bright acoustic 10 glockenspiel3 electric grand 11 music box4 honky-tonk 12 vibraphone5 electric piano 1 13 marimba6 electric piano 2 14 xylophone7 harpsichord 15 tubular bel "8 clav 16 Dulcimer (17-24 Organ) (25-32 Guitar) 17 Drawbar Organ 25 Acoustic Guitar (NYLON) 18 Percussive Organ 26 ACOUSTIC Guitar 19 Rock Organ 27 Electric Guitar (JAZ) 20 Church Organ 28 Electric Guitar 21 Reed organ 29 Electric Guitar (MUTED) 22 Accoridan 30 Overdriven Guitar23 Harmonica 31 Distort Guitar24 Tango Accordian 32 Guitar Harmonics

(33-40 bass) (41-48 strings) 33 acoustic bass 41 violin34 electric bass (finger) 42 viola35 electric bass (pick) 43 cello36 fretless bass 44 contrabass37 slap bass 1 45 tremolo strings38 slap bass 2 46 pizzicato strings39 synth bass 1 47 OrcheStral Strings40 Synth Bass 2 48 Timpani

(49-56 ensemble) (57-64 brass) 49 string ensemble 1 57 trumpet50 string ensemble 2 58 trombone51 synthstrings 1 59 tuba52 synthstrings 2 60 muted trumpet53 choir aahs 61 french horn54 voice oohs 62 brass section55 synth voice 63 synthbrass 156 orchestra hit 64 Synthbrass 2

(65-72 reed) (73-80 pipe) 65 soprano sax 73 piccolo66 alto sax 74 flute67 tenor sax 75 recorder68 baritone sax 76 pan flute69 oboe 77 blown bottle70 english horn 78 skakuhachi71 bassoon 79 whistle72 clarinet 80 ocarina

(81-88 SYNTH LEAD) (89-96 SYNTH PAD) 81 Lead 1 (Square) 89 Pad 1 (New Age 82 Lead 2 (Sawtooth) 90 Pad 2 (WARM) 83 Lead 3 (Calliope) 91 Pad 3 (POLYSYNTH 84 Lead 4 (Chiff) 92 Pad 4 (Choir) 85 Lead 5 (Charang) 93 Pad 5 (Bowed) 86 Lead 6 (Voice) 94 Pad 6 (Metallic) 87 Lead 7 (Fifts) 95 Pad 7 (Halo) 88 Lead 8 (Bass Lead) 96 Pad 8 (SWEEP)

(97-104 Synth Effects) (105-112 Ethnic) 97 FX 1 (RAIN) 105 SITAR98 FX 2 (Soundtrack) 106 Banjo99 FX 3 (Crystal) 107 Shamisen100 FX 4 (atmosphere) 108 KOTO101 FX 5 (Brightness) 109 Kalimba102 FX 6 (goblins) 110 bagpipe103 fx 7 (echoes) 111 fiddle104 fx 8 (sci-fi) 112 shanai (113-120 percussive) (121-128 sound effects) 113 tinkle bell 121 guitar fret noise114 agogo 122 breath noise115 steel drums 123 seashore116 Woodblock 124 Bird Tweet117 Taiko Drum 125 Telephone Ring118 Melody Tom 126 Helicopter119 Synth Drum 127 Applause120 Reverse Cymbal 128 Gunshot

**** Table 2 - General Midi Percussion Key Map **** (Assigns Drum Sounds to Numbers. Midi Channel 10 is for percussion)

Midi Drum Sound Midi Drum SoundKey Key

35 acoustic bass drum 59 ride cymbal 236 bass drum 1 60 hi bongo37 side stick 61 low bongo38 acoustic snare 62 mute hi conga39 hand clap 63 open hi conga40 electric snare 64 low conga41 low floor tom 65 high timbale42 closed hi-hat 66 low timbale43 high floor tom 67 high agogo44 pedal hi-hat 68 low agogo45 low tom 69 cabasa46 open hi-hat 70 maracas47 low-mid tom 71 short whistle48 hi-mid tom 72 long whistle49 crash cymbal 1 73 short guiro50 high tom 74 long guiro51 ride cymbal 1 75 Claves52 Chinese Cymbal 76 Hi Wood Block53 Ride Bell 77 Low Wood Block54 Tambourine 78 Mute Cuica55 Splash Cymbal 79 Open Cuica56 COWBELL 80 MUTE Triangle57 Crash Cymbal 2 81 Open Triangle58 VibrasLAP

**** Table 3 - General Midi Minimum Sound Module Specs ****

Voices: a minimum of Either 24 Fully Dynamically Allocated VoicesAvailable Simultaneously for Both Melody and Percussive Sounds Or 16Dynamical Allocated Voices for Melody Plus Eight for Percussion.

channe... ": general midi mode supports all sixteen midi channe" each channel canplay a variable number of voices (polyphony) each channel can play adifferent instrument (timbre) keybased percussion is always onchannel 10.instruments: a minimum of sixteen different timbres Playing Various Instruments. A Minimum of 128 Preset for Intruments.

Note ON / Note Off: Octabe Registration: Middle C (C3) = Midi Key 60. All Voices IncludingPercussion Respond to Velocity.

Controllers: controller # description1 modulation7 main volume10 pan11 expression64 sustain121 reset all controller123 all notes off

Registered DescriptionParameter # 0 Pitch Bend Sensitivity1 Fine Tuning2 Coarse TUNING

Additional Channel Messages: Channel Pressure (afterTouch) Pitch Bend

Power-Up Defaults: Pitch Bend Amount = 0pitch Bend Sensitivity = -2 Semitonesvolume = 90all Other Controllers = Reset

(After Electronic Musician, 8/91 Issue) ---------------------------- Dec.cpp ------- -----------------------------

/ * File Dec.cpp

By Dustin Caldwell (Dustin@gse.utah.edu)

* /

#include #include #include

Void helpdoc ();

Main () {file * fp;

Unsigned char ch, C;

IF ((fp = fopen (_Argv [1], "rb"))) == null) / * open file to read * / {printf ("canNot Open file% s / n", _ argv [1]); helpdoc ); Exit (-1);

C = 0; CH = FGETC (FP);

While (fp)) / * loop for whole file * / {Printf ("% u / t", ch); / * Print Every byte ''s decimal equival equiv. * / c ; if (c> 8) / * Print 8 NumBers to a line * / {c = 0; Printf ("/ n");} ch = fgetc (fp);}

Fclose (fp); / * Close Up * /}

Void helpdoc () / * print help message * / {printf ("/ n binary file decoder / n / n");

Printf ("/ n syntax: dec binary_file_name / n / n");

Printf ("" by Dustin Caldwell (Dustin@gse.utah.edu / n / n "); Printf (" This Is A Filter Program That Reads A Binary File / N "); Printf (" and Prints The Decimal Equivalent of Each BYTE / N "); Printf (" Tab-Separated. this is mostly useful when piped / n "); Printf (" INTO Another File to Be Edited Manually. Eg: / N / N "); Printf (" C: / > DEC SONATA3.MID> SON3.TXT / N / N "); Printf (" This Will Create A File Called Son3.txt Which CAN / N "); Printf (" Be edited with any ascii editor. / n / n " PRINTF ("(Rec.exe May A" O Be Useful, As It Reencodes the / N "); Printf (" ASCII TEXT FILE) ./ N / N "); Printf (" Have Fun !! / N " }

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ... ---------------

/ * File rec.cpp by Dustin Caldwell (Dustin@gse.utah.edu) * /

#include #include #include #include

Void helpdoc ();

Main () {file * RFP, * WFP;

Unsigned char ch, C; char s [20];

IF ((RFP = FOPEN (_Argv [1], "R"))) == null) / * open the read file * / {printf ("canNot Open file% S / N", _ argv [1]); helpdoc ); Exit (-1);} IF ((wfp = fopen (_Argv [2], "wb")) == null) / * open the write file * / {printf ("cannot open file% s / n" , _Argv [1]); helpdoc (); exit (-1);

C = 0;

CH = FGETC (RFP);

While (! Feof (RFP)) / * loop for whole file * / {

IF (Isalnum (CH)) / * only '' See '' Valid ASCII Chars * / {C = 0; While (Isdigit (CH)) / * Only Use Decimal Digits (0-9) * / {S [C] = CH; / * Build a string containing the number * / c ; ch = fgetc (RFP);} s [c] = null; / * must have null terminator * /

FPUTC (ATOI (S), WFP); / * Write the binary Equivalent to file * /

}

CH = FGETC (RFP); / * loop unsteil next Number Starts * /

}

Fclose (RFP); / * Close Up * / Fclose (WFP);

Void helpdoc () / * Print help message * / {printf ("/ n text file encoder / n / n");

Printf ("/ n syntax: Rec text_file_name binary_file_name / n / n");

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

New Post(0)