-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBpm_class.pde
47 lines (34 loc) · 1.04 KB
/
Bpm_class.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
public class Bpm {
private int BPMvalue;
private int timeLength, initTime,counter;
//costruttore
public Bpm(){
BPMvalue=0;
}
public int getCounter(){ return counter;}
public int getTimeLength(){ return timeLength;}
public int getInitTime(){ return initTime;}
public void setCounter(int i){counter=i;}
public void setInitTime(int i){initTime=i;}
public void setTimeLength(int i){timeLength=i;}
public void incrementCounter(){counter++;}
//metodo get BPM
public int getBPM(int tL){
//timeLenght is the observation window in milliseconds
// initTime is the starting time
// counter is the number of beats revealed in one "timeLenght" window
timeLength=tL;
int elapsedTime;
int BPM=0;
elapsedTime = millis() - initTime;
if( elapsedTime > timeLength-20 && elapsedTime < timeLength+20)
{
BPM = (counter*(60*1000)/timeLength); //resolution = (60*1000)/timeLength;
counter = 0;
initTime = millis();
BPMvalue = BPM;
}
if(BPM!=0) println(BPM);
return BPM;
}
}