Need your advice making a live BPM meter

Hey,

I am trying to make a live BPM meter using "tap tempo". I want to take the average interval between 10 keyboard presses and convert that to beats per minute. Seems simple, but I cant get it to work. If I compare the BPM I get with my code listening to a certain song to an online BPM meter I get different results.

 

Any tips would be greatly appreciated :)

 

BPM meter for comparison: http://www.beatsperminuteonline.com/

code I use:

float[] beat = new float[10]; float oldMillis = 0; float interval = 0; boolean gate = true; void setup() { for (int i = 0; i < beat.length; i++) { beat[i] = 0; } } void draw() { println(60000/interval); } void keyPressed() { if (gate == true) { beat[0] = millis() - oldMillis; for (int i = beat.length-1; i >= 1; i--) { beat[i] = beat[i-1]; } int beatLength = 0; for (int j = 0; j < beat.length; j++) { if (beat[j] != 0) { interval += beat[j]; beatLength += 1; } } interval /= beatLength; oldMillis = millis(); } gate = false; } void keyReleased() { gate = true; } 

Thanks in advance!

submitted by /u/Floempie
[link] [comments]