From 0bb0f22ddec2de97f7938916c9cf278b99e6a9e7 Mon Sep 17 00:00:00 2001 From: Jamie Bullock Date: Mon, 17 Mar 2014 16:39:30 +0000 Subject: Fixed bugs in xtract_failsafe_f0(). Should now actually be failsafe. Only exception is silent input. --- src/scalar.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/scalar.c b/src/scalar.c index ea798eb..020bd30 100644 --- a/src/scalar.c +++ b/src/scalar.c @@ -942,23 +942,27 @@ int xtract_f0(const double *data, const int N, const void *argv, double *result) int xtract_failsafe_f0(const double *data, const int N, const void *argv, double *result) { - double *spectrum = NULL, argf[2], *peaks = NULL, return_code, sr; + double *spectrum = NULL, argf[4], *peaks = NULL, return_code, sr; return_code = xtract_f0(data, N, argv, result); - if(return_code == XTRACT_NO_RESULT) + if(return_code == XTRACT_NO_RESULT || *result == 0) { sr = *(double *)argv; if(sr == 0) sr = 44100.0; spectrum = (double *)malloc(N * sizeof(double)); peaks = (double *)malloc(N * sizeof(double)); - argf[0] = sr; + argf[0] = sr / (double)N; argf[1] = XTRACT_MAGNITUDE_SPECTRUM; + argf[2] = 0.f; /* DC component not Nyquist */ + argf[3] = 1.f; /* Normalize */ xtract_spectrum(data, N, argf, spectrum); - argf[1] = 10.0; + argf[1] = 50.0; /* Peak threshold is 70% of maximum peak found */ xtract_peak_spectrum(spectrum, N >> 1, argf, peaks); argf[0] = 0.0; + + /* Assume the peak with the lowest frequency is the fundamental */ xtract_lowest_value(peaks+(N >> 1), N >> 1, argf, result); free(spectrum); -- cgit v1.2.3