changeset 106:3693573a07fa

Added l-norm/spectral flux
author Jamie Bullock <jamie@postlude.co.uk>
date Thu, 27 Dec 2007 20:37:15 +0000
parents f2af1c75e3ed
children 3e648eec95cb
files src/delta.c src/descriptors.c src/libxtract.c xtract/libxtract.h xtract/xtract_delta.h
diffstat 5 files changed, 112 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/delta.c	Thu Dec 27 17:51:07 2007 +0000
+++ b/src/delta.c	Thu Dec 27 20:37:15 2007 +0000
@@ -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_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;
 
 }
-
--- a/src/descriptors.c	Thu Dec 27 17:51:07 2007 +0000
+++ b/src/descriptors.c	Thu Dec 27 20:37:15 2007 +0000
@@ -197,6 +197,8 @@
 	    /* 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 @@
 	    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 @@
 	    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 @@
 	    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 @@
 			"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 @@
 		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 @@
 	    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 @@
 	    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 @@
 	    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 @@
 		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;
--- a/src/libxtract.c	Thu Dec 27 17:51:07 2007 +0000
+++ b/src/libxtract.c	Thu Dec 27 20:37:15 2007 +0000
@@ -65,10 +65,11 @@
     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,
--- a/xtract/libxtract.h	Thu Dec 27 17:51:07 2007 +0000
+++ b/xtract/libxtract.h	Thu Dec 27 20:37:15 2007 +0000
@@ -67,7 +67,7 @@
   * @{
   */
 
-#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 @@
     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 @@
     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,
--- a/xtract/xtract_delta.h	Thu Dec 27 17:51:07 2007 +0000
+++ b/xtract/xtract_delta.h	Thu Dec 27 20:37:15 2007 +0000
@@ -29,8 +29,21 @@
 
 #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 @@
 /* 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*/