// PCM 8000 KHz, 8 bits, 1 channel (mono), unsigned, little endian
AudioFormat format = new AudioFormat(8000, 8, 1, false, false);
OutputAudioLine line = new MidpOutputAudioLine();
byte[] audioBuffer;
try {
// Open the line and configure it to accept audio data with
// a given format.
line.open(format, bufferSize);
line.start();
while(!stopped) {
//Obtains the number of bytes of data that can be written
// to the buffer without blocking.
int available = line.available();
// Get/Generate audio buffer with corresponding size.
audioBuffer = generator.generate(available);
// Write data to the line
line.write(audioBuffer, 0, audioBuffer.length);
}
// Don't forget to drain the line, i.e push audio data inside
// the buffer to the line.
line.drain();
// Close line for releasing ressources.
line.close();
} catch (IOException e) {
// ...
}