Skip to content

Instantly share code, notes, and snippets.

@x42

x42/bpms.c

Created Jul 11, 2020
Embed
What would you like to do?
// gcc -o bpms bpms.c -Wall && ./bpms
#include<stdio.h>
int main (int argc, char** argv)
{
// 176400: 2 2 2 2 3 3 5 5 7 7 == 2^4 * 3^2 * 5^2 * 7^2
// 384000: 2 2 2 2 2 2 2 2 2 2 3 5 5 5 == 2^10 * 3^1 * 5^3
int sr = 56448000; // 2^10 * 3^2 * 5^3 * 7^2
int i = 0;
double pbpm = 0;
double dmax = 0;
double bmax = 0;
while (1) {
// assume shortest note is a 128th
double bpm = 60.0/128.0 * sr / ++i;
if (bpm > 400) {
pbpm = bpm;
continue;
}
double diff = pbpm - bpm;
if (diff > dmax) {
dmax = diff;
bmax = bpm;
}
pbpm = bpm;
if (bpm < 20) {
printf ("Min delta at %6.2f: %f\n", bpm, diff);
break;
}
}
printf ("Max delta at %6.2f: %f\n", bmax, dmax);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.