Here's the code:
import processing.serial.*;
import cc.arduino.*;
import pitaru.sonia_v2_9.*;
Arduino arduino;
int[] ledPin = {2,3,4}; // EL Escudo pinOuts start at A=2, B=3, etc.
float beat;
void setup() {
//println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[1], 57600);
for(int i = 0;i<3;i++) {
arduino.pinMode(ledPin[i], Arduino.OUTPUT);
}
size(200,200);
frameRate(30);
// change beat value or input volume if beat isn't accurate, or maybe your sample does not have a clear enough beat
beat = 0.03;
Sonia.start(this);
// Start listening to the microphone
LiveInput.start();
}
void draw() {
float level = LiveInput.getLevel();
if(level > beat) {
blink();
}
}
void blink() {
for(int i = 0;i<ledPin.length;i++) {
arduino.digitalWrite(ledPin[i], Arduino.HIGH);
}
delay(100);
for(int i = 0;i<ledPin.length;i++) {
arduino.digitalWrite(ledPin[i], Arduino.LOW);
}
delay(100);
}
// Close the sound engine
public void stop() {
Sonia.stop();
super.stop();
}
1 comment :
I tried the Minim library which even has a beatDetect class and just couldn't get it to do any better than the Sonia library. Oh well, the main thing I'm looking for is an application that can return a tempo in milliseconds, which the Sonia does pretty well.
Post a Comment