We are about to switch to a new forum software. Until then we have removed the registration on this forum.
The code below works from AudioPlayer but I can't get it to
work from AudioInput instead :
import ddf.minim.*;
import ddf.minim.analysis.*;
Minim minim;
AudioInput in;
AudioPlayer song;
BeatDetect beat;
BeatListener bl;
float kickSize, snareSize, hatSize;
PShape m;
PShape n;
PShape o;
PShape p;
void setup()
{
size(900, 850);
colorMode(HSB, 360,100,100);
minim = new Minim(this);
//in = minim.getLineIn();
//song = minim.getLineIn(); // cannot covert fromAudioInput to AudioPlayer
song = minim.loadFile("beat1.mp3");
song.play();
//beat = new BeatDetect(in.bufferSize(), in.sampleRate());
beat = new BeatDetect(song.bufferSize(), song.sampleRate());
beat.setSensitivity(300);
kickSize = snareSize = hatSize = 16;
//bl = new BeatListener(beat, in);
bl = new BeatListener(beat, song);
m = loadShape("12.svg");
n = loadShape("2.svg");
o = loadShape("7.svg");
p = loadShape("4.svg");
}
void draw() {
background(280,100,20);
fill(255);
if ( beat.isKick() ) kickSize = 22;
if ( beat.isSnare() ) snareSize = 32;
if ( beat.isHat() ) hatSize = 42;
shape(m,kickSize/2, kickSize *2, width, height);
shape(n,snareSize, snareSize, width, height);
shape(o,hatSize, snareSize, width, height);
shape(p,hatSize/2 + 250, hatSize + 400, 500, 350);
kickSize = constrain(kickSize * 0.95, 16, 32);
snareSize = constrain(snareSize * 0.95, 16, 32);
hatSize = constrain(hatSize * 0.95, 16, 32);
}
void stop() {
song.close();
minim.stop();
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);
}
}
Answers