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 › Minim beat detection on live audio mic input
Page Index Toggle Pages: 1
Minim beat detection on live audio mic input? (Read 3292 times)
Minim beat detection on live audio mic input?
Dec 30th, 2008, 1:31am
 
Hi.. i think this should be easy but i'm really new to Processing and cant seem to implement this.

I want the following beat detect example code to work off a live input from my mac laptop mic. I've tried changing the 'song' variable to a line in like this;

lineIn = minim.getLineIn(Minim.STEREO, 512);

but keep running into problems with the object/class types not matching up. I think? Any suggestions would be great! Thanks.


//----------------------------
import ddf.minim.*;
import ddf.minim.analysis.*;

Minim minim;
AudioPlayer song;
BeatDetect beat;
BeatListener bl;
AudioInput in;

float kickSize, snareSize, hatSize;

void setup()
{
 size(512, 200);
 smooth();
 
 minim = new Minim(this);
 
 song = minim.loadFile("test.mp3", 2048);
 song.play();
 // a beat detection object that is FREQ_ENERGY mode that
 // expects buffers the length of song's buffer size
 // and samples captured at songs's sample rate
 beat = new BeatDetect(song.bufferSize(), song.sampleRate());
 // set the sensitivity to 300 milliseconds
 // After a beat has been detected, the algorithm will wait for 300 milliseconds
 // before allowing another beat to be reported. You can use this to dampen the
 // algorithm if it is giving too many false-positives. The default value is 10,
 // which is essentially no damping. If you try to set the sensitivity to a negative value,
 // an error will be reported and it will be set to 10 instead.
 beat.setSensitivity(100);  
 kickSize = snareSize = hatSize = 16;
 // make a new beat listener, so that we won't miss any buffers for the analysis
 bl = new BeatListener(beat, song);  
 textFont(createFont("SanSerif", 16));
 textAlign(CENTER);
}

void draw()
{
 background(0);
 fill(255);
 if ( beat.isKick() ) kickSize = 32;
 if ( beat.isSnare() ) snareSize = 32;
 if ( beat.isHat() ) hatSize = 32;
 textSize(kickSize);
 text("KICK", width/4, height/2);
 textSize(snareSize);
 text("SNARE", width/2, height/2);
 textSize(hatSize);
 text("HAT", 3*width/4, height/2);
 kickSize = constrain(kickSize * 0.95, 16, 32);
 snareSize = constrain(snareSize * 0.95, 16, 32);
 hatSize = constrain(hatSize * 0.95, 16, 32);
}

void stop()
{
 // always close Minim audio classes when you are finished with them
 song.close();
 // always stop Minim before exiting
 minim.stop();
 // this closes the sketch
 super.stop();
}



class BeatListener implements AudioListener
{
 private BeatDetect beat;
 private AudioPlayer source;
 
 BeatListener(BeatDetect beat, AudioPlayer source)
 {
   this.source = source;
   this.source.addListener(this);
   this.beat = beat;
 }
 
 void samples(float[] samps)
 {
   beat.detect(source.mix);
 }
 
 void samples(float[] sampsL, float[] sampsR)
 {
   beat.detect(source.mix);
 }
}
Re: Minim beat detection on live audio mic input?
Reply #1 - Dec 31st, 2008, 6:25pm
 
It should work to use an AudioInput in this program instead of an AudioPlayer. You may have just changed the variable name without changing the type you declared it as. You should have this outside of setup:

AudioInput lineIn;

And then in setup:

lineIn = minim.getLineIn(Minim.STEREO, 512)
Re: Minim beat detection on live audio mic input?
Reply #2 - Jan 1st, 2009, 2:15am
 
Yeah i've tried that.. i must still be missing something. Instead of only creating a bird when various beats are detected, the program starts sptting them out even when i'm not playing audio and doesnt seem to be affected by sound when i do start playing?

http://pastebin.com/f54d06852

Cheers.
Re: Minim beat detection on live audio mic input?
Reply #3 - Jan 2nd, 2009, 8:22am
 
What operating system are you running? You usually have to tell the OS which audio channel to use as LineIn (Mic, SPDIF, Waveout, etc).
I just tried your code out, and it seems to be working for me when pausing and/or muting music I have playing.
Re: Minim beat detection on live audio mic input?
Reply #4 - Jan 2nd, 2009, 11:17am
 
oh thanks.. i'm on a mac and want to use the built in mic. I couldnt find a reference to it in the example file i was using.. where would i put this?
Re: Minim beat detection on live audio mic input?
Reply #5 - Jan 2nd, 2009, 6:53pm
 
Unfortunately I'm not familiar with Mac... However, the mic should usually be the default..
You could try turning down the beat detection sensitivity (by increasing the delay time) to lower the likelihood of false positives.
Re: Minim beat detection on live audio mic input?
Reply #6 - Jan 3rd, 2009, 8:59am
 
yeah i tried that also.. i'll have a search around for more info about using this on a mac.
Re: Minim beat detection on live audio mic input?
Reply #7 - Jan 6th, 2009, 5:45pm
 
Hi,
I'm also buzzy with the live beat detection and a f#cking beginner in Processing ;(

On my XP system I can get the inLine signal for

 Minim minim;
 AudioInput in;
 BeatDetect beat;
...
 minim = new Minim(this);
 in = minim.getLineIn(Minim.STEREO, 512);
 beat = new BeatDetect();
...
 beat.detect(in.mix);
...
 in.left.get(in.bufferSize()
 beat.isOnset()

Everything works perfectly :D

But my modulation of the example with BeatListener I get an error and seeming I'm not intelligent enough (joke) to find the reason.

import ddf.minim.*;
import ddf.minim.analysis.*;

Minim minim;
AudioInput lineIn;
BeatDetect beat;
BeatListener bl;

float kickSize, snareSize, hatSize;

void setup()
{
 size(512, 200, P3D);
 
 minim = new Minim(this);
 lineIn = minim.getLineIn(Minim.STEREO, 512);
 beat = new BeatDetect(lineIn.bufferSize(), lineIn.sampleRate());
 beat.setSensitivity(300);  
 kickSize = snareSize = hatSize = 16;  
 bl = new BeatListener(beat, lineIn);

====== >
then I get the following error :((((
The constructor Frequency BeatListener{BeatDetect, AudioInput) is undefined

If someone can help me to solve this problem, my unHappyness would disappear.
Thanks
Re: Minim beat detection on live audio mic input?
Reply #8 - Jan 6th, 2009, 6:02pm
 
You are trying to pass in a BeatDetect object and an AudioInput object to the BeatListener constructor but the BeatListener constructor only accepts a BeatDetect object and an AudioPlayer object. (Hence the The constructor Frequency BeatListener{BeatDetect, AudioInput) is undefined )

Go to the BeatListener class (it should be a tab called BeatListener) and if you change every instance of AudioPlayer to AudioInput, you should be fine.
Re: Minim beat detection on live audio mic input?
Reply #9 - Jan 6th, 2009, 7:54pm
 
I didn't notice the class tabs :(
Yes that's it:
Thanks, you made me happy again :D
Page Index Toggle Pages: 1