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)
/** * This sketch demonstrates how to use the <code>getLineOut</code> method of <code>Minim</code>. This method * returns an <code>AudioOutput</code> object. An <code>AudioOutput</code> represents a connection to the * computer's speakers and is used to generate audio with <code>AudioSignal</code>s. There are five versions of * <code>getLineOut</code>: * <pre> * getLineOut() * getLineOut(int type) * getLineOut(int type, int bufferSize) * getLineOut(int type, int bufferSize, float sampleRate) * getLineOut(int type, int bufferSize, float sampleRate, int bitDepth) * </pre> * The value you can use for <code>type</code> is either <code>Minim.MONO</code> or <code>Minim.STEREO</code>. * <code>bufferSize</code> specifies how large you want the sample buffer to be, <code>sampleRate</code> specifies * what the sample rate of the audio you will be generating is, and <code>bitDepth</code> specifies what the bit * depth of the audio you will be generating is (8 or 16). <code>type</code> defaults to <code>Minim.STEREO</code>, * <code>bufferSize</code> defaults to 1024, <code>sampleRate</code> defaults to 44100, and <code>bitDepth</code> * defaults to 16. * * Before you exit your sketch make sure you call the <code>close</code> method of any <code>AudioOutput</code>'s * you have received from <code>getLineOut</code>. */ import ddf.minim.*; import ddf.minim.signals.*; Minim minim; AudioOutput out; SineWave sine; void setup() { size(512, 200, P3D); minim = new Minim(this); // get a line out from Minim, default sample rate is 44100, default bit depth is 16 out = minim.getLineOut(Minim.STEREO, 2048); // create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude, sample rate 44100 to match the line out 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.bufferSize() - 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(); 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.
-
Pingback from Processing brain pain « Carina Westling on January 20, 2010 at 8:53 am
-
Hello , I’m trying to output from my souncard ( a 8 channells out , fireface 800) a set of 5 sounds that should exit from audio autput 1–3-4–5 in different times, using processing, I tryied with audioOutput ,but it works with the sinewave in the code but not if I call a sample from my pc. Any suggestion?
-
hum, now I try , many many thanks!
-
so , with the sine in the sketch of minim it works , I can move between the channels ,but I can’t play a selected file audio from my disk
this the last I tryed , Can somebody pleeeease help me?/**
* This sketch demonstrates how to use thesetOutputMixer
* method ofMinimin conjunction with thegetLineOut
* method. By accessing the Mixer objects of Javasound, you can find one that
* corresponds to the output mixer of the sound device of your choice. You can
* then set this Mixer as the one that should use when creating an AudioOutput for you.
* This Mixer will also be used when obtaining outputs for AudioPlayers, AudioSamples,
* and any other classes that result in sound being ouput to your speakers.
*
* This sketch uses controlP5 for the GUI, a user-contributed Processing library.
*/import ddf.minim.*;
// need signals package for SineWaveimport ddf.minim.signals.*;
import controlP5.*;
AudioSample kick;
AudioSample snare;// need to import this so we can use Mixer and Mixer.Info objects
import javax.sound.sampled.*;Minim minim;
AudioOutput out;
// an array of info objects describing all of
// the mixers the AudioSystem has. we’ll use
// this to populate our gui scroll list and
// also to obtain an actual Mixer when the
// user clicks on an item in the list.
Mixer.Info[] mixerInfo;// a signal for our output
SineWave sine;ControlP5 gui;
void setup()
{
size(512, 200, P3D);minim = new Minim(this);
gui = new ControlP5(this);ScrollList mixers = gui.addScrollList(“Mixers”, 10, 10, 475, 280);
mixers.setLabel(“Choose A Mixer”);mixerInfo = AudioSystem.getMixerInfo();
for(int i = 0; i < mixerInfo.length; i++)
{
controlP5.Button b = mixers.addItem("item"+i, i);
b.setLabel(mixerInfo[i].getName());
}sine = new SineWave(220, 0.3, 44100);
}
void draw()
{
background(0);//gui.draw();
if ( out != null )
{
stroke(255);
// draw the waveforms
for(int i = 0; i < out.bufferSize() – 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);
}
}
}public void controlEvent(ControlEvent theEvent)
{
int mixerIndex = (int)theEvent.controller().value();println("User chose " + theEvent.controller().label());
println("Using mixer info " + mixerInfo[mixerIndex].getName());Mixer mixer = AudioSystem.getMixer(mixerInfo[mixerIndex]);
minim.setOutputMixer(mixer);
// load BD.wav from the data folder
kick = minim.loadSample("file1.wav", 2048);
if ( kick == null ) println("Didn't get kick!");
// load SD.wav from the data folder
snare = minim.loadSample("file2.wav", 2048);
if ( snare == null ) println("Didn't get snare!");if ( out != null )
{
out.close();
}out = minim.getLineOut(Minim.STEREO);
if ( out != null )
{
snare.trigger();
}
}
void keyPressed()
{
if ( key == 's' ) snare.trigger();
if ( key == 'k' ) kick.trigger();
}void stop()
{ // always close Minim audio classes when you are done with them
kick.close();
snare.close();
// always close Minim audio classes when you are done with them
if ( out != null )
{
out.close();
}
minim.stop();super.stop();
} -
Hi guys,
Just had to complete a quick project that required different mp3 files playing to different sound channels. Processing can accomplish this, here’s how I solved it:
import ddf.minim.*;
import ddf.minim.signals.*;
import javax.sound.sampled.*;Minim minim1;
Minim minim2;AudioOutput out1;
AudioOutput out2;AudioPlayer song1;
AudioPlayer song2;Mixer.Info[] mixerInfo;
void setup()
{
size(512, 256);minim1 = new Minim(this);
minim2 = new Minim(this);//–GET THE LIST OF AVAILABLE MIXERS
mixerInfo = AudioSystem.getMixerInfo();println(AudioSystem.getMixerInfo());
//–SELECT A MIXER BASED ON THE INDEX IN THE mixerInfo ARRAY
mixer1 = AudioSystem.getMixer(mixerInfo[1]);
mixer2 = AudioSystem.getMixer(mixerInfo[2]);minim1.setOutputMixer(mixer1);
minim2.setOutputMixer(mixer2);out1 = minim1.getLineOut(Minim.STEREO);
out2 = minim2.getLineOut(Minim.STEREO);song1 = minim1.loadFile(“YOUR SONG FILE.mp3″);
song2 = minim2.loadFile(“YOUR SONG FILE.mp3″);song1.play();
song2.play();
}void stop()
{
//–ALWAYS CLOSE THE SONG
song1.close();
song2.close();//–ALWAYS STOP THE MINIM
minim1.stop();
minim2.stop();//–CLOSE THE OUT CHANNEL
out1.close();
out2.close();//–ALWATSYS STOP .super()
super.stop();
}I’ve cut down the code to past here so may not work first time.
-
Yes, I tried passing 4 to getLineOut. But i receive this ERROR:
==== JavaSound Minim Error ====
==== Unable to return a SourceDataLine: unsupported format – PCM_SIGNED 44100.0 Hz, 16 bit, 4 channels, 8 bytes/frame, little-endian=== Minim Error ===
=== Minim.getLineOut: attempt failed, could not secure a LineOut.Not setting the OutputMixer with Minim and setting the soundcard as output in the systempreferences, I can use Minim.MONO and Minim.STEREO on two channels. But with setting the mixer with minim.setOutputMixer to the MAYA44, I get an ERROR in any cases.

10 comments
Comments feed for this article
Trackback link: http://code.compartmental.net/tools/minim/manual-audiooutput/trackback/