Manual: AudioOutput
An AudioOutput is a connection to the output of a computer’s sound card. Typically the computer speakers are connected to this. You can use an AudioOutput to do real-time sound synthesis by attaching AudioSignals to an output object. You can get an AudioOutput object from Minim using one of five methods:
AudioOutput getLineOut() // specifiy either Minim.MONO or Minim.STEREO for type AudioOutput getLineOut(int type) // bufferSize is the size of the left, right, // and mix buffers of the output you get back AudioOutput getLineOut(int type, int bufferSize) // sampleRate is a request for an output of a certain sample rate AudioOutput getLineOut(int type, int bufferSize, float sampleRate) // bitDepth is a request for an output with a certain bit depth AudioInput getLineOut(int type, int bufferSize, float sampleRate, int bitDepth)
In the event that an output doesn’t exist with the requested parameters, Minim will spit out an error and return null. In general, you will want to use the first two methods listed above. Once you have an output you can add a signal to it.
Code Sample (online example)
import ddf.minim.*; import ddf.minim.signals.*; AudioOutput out; SineWave sine; void setup() { size(512, 200); // always start Minim before you do anything with it Minim.start(this); // get a line out from Minim, // default sample rate is 44100, default bit depth is 16 out = Minim.getLineOut(Minim.STEREO, 512); // create a sine wave Oscillator, // set to 440 Hz, at 0.5 amplitude, // using the sample rate of the output sine = new SineWave(440, 0.5, out.sampleRate()); // add the oscillator to the line out out.addSignal(sine); } void draw() { background(0); stroke(255); // draw the waveforms for(int i = 0; i < out.left.size()-1; i++) { line(i, 50 + out.left.get(i)*50, i+1, 50 + out.left.get(i+1)*50); line(i, 150 + out.right.get(i)*50, i+1, 150 + out.right.get(i+1)*50); } } void stop() { // always close Minim audio classes when you are done with them out.close(); // always stop Minim before exiting Minim.stop(); super.stop(); }
Supported Interfaces
As seen above, AudioOutput implements the Polyphonic interface, meaning you can add and remove AudioSignals on it. An output is “always on”, which means that it is always generating audio to send to the system. This could be silence if there are no signals attached or if all attached signals have been disabled. When you add a signal, it is added as enabled so that you will hear it right away. If this is not what you want, be sure to call the disableSignal method immediately after adding it. Please see the Polyphonic section for a complete description of the interface.
An AudioOutput derives from AudioSource meaning that it is Recordable and Effectable. See the the AudioSource section for a complete description of that class. AudioSource derives from Controller, so an AudioOutput provides all of that functionality as well. Please see the Controller section for a complete description.