Mercurial > hg > libxtract
diff src/scalar.c @ 211:ef80f7c52c6d
add VC2012 project to compile static and dynamic lib, also fix some C
issues
author | Q <andrea@nocte.co.uk> |
---|---|
date | Thu, 27 Mar 2014 09:48:26 +0000 |
parents | c99c00e1c508 |
children | 44401945d850 |
line wrap: on
line diff
--- a/src/scalar.c Mon Mar 17 16:39:30 2014 +0000 +++ b/src/scalar.c Thu Mar 27 09:48:26 2014 +0000 @@ -872,8 +872,8 @@ 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_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 @@ note = 69 + log(f0 / 440.f) * 17.31234; note *= 100; - note = round(note); + note = floor( 0.5f + note ); // replace -> round(note); *result = note;