diff options
author | Jamie Bullock <jamie@jamiebullock.com> | 2014-03-27 14:56:36 +0000 |
---|---|---|
committer | Jamie Bullock <jamie@jamiebullock.com> | 2014-03-27 14:56:36 +0000 |
commit | f5423497d2d4718fc3385003329a135ee8078615 (patch) | |
tree | 0669b31b8ca90444b4e92c7c239568d2729c11c9 /src/scalar.c | |
parent | 0bb0f22ddec2de97f7938916c9cf278b99e6a9e7 (diff) | |
parent | 8e718bfda48218dc4f007cad578d308227f2bb41 (diff) | |
download | LibXtract-f5423497d2d4718fc3385003329a135ee8078615.tar.gz LibXtract-f5423497d2d4718fc3385003329a135ee8078615.tar.bz2 LibXtract-f5423497d2d4718fc3385003329a135ee8078615.zip |
Merge pull request #58 from q-depot/master
add VC2012 project to compile static and dynamic lib, also fix some C
Diffstat (limited to 'src/scalar.c')
-rw-r--r-- | src/scalar.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/scalar.c b/src/scalar.c index 020bd30..e0d2578 100644 --- a/src/scalar.c +++ b/src/scalar.c @@ -872,8 +872,8 @@ int xtract_f0(const double *data, const int N, const void *argv, double *result) if(sr == 0) sr = 44100.0; - input = (double *)malloc(bytes = N * sizeof(double)); - input = memcpy(input, data, bytes); + input = (double*)malloc(bytes = N * sizeof(double)); + input = (double*)memcpy(input, data, bytes); /* threshold_peak = *((double *)argv+1); threshold_centre = *((double *)argv+2); printf("peak: %.2\tcentre: %.2\n", threshold_peak, threshold_centre);*/ @@ -942,27 +942,23 @@ 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[4], *peaks = NULL, return_code, sr; + double *spectrum = NULL, argf[2], *peaks = NULL, return_code, sr; return_code = xtract_f0(data, N, argv, result); - if(return_code == XTRACT_NO_RESULT || *result == 0) + if(return_code == XTRACT_NO_RESULT) { sr = *(double *)argv; if(sr == 0) sr = 44100.0; spectrum = (double *)malloc(N * sizeof(double)); peaks = (double *)malloc(N * sizeof(double)); - argf[0] = sr / (double)N; + argf[0] = sr; 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] = 50.0; /* Peak threshold is 70% of maximum peak found */ + argf[1] = 10.0; 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); @@ -994,7 +990,7 @@ int xtract_midicent(const double *data, const int N, const void *argv, double *r note = 69 + log(f0 / 440.f) * 17.31234; note *= 100; - note = round(note); + note = floor( 0.5f + note ); // replace -> round(note); *result = note; |