Я реализовал простую программу, которая принимает ввод с клавиатуры Midi, а затем выводит соответствующий звук с помощью интерфейса синтезатора javax. Это очень хорошо работает на моем ПК под управлением Windows, однако я хочу запустить его на Raspberry Pi с Raspbian. На самом деле это тоже работает, но как только я играю больше/быстрее ноты, звук начинает очень сильно дрожать и трещать, и мне приходится прекращать воспроизведение нот примерно на 2 секунды, чтобы дрожание стихло. Я уже использую внешний звуковой USB-адаптер, который на самом деле не очень помог. Вот класс, который обрабатывает миди-ввод:
public class MidiHandler {
public MidiHandler() {
MidiDevice device;
MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
for (int i = 0; i < infos.length; i++) {
try {
device = MidiSystem.getMidiDevice(infos[i]);
// does the device have any transmitters?
// if it does, add it to the device list
System.out.println(infos[i]);
// get all transmitters
List<Transmitter> transmitters = device.getTransmitters();
// and for each transmitter
for (int j = 0; j < transmitters.size(); j++) {
// create a new receiver
transmitters.get(j).setReceiver(
// using my own MidiInputReceiver
new MidiInputReceiver(device.getDeviceInfo()
.toString()));
}
Transmitter trans = device.getTransmitter();
trans.setReceiver(new MidiInputReceiver(device.getDeviceInfo()
.toString()));
// open each device
device.open();
// if code gets this far without throwing an exception
// print a success message
} catch (MidiUnavailableException e) {
}
}
}
// tried to write my own class. I thought the send method handles an
// MidiEvents sent to it
public class MidiInputReceiver implements Receiver {
Synthesizer synth;
MidiChannel[] mc;
Instrument[] instr;
int instrument;
int channel;
public MidiInputReceiver(String name) {
try
{
patcher p = new patcher();
this.instrument = p.getInstrument();
this.channel = p.getChannel();
this.synth = MidiSystem.getSynthesizer();
this.synth.open();
this.mc = synth.getChannels();
instr = synth.getDefaultSoundbank().getInstruments();
this.synth.loadInstrument(instr[1]);
mc[this.channel].programChange(0, this.instrument);
System.out.println(this.channel + ", " + this.instrument);
}
catch (MidiUnavailableException e)
{
e.printStackTrace();
System.exit(1);
}
}
public void send(MidiMessage msg, long timeStamp) {
/*
* Use to display midi message
*
for(int i = 0; i < msg.getMessage().length; i++) {
System.out.print("[" + msg.getMessage()[i] + "] ");
}
System.out.println();
*/
if (msg.getMessage()[0] == -112) {
mc[this.channel].noteOn(msg.getMessage()[1], msg.getMessage()[2]+1000);
}
if (msg.getMessage()[0] == -128) {
mc[this.channel].noteOff(msg.getMessage()[1], msg.getMessage()[2]+1000);
}
}
public void close() {
}
}
}
Это связано с аппаратными ограничениями Pi, или я могу что-то с этим поделать?