Manual: AudioOutput

[ javadoc | examples ]

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:

[snip java]
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)
[/snip]

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)

[snip code_sample]http://code.compartmental.net/minim/examples/Minim/getLineOut/getLineOut.pde[/snip]

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.

14 thoughts on “Manual: AudioOutput

  1. Pingback: Processing brain pain « Carina Westling

  2. 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?

  3. It should work with AudioSample, as well, as long as you call setOutputMixer before asking for the sample, as you must do before obtaining an AudioOutput.

  4. 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 the setOutputMixer
    * method of Minim in conjunction with the getLineOut
    * 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 SineWave

    import 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();
    }

  5. 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.

  6. Yah, this looks like it will work fine. You could also do the same thing with a single Minim object by setting the output mixer before each call to getLineOut.

  7. hello, has anyone ever tried playing and recording sound with the ESI MAYA 44?

    It doesn’t accept getLineOut(Minim.STEREO); or getLineOut(Minim.MONO); because (this is what I think) it has 4 channel analog line outputs/inputs, which are neither MONO or STEREO, but just channel numbers..

  8. If that’s the case, you could try passing 4 as the argument to getLineOut. Minim.MONO and Minim.STEREO are simply named variables to make the function call more clear, but what you are specifying is the number of channels you want your output to have. Typically people aren’t on systems that can provide four-channel output, so I didn’t bother creating a Minim.QUAD constant.

  9. 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. Solved. I had to add import javax.sound.sampled.*;

    However, while setting a mixer works with a sine wave, as soon as I use an AudioPlayer, it says – line unsupported.