I'm making a Java application to record midi using a midi instrument. Ive been using Java with an ASIO driver using the proyect JAsioHost to avoid latency.
Currently I'm producing pure sine waves for each note. I would like to produce sound using the synthesizer provided by java like in the following code:
import javax.sound.midi.MidiChannel;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Synthesizer;
public class Main {
public static void main(String[] args) {
Synthesizer synthesizer = null ;
MidiChannel [] channels = null ;
try {
synthesizer = MidiSystem.getSynthesizer() ;
synthesizer.open();
channels = synthesizer.getChannels();
channels[0].programChange(1) ;
channels[0].noteOn( 70, 40) ;
Thread.sleep( 3000) ;
} catch (MidiUnavailableException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
channels[ 0 ].noteOff(70) ;
}
}
To achive this I must get a float array with sampled audio that corresponds to the audio generated by the synthesizer when the noteOn function is called (so I can produce the audio with the driver using the array). Does anyone know how this could be done?
I was thinking of trying to view the noteOn function implementation to see if at some point of the code there is an array containing the sampled audio before it´s sent to the mixer, but I don´t know where to find it.
ps: when running my application I can´t call the synthesizer.open()
method because no mixers can be opened while the driver is running.