[ 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)
/** * This sketch demonstrates how to use the <code>getLineIn</code> method of <code>Minim</code>. This method * returns an <code>AudioInput</code> object. An <code>AudioInput</code> 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 <code>getLineIn</code>: * <pre> * 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) * </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 * the sample rate you want to monitor at, and <code>bitDepth</code> specifies what bit depth you want to monitor at. * <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. If an <code>AudioInput</code> * cannot be created with the properties you request, <code>Minim</code> will report an error and return <code>null</code>. * <p> * When you run your sketch as an applet you will need to sign it in order to get an input. * <p> * Before you exit your sketch make sure you call the <code>close</code> method of any <code>AudioInput</code>'s * you have received from <code>getLineIn</code>. */ 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(); }
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.
-
I recently switched from Sonia to Minim and I’d like to laud the work done on the library. Previously when I would use Sonia I would use it in conjunction with Marius Watz SoniaHelper to add a damper. I have a couple of questions concerning this:
1. Does Minim have an equivalent?
2. I didn’t find one so I started tinkering with the two together. SoniaHelper requires a float[] for it’s audio input values. I checked the some of the Javadocs (namely for FFT) and didn’t see any methods that returned a float[]. Could you point me in the right direction?
I think if the answer to the first question is no, I might try my hands to port SoniaHelper to a MinimHelper. Cheers
-
i found this library because i was looking for a alternative to sonia+soniaHelper, so im quite curious what your progress was on the implementation.
thnx

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