开发者

how to set MIDI sound pan?

开发者 https://www.devze.com 2023-03-25 19:46 出处:网络
Can anyone please suggest me how to set panning for a MIDI sound. I am using java MIDI synthesis and can make it sound. But I want the sound to pan from left to right speakers. I did google but it see

Can anyone please suggest me how to set panning for a MIDI sound. I am using java MIDI synthesis and can make it sound. But I want the sound to pan from left to right speakers. I did google but it seemed not to clear to me much? Here the example of code I am working on:

Synthesizer synthesizer = MidiSystem.getSynthesizer();

synthesizer.open();

MidiChannel channel = synthesizer.getChannels()[0];

Soundbank soundbank = synthesizer.getDefaultSoundbank();

synthesizer.loadAllInstruments(soundbank);

channel.programChange(0,instrument);
channel.noteOn(60,200);`

I am v开发者_开发知识库ery grateful for any help. Thanks much!


According to the MIDI spec, panning is controlled by Control Change message number 10. This is the "coarse" value (7 bits of precision) but apparently the "fine" 14-bit version (control change 42) is likely to be ignored by real devices.

Knowing this, you should be able to use the controlChange(int, int) method in the JavaSound MidiChannel API to control your panning:

final int PAN_CONTROLLER = 10; 
// Pan to Center:
channel.controlChange(PAN_CONTROLLER, 64);

// Pan hard left:
channel.controlChange(PAN_CONTROLLER, 0);

// Pan hard right:
channel.controlChange(PAN_CONTROLLER, 127);

// "Active stereo", Jimi-Hendrix-style
// sweep from almost-full left to almost-full right:
for (int position = 8; position < 127; position += 8) {
    channel.controlChange(PAN_CONTROLLER, position);
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号