diff options
author | Jamie Bullock <jamie@postlude.co.uk> | 2006-12-21 13:23:12 +0000 |
---|---|---|
committer | Jamie Bullock <jamie@postlude.co.uk> | 2006-12-21 13:23:12 +0000 |
commit | 436746d12ba3c33fa138dd67c9b746f655058d93 (patch) | |
tree | 1ca98fb98bc0e263c54f0ddfd3a9f74f0cfc6a95 /src/vector.c | |
parent | 8742c7e0952fb3009699426dae3505084534896f (diff) | |
download | LibXtract-436746d12ba3c33fa138dd67c9b746f655058d93.tar.gz LibXtract-436746d12ba3c33fa138dd67c9b746f655058d93.tar.bz2 LibXtract-436746d12ba3c33fa138dd67c9b746f655058d93.zip |
Added xtract_sharpness()
Diffstat (limited to 'src/vector.c')
-rw-r--r-- | src/vector.c | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/src/vector.c b/src/vector.c index bc7140b..7968e74 100644 --- a/src/vector.c +++ b/src/vector.c @@ -32,7 +32,7 @@ int xtract_magnitude_spectrum(const float *data, const int N, const void *argv, float *result){ - float *temp, *input, q; + float *temp, *input, q, sr; size_t bytes; int n , M = N >> 1; fftwf_plan plan; @@ -41,10 +41,13 @@ int xtract_magnitude_spectrum(const float *data, const int N, const void *argv, input = (float *)malloc(bytes = N * sizeof(float)); input = memcpy(input, data, bytes); - q = 0.f; + q = sr = 0.f; - q = *(float *)argv; - q = (q ? (q * .5) / M : 0.f); + sr = *(float *)argv; + + CHECK_SR; + + q = (sr * .5) / M; plan = fftwf_plan_r2r_1d(N, input, temp, FFTW_R2HC, FFTW_ESTIMATE); @@ -242,18 +245,24 @@ int xtract_peaks(const float *data, const int N, const void *argv, float *result y3, p, width, sr, *input = NULL; size_t bytes; - int n = N, M, return_code = SUCCESS; + int n = N, M, rv = SUCCESS; + + thresh = max = y = y2 = y3 = p = width = sr = 0.f; if(argv != NULL){ thresh = ((float *)argv)[0]; sr = ((float *)argv)[1]; - return_code = BAD_ARGV; } - else{ - thresh = 0.f; - sr = 44100.f; + else + rv = BAD_ARGV; + + if(thresh < 0 || thresh > 100){ + thresh = 0; + rv = BAD_ARGV; } + CHECK_SR; + input = (float *)malloc(bytes = N * sizeof(float)); if(input != NULL) @@ -263,18 +272,6 @@ int xtract_peaks(const float *data, const int N, const void *argv, float *result M = N >> 1; width = sr / N; - - y = y2 = y3 = p = max = 0.f; - - if(thresh < 0 || thresh > 100){ - thresh = 0; - return_code = BAD_ARGV; - } - - if(!sr){ - sr = 44100.f; - return_code = BAD_ARGV; - } while(n--) max = MAX(max, input[n]); @@ -302,7 +299,7 @@ int xtract_peaks(const float *data, const int N, const void *argv, float *result } free(input); - return (return_code ? return_code : SUCCESS); + return (rv ? rv : SUCCESS); } int xtract_harmonics(const float *data, const int N, const void *argv, float *result){ |