changeset 78:afb298ce1b4d

Fixes for MSP example, and changed the fundamental estimators so that if they don't get a samplerate 44100 is assumed (I'm not sure if this is a good idea!).
author Jamie Bullock <jamie@postlude.co.uk>
date Sun, 19 Aug 2007 16:54:25 +0000
parents 899c31350e8d
children 06c3ca76e007
files examples/MSP/Makefile examples/MSP/xtract~.c src/scalar.c xtract/xtract_scalar.h
diffstat 4 files changed, 42 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/examples/MSP/Makefile	Tue Jul 31 20:44:17 2007 +0000
+++ b/examples/MSP/Makefile	Sun Aug 19 16:54:25 2007 +0000
@@ -7,7 +7,7 @@
 MAXINCLUDE = /usr/local/include/max-includes 
 MSPINCLUDE = /usr/local/include/msp-includes 
 FRAMEWORKS = /Library/Frameworks
-INSTALLDIR = /Applications/MaxMSP\ 4.6/Cycling\ \'74/externals/
+INSTALLDIR = /Applications/Audio/MaxMSP\ 4.6.3/Cycling\ \'74/externals/
 
 LIPO = /usr/bin/lipo
 CC = gcc
@@ -15,7 +15,7 @@
 CFLAGS = -F$(FRAMEWORKS) -Wmost -Wno-four-char-constants -Wno-unknown-pragmas -x c -pipe -Wno-trigraphs -fpascal-strings -fasm-blocks -Os -fmessage-length=0 -I$(MAXINCLUDE) -I$(MSPINCLUDE) -include macho-prefix.h  -Werror
 
 I386CFLAGS = -arch i386 
-PPCCFLAGS = -arch ppc -faltivec -fasm-blocks
+PPCCFLAGS = -arch ppc -faltivec -fasm-blocks -Wno-unused
 
 LDFLAGS = -F$(FRAMEWORKS) -L$(MAXINCLUDE) -L$(MSPINCLUDE) -framework Carbon -framework MaxAPI -framework MaxAudioAPI -Wl,-Y,1455 -bundle -L/usr/local/lib -lxtract
 
@@ -24,10 +24,10 @@
 
 universal: 
 	$(CC) $(CFLAGS) $(I386CFLAGS) -o $(NAME)-i386.o -c $(NAME).c
-#	$(CC) $(CFLAGS) $(PPCCFLAGS) -o $(NAME)-ppc.o -c $(NAME).c
+	$(CC) $(CFLAGS) $(PPCCFLAGS) -o $(NAME)-ppc.o -c $(NAME).c
 	$(CC) $(LDFLAGS) $(I386LDFLAGS) -o $(NAME)-i386 $(NAME)-i386.o
-#	$(CC) $(LDFLAGS) $(PPCLDFLAGS) -o $(NAME)-ppc $(NAME)-ppc.o
-#	$(LIPO) -create $(NAME)-ppc $(NAME)-i386 -output $(NAME)
+	$(CC) $(LDFLAGS) $(PPCLDFLAGS) -o $(NAME)-ppc $(NAME)-ppc.o
+	$(LIPO) -create $(NAME)-ppc $(NAME)-i386 -output $(NAME)
 	$(LIPO) -create $(NAME)-i386 -output $(NAME)
 	mkdir -p $(NAME).mxo/Contents/MacOS
 	cp Info.plist PkgInfo $(NAME).mxo/Contents/
--- a/examples/MSP/xtract~.c	Tue Jul 31 20:44:17 2007 +0000
+++ b/examples/MSP/xtract~.c	Sun Aug 19 16:54:25 2007 +0000
@@ -46,11 +46,11 @@
 } t_xtract_tilde;
 
 static t_int *xtract_perform(t_int *w) {
-    t_sample *in = (t_sample *)(w[1]);
+    t_float *in = (t_float *)(w[1]);
     t_xtract_tilde *x = (t_xtract_tilde *)(w[2]);
     t_int N = (t_int)(w[3]);
     t_int return_code = 0;
-    float result = 0;
+    float result = 0.f;
 
     return_code = xtract[x->feature]((float *)in, N, x->argv, &result);
 
@@ -65,8 +65,8 @@
 }
 
 static t_int *xtract_perform_vector(t_int *w) {
-    t_sample *in = (t_sample *)(w[1]);
-    t_sample *out = (t_sample *)(w[2]);
+    t_sample *in = (t_float *)(w[1]);
+    t_sample *out = (t_float *)(w[2]);
     float *temp_in, *temp_out;
     t_xtract_tilde *x = (t_xtract_tilde *)(w[3]);
     t_int N = (t_int)(w[4]), n;
@@ -114,23 +114,31 @@
     t_symbol *tmp;
     t_xtract_tilde *x = (t_xtract_tilde *)newobject(xtract_tilde_class);
     xtract_mel_filter *mf;
-    t_int n, N, f, F, n_args, type;
+    t_int n, N, f, F, n_args, type, blocksize;
     t_float *argv_max;
     xtract_function_descriptor_t *fd;
     char *p_name, *p_desc, *author;
     int year;
 
+
+    blocksize = BLOCKSIZE; /* Default */
+    tmp = NULL;
     p_name = p_desc = author = NULL;
    
     n_args = type = x->feature = 0;
 
     f = F = XTRACT_FEATURES;
 
-    N = BLOCKSIZE;
+    /* N = BLOCKSIZE;*/
     
     x->argv = NULL;
     
-    tmp = argv->a_w.w_sym; /*atom_getsymbol(argv); */
+    if(argc)
+	tmp = argv[0].a_w.w_sym; /*atom_getsymbol(argv); */
+    if(argc > 1)
+	blocksize = (t_int)argv[1].a_w.w_long;
+
+    N = blocksize;
 
     /* get function descriptors */
     fd = (xtract_function_descriptor_t *)xtract_make_descriptors();
@@ -186,7 +194,6 @@
     else
 	post("xtract~: No arguments given");
     
-
     /* do init if needed */
     if(x->feature == XTRACT_MFCC){
 
@@ -224,7 +231,7 @@
     else x->feature_type = XTRACT_SCALAR;
 
     /* argv through right inlet */
-    inlet_new((t_pxobject *)x, "argv"); 
+    inlet_new((t_pxobject *)x, "list"); 
 
     /* DSP inlet */
     dsp_setup((t_pxobject *)x, 1);
@@ -294,7 +301,7 @@
     	A_GIMME, 0);
 
     addmess((method)xtract_tilde_dsp, "dsp", A_CANT,  0);
-    addmess((method)xtract_tilde_get_args, "argv", A_GIMME, 0);
+    addmess((method)xtract_tilde_get_args, "list", A_GIMME, 0);
     addmess((method)xtract_tilde_show_help, "help", A_DEFSYM, 0); 
     dsp_initclass();
     //class_setname("xtract~", "xtract~");
--- a/src/scalar.c	Tue Jul 31 20:44:17 2007 +0000
+++ b/src/scalar.c	Sun Aug 19 16:54:25 2007 +0000
@@ -26,6 +26,7 @@
 #include "math.h"
 #include <stdlib.h>
 #include <string.h>
+#include <stdio.h>
 
 int xtract_mean(const float *data, const int N, const void *argv, float *result){
 
@@ -658,6 +659,8 @@
 	  largest1_lwr, peak, ratio1, sr;
 
     sr = *(float*)argv;
+    if(sr == 0)
+	sr = 44100.f;
 
     coeffs2 = (float *)malloc(N * sizeof(float));
     coeffs3 = (float *)malloc(N * sizeof(float));
@@ -715,13 +718,16 @@
 
 int xtract_f0(const float *data, const int N, const void *argv, float *result){
 
-    int M, sr, tau, n;
+    int M, tau, n;
+    float sr;
     size_t bytes;
     float f0, err_tau_1, err_tau_x, array_max, 
 	  threshold_peak, threshold_centre,
 	  *input;
 
     sr = *(float *)argv;
+    if(sr == 0)
+	sr = 44100.f;
 
     input = (float *)malloc(bytes = N * sizeof(float));
     input = memcpy(input, data, bytes);
@@ -793,6 +799,8 @@
     if(return_code == XTRACT_NO_RESULT){
 
 	sr = *(float *)argv;
+	if(sr == 0)
+	    sr = 44100.f;
 	spectrum = (float *)malloc(N * sizeof(float));
 	peaks = (float *)malloc(N * sizeof(float));
 	argf[0] = sr;
--- a/xtract/xtract_scalar.h	Tue Jul 31 20:44:17 2007 +0000
+++ b/xtract/xtract_scalar.h	Sun Aug 19 16:54:25 2007 +0000
@@ -90,7 +90,7 @@
 
 /** \brief Extract the mean of an input spectrum
  * 
- * \param *data: a pointer to the first element in an array of floats representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_magnitude_spectrum(), xtract_spectral_peaks() or xtract_spectral_harmonics()).
+ * \param *data: a pointer to the first element in an array of floats representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_spectrum(), xtract_peak_spectrum() or xtract_harmonic_spectrum()).
  * \param N: the size of the array pointed to by *data
  * \param *argv: a pointer to NULL 
  * \param *result: the mean of the spectrum pointed to by *data 
@@ -99,7 +99,7 @@
 
 /** \brief Extract the variance of an input spectrum
  * 
- * \param *data: a pointer to the first element in an array of floats representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_magnitude_spectrum(), xtract_spectral_peaks() or xtract_spectral_harmonics()).
+ * \param *data: a pointer to the first element in an array of floats representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_spectrum(), xtract_peak_spectrum() or xtract_harmonic_spectrum()).
  * \param N: the number of elements to be considered
  * \param N: the size of the array pointed to by *data
  * \param *argv: a pointer to a float representing the spectral mean of the input spectrum
@@ -109,7 +109,7 @@
 
 /** \brief Extract the deviation of an input spectrum
  * 
- * \param *data: a pointer to the first element in an array of floats representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_magnitude_spectrum(), xtract_spectral_peaks() or xtract_spectral_harmonics()).
+ * \param *data: a pointer to the first element in an array of floats representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_spectrum(), xtract_peak_spectrum() or xtract_harmonic_spectrum()).
  * \param N: the size of the array pointed to by *data
  * \param *argv: a pointer to a float representing the spectral variance of the input spectrum
  * \param *result: the deviation of the spectrum pointed to by *data
@@ -118,7 +118,7 @@
 
 /** \brief Extract the average deviation of an input spectrum
  * 
- * \param *data: a pointer to the first element in an array of floats representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_magnitude_spectrum(), xtract_spectral_peaks() or xtract_spectral_harmonics()).
+ * \param *data: a pointer to the first element in an array of floats representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_spectrum(), xtract_peak_spectrum() or xtract_harmonic_spectrum()).
  * \param N: the size of the array pointed to by *data
  * \param *argv: a pointer to a float representing the spectral mean of the input spectrum
  * \param *result: the  average deviation of the spectrum pointed to by *data
@@ -127,7 +127,7 @@
 
 /** \brief Extract the skewness of an input spectrum
  * 
- * \param *data: a pointer to the first element in an array of floats representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_magnitude_spectrum(), xtract_spectral_peaks() or xtract_spectral_harmonics()).
+ * \param *data: a pointer to the first element in an array of floats representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_spectrum(), xtract_peak_spectrum() or xtract_harmonic_spectrum()).
  * \param N: the size of the array pointed to by *data
  * \param *argv: a pointer to an array of floats representing the spectral mean and spectral standard deviation of the input spectrum
  * \param *result: the skewness of the spectrum pointed to by *data
@@ -136,7 +136,7 @@
 
 /** \brief Extract the kurtosis of an input spectrum
  * 
- * \param *data: a pointer to the first element in an array of floats representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_magnitude_spectrum(), xtract_spectral_peaks() or xtract_spectral_harmonics()).
+ * \param *data: a pointer to the first element in an array of floats representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_spectrum(), xtract_peak_spectrum() or xtract_harmonic_spectrum()).
  * \param N: the size of the array pointed to by *data
  * \param *argv: a pointer to an array of values representing the spectral mean and spectral standard deviation of the input spectrum
  * \param *result: the kurtosis of the spectrum pointed to by *data
@@ -145,12 +145,12 @@
 
 /** \brief Extract the centroid of an input vector
  * 
- * \param *data: a pointer to the first element in an array of floats representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_magnitude_spectrum(), xtract_spectral_peaks() or xtract_spectral_harmonics()).
+ * \param *data: a pointer to the first element in an array of floats representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_spectrum(), xtract_peak_spectrum() or xtract_harmonic_spectrum()).
  * \param N: the number of elements to be considered
  * \param *argv: a pointer to NULL
  * \param *result: the centroid of the values pointed to by *data
  *
- * Note: for a more 'accurate' result *result from xtract_spectral_peaks() can be passed in. This gives the interpolated peak frequency locations.
+ * Note: for a more 'accurate' result *result from xtract_peak_spectrum() can be passed in. This gives the interpolated peak frequency locations.
  *
  */
 int xtract_spectral_centroid(const float *data, const int N, const void *argv,  float *result);
@@ -175,7 +175,7 @@
 
 /** \brief Calculate the Tristimulus of an input vector using a method described by Pollard and Jansson (1982)
  * 
- * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients of the harmonic spectrum of an audio vector e.g. a pointer to the first half of the array pointed to by *result from xtract_harmonics(). The amplitudes of the peak spectrum (e.g. *result from xtract_spectral_peaks()) can be used if one wishes to consider all partials not just harmonics.
+ * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients of the harmonic spectrum of an audio vector e.g. a pointer to the first half of the array pointed to by *result from xtract_harmonics(). The amplitudes of the peak spectrum (e.g. *result from xtract_peak_spectrum()) can be used if one wishes to consider all partials not just harmonics.
  * \param N: the number of elements to be considered
  * \param *argv: a pointer to NULL
  * \param *result: the tristimulus of N values from the array pointed to by *data
@@ -276,7 +276,7 @@
 
 /** \brief Extract the Inharmonicity of an input vector 
  * 
- * \param *data: a pointer to the first element in an array of floats represeting a magnitude peak spectrum of size N/2, and a frequency spectrum of size N/2 (This is the output format of xtract_spectral_peaks())
+ * \param *data: a pointer to the first element in an array of floats represeting a magnitude peak spectrum of size N/2, and a frequency spectrum of size N/2 (This is the output format of xtract_peak_spectrum())
  * \param N: the number of elements to be considered
  * \param *argv: a pointer to a float representing the fundamental frequency of the input vector.
  * \param *result: the inharmonicity of N values from the array pointed to by *data
@@ -322,7 +322,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 spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_magnitude_spectrum(), xtract_spectral_peaks() or xtract_spectral_harmonics()).
+ * \param *data: a pointer to the first element in an array of floats representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_spectrum(), xtract_peak_spectrum() or xtract_harmonic_spectrum()).
  * \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