aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJamie Bullock <jamie@postlude.co.uk>2006-12-21 12:06:44 +0000
committerJamie Bullock <jamie@postlude.co.uk>2006-12-21 12:06:44 +0000
commit8742c7e0952fb3009699426dae3505084534896f (patch)
treedac72fd10deef0cfcb833f52d863bb47ac7a8ede /src
parent0971d72ace9b0d4c956817bf88f97e15461af112 (diff)
downloadLibXtract-8742c7e0952fb3009699426dae3505084534896f.tar.gz
LibXtract-8742c7e0952fb3009699426dae3505084534896f.tar.bz2
LibXtract-8742c7e0952fb3009699426dae3505084534896f.zip
Added xtract_slope()
Diffstat (limited to 'src')
-rw-r--r--src/scalar.c51
1 files changed, 46 insertions, 5 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;
}