added puredata aubiopitch~
authorPaul Brossier <piem@altern.org>
Wed, 15 Feb 2006 10:47:13 +0000 (10:47 +0000)
committerPaul Brossier <piem@altern.org>
Wed, 15 Feb 2006 10:47:13 +0000 (10:47 +0000)
added puredata aubiopitch~

plugins/puredata/Makefile.am
plugins/puredata/aubio_setup.c
plugins/puredata/aubiopitch~.c [new file with mode: 0644]
plugins/puredata/help/help-aubiopitch~.pd [new file with mode: 0644]
python/aubio/gnuplot.py

index 81073abc4f57eb8f782e5b1d23f75a79e333526e..1c565aaee0fc33ba6e41a08f894f4b96d39e1500 100644 (file)
@@ -20,7 +20,8 @@ aubio_pd_linux_SOURCES = \
        aubioonset~.c \
        aubiotempo~.c \
        aubiotss~.c \
-       aubioquiet~.c
+       aubioquiet~.c \
+       aubiopitch~.c
 
 pdincludedir = $(pddir)/src
 
@@ -40,7 +41,8 @@ pdinstallref_DATA = \
        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
index 1f90e6fb06ceb3c8227439e76e5af351e8b327d3..2c3f848a9a27408cd1108a8fd5c18e8b8cfbcdd3 100644 (file)
@@ -8,6 +8,7 @@ extern void aubioonset_tilde_setup (void);
 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 @@ void aubio_setup (void)
        aubiotempo_tilde_setup();
        aubiotss_tilde_setup();
        aubioquiet_tilde_setup();
+       aubiopitch_tilde_setup();
 }
diff --git a/plugins/puredata/aubiopitch~.c b/plugins/puredata/aubiopitch~.c
new file mode 100644 (file)
index 0000000..62bfd75
--- /dev/null
@@ -0,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);
+}
+
diff --git a/plugins/puredata/help/help-aubiopitch~.pd b/plugins/puredata/help/help-aubiopitch~.pd
new file mode 100644 (file)
index 0000000..3948ce9
--- /dev/null
@@ -0,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;
index 9c0ec42eed246b4017eb34ca5dccffafada2db50..c63459c81548375575c308b8154bafaaba9fa62a 100644 (file)
@@ -180,6 +180,8 @@ def plot_pitch(filename, pitch, samplerate=44100., hopsize=512, outplot=None):
         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)))