aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/scalar.c51
-rw-r--r--xtract/xtract_scalar.h6
2 files changed, 47 insertions, 10 deletions
diff --git a/src/scalar.c b/src/scalar.c
index 49c4408..165cb51 100644
--- a/src/scalar.c
+++ b/src/scalar.c
@@ -245,11 +245,11 @@ int xtract_spread(const float *data, const int N, const void *argv, float *resul
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_odd_even_ratio(const float *data, const int N, const void *argv, floa
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 --git a/xtract/xtract_scalar.h b/xtract/xtract_scalar.h
index 4df5a6d..b42223a 100644
--- a/xtract/xtract_scalar.h
+++ b/xtract/xtract_scalar.h
@@ -170,9 +170,6 @@ int xtract_zcr(const float *data, const int N, const void *argv, float *result);
*/
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_odd_even_ratio(const float *data, const int N, const void *argv, floa
*/
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