changeset 44:b2e7e24c9a9c

Fixed xtract_flatness()
author Jamie Bullock <jamie@postlude.co.uk>
date Wed, 20 Dec 2006 12:28:08 +0000
parents 4a36f70a76e9
children e8f4c56de591
files config.h.in examples/puredata/Makefile.am examples/puredata/xtract~.c src/scalar.c
diffstat 4 files changed, 38 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/config.h.in	Fri Dec 15 21:17:12 2006 +0000
+++ b/config.h.in	Wed Dec 20 12:28:08 2006 +0000
@@ -18,8 +18,8 @@
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 
-/* Define to 1 if you have the <math.h */
-#undef HAVE_MATH_H
+/* Define to 1 if you have the <math.h,> header file. */
+#undef HAVE_MATH_H_
 
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
@@ -30,9 +30,12 @@
 /* Define to 1 if you have the <stdio.h> header file. */
 #undef HAVE_STDIO_H
 
-/* Define to 1 if you have the <stdlib.h */
+/* Define to 1 if you have the <stdlib.h> header file. */
 #undef HAVE_STDLIB_H
 
+/* Define to 1 if you have the <stdlib.h,> header file. */
+#undef HAVE_STDLIB_H_
+
 /* Define to 1 if you have the <strings.h> header file. */
 #undef HAVE_STRINGS_H
 
--- a/examples/puredata/Makefile.am	Fri Dec 15 21:17:12 2006 +0000
+++ b/examples/puredata/Makefile.am	Wed Dec 20 12:28:08 2006 +0000
@@ -14,35 +14,15 @@
 
 pdincludedir = $(pddir)/src
 
-#LIBTOOL=$(SHELL) $(srcdir)/libtoolkludge
-
 INCLUDES = -I$(top_srcdir)/src -I$(pdincludedir)
 
-#AM_CFLAGS  = -DPD -fPIC -DPIC
-#AM_LDFLAGS = -L$(top_builddir)/src/.libs -lxtract -export_dynamic -shared 
-
 AM_CFLAGS = @PD_CFLAGS@
 AM_LDFLAGS = @PD_LDFLAGS@ -lxtract -L$(top_builddir)/src/
 		
 ## Install the documentation.
 
 install:
+	install -d $(pdinstalldir)
 	install -m 644 $(top_builddir)/examples/puredata/.libs/xtract.@PD_SUFFIX@ $(pdinstalldir)/xtract~.@PD_SUFFIX@
 	install -d $(pddir)/doc/5.reference/xtract
 	cp xtract/* $(PDDIR)/doc/5.reference/xtract
-
-#pdinstallref_DATA = \
-#	help/aubioonset-help.pd \
-#	help/aubioquiet-help.pd \
-#	help/aubiotempo-help.pd \
-#	help/aubiotss-help.pd \
-#	help/aubiopitch-help.pd
-#
-#pdinstallexp_DATA = \
-#	examples/onset-cam.pd
-#
-### My kludge
-#noinst_SCRIPTS = libtoolkludge
-#
-#EXTRA_DIST = $(pdinstallref_DATA) $(pdinstallexp_DATA) $(noinst_SCRIPTS)
-
--- a/examples/puredata/xtract~.c	Fri Dec 15 21:17:12 2006 +0000
+++ b/examples/puredata/xtract~.c	Wed Dec 20 12:28:08 2006 +0000
@@ -187,10 +187,10 @@
 	case  TRISTIMULUS_2:
 	case  TRISTIMULUS_3:
 	case  SMOOTHNESS:
+	case  FLATNESS:
 	case  SPREAD:
 	case  ZCR:
 	case  LOUDNESS:
-	case  FLATNESS:
 	case  CREST:
 	case  NOISINESS:
 	case  RMS_AMPLITUDE:
--- a/src/scalar.c	Fri Dec 15 21:17:12 2006 +0000
+++ b/src/scalar.c	Wed Dec 20 12:28:08 2006 +0000
@@ -46,7 +46,7 @@
 	*result += pow(data[n] - *(float *)argv, 2);
 
     *result = *result / (N - 1);
-    
+
     return SUCCESS;
 }
 
@@ -60,7 +60,7 @@
 int xtract_average_deviation(const float *data, const int N, const void *argv, float *result){
 
     int n = N;
-    
+
     while(n--)
 	*result += fabs(data[n] - *(float *)argv);
 
@@ -81,7 +81,7 @@
     }
 
     *result /= N;
-	
+
     return SUCCESS;
 }
 
@@ -98,7 +98,7 @@
 
     *result /= N;
     *result -= 3.0f;
-  
+
     return SUCCESS;
 }
 
@@ -237,7 +237,7 @@
     }
 
     free(input);
-    
+
     return SUCCESS;
 }
 
@@ -301,41 +301,35 @@
     return SUCCESS;
 }
 
-
 int xtract_flatness(const float *data, const int N, const void *argv, float *result){
 
     int n;
 
-    float num, den, temp, *tmp, prescale; 
-    int lower, upper; 
+    double num, den, temp; 
 
-    tmp = (float *)argv;
-    lower = (int)tmp[0];
-    upper = (int)tmp[1];
-    prescale = (float)tmp[2]; 
+    den = data[0];
+    num = (data[0] == 0.f ? 1.f : data[0]);
 
-    upper = (upper > N ? N : upper);
-    lower = (lower < 0.f ? 0.f : lower);
-    
-    den = temp = num = 0.f;
-
-    for(n = lower; n < upper; n++){
-	if((temp = data[n] * prescale)){
-	    if(!num)
-		num = den = temp;
-	    else{
-		num *= temp;
-		den += temp;
-	    }
+    for(n = 1; n < N; n++){
+	if((temp = data[n]) != 0.f) {
+	    num *= temp;
+	    den += temp;
 	}
     }
-    
-    num = powf(num, 1.0f / N); 
+
+    num = pow(num, 1.f / N);
     den /= N;
 
+    if(num < 1e-20) 
+	num = 1e-20;
+
+    if(den < 1e-20) 
+	den = 1e-20;
+
     *result = num / den;
 
     return SUCCESS;
+
 }
 
 int xtract_tonality(const float *data, const int N, const void *argv, float *result){
@@ -408,7 +402,7 @@
     float num = 0.f, den = 0.f,  temp, f0;
 
     f0 = *(float *)argv;
-    
+
     for(n = 0; n < M; n++){
 	if((temp = data[n])){
 	    if(((int)(rintf(temp / f0)) % 2) != 0){
@@ -444,7 +438,7 @@
 
     lower = *(float *)argv;
     upper = *((float *)argv+1);
-    
+
     lowest = upper;
 
     while(n--) {
@@ -453,7 +447,7 @@
     }
 
     *result = (*result == upper ? -0 : *result);
-    
+
     return SUCCESS;
 }
 
@@ -591,13 +585,13 @@
 }
 
 int xtract_failsafe_f0(const float *data, const int N, const void *argv, float *result){
-    
+
     float *magnitudes = NULL, argf[2], *peaks = NULL, return_code;
-    
+
     return_code = xtract_f0(data, N, argv, result);
-    
+
     if(return_code == NO_RESULT){
-	
+
 	magnitudes = (float *)malloc(N * sizeof(float));
 	peaks = (float *)malloc(N * sizeof(float));
 	xtract_magnitude_spectrum(data, N, NULL, magnitudes);
@@ -607,7 +601,7 @@
 	argf[0] = 0.f;
 	argf[1] = N >> 1;
 	xtract_lowest(peaks, argf[1], argf, result);
-	
+
 	free(magnitudes);
 	free(peaks);
     }
@@ -615,4 +609,4 @@
     return SUCCESS;
 
 }
-	
+