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 | |
parent | 8742c7e0952fb3009699426dae3505084534896f (diff) | |
download | LibXtract-436746d12ba3c33fa138dd67c9b746f655058d93.tar.gz LibXtract-436746d12ba3c33fa138dd67c9b746f655058d93.tar.bz2 LibXtract-436746d12ba3c33fa138dd67c9b746f655058d93.zip |
Added xtract_sharpness()
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | src/scalar.c | 2 | ||||
-rw-r--r-- | src/vector.c | 41 | ||||
-rw-r--r-- | xtract/xtract_macros.h | 1 | ||||
-rw-r--r-- | xtract/xtract_scalar.h | 3 |
5 files changed, 23 insertions, 26 deletions
@@ -5,6 +5,6 @@ Add Pure Data help file Add delta functions Add Max/MSP external example Add self documentation -Check sfm and tonality +Check and add return values as appropriate. Make them more sensible! ...do other stuff and eventually... ...optimise! diff --git a/src/scalar.c b/src/scalar.c index 165cb51..139cd05 100644 --- a/src/scalar.c +++ b/src/scalar.c @@ -458,7 +458,7 @@ int xtract_sharpness(const float *data, const int N, const void *argv, float *re while(n--){ sl = pow(data[n], 0.23); g = (n < 15 ? 1.f : 0.066 * exp(0.171 * n)); - temp = n * g * sl; + temp += n * g * sl; } *result = 0.11 * temp / N; 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){ diff --git a/xtract/xtract_macros.h b/xtract/xtract_macros.h index f2a89b7..8b55d48 100644 --- a/xtract/xtract_macros.h +++ b/xtract/xtract_macros.h @@ -35,6 +35,7 @@ extern "C" { #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define NEEDS_FFTW printf("LibXtract must be compiled with fftw support to use this function.\n") +#define CHECK_SR if(!sr) sr = 44100.f #define VERY_SMALL_NUMBER 1e-20 #define LOG_LIMIT VERY_SMALL_NUMBER diff --git a/xtract/xtract_scalar.h b/xtract/xtract_scalar.h index b42223a..959d06a 100644 --- a/xtract/xtract_scalar.h +++ b/xtract/xtract_scalar.h @@ -258,7 +258,6 @@ int xtract_odd_even_ratio(const float *data, const int N, const void *argv, floa /** \brief Extract the Sharpness of an input vector * - * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum(). * \param N: the number of elements to be considered * \param *argv: a pointer to NULL @@ -268,7 +267,7 @@ int xtract_sharpness(const float *data, const int N, const void *argv, float *re /** \brief Extract the Slope of an input vector using a method described by Peeters(2003) * - * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum(). + * \param *data: a pointer to the first element in an array of floats representing a set of BARK_BANDS bark coefficients * \param N: the number of elements to be considered * \param *argv: a pointer to NULL * \param *result: the Slope of N values from the array pointed to by *data |