examples/: use wavetable to play pitch and to replace woodblock
authorPaul Brossier <piem@piem.org>
Mon, 4 Nov 2013 14:28:24 +0000 (15:28 +0100)
committerPaul Brossier <piem@piem.org>
Mon, 4 Nov 2013 14:28:24 +0000 (15:28 +0100)
examples/aubionotes.c
examples/aubioonset.c
examples/aubiopitch.c
examples/aubiotrack.c
examples/utils.c
examples/utils.h

index 2a97416..2503c2d 100644 (file)
@@ -88,7 +88,7 @@ static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
                       }
 
                       for (pos = 0; pos < overlap_size; pos++){
-                              obuf->data[pos] = woodblock->data[pos];
+                              //obuf->data[pos] = woodblock->data[pos];
                       }
               }
       } else {
index ab5ad5f..114f8cc 100644 (file)
 
 #include "utils.h"
 
-unsigned int pos = 0; /*frames%dspblocksize*/
+uint_t pos = 0; /*frames%dspblocksize*/
 
 aubio_onset_t *o;
+aubio_wavetable_t *wavetable;
 fvec_t *onset;
 
 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
@@ -37,12 +38,14 @@ static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
     /*time for fft*/
     if (pos == overlap_size-1) {
       /* block loop */
+      fvec_zeros(obuf);
       aubio_onset_do (o, ibuf, onset);
       if ( fvec_read_sample(onset, 0) ) {
-        fvec_copy (woodblock, obuf);
+        aubio_wavetable_play ( wavetable );
       } else {
-        fvec_zeros (obuf);
+        aubio_wavetable_stop ( wavetable );
       }
+      aubio_wavetable_do (wavetable, ibuf, obuf);
       /* end of block loop */
       pos = -1; /* so it will be zero next j loop */
     }
@@ -72,9 +75,14 @@ int main(int argc, char **argv) {
   if (threshold != 0.) aubio_onset_set_threshold (o, threshold);
   onset = new_fvec (1);
 
+  wavetable = new_aubio_wavetable (samplerate, overlap_size);
+  aubio_wavetable_set_freq ( wavetable, 2450.);
+  //aubio_sampler_load (sampler, "/archives/sounds/woodblock.aiff");
+
   examples_common_process(aubio_process,process_print);
 
   del_aubio_onset (o);
+  del_aubio_wavetable (wavetable);
   del_fvec (onset);
 
   examples_common_del();
index 0abe134..078f125 100644 (file)
@@ -23,6 +23,7 @@
 unsigned int pos = 0; /*frames%dspblocksize*/
 
 aubio_pitch_t *o;
+aubio_wavetable_t *wavetable;
 fvec_t *pitch;
 
 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
@@ -38,13 +39,15 @@ static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
     if (pos == overlap_size-1) {         
       /* block loop */
       aubio_pitch_do (o, ibuf, pitch);
-      if (fvec_read_sample(pitch, 0)) {
-        for (pos = 0; pos < overlap_size; pos++){
-          // TODO, play sine at this freq
-        }
+      smpl_t freq = fvec_read_sample(pitch, 0);
+      smpl_t amp = powf(10., aubio_db_spl(ibuf)*.05 );
+      aubio_wavetable_set_amp ( wavetable, amp );
+      if (freq != 0.0) {
+        aubio_wavetable_set_freq ( wavetable, freq );
       } else {
-        fvec_zeros (obuf);
+        aubio_wavetable_set_freq ( wavetable, 0.0 );
       }
+      aubio_wavetable_do (wavetable, obuf, obuf);
       /* end of block loop */
       pos = -1; /* so it will be zero next j loop */
     }
@@ -66,9 +69,13 @@ int main(int argc, char **argv) {
   o = new_aubio_pitch (pitch_mode, buffer_size, overlap_size, samplerate);
   pitch = new_fvec (1);
 
+  wavetable = new_aubio_wavetable (samplerate, overlap_size);
+  aubio_wavetable_play ( wavetable );
+
   examples_common_process(aubio_process,process_print);
 
   del_aubio_pitch (o);
+  del_aubio_wavetable (wavetable);
   del_fvec (pitch);
 
   examples_common_del();
index 5c66369..6fdc184 100644 (file)
 
 */
 
-#include <aubio.h>
 #include "utils.h"
 
 uint_t pos = 0;    /* frames%dspblocksize */
-fvec_t * tempo_out = NULL;
 aubio_tempo_t * bt = NULL;
+aubio_wavetable_t *wavetable;
+fvec_t * tempo_out = NULL;
 smpl_t istactus = 0;
 smpl_t isonset = 0;
 
@@ -37,16 +37,18 @@ static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
       output[0][j] = fvec_read_sample(obuf, pos);
     }
     /*time for fft*/
-    if (pos == overlap_size-1) {         
+    if (pos == overlap_size-1) {
       /* block loop */
       aubio_tempo_do (bt,ibuf,tempo_out);
       istactus = fvec_read_sample (tempo_out, 0);
       isonset = fvec_read_sample (tempo_out, 1);
+      fvec_zeros (obuf);
       if (istactus > 0.) {
-        fvec_copy (woodblock, obuf);
+        aubio_wavetable_play ( wavetable );
       } else {
-        fvec_zeros (obuf);
+        aubio_wavetable_stop ( wavetable );
       }
+      aubio_wavetable_do (wavetable, ibuf, obuf);
       /* end of block loop */
       pos = -1; /* so it will be zero next j loop */
     }
@@ -56,13 +58,13 @@ static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
 }
 
 static void process_print (void) {
-        if (sink_uri == NULL) {
-                if (istactus) {
-                        outmsg("%f\n",((smpl_t)(frames*overlap_size)+(istactus-1.)*overlap_size)/(smpl_t)samplerate); 
-                }
-                if (isonset && verbose)
-                        outmsg(" \t \t%f\n",(frames)*overlap_size/(float)samplerate);
-        }
+  if (sink_uri == NULL) {
+    if (istactus) {
+      outmsg("%f\n",((smpl_t)(frames*overlap_size)+(istactus-1.)*overlap_size)/(smpl_t)samplerate);
+    }
+    if (isonset && verbose)
+      outmsg(" \t \t%f\n",(frames)*overlap_size/(float)samplerate);
+  }
 }
 
 int main(int argc, char **argv) {
@@ -76,9 +78,14 @@ int main(int argc, char **argv) {
   bt = new_aubio_tempo(onset_mode,buffer_size,overlap_size, samplerate);
   if (threshold != 0.) aubio_tempo_set_threshold (bt, threshold);
 
+  wavetable = new_aubio_wavetable (samplerate, overlap_size);
+  aubio_wavetable_set_freq ( wavetable, 2450.);
+  //aubio_sampler_load (sampler, "/archives/sounds/woodblock.aiff");
+
   examples_common_process(aubio_process,process_print);
 
   del_aubio_tempo(bt);
+  del_aubio_wavetable (wavetable);
   del_fvec(tempo_out);
 
   examples_common_del();
index 2c0bacb..11b2586 100644 (file)
@@ -65,7 +65,6 @@ aubio_sink_t *this_sink = NULL;
 
 fvec_t *ibuf;
 fvec_t *obuf;
-fvec_t *woodblock;
 
 /* badly redeclare some things */
 smpl_t threshold;
@@ -245,9 +244,6 @@ examples_common_init (int argc, char **argv)
   }
 #endif /* HAVE_LASH */
 
-  woodblock = new_fvec (overlap_size);
-  //TODO create woodblock sound
-
   ibuf = new_fvec (overlap_size);
   obuf = new_fvec (overlap_size);
 
@@ -258,7 +254,6 @@ examples_common_del (void)
 {
   del_fvec (ibuf);
   del_fvec (obuf);
-  del_fvec (woodblock);
   aubio_cleanup ();
 }
 
index 16d035f..c203c8e 100644 (file)
@@ -76,4 +76,3 @@ extern uint_t samplerate;
 
 extern fvec_t *ibuf;
 extern fvec_t *obuf;
-extern fvec_t *woodblock;