aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/delta.c57
-rw-r--r--src/descriptors.c36
-rw-r--r--src/libxtract.c3
-rw-r--r--xtract/libxtract.h10
-rw-r--r--xtract/xtract_delta.h26
5 files changed, 112 insertions, 20 deletions
diff --git a/src/delta.c b/src/delta.c
index 6ca3794..79250e2 100644
--- a/src/delta.c
+++ b/src/delta.c
@@ -20,12 +20,49 @@
/* xtract_delta.c: defines functions that extract a feature as a single value from more than one input vector */
+#include <math.h>
+
#include "xtract/libxtract.h"
int xtract_flux(const float *data, const int N, const void *argv , float *result){
+ return xtract_lnorm(data, N, argv, result);
- return XTRACT_FEATURE_NOT_IMPLEMENTED;
+}
+
+int xtract_lnorm(const float *data, const int N, const void *argv , float *result){
+
+ int feature,
+ n,
+ type;
+
+ float order,
+ temp = 0.f;
+
+ order = *(float *)argv;
+ type = (int)*(float *)argv+1;
+
+ order = order > 0 ? order : 1.f;
+
+ switch(type){
+
+ case XTRACT_POSITIVE_SLOPE:
+ for(n = 0; n < N; n++){
+ temp = powf(data[n], order);
+ if(data[n] > 0)
+ *result += temp;
+ }
+ break;
+ default:
+ for(n = 0; n < N; n++)
+ *result += powf(data[n], order);
+ break;
+
+ }
+
+ *result = powf(*result, 1.f / order);
+
+ return XTRACT_SUCCESS;
}
@@ -41,9 +78,21 @@ int xtract_decay_time(const float *data, const int N, const void *argv, float *r
}
-int xtract_delta_feature(const float *data, const int N, const void *argv, float *result){
+int xtract_difference_vector(const float *data, const int N, const void *argv, float *result){
- return XTRACT_FEATURE_NOT_IMPLEMENTED;
+ float *frame1,
+ *frame2;
-}
+ int n;
+ n = N >> 1;
+
+ frame1 = data;
+ frame2 = data + n;
+
+ while(n--)
+ result[n] = frame1[n] - frame2[n];
+
+ return XTRACT_SUCCESS;
+
+}
diff --git a/src/descriptors.c b/src/descriptors.c
index 4584899..4297539 100644
--- a/src/descriptors.c
+++ b/src/descriptors.c
@@ -197,6 +197,8 @@ void *xtract_make_descriptors(){
/* argc = 2 */;
case XTRACT_ROLLOFF:
case XTRACT_PEAK_SPECTRUM:
+ case XTRACT_FLUX:
+ case XTRACT_LNORM:
*argv_donor = XTRACT_ANY;
*(argv_donor + 1) = XTRACT_ANY;
break;
@@ -301,6 +303,8 @@ void *xtract_make_descriptors(){
case XTRACT_ASDF:
case XTRACT_ZCR:
case XTRACT_RMS_AMPLITUDE:
+ case XTRACT_FLUX:
+ case XTRACT_LNORM:
*data_format = XTRACT_AUDIO_SAMPLES;
break;
case XTRACT_TONALITY:
@@ -316,10 +320,9 @@ void *xtract_make_descriptors(){
case XTRACT_SHARPNESS:
*data_format = XTRACT_BARK_COEFFS;
break;
- case XTRACT_FLUX:
case XTRACT_ATTACK_TIME:
case XTRACT_DECAY_TIME:
- case XTRACT_DELTA_FEATURE:
+ case XTRACT_DIFFERENCE_VECTOR:
default:
*data_format = XTRACT_NO_DATA;
break;
@@ -350,8 +353,9 @@ void *xtract_make_descriptors(){
case XTRACT_IRREGULARITY_J:
case XTRACT_ATTACK_TIME:
case XTRACT_DECAY_TIME:
- case XTRACT_DELTA_FEATURE:
+ case XTRACT_DIFFERENCE_VECTOR:
case XTRACT_FLUX:
+ case XTRACT_LNORM:
case XTRACT_F0:
case XTRACT_FAILSAFE_F0:
case XTRACT_MFCC:
@@ -798,6 +802,13 @@ void *xtract_make_descriptors(){
"Extract the spectral flux of an audio spectrum");
strcpy(author, "");
break;
+ case XTRACT_LNORM:
+ strcpy(name, "L-norm");
+ strcpy(p_name, "L-norm");
+ strcpy(desc, "Extract the L-norm of a vector");
+ strcpy(p_desc, "Extract the L-norm of a vector");
+ strcpy(author, "");
+ break;
case XTRACT_ATTACK_TIME:
strcpy(name, "attack_time");
strcpy(p_name, "Attack Time");
@@ -812,11 +823,11 @@ void *xtract_make_descriptors(){
strcpy(p_desc, "Extract the decay time of an audio signal");
strcpy(author, "");
break;
- case XTRACT_DELTA_FEATURE:
- strcpy(name, "delta_feature");
- strcpy(p_name, "Delta Feature");
- strcpy(desc, "Extract the time derivative of a feature");
- strcpy(p_desc, "Extract the time derivative of a feature");
+ case XTRACT_DIFFERENCE_VECTOR:
+ strcpy(name, "difference_vector");
+ strcpy(p_name, "Difference vector");
+ strcpy(desc, "Extract the difference between two vectors");
+ strcpy(p_desc, "Extract the difference between two vectors");
strcpy(author, "");
break;
case XTRACT_AUTOCORRELATION_FFT:
@@ -897,6 +908,8 @@ void *xtract_make_descriptors(){
case XTRACT_NOISINESS:
case XTRACT_CREST:
case XTRACT_ROLLOFF:
+ case XTRACT_FLUX:
+ case XTRACT_LNORM:
*argc = 2;
*argv_type = XTRACT_FLOAT;
break;
@@ -936,10 +949,9 @@ void *xtract_make_descriptors(){
case XTRACT_SHARPNESS:
case XTRACT_SPECTRAL_SLOPE:
case XTRACT_HPS:
- case XTRACT_FLUX:
case XTRACT_ATTACK_TIME:
case XTRACT_DECAY_TIME:
- case XTRACT_DELTA_FEATURE:
+ case XTRACT_DIFFERENCE_VECTOR:
case XTRACT_AUTOCORRELATION_FFT:
case XTRACT_DCT:
case XTRACT_AUTOCORRELATION:
@@ -995,6 +1007,8 @@ void *xtract_make_descriptors(){
case XTRACT_HPS:
case XTRACT_F0:
case XTRACT_FAILSAFE_F0:
+ case XTRACT_FLUX:
+ case XTRACT_LNORM:
case XTRACT_NONZERO_COUNT:
*is_scalar = XTRACT_TRUE;
break;
@@ -1035,6 +1049,8 @@ void *xtract_make_descriptors(){
case XTRACT_LOWEST_VALUE:
case XTRACT_HIGHEST_VALUE:
case XTRACT_SUM:
+ case XTRACT_FLUX:
+ case XTRACT_LNORM:
case XTRACT_NONZERO_COUNT:
*result_unit = XTRACT_ANY;
*result_min = XTRACT_ANY;
diff --git a/src/libxtract.c b/src/libxtract.c
index a3ed984..cf0dd1a 100644
--- a/src/libxtract.c
+++ b/src/libxtract.c
@@ -65,10 +65,11 @@ int(*xtract[])(const float *, const int, const void *, float *) = {
xtract_f0,
xtract_failsafe_f0,
/* xtract_delta.h */
+ xtract_lnorm,
xtract_flux,
xtract_attack_time,
xtract_decay_time,
- xtract_delta_feature,
+ xtract_difference_vector,
/* xtract_vector.h */
xtract_autocorrelation,
xtract_amdf,
diff --git a/xtract/libxtract.h b/xtract/libxtract.h
index 4b948f1..b540c6a 100644
--- a/xtract/libxtract.h
+++ b/xtract/libxtract.h
@@ -67,7 +67,7 @@ extern "C" {
* @{
*/
-#define XTRACT_FEATURES 56
+#define XTRACT_FEATURES 57
/** \brief Enumeration of features, elements are used as indixes to an array of pointers to feature extracton functions */
enum xtract_features_ {
@@ -111,10 +111,11 @@ enum xtract_features_ {
XTRACT_HPS,
XTRACT_F0,
XTRACT_FAILSAFE_F0,
+ XTRACT_LNORM,
XTRACT_FLUX,
XTRACT_ATTACK_TIME,
XTRACT_DECAY_TIME,
- XTRACT_DELTA_FEATURE,
+ XTRACT_DIFFERENCE_VECTOR,
XTRACT_AUTOCORRELATION,
XTRACT_AMDF,
XTRACT_ASDF,
@@ -148,6 +149,11 @@ enum xtract_mfcc_types_ {
XTRACT_EQUAL_AREA
};
+enum xtract_lnorm_filter_types_ {
+ XTRACT_POSITIVE_SLOPE,
+ XTRACT_NEGATIVE_SLOPE
+};
+
/** \brief Enumeration of return codes */
enum xtract_return_codes_ {
XTRACT_SUCCESS,
diff --git a/xtract/xtract_delta.h b/xtract/xtract_delta.h
index 706c812..9b4f28f 100644
--- a/xtract/xtract_delta.h
+++ b/xtract/xtract_delta.h
@@ -29,8 +29,21 @@ extern "C" {
#include "xtract_types.h"
-/* \brief Extract spectral flux as defined by Gaƫl Richard (2006)*/
+/* \brief Extract flux
+ *
+ * An alias for xtract_lnorm()
+ */
int xtract_flux(const float *data, const int N, const void *argv , float *result);
+
+/* \brief Extract the L-norm of a vector
+ *
+ * \param *data: a pointer to the first element in an array of floats representing the difference between two subsequent frames of output from a vector-based feature e.g. the *result from xtract_difference_vector()
+ * \param N: the length of the array pointed to by *data
+ * \param *argv: a pointer to an array of floats, the first representing the "norm order". The second argument represents the filter type determining what values we consider from the difference vector as given in the enumeration xtract_lnorm_filter_types_ (libxtract.h)
+ * \param *result: a pointer to a float representing the flux
+ *
+ */
+int xtract_lnorm(const float *data, const int N, const void *argv , float *result);
/*xtract_frame_tracker *xf */
/** \brief Extract attack Time */
@@ -42,8 +55,15 @@ int xtract_decay_time(const float *data, const int N, const void *argv, float *r
/* xtract_amp_tracker *xa */
-/** \brief A generic function to calculate the delta of a feature over a given period (in frames) */
-int xtract_delta_feature(const float *data, const int N, const void *argv, float *result);
+/** \brief Extract the difference between two vectors
+ *
+ * \param *data a pointer to an array representing two distinct vectors, e.g. two successive magnitude spectra.
+ * \param N the size of the array pointed to by *data
+ * \param *argv a pointer to NULL
+ * \param *result a pointer to an array of size N / 2 representing the difference between the two input vectors.
+ *
+ * */
+int xtract_difference_vector(const float *data, const int N, const void *argv, float *result);
/*xtract_frame_tracker *xf */
/*float frames*/