Using minims beatdetect with line in
in
Core Library Questions
•
3 years ago
I have been tinkering with the beat detection of minim but I can't get it to work with the line in, anyone got an idea how to make this code work?
- import ddf.minim.*;
import ddf.minim.effects.*;
import ddf.minim.analysis.*;
Minim minim;
AudioInput in;
BandPass bpf;
BeatDetect beat;
BeatListener bl;
void setup()
{
minim = new Minim(this);
in = minim.getLineIn();
bpf = new BandPass(55, 12, in.sampleRate());
in.addEffect(bpf);
beat = new BeatDetect(in.bufferSize(), in.sampleRate());
beat.setSensitivity(300);
bl = new BeatListener(beat, in);
//beat.detect(in.mix);
//bpf filter helps beatDetection algo when bass beat detection is only //wanted
}
void draw(){
if ( beat.isOnset() )
{
println("beat!");
//what you want it to do
}
}
void stop()
{
// always close Minim audio classes when you are finished with them
in.close();
// always stop Minim before exiting
minim.stop();
// this closes the sketch
super.stop();
}
class BeatListener implements AudioListener
{
private BeatDetect beat;
private AudioInput source;
BeatListener(BeatDetect beat, AudioInput 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);
}
}
1