Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

macos - Why java midi synth on mac stop playing notes

I am trying to make a simple app that read from a midi port (hardware) and forward events to the software synth. It mostly work except that the soft synth stop playing from time to time. I can see midi messages being forwarded in the logs, I can trace in debug and see that the event reach the native code in the synth receiver but for some reason, the synth does not play the note. If you wait then the sound play again, then stop, then play again...

Here is a demo app that shows the problem. If you hold the enter button in the console, you will hear a note repeatedly. After some time (likely less than a minute), the sound will stop (event if you keep the button pressed), and then it will come back.

import java.io.BufferedReader;
import java.io.InputStreamReader;

import javax.sound.midi.MidiSystem;
import javax.sound.midi.Synthesizer;

public class TestMidi2 {

    public static void main( String[] args ) throws Exception {
        Synthesizer synth = MidiSystem.getSynthesizer();
        synth.open();

        BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) );
        boolean on = true;
        while ( in.readLine() != null ) {
            if ( on ) {
                synth.getChannels()[0].noteOn( 45, 127 );
            } else {
                synth.getChannels()[0].noteOff( 45 );
            }
            on = !on;
        }
    }

}

I am on MacOS X lion if this make a difference (which I guess it does).

Any idea? Workaround? I would like to try other software synth but could not find any. I am also willing to try hardware midi synth as long as they can play basic piano, flute and guitar (I don't need anything pro, just decent sound).

Thank you!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's a Lion Problem. I'm developing a tool which sends MIDI to different ports and tested it on many platforms. Java Sound Synthesiser works well for all OS X - Versions except Lion. There it seems like the buffer of the Synthesiser overflows. After a few notes it stops playing, if I send a punch of notes it starts working again and stops again,..

However, sadly the Java Sound Synthesiser is an old thing where it seems nobody supports it any more.

Does anyone know other possibilities to play MIDI Sounds via Java except sending it to an third party sequencer? Would be nice if there would be something like just another General MIDI Library.

Thanks and greez!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...