Manual: AudioInput
[ javadoc ]
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:
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.
Code Sample (online example)
import ddf.minim.*; AudioInput in; void setup() { size(512, 200); // always start Minim before you do anything with it Minim.start(this); // get a line out from Minim, default bit depth is 16 in = Minim.getLineIn(Minim.STEREO, 512, 11050); } 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(); // always stop Minim before exiting Minim.stop(); super.stop(); }
Supported Interfaces
An AudioInput derives from AudioSource meaning that it is Recordable and Effectable. See the the AudioSource section for a complete description of that class. An input is readonly, so adding effects to an AudioInput object will not cause you to hear the input through the speakers with an effect on it. To do that, you’d need to pipe the input back through an AudioOutput object. An easier and more common usage, however, will be to record the input to a file. For information about that, please see the AudioRecorder section. AudioSource derives from Controller, so an AudioInput provides all of that functionality as well. Please see the Controller section for a complete description.