/**
* Get Line In
* by Damien Di Fede.
*
* This sketch demonstrates how to use the getLineIn
method of
* Minim
. This method returns an AudioInput
object.
* An AudioInput
represents a connection to the computer's current
* record source (usually the line-in) and is used to monitor audio coming
* from an external source. There are five versions of getLineIn
:
*
* getLineIn() * getLineIn(int type) * getLineIn(int type, int bufferSize) * getLineIn(int type, int bufferSize, float sampleRate) * getLineIn(int type, int bufferSize, float sampleRate, int bitDepth) ** The value you can use for
type
is either Minim.MONO
* or Minim.STEREO
. bufferSize
specifies how large
* you want the sample buffer to be, sampleRate
specifies the
* sample rate you want to monitor at, and bitDepth
specifies what
* bit depth you want to monitor at. type
defaults to Minim.STEREO
,
* bufferSize
defaults to 1024, sampleRate
defaults to
* 44100, and bitDepth
defaults to 16. If an AudioInput
* cannot be created with the properties you request, Minim
will report
* an error and return null
.
*
* When you run your sketch as an applet you will need to sign it in order to get an input.
*
* Before you exit your sketch make sure you call the close
method
* of any AudioInput
's you have received from getLineIn
.
*/
import ddf.minim.*;
Minim minim;
AudioInput in;
void setup()
{
size(512, 200, P3D);
minim = new Minim(this);
minim.debugOn();
// get a line in from Minim, default bit depth is 16
in = minim.getLineIn(Minim.STEREO, 512);
}
void draw()
{
background(0);
stroke(255);
// draw the waveforms
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);
}
}
void stop()
{
// always close Minim audio classes when you are done with them
in.close();
minim.stop();
super.stop();
}