Skip to content

Instantly share code, notes, and snippets.

@RemyPorter
Created June 8, 2015 00:33
Show Gist options
  • Save RemyPorter/f8588c1d07f68325200c to your computer and use it in GitHub Desktop.
Save RemyPorter/f8588c1d07f68325200c to your computer and use it in GitHub Desktop.
First stab at beat detection
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