Created
June 8, 2015 00:33
-
-
Save RemyPorter/f8588c1d07f68325200c to your computer and use it in GitHub Desktop.
First stab at beat detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 => int bands; | |
6 => int threshold; | |
2048 => int size; | |
20 => int low; | |
10000 => int high; | |
(high - low) / bands => float step; | |
BPF banded[bands]; | |
FFT ffts[bands]; | |
RMS rmses[bands]; | |
float runningMeans[bands]; | |
for (0 => int i; i < bands; i++) { | |
adc => banded[i] => ffts[i] =^ rmses[i] => blackhole; | |
step * (i + 1) => banded[i].freq; | |
0.5 => banded[i].Q; | |
size => ffts[i].size; | |
Windowing.blackmanHarris(size/2) => ffts[i].window; | |
0 => runningMeans[i]; | |
} | |
0 => int frames; | |
while (true) { | |
size::samp => now; | |
frames++; | |
0 => int highBands; | |
for (0 => int i; i < bands; i++) { | |
UAnaBlob d; | |
rmses[i].upchuck() @=> d; | |
d.fval(0) +=> runningMeans[i]; | |
if (d.fval(0) > runningMeans[i] / frames && d.fval(0) > 0.00005) { | |
<<< d.fval(0) >>>; | |
highBands++; | |
} | |
} | |
if (highBands > threshold) { | |
<<< "beat" >>>; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment