Minim core
ugens
analysis
Name AudioInput
Description An AudioInput is a connection to the current record source of the computer. How the record source for a computer is set will depend on the soundcard and OS, but typically a user can open a control panel and set the source from there. Unfortunately, there is no way to set the record source from Java. This is particularly problematic on the Mac because the input will always wind up being connected to the Mic-In, even if the user has set the input differently using their audio control panel.

You can obtain an AudioInput from Minim by using one of the getLineIn methods:

 // get the default STEREO input
 AudioInput getLineIn()
 
 // specifiy either Minim.MONO or Minim.STEREO for type
 AudioInput getLineIn(int type)
 
 // bufferSize is the size of the left, right,
 // and mix buffers of the input you get back
 AudioInput getLineIn(int type, int bufferSize)
 
 // sampleRate is a request for an input of a certain sample rate
 AudioInput getLineIn(int type, int bufferSize, float sampleRate)
 
 // bitDepth is a request for an input with a certain bit depth
 AudioInput getLineIn(int type, int bufferSize, float sampleRate, int bitDepth)
 
In the event that an input 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.
Examples
/**
  * This sketch demonstrates how to monitor the currently active audio input 
  * of the computer using an AudioInput. What you will actually 
  * be monitoring depends on the current settings of the machine the sketch is running on. 
  * Typically, you will be monitoring the built-in microphone, but if running on a desktop
  * it's feasible that the user may have the actual audio output of the computer 
  * as the active audio input, or something else entirely.
  * <p>
  * Press 'm' to toggle monitoring on and off.
  * <p>
  * When you run your sketch as an applet you will need to sign it in order to get an input.
  * <p>
  * For more information about Minim and additional features, 
  * visit http://code.compartmental.net/minim/ 
  */

import ddf.minim.*;

Minim minim;
AudioInput in;

void setup()
{
  size(512, 200, P3D);

  minim = new Minim(this);
  
  // use the getLineIn method of the Minim object to get an AudioInput
  in = minim.getLineIn();
}

void draw()
{
  background(0);
  stroke(255);
  
  // draw the waveforms so we can see what we are monitoring
  for(int i = 0; i < in.bufferSize() - 1; i++)
  {
    line( i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50 );
    line( i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50 );
  }
  
  String monitoringState = in.isMonitoring() ? "enabled" : "disabled";
  text( "Input monitoring is currently " + monitoringState + ".", 5, 15 );
}

void keyPressed()
{
  if ( key == 'm' || key == 'M' )
  {
    if ( in.isMonitoring() )
    {
      in.disableMonitoring();
    }
    else
    {
      in.enableMonitoring();
    }
  }
}
Constructors
Fields
left   The AudioBuffer containing the left channel samples. If this is a mono sound, it contains the single channel of audio.

mix   The AudioBuffer containing the mix of the left and right channels. If this is a mono sound, mix contains the same samples as left.

right   The AudioBuffer containing the right channel samples. If this is a mono sound, right contains the same samples as left.

Methods
addListener ( )   Add an AudioListener to this sound generating object.

bufferSize ( )   The internal buffer size of this sound object.

disableMonitoring ( )   When monitoring is disabled, you will not hear the audio that is coming through the input.

enableMonitoring ( )   When monitoring is enabled, you will be able to hear the audio that is coming through the input.

getBalance ( )   Returns the current balance.

getFormat ( )   Returns AudioFormat object that describes the audio properties of this sound generating object.

getGain ( )   Returns the current gain.

getPan ( )   Returns the current pan.

getVolume ( )   Returns the current volume.

isMonitoring ( )   Returns whether or not this AudioInput is monitoring. In other words, whether you will hear in your speakers the audio coming into the input.

isMuted ( )   Returns true if the sound is muted.

mute ( )   Mutes the sound.

removeListener ( )   Removes an AudioListener that was previously added to this sound object.

sampleRate ( )   Returns the sample rate of this sound object.

setBalance ( )   Sets the balance.

setGain ( )   Sets the gain.

setPan ( )   Sets the pan.

setVolume ( )   Sets the volume.

shiftBalance ( )   Transitions the balance from one value to another.

shiftGain ( )   Transitions the gain from one value to another.

shiftPan ( )   Transitions the pan from one value to another.

shiftVolume ( )   Transitions the volume from one value to another.

type ( )   The type is an int describing the number of channels this sound object has.

unmute ( )   Unmutes the sound.

Usage Web & Application
Related Minim