diff options
author | Jamie Bullock <jamie@postlude.co.uk> | 2006-12-20 12:28:08 +0000 |
---|---|---|
committer | Jamie Bullock <jamie@postlude.co.uk> | 2006-12-20 12:28:08 +0000 |
commit | e5051b14a4642a6a6c6097c0ae24ecdfa53594e9 (patch) | |
tree | 99f231bd5a6ca12d4d9e66f8019ceb0205d3a40a | |
parent | 18fc7723fd66941f394c1657c48bb996670d4ac5 (diff) | |
download | LibXtract-e5051b14a4642a6a6c6097c0ae24ecdfa53594e9.tar.gz LibXtract-e5051b14a4642a6a6c6097c0ae24ecdfa53594e9.tar.bz2 LibXtract-e5051b14a4642a6a6c6097c0ae24ecdfa53594e9.zip |
Fixed xtract_flatness()
-rw-r--r-- | config.h.in | 9 | ||||
-rw-r--r-- | examples/puredata/Makefile.am | 22 | ||||
-rw-r--r-- | examples/puredata/xtract~.c | 2 | ||||
-rw-r--r-- | src/scalar.c | 66 |
4 files changed, 38 insertions, 61 deletions
diff --git a/config.h.in b/config.h.in index b05b0e5..babd7f3 100644 --- a/config.h.in +++ b/config.h.in @@ -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 diff --git a/examples/puredata/Makefile.am b/examples/puredata/Makefile.am index dda94f4..ec5c197 100644 --- a/examples/puredata/Makefile.am +++ b/examples/puredata/Makefile.am @@ -14,35 +14,15 @@ xtract_@PD_SUFFIX@_SOURCES = xtract~.c 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) - diff --git a/examples/puredata/xtract~.c b/examples/puredata/xtract~.c index 04d1079..3e855c7 100644 --- a/examples/puredata/xtract~.c +++ b/examples/puredata/xtract~.c @@ -187,10 +187,10 @@ static void *xtract_new(t_symbol *me, t_int argc, t_atom *argv) { 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: diff --git a/src/scalar.c b/src/scalar.c index 55e7a00..02f0f18 100644 --- a/src/scalar.c +++ b/src/scalar.c @@ -46,7 +46,7 @@ int xtract_variance(const float *data, const int N, const void *argv, float *res *result += pow(data[n] - *(float *)argv, 2); *result = *result / (N - 1); - + return SUCCESS; } @@ -60,7 +60,7 @@ int xtract_standard_deviation(const float *data, const int N, const void *argv, 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 @@ int xtract_skewness(const float *data, const int N, const void *argv, float *re } *result /= N; - + return SUCCESS; } @@ -98,7 +98,7 @@ int xtract_kurtosis(const float *data, const int N, const void *argv, float *re *result /= N; *result -= 3.0f; - + return SUCCESS; } @@ -237,7 +237,7 @@ int xtract_smoothness(const float *data, const int N, const void *argv, float *r } free(input); - + return SUCCESS; } @@ -301,41 +301,35 @@ int xtract_loudness(const float *data, const int N, const void *argv, float *res 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 @@ int xtract_odd_even_ratio(const float *data, const int N, const void *argv, floa 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 @@ int xtract_lowest(const float *data, const int N, const void *argv, float *resul lower = *(float *)argv; upper = *((float *)argv+1); - + lowest = upper; while(n--) { @@ -453,7 +447,7 @@ int xtract_lowest(const float *data, const int N, const void *argv, float *resul } *result = (*result == upper ? -0 : *result); - + return SUCCESS; } @@ -591,13 +585,13 @@ int xtract_f0(const float *data, const int N, const void *argv, float *result){ } 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 @@ int xtract_failsafe_f0(const float *data, const int N, const void *argv, float * argf[0] = 0.f; argf[1] = N >> 1; xtract_lowest(peaks, argf[1], argf, result); - + free(magnitudes); free(peaks); } @@ -615,4 +609,4 @@ int xtract_failsafe_f0(const float *data, const int N, const void *argv, float * return SUCCESS; } - + |