Android 6.0+:使用新的 MIDI 没有声音 API
Android 6.0+: No Sound Using the New MIDI API
我正在使用 new MIDI API 来演奏一些 MIDI 音符。但是,我听不到任何声音,也没有抛出任何异常。其代码如下:
//initialising the MidiReceiver
private MidiReceiver midiReceiver;
midiReceiver = new MidiReceiver() {
@Override
public void onSend(byte[] msg, int offset,
int count, long timestamp) throws IOException {
}
};
/*Then in my loop containing note_on or note_off events*/
byte[] buffer = new byte[32];
int numBytes = 0;
int channel = 2; // MIDI channels 1-16 are encoded as 0-15.
// NOTE_STATUS is either 0x90 or 0x80
buffer[numBytes++] = (byte)(NOTE_STATUS + (channel - 1));
buffer[numBytes++] = (byte)noteValue; // the required MIDI pitch
buffer[numBytes++] = (byte)127; // max velocity
int offset = 0;
midiReceiver.send(buffer, offset, numBytes);
我在这里做错了什么?我想一定是因为 onSend
方法是空的。我如何使用它来让我的应用程序在 Android 设备中播放笔记?
我在 documentation 中找不到任何迹象表明新的 MIDI API 实际上可以让你合成音频,所以,看来你需要自己生成声音。
也许this library可能有用。
我正在使用 new MIDI API 来演奏一些 MIDI 音符。但是,我听不到任何声音,也没有抛出任何异常。其代码如下:
//initialising the MidiReceiver
private MidiReceiver midiReceiver;
midiReceiver = new MidiReceiver() {
@Override
public void onSend(byte[] msg, int offset,
int count, long timestamp) throws IOException {
}
};
/*Then in my loop containing note_on or note_off events*/
byte[] buffer = new byte[32];
int numBytes = 0;
int channel = 2; // MIDI channels 1-16 are encoded as 0-15.
// NOTE_STATUS is either 0x90 or 0x80
buffer[numBytes++] = (byte)(NOTE_STATUS + (channel - 1));
buffer[numBytes++] = (byte)noteValue; // the required MIDI pitch
buffer[numBytes++] = (byte)127; // max velocity
int offset = 0;
midiReceiver.send(buffer, offset, numBytes);
我在这里做错了什么?我想一定是因为 onSend
方法是空的。我如何使用它来让我的应用程序在 Android 设备中播放笔记?
我在 documentation 中找不到任何迹象表明新的 MIDI API 实际上可以让你合成音频,所以,看来你需要自己生成声音。
也许this library可能有用。