ref: 660c1d824f10572727d987d7c3e166e286c6749e
parent: d9101a58af07bb74ec621f6ace98de318a18c976
author: Paul Brossier <piem@altern.org>
date: Wed Feb 15 05:47:13 EST 2006
added puredata aubiopitch~ added puredata aubiopitch~
--- a/plugins/puredata/Makefile.am
+++ b/plugins/puredata/Makefile.am
@@ -20,7 +20,8 @@
aubioonset~.c \
aubiotempo~.c \
aubiotss~.c \
- aubioquiet~.c
+ aubioquiet~.c \
+ aubiopitch~.c
pdincludedir = $(pddir)/src
@@ -40,7 +41,8 @@
help/help-aubioonset~.pd \
help/help-aubioquiet~.pd \
help/help-aubiotempo~.pd \
- help/help-aubiotss~.pd
+ help/help-aubiotss~.pd \
+ help/help-aubiopitch~.pd
pdinstallexp_DATA = \
examples/onset-cam.pd
--- a/plugins/puredata/aubio_setup.c
+++ b/plugins/puredata/aubio_setup.c
@@ -8,6 +8,7 @@
extern void aubiotempo_tilde_setup (void);
extern void aubiotss_tilde_setup (void);
extern void aubioquiet_tilde_setup (void);
+extern void aubiopitch_tilde_setup (void);
void aubio_setup (void)
{
@@ -16,4 +17,5 @@
aubiotempo_tilde_setup();
aubiotss_tilde_setup();
aubioquiet_tilde_setup();
+ aubiopitch_tilde_setup();
}
--- /dev/null
+++ b/plugins/puredata/aubiopitch~.c
@@ -1,0 +1,109 @@
+/**
+ *
+ * a puredata wrapper for aubio pitch detection functions
+ *
+ * Thanks to Johannes M Zmolnig for writing the excellent HOWTO:
+ * http://iem.kug.ac.at/pd/externals-HOWTO/
+ *
+ * */
+
+#include <m_pd.h>
+#include <aubio.h>
+
+char aubiopitch_version[] = "aubiopitch~ version 0.1";
+
+aubio_pitchdetection_type type_pitch = aubio_pitch_schmitt; // aubio_pitch_mcomb
+aubio_pitchdetection_mode mode_pitch = aubio_pitchm_freq;
+
+static t_class *aubiopitch_tilde_class;
+
+void aubiopitch_tilde_setup (void);
+
+typedef struct _aubiopitch_tilde
+{
+ t_object x_obj;
+ t_float threshold;
+ t_float threshold2;
+ t_int pos; /*frames%dspblocksize*/
+ t_int bufsize;
+ t_int hopsize;
+ aubio_pitchdetection_t *o;
+ fvec_t *vec;
+ t_outlet *pitch;
+} t_aubiopitch_tilde;
+
+static t_int *aubiopitch_tilde_perform(t_int *w)
+{
+ t_aubiopitch_tilde *x = (t_aubiopitch_tilde *)(w[1]);
+ t_sample *in = (t_sample *)(w[2]);
+ int n = (int)(w[3]);
+ int j;
+ smpl_t pitch;
+ for (j=0;j<n;j++) {
+ /* write input to datanew */
+ fvec_write_sample(x->vec, in[j], 0, x->pos);
+ /*time for fft*/
+ if (x->pos == x->hopsize-1) {
+ /* block loop */
+ pitch = aubio_pitchdetection(x->o,x->vec);
+ outlet_float(x->pitch, pitch);
+ /* end of block loop */
+ x->pos = -1; /* so it will be zero next j loop */
+ }
+ x->pos++;
+ }
+ return (w+4);
+}
+
+static void aubiopitch_tilde_dsp(t_aubiopitch_tilde *x, t_signal **sp)
+{
+ dsp_add(aubiopitch_tilde_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
+}
+
+static void aubiopitch_tilde_debug(t_aubiopitch_tilde *x)
+{
+ post("aubiopitch~ bufsize:\t%d", x->bufsize);
+ post("aubiopitch~ hopsize:\t%d", x->hopsize);
+ post("aubiopitch~ threshold:\t%f", x->threshold);
+ post("aubiopitch~ audio in:\t%f", x->vec->data[0][0]);
+}
+
+//static void *aubiopitch_tilde_new (t_floatarg f)
+static void *aubiopitch_tilde_new (void)
+{
+ t_aubiopitch_tilde *x =
+ (t_aubiopitch_tilde *)pd_new(aubiopitch_tilde_class);
+
+ x->bufsize = 2048;
+ x->hopsize = x->bufsize / 2;
+
+ //FIXME: get the real samplerate
+ x->o = new_aubio_pitchdetection(x->bufsize*4,
+ x->hopsize, 1, 44100., type_pitch, mode_pitch);
+ x->vec = (fvec_t *)new_fvec(x->hopsize,1);
+
+ //floatinlet_new (&x->x_obj, &x->threshold);
+ x->pitch = outlet_new (&x->x_obj, &s_float);
+
+ post(aubiopitch_version);
+ return (void *)x;
+}
+
+void aubiopitch_tilde_setup (void)
+{
+ aubiopitch_tilde_class = class_new (gensym ("aubiopitch~"),
+ (t_newmethod)aubiopitch_tilde_new,
+ 0, sizeof (t_aubiopitch_tilde),
+ CLASS_DEFAULT, A_DEFFLOAT, 0);
+ class_addmethod(aubiopitch_tilde_class,
+ (t_method)aubiopitch_tilde_dsp,
+ gensym("dsp"), 0);
+ class_addmethod(aubiopitch_tilde_class,
+ (t_method)aubiopitch_tilde_debug,
+ gensym("debug"), 0);
+ class_sethelpsymbol(aubiopitch_tilde_class,
+ gensym("help-aubiopitch~.pd"));
+ CLASS_MAINSIGNALIN(aubiopitch_tilde_class,
+ t_aubiopitch_tilde, threshold);
+}
+
--- /dev/null
+++ b/plugins/puredata/help/help-aubiopitch~.pd
@@ -1,0 +1,18 @@
+#N canvas 254 165 450 425 10;
+#X floatatom 126 230 5 0 0 0 - - -;
+#X obj 125 168 osc~ 440;
+#X obj 128 111 hsl 128 15 0 127 0 0 empty empty empty -2 -6 0 8 -262144
+-1 -1 8100 1;
+#X obj 125 131 mtof;
+#X floatatom 125 151 5 0 0 0 - - -;
+#X obj 141 200 aubiopitch~;
+#X obj 103 274 dac~;
+#X obj 126 250 osc~;
+#X connect 0 0 7 0;
+#X connect 1 0 5 0;
+#X connect 1 0 6 0;
+#X connect 2 0 3 0;
+#X connect 3 0 4 0;
+#X connect 4 0 1 0;
+#X connect 5 0 0 0;
+#X connect 7 0 6 1;
--- a/python/aubio/gnuplot.py
+++ b/python/aubio/gnuplot.py
@@ -180,6 +180,8 @@
d = []
maxpitch = 100
for i in range(len(pitch)):
+ #if len(pitch[i]) == 0: pitch[i] = [0.];
+
downtime = (hopsize/samplerate)*numarray.arange(len(pitch[i]))
d.append(Gnuplot.Data(downtime,pitch[i],with='lines',
title=('%d' % i)))