2019年7月30日 星期二

【筆記】開發MIDI通訊協定 Note & Control Change入門

簡述

簡單來說,MIDI是一項通訊協定,將原始的串列資料轉換為具有標準的音樂資料。
就像電子琴可發出不同聲音,但並不是利用基本的鋼琴發聲原理,而是使用按鈕(琴鍵)傳輸電子信號到晶片並判別琴鍵的位置對應鋼琴是甚麼音調,在透過電子喇叭輸出。
當你將電子琴接到電腦上作輸入,電子琴並不是把聲音傳入電腦,而是使用MIDI這個通訊協定將音高傳入電腦中,輸出的音色可由軟體自行調整。






像是音高就可以使用數位的方式傳輸,因為音高可以被量化成為頻率,而在MIDI中有0~127總共128種音高。每個數字都特定的音高,像是60就是代表C4


MIDI Messages(MIDI信息)

MIDI Messages是受MIDI所規範的資料封包,在開發MIDI樂器時必須遵守MIDI所是制定的傳輸規則

MIDI Messages是一個封包,最多由3 bytes組成,每一個byte都有相對應的功能。
  • Status Byte
  • Data Byte 1
  • Data Byte 2
排列方式為:
Status Byte Data Byte 1 Data Byte 2
Status Byte:MIDI Messages有非常多種,必須透過Status Byte讓裝置知道要做甚麼事情。
Data Byte 1:用途必須先看Status Byte是什麼類型。
Data Byte 2:用途必須先看Status Byte是什麼類型。

Channel Voice Messages

MIDI Messages又分為好幾種,本文先探討比較常用的Voice Messages。MIDI Messages種類

Channel:當連接上多個MIDI裝置時,每個樂器必須要有各自的Channel做區分。
Channel Voice Messages 總共有16個Channels,從1~16


Note on & off:
Note on及Note off可比喻為按下琴鍵和放開琴鍵。
Key number意思就是鋼琴的音高(可比照前圖),數字範圍為0~127。
velocity即鋼琴按下按鍵後發出聲音的強度,數字越大琴聲越強,數字範圍為0~127。

封包範例(通道1;Note On;音高64;強度127)
14564127
封包範例(通道0;Note Off;音高64;強度64)
1286464




Control Change:
Control Change | CC 
像是音訊效果器的旋鈕或是鋼琴下的踏板,資料會因為你轉的位置或是往下踩的深度做改變。
Controller number就是單指那個旋鈕的編號有分種類,數字範圍為0~127。Controller value即是代表位置、深度資料,數字範圍為0~127。

封包範例(通道1;Control Change;4 Foot Controller;值127)
1774127
封包範例(通道0;Control Change;0 Undefined;值64)
176064

Voice Message定義

Voice Message
Status Byte(十六進制)
Data Byte 1
Data Byte 2
Note off 8x Key number Note Off velocity
Note on 9x Key number Note on velocity
Polyphonic Key Pressure Ax Key number Amount of pressure
Control Change Bx Controller number Controller value
Program Change Cx Program number None
Channel Pressure Dx Pressure value None
Pitch Bend Ex  MSB LSB

MIDI Messages總表

Command NameStatus ByteData Byte 1Data Byte 2
Note Off128 + Channel0-127 Pitch0-127 Velocity
Note On144 + Channel0-127 Pitch0-127 Velocity
Poly Pressure160 + Channel0-127 Pitch0-127 Pressure
Control Change176 + Channel0 Undefined0-127 MSB
Control Change176 + Channel1 Modulation Wheel0-127 MSB
Control Change176 + Channel2 Breath Controller0-127 MSB
Control Change176 + Channel3 After Touch0-127 MSB
Control Change176 + Channel4 Foot Controller0-127 MSB
Control Change176 + Channel5 Portamento Time0-127 MSB
Control Change176 + Channel6 Data Entry0-127 MSB
Control Change176 + Channel7 Main Volume0-127 MSB
Control Change176 + Channel8-31 Undefined0-127 MSB
Control Change176 + Channel32-63 LSB of 0-310-127 MSB
Control Change176 + Channel64 Damper Pedal0:off 127:on
Control Change176 + Channel65 Portamento0:off 127:on
Control Change176 + Channel66 Sostenuto0:off 127:on
Control Change176 + Channel67 Soft Pedal0:off 127:on
Control Change176 + Channel68-92 Undefined0:off 127:on
Control Change176 + Channel93 Chorus0:off 127:on
Control Change176 + Channel94 Celeste0:off 127:on
Control Change176 + Channel95 Phaser0:off 127:on
Control Change176 + Channel96 Data Entry + 10:off 127:on
Control Change176 + Channel97 Data Entry - 10:off 127:on
Control Change176 + Channel98-121 Undefined0:off 127:on
Control Change176 + Channel122 Local Control0-127
Control Change176 + Channel123 All Notes Off0
Control Change176 + Channel124 Omni Mode off0-15
Control Change176 + Channel125 Omni Mode on0
Control Change176 + Channel126 Mono on/Poly off0
Control Change176 + Channel127 Poly on/Mono off0
Program Change192 + Channel0-127 ProgramNot used
Channel Pressure208 + Channel0-127 PressureNot used
Pitch Wheel224 + Channel0-127 LSB0-127 MSB
System Exclusive2400-127 Id CodeAny number of bytes
Undefined241Not usedNot used
Song Position2420-127 LSB0-127 MSB
Song Select2430-127 SongNot used
Undefined244Not usedNot used
Undefined245Not usedNot used
Tune Request246Not usedNot used
End of Exclusive247Not usedNot used
Timing Clock248Not usedNot used
Undefined249Not usedNot used
Start250Not usedNot used
Continue251Not usedNot used
Stop252Not usedNot used
Undefined253Not usedNot used
Active Sensing254Not usedNot used
System Reset255Not usedNot used

沒有留言:

張貼留言