# HG changeset patch # User Jamie Bullock # Date 1166702804 0 # Node ID 8703c202a247f73666bc0a175729cb7c51bdb8c6 # Parent c20e91e86f088fb576e8fedbae274331c62f3e49 Added xtract_slope() diff -r c20e91e86f08 -r 8703c202a247 src/scalar.c --- a/src/scalar.c Thu Dec 21 11:31:51 2006 +0000 +++ b/src/scalar.c Thu Dec 21 12:06:44 2006 +0000 @@ -245,11 +245,11 @@ int n = N; - float num = 0.f, den = 0.f, tmp; + float num = 0.f, den = 0.f, temp; while(n--){ - tmp = n - *(float *)argv; - num += SQ(tmp) * data[n]; + temp = n - *(float *)argv; + num += SQ(temp) * data[n]; den += data[n]; } @@ -444,13 +444,54 @@ int xtract_sharpness(const float *data, const int N, const void *argv, float *result){ - return FEATURE_NOT_IMPLEMENTED; + int n = N, rv; + float sl, g, temp; /* sl = specific loudness */ + + sl = g = temp = 0.f; + + if(n > BARK_BANDS) + rv = BAD_VECTOR_SIZE; + else + rv = SUCCESS; + + + while(n--){ + sl = pow(data[n], 0.23); + g = (n < 15 ? 1.f : 0.066 * exp(0.171 * n)); + temp = n * g * sl; + } + + *result = 0.11 * temp / N; + + return rv; } int xtract_slope(const float *data, const int N, const void *argv, float *result){ - return FEATURE_NOT_IMPLEMENTED; + const float *freqs, *amps; + float f, a, + F, A, FA, FSQ; /* sums of freqs, amps, freq * amps, freq squared */ + int n, M; + + F = A = FA = FSQ = 0.f; + n = M = N >> 1; + + freqs = data; + amps = data + n; + + while(n--){ + f = freqs[n]; + a = amps[n]; + F += f; + A += a; + FA += f * a; + FSQ += f * f; + } + + *result = (1.f / A) * (M * FA - F * A) / (M * FSQ - F * F); + + return SUCCESS; } diff -r c20e91e86f08 -r 8703c202a247 xtract/xtract_scalar.h --- a/xtract/xtract_scalar.h Thu Dec 21 11:31:51 2006 +0000 +++ b/xtract/xtract_scalar.h Thu Dec 21 12:06:44 2006 +0000 @@ -170,9 +170,6 @@ */ int xtract_rolloff(const float *data, const int N, const void *argv, float *result); -/* Loudness */ -/* A set of BARK_BANDS bark coefficients must be passed in, the loudness is calculated approximately according to Moore, Glasberg et al, 1997 */ - /** \brief Extract the 'total loudness' of an input vector using a method described by Moore, Glasberg et al (2005) * * \param *data: a pointer to the first element in an array of floats representing a set of BARK_BANDS bark coefficients @@ -269,9 +266,8 @@ */ int xtract_sharpness(const float *data, const int N, const void *argv, float *result); -/** \brief Extract the Slope of an input vector +/** \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 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