diff --git a/makefile b/makefile index b45c68b..99f53ba 100644 --- a/makefile +++ b/makefile @@ -25,7 +25,7 @@ mkdir -p $(LOCPATH)/prof gcc $(SRC) -o $(LOCPATH)/prof/$(NAME)_prof $(CFLAGS) $(LFLAGS) $(LFLAGS_STATUS) -pg asan: - gcc $(SRC) -o $(LOCPATH)/debug/$(NAME)_debug_asan $(CFLAGS) $(LFLAGS) $(DEBFLAGS) -fsanitize=address + gcc $(SRC) -o $(LOCPATH)/debug/$(NAME)_debug_asan $(CFLAGS) $(LFLAGS) $(DEBFLAGS) $(LFLAGS_STATUS) -fsanitize=address clean: rm -f $(LOCPATH)/$(NAME) rm -f $(LOCPATH)/debug/$(NAME)_debug diff --git a/src/beat_track.c b/src/beat_track.c index 02dba52..76a8245 100644 --- a/src/beat_track.c +++ b/src/beat_track.c @@ -34,14 +34,14 @@ } } -unsigned int cb_avg(cebuffer *cb) +energy_t cb_avg(cebuffer *cb) { - unsigned int avg = 0; + energy_t avg = 0; unsigned int i = 0; unsigned int cnt = 0; for(i=cb->tail; ihead; ++i) { - unsigned int val = cb->buffer[i % cb->capacity]; + energy_t val = cb->buffer[i % cb->capacity]; if(val > 0) { cnt++; avg += cb->buffer[i % cb->capacity]; @@ -49,7 +49,7 @@ } if(cnt == 0) return 0; - return (int)(avg / cnt); + return (energy_t)(avg / cnt); } double cb_variance(cebuffer *cb) @@ -76,13 +76,11 @@ bool beat = false; // compute the avg of the circular buffer up to now - *energyThreshold = (unsigned int)cb_avg(cb)*(3/2); + *energyThreshold = (energy_t)cb_avg(cb)*(3/2); if(item > *energyThreshold) { beat = true; } - fprintf(stderr, "threshold: %d, item: %d\n", *energyThreshold, item); - return beat; } diff --git a/src/fft.c b/src/fft.c index a21c3d5..6a1016c 100644 --- a/src/fft.c +++ b/src/fft.c @@ -108,7 +108,7 @@ for(i=0; i maxfreq) { + if (i+j < inLen && fftBuf[i+j] > maxfreq) { maxfreq = fftBuf[i+j]; } } @@ -126,8 +126,8 @@ void avgEnergy(unsigned int* fftBuf, const int inLen, unsigned int* energyBuf) { unsigned int i; - for(i=0; isong && status->song->duration_sec) { - print_rate_info(sampleRate, nsamples, maxC, status->song->duration_sec); + print_rate_info(sampleRate, nsamples, maxC, status->song->duration_sec, beat); cnt_over = 0; } print_mpd_status(status, maxC, statusHeight+maxR/6, statusCol); diff --git a/src/utils_curses.c b/src/utils_curses.c index 0889c09..0a9fcaf 100644 --- a/src/utils_curses.c +++ b/src/utils_curses.c @@ -149,7 +149,7 @@ #ifdef STATUS_CHECK void -print_rate_info(const int rate, const int nsamples, const int maxC, int seed) +print_rate_info(const int rate, const int nsamples, const int maxC, int seed, const bool beat) { int center = (int) maxC/2-18; // adjust to screen center int i; @@ -167,6 +167,9 @@ mvprintw(0, center, " -------------------------------- ", rate, nsamples); mvprintw(2, center, " ------------[mvc]--------------- ", rate, nsamples); } + if(beat) { + mvprintw(3, center, " ============ *BEAT ============== ", rate, nsamples); + } } diff --git a/src/utils_curses.h b/src/utils_curses.h index 61a24bf..fef4293 100644 --- a/src/utils_curses.h +++ b/src/utils_curses.h @@ -9,7 +9,7 @@ void init_color_pairs(); WINDOW* curses_init(); void print_col(int col, int length, const int maxR, const int maxC, PATTERN pattern, int seed); -void print_rate_info(const int rate, const int nsamples, const int maxC, int seed); +void print_rate_info(const int rate, const int nsamples, const int maxC, int seed, const bool beat); void print_help(const int maxR, const int maxC); #ifdef STATUS_CHECK