[ javadoc ]
The AudioListener interface is used by the Recordable interface and defines only two methods. These methods are:
void samples(float[] samples) void samples(float[] samplesLeft, float[] samplesRight)
One of these methods will be called repeatedly by the Recordable object that an AudioListener has been added to, depending upon whether the audio being monitored is mono or stereo. There is no guarantee that the array(s) passed to listeners are unique. For efficiency reasons, the same array(s) could be passed to all listeners of a particular Recordable. It is therefore important that an AudioListener not modify the array(s) it receives so that all listeners are guaranteed to receive the same information. Unfortunately, Java does not provide away to enforce this, so it is left to implementers to play nice. Another thing to be aware of is that the samples method of a listener will likely be called from a thread other than the one the object is created in. This means that implementers will probably want to make their implementations synchronized to prevent inconsistency.
Code Sample (online example)
/** * This sketch demonstrates how to use the <code>addListener</code> method of a <code>Recordable</code> class. * The class used here is <code>AudioPlayer</code>, but you can also add listeners to <code>AudioInput</code>, * <code>AudioOutput</code>, and <code>AudioSample</code> objects. The class defined in waveform.pde implements * the <code>AudioListener</code> interface and can therefore be added as a listener to <code>groove</code>. */ import ddf.minim.*; Minim minim; AudioPlayer groove; WaveformRenderer waveform; void setup() { size(512, 200, P3D); minim = new Minim(this); groove = minim.loadFile("groove.mp3", 512); groove.loop(); waveform = new WaveformRenderer(); groove.addListener(waveform); } void draw() { background(0); // see waveform.pde for an explanation of how this works waveform.draw(); } void stop() { // always close Minim audio classes when you are done with them groove.close(); // always stop Minim before exiting. minim.stop(); super.stop(); }

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