简体   繁体   English

带立体声输出的midiOutShortMsg和midiOutSetVolume

[英]midiOutShortMsg and midiOutSetVolume with output in stereo

I'm writing C++ code to output midi messages. 我正在编写C ++代码以输出Midi消息。 I need this to work in stereo, so that some notes are played through the left channel/speaker, others through the right. 我需要以立体声方式工作,以便一些音符通过左声道/扬声器播放,另一些音符通过右声道播放。 If I call midiOutSetVolume(midiOutHandle, 0xFFFF) followed by several calls to midiOutShortMsg, with each call separated by a few hundred milliseconds, the notes come through the left speaker. 如果我先调用midiOutSetVolume(midiOutHandle,0xFFFF),然后再多次调用midiOutShortMsg,而每次调用之间的间隔为几百毫秒,则音符将通过左扬声器发出。 Likewise if I first call midiOutSetVolume(midiOutHandle, 0xFFFF0000) before the calls to midiOutShortMsg everything comes out the right speaker. 同样,如果我在调用midiOutShortMsg之前先调用midiOutSetVolume(midiOutHandle,0xFFFF0000),则所有声音都来自正确的扬声器。 However if I attempt to simultaneously output one note through the left speaker and one through the right by doing the following: 但是,如果我尝试通过以下操作同时通过左扬声器输出一个音符并通过右扬声器输出一个音符:

midiOutSetVolume(midiOutHandle, 0xFFFF);
midiOutShortMsg(...);
midiOutSetVolume(midiOutHandle, 0xFFFF0000);
midiOutShortMsg(...);

Both notes simply come out the right speaker. 这两个音符只是发出正确的声音。 I thought if I perhaps had 2 separate handles to the device I could set one to play the left channel notes, the other the right. 我以为,如果我可能对设备有2个单独的手柄,则可以将其中一个设置为播放左声道音符,另一个设置为右声道。 However if I try and open 2 handles to the same device via 2 calls to midiOutOpen I get an MMSYSERR_ALLOCATED error on the second call. 但是,如果我尝试通过2次对midiOutOpen的调用来打开同一设备的2个句柄,则在第二次调用时会收到MMSYSERR_ALLOCATED错误。

Any advice much appreciated. 任何建议,不胜感激。

You should use two channels and set the pan on each channel. 您应该使用两个通道,并在每个通道上设置声像 Then play your notes for the left speaker on channel 0, and your notes for the right speaker on channel 1. 然后在通道0上播放左扬声器的音符,在通道1上播放右扬声器的音符。

To set the channel of a note, your Note On event has 4 bits for the channel: 要设置便笺的通道,您的“ 便笺开启”事件具有4位通道:

1001nnnn (Note On)
nnnn = channel number (0..15)

So use channel 0 for your left speaker and channel 1 for your right speaker. 因此,将0声道用作左扬声器,将1声道用作右扬声器。

To set the pan of a channel, output a Control Change message to that channel: 要设置通道的声相,请向该通道输出一条控制更改消息:

Status byte: 1011nnnn (Control Change)
nnnn = channel number (0..15)

First data byte - Controller number: 0ccccccc
Second data byte - Controller value: 0vvvvvvv
ccccccc = 10 (0x0A) for Pan
vvvvvvv = 0..127 (left = 0, right = 127)

Set the pan of channel 0 to 0, and the pan of channel 1 to 127. 将通道0的声相设置为0,将通道1的声相设置为127。

See the MIDI messages reference for more detail. 有关更多详细信息,请参见MIDI消息参考 Also, here is a short list of Control Change numbers. 另外,这是控制更改编号的简短列表


UPDATE: Using simultaneous percussion kits requires MIDI standard XG or GM Level 2. Read about them here . 更新:使用同时敲击包需要对他们MIDI标准XG或GM级别2.读这里 Which method you use depends on your device's MIDI standard: 您使用哪种方法取决于设备的MIDI标准:

  • XG: Send a Bank Select Control Change message (controller number 0 ) with value 127 (0x7F). XG:发送值为127 (0x7F)的Bank Select Control Change消息(控制器编号0 )。
  • GM Level 2: Use channels 10 and 11 for your two kits (ie. 9 and 10 when you send Note On). GM级别2:为两个套件使用通道1011 (即,发送Note On时为9和10)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM