diff options
-rw-r--r-- | examples/MSP/Makefile | 10 | ||||
-rw-r--r-- | examples/MSP/xtract~.c | 27 | ||||
-rw-r--r-- | src/scalar.c | 10 | ||||
-rw-r--r-- | xtract/xtract_scalar.h | 22 |
4 files changed, 42 insertions, 27 deletions
diff --git a/examples/MSP/Makefile b/examples/MSP/Makefile index d990d85..8078861 100644 --- a/examples/MSP/Makefile +++ b/examples/MSP/Makefile @@ -7,7 +7,7 @@ current: universal 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 @@ CC = gcc 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 @@ PPCLDFLAGS = -arch ppc 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/
diff --git a/examples/MSP/xtract~.c b/examples/MSP/xtract~.c index fcc2190..3f8115a 100644 --- a/examples/MSP/xtract~.c +++ b/examples/MSP/xtract~.c @@ -46,11 +46,11 @@ typedef struct _xtract { } 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(t_int *w) { } 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 @@ static void *xtract_tilde_new(t_symbol *me, t_int argc, t_atom *argv) { 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 @@ static void *xtract_tilde_new(t_symbol *me, t_int argc, t_atom *argv) { else post("xtract~: No arguments given"); - /* do init if needed */ if(x->feature == XTRACT_MFCC){ @@ -224,7 +231,7 @@ static void *xtract_tilde_new(t_symbol *me, t_int argc, t_atom *argv) { 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 @@ int main(void) { 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~"); diff --git a/src/scalar.c b/src/scalar.c index 1a52bd0..6732422 100644 --- a/src/scalar.c +++ b/src/scalar.c @@ -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 @@ int xtract_hps(const float *data, const int N, const void *argv, float *result){ 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_hps(const float *data, const int N, const void *argv, float *result){ 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 @@ int xtract_failsafe_f0(const float *data, const int N, const void *argv, float * 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; diff --git a/xtract/xtract_scalar.h b/xtract/xtract_scalar.h index dc2e4ac..a2e2d7b 100644 --- a/xtract/xtract_scalar.h +++ b/xtract/xtract_scalar.h @@ -90,7 +90,7 @@ int xtract_kurtosis(const float *data, const int N, const void *argv, float *re /** \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 @@ int xtract_spectral_mean(const float *data, const int N, const void *argv, float /** \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 @@ int xtract_spectral_variance(const float *data, const int N, const void *argv, f /** \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 @@ int xtract_spectral_standard_deviation(const float *data, const int N, const voi /** \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 @@ int xtract_spectral_average_deviation(const float *data, const int N, const void /** \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 @@ int xtract_spectral_skewness(const float *data, const int N, const void *argv, /** \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 @@ int xtract_spectral_kurtosis(const float *data, const int N, const void *argv, /** \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 @@ int xtract_irregularity_j(const float *data, const int N, const void *argv, floa /** \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 @@ int xtract_rms_amplitude(const float *data, const int N, const void *argv, float /** \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 @@ int xtract_sharpness(const float *data, const int N, const void *argv, float *re /** \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 |