diff options
author | Q <andrea@nocte.co.uk> | 2014-03-27 09:48:26 +0000 |
---|---|---|
committer | Q <andrea@nocte.co.uk> | 2014-03-27 09:48:26 +0000 |
commit | cc719183cbc1fb6d2aebeb3150780d5c0e3f86e5 (patch) | |
tree | 65dcab27479085b99305a7a8a41beeefee37deb7 /src | |
parent | 0bb0f22ddec2de97f7938916c9cf278b99e6a9e7 (diff) | |
download | LibXtract-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')
-rw-r--r-- | src/descriptors.c | 42 | ||||
-rw-r--r-- | src/fft.h | 11 | ||||
-rw-r--r-- | src/helper.c | 6 | ||||
-rw-r--r-- | src/init.c | 6 | ||||
-rw-r--r-- | src/scalar.c | 18 | ||||
-rw-r--r-- | src/vector.c | 10 |
6 files changed, 50 insertions, 43 deletions
diff --git a/src/descriptors.c b/src/descriptors.c index efcf02d..2bfdd35 100644 --- a/src/descriptors.c +++ b/src/descriptors.c @@ -42,7 +42,7 @@ xtract_function_descriptor_t *xtract_make_descriptors(void) f = F = XTRACT_FEATURES; - fd = malloc(XTRACT_FEATURES * sizeof(xtract_function_descriptor_t)); + fd = (xtract_function_descriptor_t*)malloc(XTRACT_FEATURES * sizeof(xtract_function_descriptor_t)); /* FIX - this file probably needs a rewrite for readability */ @@ -129,7 +129,7 @@ xtract_function_descriptor_t *xtract_make_descriptors(void) *(argv_min + 1) = 0.0; *(argv_max + 1) = 1.0 ; *(argv_def + 1) = .1 ; - *(argv_unit + 1) = XTRACT_NONE; + *(argv_unit + 1) = (xtract_unit_t)XTRACT_NONE; break; case XTRACT_NOISINESS: case XTRACT_SKEWNESS: @@ -140,11 +140,11 @@ xtract_function_descriptor_t *xtract_make_descriptors(void) *argv_min = XTRACT_NONE; *argv_max = XTRACT_NONE; *argv_def = XTRACT_NONE; - *argv_unit = XTRACT_NONE; + *argv_unit = (xtract_unit_t)XTRACT_NONE; *(argv_min + 1) = XTRACT_NONE; *(argv_max + 1) = XTRACT_NONE; *(argv_def + 1) = XTRACT_NONE; - *(argv_unit + 1) = XTRACT_NONE; + *(argv_unit + 1) = (xtract_unit_t)XTRACT_NONE; break; /* argc = 4 */ case XTRACT_SPECTRUM: @@ -155,29 +155,29 @@ xtract_function_descriptor_t *xtract_make_descriptors(void) *(argv_min + 1) = 0; *(argv_max + 1) = 3 ; *(argv_def + 1) = 0; - *(argv_unit + 1) = XTRACT_NONE; + *(argv_unit + 1) = (xtract_unit_t)XTRACT_NONE; *(argv_min + 2) = 0; *(argv_max + 2) = 1; *(argv_def + 2) = 0; - *(argv_unit + 2) = XTRACT_NONE; + *(argv_unit + 2) = (xtract_unit_t)XTRACT_NONE; *(argv_min + 3) = 0; *(argv_max + 3) = 1; *(argv_def + 3) = 0; - *(argv_unit + 3) = XTRACT_NONE; + *(argv_unit + 3) = (xtract_unit_t)XTRACT_NONE; break; case XTRACT_SUBBANDS: *argv_min = XTRACT_ANY; *argv_max = XTRACT_ANY; *argv_def = XTRACT_MEAN; - *argv_unit = XTRACT_NONE; + *argv_unit = (xtract_unit_t)XTRACT_NONE; *(argv_min + 1) = 1; *(argv_max + 1) = 16384; *(argv_def + 1) = 4; - *(argv_unit + 1) = XTRACT_NONE; + *(argv_unit + 1) = (xtract_unit_t)XTRACT_NONE; *(argv_min + 2) = 0; *(argv_max + 2) = 32; *(argv_def + 2) = 0; - *(argv_unit + 2) = XTRACT_NONE; + *(argv_unit + 2) = (xtract_unit_t)XTRACT_NONE; *(argv_min + 3) = 0; *(argv_max + 3) = XTRACT_ANY; *(argv_def + 3) = 0; @@ -191,7 +191,7 @@ xtract_function_descriptor_t *xtract_make_descriptors(void) *argv_min = XTRACT_NONE; *argv_max = XTRACT_NONE; *argv_def = XTRACT_NONE; - *argv_unit = XTRACT_NONE; + *argv_unit = (xtract_unit_t)XTRACT_NONE; break; } @@ -443,7 +443,7 @@ xtract_function_descriptor_t *xtract_make_descriptors(void) case XTRACT_LPCC: case XTRACT_WINDOWED: case XTRACT_SUBBANDS: - *data_unit = XTRACT_ANY; + *data_unit = (xtract_unit_t)XTRACT_ANY; break; case XTRACT_SPECTRAL_MEAN: case XTRACT_SPECTRAL_VARIANCE: @@ -1251,7 +1251,7 @@ xtract_function_descriptor_t *xtract_make_descriptors(void) case XTRACT_LNORM: case XTRACT_NONZERO_COUNT: case XTRACT_WINDOWED: - *result_unit = XTRACT_ANY; + *result_unit = (xtract_unit_t)XTRACT_ANY; *result_min = XTRACT_ANY; *result_max = XTRACT_ANY; break; @@ -1264,7 +1264,7 @@ xtract_function_descriptor_t *xtract_make_descriptors(void) case XTRACT_TRISTIMULUS_3: case XTRACT_NOISINESS: case XTRACT_SMOOTHNESS: - *result_unit = XTRACT_NONE; + *result_unit = (xtract_unit_t)XTRACT_NONE; *result_min = XTRACT_ANY; /* FIX: need to check these */ *result_max = XTRACT_ANY; break; @@ -1293,7 +1293,7 @@ xtract_function_descriptor_t *xtract_make_descriptors(void) *result_max = XTRACT_ANY; break; case XTRACT_ODD_EVEN_RATIO: - *result_unit = XTRACT_NONE; + *result_unit = (xtract_unit_t)XTRACT_NONE; *result_min = 0.0; *result_max = 1.0; break; @@ -1313,7 +1313,7 @@ xtract_function_descriptor_t *xtract_make_descriptors(void) case XTRACT_LPC: case XTRACT_LPCC: default: - *result_unit = XTRACT_UNKNOWN; + *result_unit = (xtract_unit_t)XTRACT_UNKNOWN; *result_min = XTRACT_UNKNOWN; *result_max = XTRACT_UNKNOWN; break; @@ -1336,11 +1336,11 @@ xtract_function_descriptor_t *xtract_make_descriptors(void) case XTRACT_SUBBANDS: case XTRACT_WINDOWED: *result_format = XTRACT_ARBITRARY_SERIES; - *result_unit = XTRACT_ANY; + *result_unit = (xtract_unit_t)XTRACT_ANY; break; case XTRACT_BARK_COEFFICIENTS: *result_format = XTRACT_BARK_COEFFS; - *result_unit = XTRACT_UNKNOWN; /* FIX: check */ + *result_unit = (xtract_unit_t)XTRACT_UNKNOWN; /* FIX: check */ break; case XTRACT_PEAK_SPECTRUM: case XTRACT_SPECTRUM: @@ -1352,15 +1352,15 @@ xtract_function_descriptor_t *xtract_make_descriptors(void) break; case XTRACT_MFCC: *result_format = XTRACT_MEL_COEFFS; - *result_unit = XTRACT_UNKNOWN; /* FIX: check */ + *result_unit = (xtract_unit_t)XTRACT_UNKNOWN; /* FIX: check */ break; case XTRACT_LPC: *result_format = XTRACT_LPC_COEFFS; - *result_unit = XTRACT_UNKNOWN; + *result_unit = (xtract_unit_t)XTRACT_UNKNOWN; break; case XTRACT_LPCC: *result_format = XTRACT_LPCC_COEFFS; - *result_unit = XTRACT_UNKNOWN; + *result_unit = (xtract_unit_t)XTRACT_UNKNOWN; break; default: break; @@ -28,7 +28,16 @@ #include <config.h> #endif -#include <stdbool.h> +#ifdef _MSC_VER + #define USE_OOURA + #ifndef __cplusplus + typedef int bool; + #define false 0 + #define true 1 + #endif +#else + #include <stdbool.h> +#endif #ifdef USE_OOURA #include "ooura/fftsg.h" diff --git a/src/helper.c b/src/helper.c index 182276f..5b7155f 100644 --- a/src/helper.c +++ b/src/helper.c @@ -75,7 +75,8 @@ int xtract_features_from_subframes(const double *data, const int N, const int fe } -inline int xtract_is_denormal(double const d) +//inline int xtract_is_denormal(double const d) +int xtract_is_denormal(double const d) { if(sizeof(d) != 2 * sizeof(int)) fprintf(stderr, "libxtract: Error: xtract_is_denormal() detects inconsistent wordlength for type 'double'\n"); @@ -84,7 +85,8 @@ inline int xtract_is_denormal(double const d) return (l&0x7ff00000) == 0 && d!=0; //Check for 0 may not be necessary } -inline bool xtract_is_poweroftwo(unsigned int x) +//inline bool xtract_is_poweroftwo(unsigned int x) +bool xtract_is_poweroftwo(unsigned int x) { return ((x != 0) && !(x & (x - 1))); } @@ -43,7 +43,7 @@ #ifdef USE_OOURA void xtract_init_ooura_data(xtract_ooura_data *ooura_data, unsigned int N) { - ooura_data->ooura_ip = (int *)calloc(2 + sqrt(N), sizeof(int)); + ooura_data->ooura_ip = (int *)calloc(2 + sqrt((double)N), sizeof(int)); ooura_data->ooura_w = (double *)calloc(N * 5 / 4, sizeof(double)); ooura_data->initialised = true; } @@ -397,7 +397,7 @@ double *xtract_init_window(const int N, const int type) { double *window; - window = malloc(N * sizeof(double)); + window = (double*)malloc(N * sizeof(double)); switch (type) { @@ -444,7 +444,7 @@ void xtract_free_window(double *window) #ifdef __GNUC__ __attribute__((constructor)) void init() #else -void _init()ยท +void _init() #endif { #ifdef USE_OOURA 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; diff --git a/src/vector.c b/src/vector.c index 5074b65..9c49c2c 100644 --- a/src/vector.c +++ b/src/vector.c @@ -83,7 +83,7 @@ int xtract_spectrum(const double *data, const int N, const void *argv, double *r * the output format is * a[0] - DC, a[1] - nyquist, a[2...N-1] - remaining bins */ - fft = malloc(N * sizeof(double)); + fft = (double*)malloc(N * sizeof(double)); assert(fft != NULL); memcpy(fft, data, N * sizeof(double)); @@ -375,7 +375,7 @@ int xtract_dct(const double *data, const int N, const void *argv, double *result int n; int m; - double *temp = calloc(N, sizeof(double)); + double *temp = (double*)calloc(N, sizeof(double)); for (n = 0; n < N; ++n) { @@ -502,7 +502,7 @@ int xtract_peak_spectrum(const double *data, const int N, const void *argv, doub bytes = N * sizeof(double); if(input != NULL) - input = memcpy(input, data, bytes); + input = (double*)memcpy(input, data, bytes); else return XTRACT_MALLOC_FAILED; @@ -562,8 +562,8 @@ int xtract_harmonic_spectrum(const double *data, const int N, const void *argv, if(freqs[n]) { ratio = freqs[n] / f0; - nearest = round(ratio); - distance = fabs(nearest - ratio); + nearest = floor( 0.5f + ratio); // replace -> nearest = round(ratio); + distance = fabs(nearest - ratio); if(distance > threshold) result[n] = result[M + n] = 0.0; else |