aboutsummaryrefslogtreecommitdiff
path: root/src/scalar.c
diff options
context:
space:
mode:
authorQ <andrea@nocte.co.uk>2014-03-27 09:48:26 +0000
committerQ <andrea@nocte.co.uk>2014-03-27 09:48:26 +0000
commitcc719183cbc1fb6d2aebeb3150780d5c0e3f86e5 (patch)
tree65dcab27479085b99305a7a8a41beeefee37deb7 /src/scalar.c
parent0bb0f22ddec2de97f7938916c9cf278b99e6a9e7 (diff)
downloadLibXtract-cc719183cbc1fb6d2aebeb3150780d5c0e3f86e5.tar.gz
LibXtract-cc719183cbc1fb6d2aebeb3150780d5c0e3f86e5.tar.bz2
LibXtract-cc719183cbc1fb6d2aebeb3150780d5c0e3f86e5.zip
add VC2012 project to compile static and dynamic lib, also fix some C
issues
Diffstat (limited to 'src/scalar.c')
-rw-r--r--src/scalar.c18
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;