changeset 49:4e931b464278

Added xtract_sharpness()
author Jamie Bullock <jamie@postlude.co.uk>
date Thu, 21 Dec 2006 13:23:12 +0000
parents 8703c202a247
children 435be4a78aac
files TODO src/scalar.c src/vector.c xtract/xtract_macros.h xtract/xtract_scalar.h
diffstat 5 files changed, 23 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/TODO	Thu Dec 21 12:06:44 2006 +0000
+++ b/TODO	Thu Dec 21 13:23:12 2006 +0000
@@ -5,6 +5,6 @@
 Add delta functions
 Add Max/MSP external example
 Add self documentation
-Check sfm and tonality
+Check and add return values as appropriate. Make them more sensible!
 ...do other stuff and eventually...
 ...optimise!
--- a/src/scalar.c	Thu Dec 21 12:06:44 2006 +0000
+++ b/src/scalar.c	Thu Dec 21 13:23:12 2006 +0000
@@ -458,7 +458,7 @@
     while(n--){
 	sl = pow(data[n], 0.23);
 	g = (n < 15 ? 1.f : 0.066 * exp(0.171 * n));
-	temp = n * g * sl;
+	temp += n * g * sl;
     }
 
     *result = 0.11 * temp / N;
--- a/src/vector.c	Thu Dec 21 12:06:44 2006 +0000
+++ b/src/vector.c	Thu Dec 21 13:23:12 2006 +0000
@@ -32,7 +32,7 @@
 
 int xtract_magnitude_spectrum(const float *data, const int N, const void *argv, float *result){
 
-    float *temp, *input, q;
+    float *temp, *input, q, sr;
     size_t bytes;
     int n , M = N >> 1;
     fftwf_plan plan;
@@ -41,10 +41,13 @@
     input = (float *)malloc(bytes = N * sizeof(float));
     input = memcpy(input, data, bytes);
 
-    q = 0.f;
+    q = sr = 0.f;
 
-    q = *(float *)argv; 
-    q = (q ? (q * .5) / M : 0.f);
+    sr = *(float *)argv;
+
+    CHECK_SR;
+
+    q = (sr * .5) / M;
 
     plan = fftwf_plan_r2r_1d(N, input, temp, FFTW_R2HC, FFTW_ESTIMATE);
     
@@ -242,18 +245,24 @@
 	  y3, p, width, sr,
 	  *input = NULL;
     size_t bytes;
-    int n = N, M, return_code = SUCCESS;
+    int n = N, M, rv = SUCCESS;
+
+    thresh = max = y = y2 = y3 = p = width = sr = 0.f;
     
     if(argv != NULL){
         thresh = ((float *)argv)[0];
         sr = ((float *)argv)[1];
-        return_code = BAD_ARGV;
     }
-    else{
-        thresh = 0.f;
-        sr = 44100.f;
+    else
+        rv = BAD_ARGV;
+
+    if(thresh < 0 || thresh > 100){
+        thresh = 0;
+        rv = BAD_ARGV;
     }
 
+    CHECK_SR;
+
     input = (float *)malloc(bytes = N * sizeof(float));
 
     if(input != NULL)
@@ -263,18 +272,6 @@
 
     M = N >> 1;
     width = sr / N;
-    
-    y = y2 = y3 = p = max = 0.f;
-
-    if(thresh < 0 || thresh > 100){
-        thresh = 0;
-        return_code = BAD_ARGV;
-    }
-
-    if(!sr){
-        sr = 44100.f;
-        return_code = BAD_ARGV;
-    }
 
     while(n--)
         max = MAX(max, input[n]);
@@ -302,7 +299,7 @@
     }	  
    
     free(input);
-    return (return_code ? return_code : SUCCESS);
+    return (rv ? rv : SUCCESS);
 }
 	    
 int xtract_harmonics(const float *data, const int N, const void *argv, float *result){
--- a/xtract/xtract_macros.h	Thu Dec 21 12:06:44 2006 +0000
+++ b/xtract/xtract_macros.h	Thu Dec 21 13:23:12 2006 +0000
@@ -35,6 +35,7 @@
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 #define MAX(a, b) ((a) > (b) ? (a) : (b))
 #define NEEDS_FFTW printf("LibXtract must be compiled with fftw support to use this function.\n")
+#define CHECK_SR if(!sr) sr = 44100.f
 
 #define VERY_SMALL_NUMBER 1e-20
 #define LOG_LIMIT VERY_SMALL_NUMBER
--- a/xtract/xtract_scalar.h	Thu Dec 21 12:06:44 2006 +0000
+++ b/xtract/xtract_scalar.h	Thu Dec 21 13:23:12 2006 +0000
@@ -258,7 +258,6 @@
 
 /** \brief Extract the Sharpness of an input vector 
  * 
- * \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
@@ -268,7 +267,7 @@
 
 /** \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 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 *data: a pointer to the first element in an array of floats representing a set of BARK_BANDS bark coefficients
  * \param N: the number of elements to be considered
  * \param *argv: a pointer to NULL
  * \param *result: the Slope of N values from the array pointed to by *data