aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJamie Bullock <jamie@jamiebullock.com>2014-06-06 09:55:01 +0100
committerJamie Bullock <jamie@jamiebullock.com>2014-06-06 09:55:01 +0100
commite028f0d8204722f01495ec28edadbb4bdf1b6f1b (patch)
treeebe19aef151d7f34755163db7c83edd64cdb45b3 /src
parent0c54ec464079b450e07abe57be680ab88249b76a (diff)
downloadLibXtract-e028f0d8204722f01495ec28edadbb4bdf1b6f1b.tar.gz
LibXtract-e028f0d8204722f01495ec28edadbb4bdf1b6f1b.tar.bz2
LibXtract-e028f0d8204722f01495ec28edadbb4bdf1b6f1b.zip
Add new helper function xtract_smoothed(), e.g. can be used to extract smoothed spectrum
Diffstat (limited to 'src')
-rw-r--r--src/helper.c26
-rw-r--r--src/libxtract.c3
2 files changed, 28 insertions, 1 deletions
diff --git a/src/helper.c b/src/helper.c
index 5b7155f..9b10294 100644
--- a/src/helper.c
+++ b/src/helper.c
@@ -75,6 +75,32 @@ int xtract_features_from_subframes(const double *data, const int N, const int fe
}
+
+/*
+ * Implements y[n] = k * x[n] + (1-k) * y[n-1]
+ */
+int xtract_smoothed(const double *data, const int N, const void *argv, double *result)
+{
+ double gain = *(double *)argv;
+ double oneminusgain = 1.0 - gain;
+ int i;
+
+ // reverse filtering first
+ for (i = N - 2; i >= 0; i--)
+ {
+ result[i] = gain * data[i] + oneminusgain * data[i+1];
+ }
+
+ // then forward filtering
+ for (i = 1; i < N; i++)
+ {
+ result[i] = gain * result[i] + oneminusgain * result[i-1];
+ }
+
+ return XTRACT_SUCCESS;
+}
+
+
//inline int xtract_is_denormal(double const d)
int xtract_is_denormal(double const d)
{
diff --git a/src/libxtract.c b/src/libxtract.c
index 624e8cd..168b106 100644
--- a/src/libxtract.c
+++ b/src/libxtract.c
@@ -90,6 +90,7 @@ int(*xtract[])(const double *, const int, const void *, double *) =
xtract_lpcc,
xtract_subbands,
/* xtract_helper.h */
- xtract_windowed
+ xtract_windowed,
+ xtract_smoothed
};