Last active
May 8, 2019 00:54
-
-
Save J3698/3cb2e56b7b4d130859ac5734870c0e74 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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