diff options
author | Jamie Bullock <jamie@jamiebullock.com> | 2014-03-17 16:39:30 +0000 |
---|---|---|
committer | Jamie Bullock <jamie@jamiebullock.com> | 2014-03-17 16:39:30 +0000 |
commit | 0bb0f22ddec2de97f7938916c9cf278b99e6a9e7 (patch) | |
tree | 47013245cf51184c5088eabfa22644a792ced347 | |
parent | f7da913ac4778e37b123154f9687667f5f50a2f1 (diff) | |
download | LibXtract-0bb0f22ddec2de97f7938916c9cf278b99e6a9e7.tar.gz LibXtract-0bb0f22ddec2de97f7938916c9cf278b99e6a9e7.tar.bz2 LibXtract-0bb0f22ddec2de97f7938916c9cf278b99e6a9e7.zip |
Fixed bugs in xtract_failsafe_f0(). Should now actually be failsafe. Only exception is silent input.
-rw-r--r-- | src/scalar.c | 12 |
1 files changed, 8 insertions, 4 deletions
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); |