We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › Problems using minim library
Page Index Toggle Pages: 1
Problems using minim library (Read 1022 times)
Problems using minim library
Dec 1st, 2008, 12:04am
 
I put the minim folder containing the library in the folder with the rest of the libraries that already came with Processing. I tried to run an example using minim, but it said I'm missing a library.

Code:

import ddf.minim.*;

Minim minim;
AudioPlayer groove;
WaveformRenderer waveform;

void setup()
{
size(512, 200, P2D);

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();
}



// This class is a very simple implementation of AudioListener. By implementing this interface,
// you can add instances of this class to any class in Minim that implements Recordable and receive
// buffers of samples in a callback fashion. In other words, every time that a Recordable object has
// a new buffer of samples, it will send a copy to all of its AudioListeners. You can add an instance of
// an AudioListener to a Recordable by using the addListener method of the Recordable. If you want to
// remove a listener that you previously added, you call the removeListener method of Recordable, passing
// the listener you want to remove.
//
// Although possible, it is not advised that you add the same listener to more than one Recordable.
// Your listener will be called any time any of the Recordables you've added it have new samples. This
// means that the stream of samples the listener sees will likely be interleaved buffers of samples from
// all of the Recordables it is listening to, which is probably not what you want.
//
// You'll notice that the three methods of this class are synchronized. This is because the samples methods
// will be called from a different thread than the one instances of this class will be created in. That thread
// might try to send samples to an instance of this class while the instance is in the middle of drawing the
// waveform, which would result in a waveform made up of samples from two different buffers. Synchronizing
// all the methods means that while the main thread of execution is inside draw, the thread that calls
// samples will block until draw is complete. Likewise, a call to draw will block if the sample thread is inside
// one of the samples methods. Hope that's not too confusing!

class WaveformRenderer implements AudioListener
{
private float[] left;
private float[] right;

WaveformRenderer()
{
left = null;
right = null;
}

synchronized void samples(float[] samp)
{
left = samp;
}

synchronized void samples(float[] sampL, float[] sampR)
{
left = sampL;
right = sampR;
}

synchronized void draw()
{
// we've got a stereo signal if right or left are not null
if ( left != null && right != null )
{
noFill();
stroke(255);
beginShape();
for ( int i = 0; i < left.length; i++ )
{
vertex(i, height/4 + left[i]*50);
}
endShape();
beginShape();
for ( int i = 0; i < right.length; i++ )
{
vertex(i, 3*(height/4) + right[i]*50);
}
endShape();
}
else if ( left != null )
{
noFill();
stroke(255);
beginShape();
for ( int i = 0; i < left.length; i++ )
{
vertex(i, height/2 + left[i]*50);
}
endShape();
}
}
}



There's no folder in the minim library called "ddf", so am I missing something that's supposed to have that name?
Re: Problems using minim library
Reply #1 - Dec 1st, 2008, 8:46pm
 
I tried the same code and it runs well with the minim library that's include in the last download of Processing.
Re: Problems using minim library
Reply #2 - Dec 2nd, 2008, 7:50pm
 
indeed, new versions of processing include Minim.
There is therfore no need to download and install it in the libraries folder.

Page Index Toggle Pages: 1