Skip to content

Instantly share code, notes, and snippets.

@J3698
Last active May 8, 2019 00:54
Show Gist options
  • Save J3698/3cb2e56b7b4d130859ac5734870c0e74 to your computer and use it in GitHub Desktop.
Save J3698/3cb2e56b7b4d130859ac5734870c0e74 to your computer and use it in GitHub Desktop.
bool has_beat(sample_t *audio_left, sample_t *audio_right, jack_nframes_t num_samples) {
static movingAverage_t *moving_avg = NULL;
if (moving_avg == NULL) {
moving_avg = movingAverage_new(FILTER_SAMPLES);
}
// beat detected if volume much higher than moving avg
double volume = calc_volume(audio_left, audio_right, num_samples);
bool beat_detected =
volume * FILTER_SAMPLES > BEAT_FACTOR * moving_avg->average;
movingAverage_update(moving_avg, volume);
return beat_detected;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment