Manual: Recordable

[ javadoc | examples ]

The Recordable interface defines functionality that provides a program with floating point samples of the audio passing through it. It does this using AudioListeners. You add listeners to the Recordable and then the Recordable will call the appropriate samples method of all its listeners when it has a new buffer of samples. It is also possible to query a Recordable object for its buffer size, type (mono or stereo), and audio format. Sample values are between -1 and 1, inclusive. Recordable is implemented by AudioSource and SignalSplitter.

Adding and Removing AudioListeners

[snip java]
addListener(AudioListener al)
removeListener(AudioListener al)
[/snip]

The above methods can be called on a Recordable to add or remove an instance of a class that implements AudioListener. When a listener has been added to a Recordable, one of it’s samples methods will be called each time the Recordable generates a new buffer of samples or receives a new buffer of samples. This is the best way to monitor input or output. An AudioListener cannot be added more than once to a Recordable.

Code Sample (online example)

[snip code_sample]http://code.compartmental.net/minim/examples/Recordable/removeListener/removeListener.pde[/snip]

The format of a Recordable

A Recordable object can give you information about the kind of audio that it represents. These properties are accessed by the following methods:

[snip java]
int bufferSize()
int sampleRate()
int type()
AudioFormat getFormat()
[/snip]

bufferSize() returns the length of the float buffers sent to AudioListeners. sampleRate() returns the sample rate, in Hz, of the audio that the Recordable represents, such as 44100 or 96000. type() returns the number of channels in the audio, which will be either 1 or 2 and can be compared to Minim.MONO and Minim.STEREO for readability. getFormat() returns an AudioFormat object that contains the sample rate and type, as well as some extra information. Specifically, getFormat().getChannels() will return the same value as type() and getFormat().getSampleRate() will return the same value as sampleRate().

Code Sample (online example)

[snip code_sample]http://code.compartmental.net/minim/examples/Recordable/getFormat/getFormat.pde[/snip]