Tuesday, August 3, 2010

Behind the scenes - how sound is produced in Frinika

Frinika uses the Toot audio framework for bringing all the audio together and sending it to the audio ouput. Toot provides effect plugins and advanced mixing features, not to mention a versatile model for developing audio applications.

Here's a quick example of how to get Toot "up and sounding":



JavaSoundAudioServer as = new JavaSoundAudioServer();
final AudioProcess output = as.openAudioOutput("plughw:0,0", "Line Out");
final AudioBuffer buffer = as.createAudioBuffer("test");
as.setClient(new AudioClient() {

double wavePos = 0;

public void work(int nFrames) {
float[] channel0 = buffer.getChannel(0);
for(int n=0;n<nFrames;n++)
{
double sample = Math.sin(wavePos);
wavePos+=Math.PI*2*440.0/44100.0;
channel0[n] = (float)sample;
}

output.processAudio(buffer);
}

public void setEnabled(boolean enabled) {
}
});
as.start();


Note that the audio output "plughw:0,0" is Linux specific and should be replaced with the name of the Javasound audio output of your platform.

No comments: