examples/: large refactoring, improve option management, remove old stuff, move block...
authorPaul Brossier <piem@piem.org>
Sat, 7 Dec 2013 03:09:00 +0000 (22:09 -0500)
committerPaul Brossier <piem@piem.org>
Sat, 7 Dec 2013 03:09:00 +0000 (22:09 -0500)
examples/aubiomfcc.c
examples/aubionotes.c
examples/aubioonset.c
examples/aubiopitch.c
examples/aubioquiet.c
examples/aubiotrack.c
examples/jackio.c
examples/jackio.h
examples/parse_args.h
examples/utils.c
examples/utils.h

index 21526eb..02ab75e 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2007-2009 Paul Brossier <piem@aubio.org>
+  Copyright (C) 2007-2013 Paul Brossier <piem@aubio.org>
 
   This file is part of aubio.
 
 #include "utils.h"
 #include "parse_args.h"
 
-/* mfcc objects */
-fvec_t * mfcc_out;
-aubio_mfcc_t * mfcc;
-aubio_pvoc_t *pv;
-cvec_t *fftgrain;
+aubio_pvoc_t *pv;    // a phase vocoder
+cvec_t *fftgrain;    // outputs a spectrum
+aubio_mfcc_t * mfcc; // which the mfcc will process
+fvec_t * mfcc_out;   // to get the output coefficients
 
 uint_t n_filters = 40;
 uint_t n_coefs = 13;
 
-unsigned int pos = 0; /*frames%dspblocksize*/
-
-static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
-  unsigned int j;       /*frames*/
-  
-  for (j=0;j<(unsigned)nframes;j++) {
-    if(usejack) {
-      /* write input to datanew */
-      fvec_write_sample(ibuf, input[0][j], pos);
-      /* put synthnew in output */
-      output[0][j] = fvec_read_sample(obuf, pos);
-    }
-    /*time for fft*/
-    if (pos == overlap_size-1) {         
-      /* block loop */
-      
-      //compute mag spectrum
-      aubio_pvoc_do (pv, ibuf, fftgrain);
-     
-      //compute mfccs
-      aubio_mfcc_do(mfcc, fftgrain, mfcc_out);
-      
-      /* end of block loop */
-      pos = -1; /* so it will be zero next j loop */
-    }
-    pos++;
-  }
-  return 1;
+static void
+process_block(fvec_t *ibuf, fvec_t *obuf) {
+  fvec_zeros(obuf);
+  //compute mag spectrum
+  aubio_pvoc_do (pv, ibuf, fftgrain);
+  //compute mfccs
+  aubio_mfcc_do(mfcc, fftgrain, mfcc_out);
 }
 
 static void process_print (void) {
   /* output times in seconds and extracted mfccs */
-  if (sink_uri == NULL) {
-    outmsg("%f\t",frames*overlap_size/(float)samplerate);
-    fvec_print(mfcc_out);
-  }
+  outmsg("%f\t",blocks*hop_size/(float)samplerate);
+  fvec_print(mfcc_out);
 }
 
 int main(int argc, char **argv) {
-  // params
+  // change some default params
   buffer_size  = 512;
-  overlap_size = 256;
-  
+  hop_size = 256;
+
   examples_common_init(argc,argv);
 
-  /* phase vocoder */
-  pv = new_aubio_pvoc (buffer_size, overlap_size);
+  verbmsg ("using source: %s at %dHz\n", source_uri, samplerate);
+  verbmsg ("buffer_size: %d, ", buffer_size);
+  verbmsg ("hop_size: %d\n", hop_size);
 
+  pv = new_aubio_pvoc (buffer_size, hop_size);
   fftgrain = new_cvec (buffer_size);
-
-  //populating the filter
   mfcc = new_aubio_mfcc(buffer_size, n_filters, n_coefs, samplerate);
-  
   mfcc_out = new_fvec(n_coefs);
-  
-  //process
-  examples_common_process(aubio_process,process_print);
-  
-  //destroying mfcc 
+
+  examples_common_process((aubio_process_func_t)process_block, process_print);
+
   del_aubio_pvoc (pv);
   del_cvec (fftgrain);
   del_aubio_mfcc(mfcc);
   del_fvec(mfcc_out);
 
   examples_common_del();
-  debug("End of program.\n");
-  fflush(stderr);
-  
   return 0;
 }
 
index 3b7ee63..0aafabf 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
+  Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
 
   This file is part of aubio.
 
 #define PROG_HAS_ONSET 1
 #include "parse_args.h"
 
-/* pitch objects */
-smpl_t pitch = 0.;
-
 uint_t median = 6;
-smpl_t curlevel = 0.;
-
-aubio_pitch_t *pitchdet;
 
-fvec_t *note_buffer = NULL;
-fvec_t *note_buffer2 = NULL;
+fvec_t *note_buffer;
+fvec_t *note_buffer2;
 
 smpl_t curnote = 0.;
 smpl_t newnote = 0.;
 uint_t isready = 0;
-unsigned int pos = 0; /*frames%dspblocksize*/
 
-aubio_pitch_t *pitchdet;
+aubio_pitch_t *pitch;
 aubio_onset_t *o;
 fvec_t *onset;
 fvec_t *pitch_obuf;
@@ -50,78 +43,58 @@ fvec_t *pitch_obuf;
 void note_append (fvec_t * note_buffer, smpl_t curnote);
 uint_t get_note (fvec_t * note_buffer, fvec_t * note_buffer2);
 
-static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
-  unsigned int j;       /*frames*/
-  for (j=0;j<(unsigned)nframes;j++) {
-    if(usejack) {
-      /* write input to datanew */
-      fvec_write_sample(ibuf, input[0][j], pos);
-      /* put synthnew in output */
-      output[0][j] = fvec_read_sample(obuf, pos);
-    }
-    /*time for fft*/
-    if (pos == overlap_size-1) {         
-      /* block loop */
-      aubio_onset_do(o, ibuf, onset);
-      
-      aubio_pitch_do (pitchdet, ibuf, pitch_obuf);
-      pitch = fvec_read_sample(pitch_obuf, 0);
-      if(median){
-              note_append(note_buffer, pitch);
-      }
+static void
+process_block(fvec_t *ibuf, fvec_t *obuf) {
+  fvec_zeros(obuf);
+  aubio_onset_do(o, ibuf, onset);
+
+  aubio_pitch_do (pitch, ibuf, pitch_obuf);
+  smpl_t new_pitch = fvec_read_sample(pitch_obuf, 0);
+  if(median){
+    note_append(note_buffer, new_pitch);
+  }
 
-      /* curlevel is negatif or 1 if silence */
-      curlevel = aubio_level_detection(ibuf, silence);
-      if (fvec_read_sample(onset, 0)) {
-              /* test for silence */
-              if (curlevel == 1.) {
-                      if (median) isready = 0;
-                      /* send note off */
-                      send_noteon(curnote,0);
-              } else {
-                      if (median) {
-                              isready = 1;
-                      } else {
-                              /* kill old note */
-                              send_noteon(curnote,0);
-                              /* get and send new one */
-                              send_noteon(pitch,127+(int)floor(curlevel));
-                              curnote = pitch;
-                      }
-
-                      for (pos = 0; pos < overlap_size; pos++){
-                              //obuf->data[pos] = woodblock->data[pos];
-                      }
-              }
+  /* curlevel is negatif or 1 if silence */
+  smpl_t curlevel = aubio_level_detection(ibuf, silence);
+  if (fvec_read_sample(onset, 0)) {
+    /* test for silence */
+    if (curlevel == 1.) {
+      if (median) isready = 0;
+      /* send note off */
+      send_noteon(curnote,0);
+    } else {
+      if (median) {
+        isready = 1;
       } else {
-              if (median) {
-                      if (isready > 0)
-                              isready++;
-                      if (isready == median)
-                      {
-                              /* kill old note */
-                              send_noteon(curnote,0);
-                              newnote = get_note(note_buffer, note_buffer2);
-                              curnote = newnote;
-                              /* get and send new one */
-                              if (curnote>45){
-                                      send_noteon(curnote,127+(int)floor(curlevel));
-                              }
-                      }
-              } // if median
-        for (pos = 0; pos < overlap_size; pos++)
-          obuf->data[pos] = 0.;
+        /* kill old note */
+        send_noteon(curnote,0);
+        /* get and send new one */
+        send_noteon(new_pitch,127+(int)floor(curlevel));
+        curnote = new_pitch;
       }
-      /* end of block loop */
-      pos = -1; /* so it will be zero next j loop */
     }
-    pos++;
+  } else {
+    if (median) {
+      if (isready > 0)
+        isready++;
+      if (isready == median)
+      {
+        /* kill old note */
+        send_noteon(curnote,0);
+        newnote = get_note(note_buffer, note_buffer2);
+        curnote = newnote;
+        /* get and send new one */
+        if (curnote>45){
+          send_noteon(curnote,127+(int)floor(curlevel));
+        }
+      }
+    } // if median
   }
-  return 1;
 }
 
-static void process_print (void) {
-      if (verbose) outmsg("%f\n",pitch);
+static void
+process_print (void) {
+  //if (verbose) outmsg("%f\n",pitch_obuf->data[0]);
 }
 
 void
@@ -148,23 +121,37 @@ get_note (fvec_t * note_buffer, fvec_t * note_buffer2)
 int main(int argc, char **argv) {
   examples_common_init(argc,argv);
 
-  o = new_aubio_onset (onset_method, buffer_size, overlap_size, samplerate);
+  verbmsg ("using source: %s at %dHz\n", source_uri, samplerate);
+
+  verbmsg ("onset method: %s, ", onset_method);
+  verbmsg ("buffer_size: %d, ", buffer_size);
+  verbmsg ("hop_size: %d, ", hop_size);
+  verbmsg ("threshold: %f\n", onset_threshold);
+
+  verbmsg ("pitch method: %s, ", pitch_method);
+  verbmsg ("buffer_size: %d, ", buffer_size * 4);
+  verbmsg ("hop_size: %d, ", hop_size);
+  verbmsg ("tolerance: %f\n", pitch_tolerance);
+
+  o = new_aubio_onset (onset_method, buffer_size, hop_size, samplerate);
   if (onset_threshold != 0.) aubio_onset_set_threshold (o, onset_threshold);
   onset = new_fvec (1);
 
-  pitchdet = new_aubio_pitch (pitch_method, buffer_size * 4,
-          overlap_size, samplerate);
-  aubio_pitch_set_tolerance (pitchdet, 0.7);
+  pitch = new_aubio_pitch (pitch_method, buffer_size * 4, hop_size, samplerate);
+  if (pitch_tolerance != 0.) aubio_pitch_set_tolerance (pitch, pitch_tolerance);
   pitch_obuf = new_fvec (1);
+
   if (median) {
       note_buffer = new_fvec (median);
       note_buffer2 = new_fvec (median);
   }
 
-  examples_common_process(aubio_process, process_print);
+  examples_common_process((aubio_process_func_t)process_block, process_print);
 
+  // send a last note off
   send_noteon (curnote, 0);
-  del_aubio_pitch (pitchdet);
+
+  del_aubio_pitch (pitch);
   if (median) {
       del_fvec (note_buffer);
       del_fvec (note_buffer2);
@@ -172,8 +159,6 @@ int main(int argc, char **argv) {
   del_fvec (pitch_obuf);
 
   examples_common_del();
-  debug("End of program.\n");
-  fflush(stderr);
   return 0;
 }
 
index c1b11b2..7a80acc 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
+  Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
 
   This file is part of aubio.
 
 */
 
 #include "utils.h"
-#define PROG_HAS_ONSET
+#define PROG_HAS_ONSET 1
 #include "parse_args.h"
 
-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) {
-  unsigned int j;       /*frames*/
-  for (j=0;j<(unsigned)nframes;j++) {
-    if(usejack) {
-      /* write input to datanew */
-      fvec_write_sample(ibuf, input[0][j], pos);
-      /* put synthnew in output */
-      output[0][j] = fvec_read_sample(obuf, pos);
-    }
-    /*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) ) {
-        aubio_wavetable_play ( wavetable );
-      } else {
-        aubio_wavetable_stop ( wavetable );
-      }
-      aubio_wavetable_do (wavetable, obuf, obuf);
-      /* end of block loop */
-      pos = -1; /* so it will be zero next j loop */
-    }
-    pos++;
+void
+process_block(fvec_t *ibuf, fvec_t *obuf) {
+  fvec_zeros(obuf);
+  aubio_onset_do (o, ibuf, onset);
+  if ( fvec_read_sample(onset, 0) ) {
+    aubio_wavetable_play ( wavetable );
+  } else {
+    aubio_wavetable_stop ( wavetable );
   }
-  return 1;
+  aubio_wavetable_do (wavetable, obuf, obuf);
 }
 
-static void
+void
 process_print (void)
 {
-  /* output times in seconds, taking back some delay to ensure the label is
-   * _before_ the actual onset */
-  if (!verbose && usejack)
-    return;
   smpl_t onset_found = fvec_read_sample (onset, 0);
   if (onset_found) {
     outmsg ("%f\n", aubio_onset_get_last_s (o) );
@@ -72,23 +50,26 @@ process_print (void)
 int main(int argc, char **argv) {
   examples_common_init(argc,argv);
 
-  o = new_aubio_onset (onset_method, buffer_size, overlap_size, samplerate);
+  verbmsg ("using source: %s at %dHz\n", source_uri, samplerate);
+  verbmsg ("onset method: %s, ", onset_method);
+  verbmsg ("buffer_size: %d, ", buffer_size);
+  verbmsg ("hop_size: %d, ", hop_size);
+  verbmsg ("threshold: %f\n", onset_threshold);
+
+  o = new_aubio_onset (onset_method, buffer_size, hop_size, samplerate);
   if (onset_threshold != 0.) aubio_onset_set_threshold (o, onset_threshold);
   onset = new_fvec (1);
 
-  wavetable = new_aubio_wavetable (samplerate, overlap_size);
+  wavetable = new_aubio_wavetable (samplerate, hop_size);
   aubio_wavetable_set_freq ( wavetable, 2450.);
   //aubio_sampler_load (sampler, "/archives/sounds/woodblock.aiff");
 
-  examples_common_process(aubio_process,process_print);
+  examples_common_process((aubio_process_func_t)process_block, process_print);
 
   del_aubio_onset (o);
   del_aubio_wavetable (wavetable);
   del_fvec (onset);
 
   examples_common_del();
-  debug("End of program.\n");
-  fflush(stderr);
   return 0;
 }
-
index dfd9fe0..dd615bd 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
+  Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
 
   This file is part of aubio.
 
 #define PROG_HAS_PITCH 1
 #include "parse_args.h"
 
-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) {
-  unsigned int j;       /*frames*/
-  for (j=0;j<(unsigned)nframes;j++) {
-    if(usejack) {
-      /* write input to datanew */
-      fvec_write_sample(ibuf, input[0][j], pos);
-      /* put synthnew in output */
-      output[0][j] = fvec_read_sample(obuf, pos);
-    }
-    /*time for fft*/
-    if (pos == overlap_size-1) {         
-      /* block loop */
-      aubio_pitch_do (o, ibuf, pitch);
-      smpl_t freq = fvec_read_sample(pitch, 0);
-      aubio_wavetable_set_amp ( wavetable, aubio_level_lin (ibuf) );
-      if (freq != 0.0) {
-        aubio_wavetable_set_freq ( wavetable, freq );
-      } else {
-        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 */
-    }
-    pos++;
+void
+process_block(fvec_t * ibuf, fvec_t * obuf) {
+  fvec_zeros(obuf);
+  aubio_pitch_do (o, ibuf, pitch);
+  smpl_t freq = fvec_read_sample(pitch, 0);
+  aubio_wavetable_set_amp ( wavetable, aubio_level_lin (ibuf) );
+  if (freq != 0.0) {
+    aubio_wavetable_set_freq ( wavetable, freq );
+  } else {
+    aubio_wavetable_set_freq ( wavetable, 0.0 );
   }
-  return 1;
+  aubio_wavetable_do (wavetable, obuf, obuf);
 }
 
-static void process_print (void) {
-      if (!verbose && usejack) return;
-      smpl_t pitch_found = fvec_read_sample(pitch, 0);
-      outmsg("%f %f\n",(frames) 
-              *overlap_size/(float)samplerate, pitch_found);
+void
+process_print (void) {
+  smpl_t pitch_found = fvec_read_sample(pitch, 0);
+  outmsg("%f %f\n",(blocks)
+      *hop_size/(float)samplerate, pitch_found);
 }
 
 int main(int argc, char **argv) {
   examples_common_init(argc,argv);
 
-  o = new_aubio_pitch (pitch_method, buffer_size, overlap_size, samplerate);
+  verbmsg ("using source: %s at %dHz\n", source_uri, samplerate);
+  verbmsg ("pitch method: %s, ", pitch_method);
+  verbmsg ("buffer_size: %d, ", buffer_size);
+  verbmsg ("hop_size: %d, ", hop_size);
+  verbmsg ("tolerance: %f\n", pitch_tolerance);
+
+  o = new_aubio_pitch (pitch_method, buffer_size, hop_size, samplerate);
+  if (pitch_tolerance != 0.) aubio_pitch_set_tolerance (o, pitch_tolerance);
   pitch = new_fvec (1);
 
-  wavetable = new_aubio_wavetable (samplerate, overlap_size);
+  wavetable = new_aubio_wavetable (samplerate, hop_size);
   aubio_wavetable_play ( wavetable );
 
-  examples_common_process(aubio_process,process_print);
+  examples_common_process((aubio_process_func_t)process_block,process_print);
 
   del_aubio_pitch (o);
   del_aubio_wavetable (wavetable);
   del_fvec (pitch);
 
   examples_common_del();
-  debug("End of program.\n");
-  fflush(stderr);
   return 0;
 }
 
index b369edd..e1fbbfa 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
+  Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
 
   This file is part of aubio.
 
 #include "utils.h"
 #include "parse_args.h"
 
-unsigned int pos = 0; /*frames%dspblocksize*/
 sint_t wassilence = 1, issilence;
 
-int aubio_process(smpl_t **input, smpl_t **output, int nframes);
-int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
-  unsigned int j;       /*frames*/
-  for (j=0;j<(unsigned)nframes;j++) {
-    if(usejack) {
-      /* write input to datanew */
-      fvec_write_sample(ibuf, input[0][j], pos);
-      /* put synthnew in output */
-      output[0][j] = fvec_read_sample(obuf, pos);
-    }
-    /*time for fft*/
-    if (pos == overlap_size-1) {         
-      /* test for silence */
-      if (aubio_silence_detection(ibuf, silence)==1) {
-        if (wassilence==1) issilence = 1;
-        else issilence = 2;
-        wassilence=1;
-      } else { 
-        if (wassilence<=0) issilence = 0;
-        else issilence = -1;
-        wassilence=0;
-      }
-      /* end of block loop */
-      pos = -1; /* so it will be zero next j loop */
-    }
-    pos++;
+void process_block(fvec_t * ibuf, fvec_t * obuf) {
+  fvec_zeros (obuf);
+  if (aubio_silence_detection(ibuf, silence)==1) {
+    if (wassilence==1) issilence = 1;
+    else issilence = 2;
+    wassilence=1;
+  } else {
+    if (wassilence<=0) issilence = 0;
+    else issilence = -1;
+    wassilence=0;
   }
-  return 1;
 }
 
 static void process_print (void) {
-      int curframes = (frames - 4) > 0 ? frames -4 : 0;
-      if (issilence == -1) {
-          outmsg("NOISY: %f\n",curframes*overlap_size/(float)samplerate);
-      } else if (issilence == 2) { 
-          outmsg("QUIET: %f\n",curframes*overlap_size/(float)samplerate);
-      }
+  int curblocks = (blocks - 4) > 0 ? blocks - 4 : 0;
+  if (issilence == -1) {
+    outmsg("NOISY: %f\n",curblocks*hop_size/(float)samplerate);
+  } else if (issilence == 2) {
+    outmsg("QUIET: %f\n",curblocks*hop_size/(float)samplerate);
+  }
 }
 
 int main(int argc, char **argv) {
   examples_common_init(argc,argv);
-  examples_common_process(aubio_process,process_print);
+  verbmsg ("using source: %s at %dHz\n", source_uri, samplerate);
+  verbmsg ("buffer_size: %d, ", buffer_size);
+  verbmsg ("hop_size: %d\n", hop_size);
+  examples_common_process((aubio_process_func_t)process_block,process_print);
   examples_common_del();
-  debug("End of program.\n");
-  fflush(stderr);
   return 0;
 }
 
index d4b4b41..b862c2b 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
+  Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
 
   This file is part of aubio.
 
 #define PROG_HAS_TEMPO 1
 #include "parse_args.h"
 
-uint_t pos = 0;    /* frames%dspblocksize */
-aubio_tempo_t * bt = NULL;
+aubio_tempo_t * tempo;
 aubio_wavetable_t *wavetable;
-fvec_t * tempo_out = NULL;
+fvec_t * tempo_out;
 smpl_t istactus = 0;
 smpl_t isonset = 0;
 
-static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
-  unsigned int j;       /*frames*/
-  for (j=0;j<(unsigned)nframes;j++) {
-    if(usejack) {
-      /* write input to datanew */
-      fvec_write_sample(ibuf, input[0][j], pos);
-      /* put synthnew in output */
-      output[0][j] = fvec_read_sample(obuf, pos);
-    }
-    /*time for fft*/
-    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.) {
-        aubio_wavetable_play ( wavetable );
-      } else {
-        aubio_wavetable_stop ( wavetable );
-      }
-      aubio_wavetable_do (wavetable, obuf, obuf);
-      /* end of block loop */
-      pos = -1; /* so it will be zero next j loop */
-    }
-    pos++;
+void process_block(fvec_t * ibuf, fvec_t *obuf) {
+  aubio_tempo_do (tempo, ibuf, tempo_out);
+  istactus = fvec_read_sample (tempo_out, 0);
+  isonset = fvec_read_sample (tempo_out, 1);
+  fvec_zeros (obuf);
+  if (istactus > 0.) {
+    aubio_wavetable_play ( wavetable );
+  } else {
+    aubio_wavetable_stop ( wavetable );
   }
-  return 1;
+  aubio_wavetable_do (wavetable, obuf, obuf);
 }
 
-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);
+void process_print (void) {
+  if (istactus) {
+    outmsg("%f\n", aubio_tempo_get_last_s(tempo) );
   }
+  //if (isonset && verbose)
+  //  outmsg(" \t \t%f\n",(blocks)*hop_size/(float)samplerate);
 }
 
 int main(int argc, char **argv) {
-  
+  // override general settings from utils.c
   buffer_size = 1024;
-  overlap_size = 512;
-  /* override default settings */
+  hop_size = 512;
+
   examples_common_init(argc,argv);
 
+  verbmsg ("using source: %s at %dHz\n", source_uri, samplerate);
+
+  verbmsg ("tempo method: %s, ", tempo_method);
+  verbmsg ("buffer_size: %d, ", buffer_size);
+  verbmsg ("hop_size: %d, ", hop_size);
+  verbmsg ("threshold: %f\n", onset_threshold);
+
   tempo_out = new_fvec(2);
-  bt = new_aubio_tempo(tempo_method,buffer_size,overlap_size, samplerate);
-  if (onset_threshold != 0.) aubio_tempo_set_threshold (bt, onset_threshold);
+  tempo = new_aubio_tempo(tempo_method, buffer_size, hop_size, samplerate);
+  if (onset_threshold != 0.) aubio_tempo_set_threshold (tempo, onset_threshold);
 
-  wavetable = new_aubio_wavetable (samplerate, overlap_size);
+  wavetable = new_aubio_wavetable (samplerate, hop_size);
   aubio_wavetable_set_freq ( wavetable, 2450.);
   //aubio_sampler_load (sampler, "/archives/sounds/woodblock.aiff");
 
-  examples_common_process(aubio_process,process_print);
+  examples_common_process((aubio_process_func_t)process_block,process_print);
 
-  del_aubio_tempo(bt);
+  del_aubio_tempo(tempo);
   del_aubio_wavetable (wavetable);
   del_fvec(tempo_out);
 
   examples_common_del();
-
-  debug("End of program.\n");
-
-  fflush(stderr);
-
   return 0;
 }
 
index bcb7fb9..83290b3 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
+  Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
 
   This file is part of aubio.
 
@@ -35,7 +35,7 @@ typedef jack_default_audio_sample_t jack_sample_t;
 #define RINGBUFFER_SIZE 1024*sizeof(jack_midi_event_t)
 
 /**
- * jack device structure 
+ * jack device structure
  */
 struct _aubio_jack_t
 {
@@ -69,19 +69,23 @@ struct _aubio_jack_t
   uint_t samplerate;
   /** jack processing function */
   aubio_process_func_t callback;
+  /** internal fvec */
+  fvec_t *ibuf;
+  fvec_t *obuf;
+  uint_t hop_size;
+  int pos;
 };
 
 /* static memory management */
 static aubio_jack_t *aubio_jack_alloc (uint_t ichan, uint_t ochan,
     uint_t imidichan, uint_t omidichan);
-static uint_t aubio_jack_free (aubio_jack_t * jack_setup);
 /* jack callback functions */
 static int aubio_jack_process (jack_nframes_t nframes, void *arg);
 static void aubio_jack_shutdown (void *arg);
 
 aubio_jack_t *
-new_aubio_jack (uint_t ichan, uint_t ochan,
-    uint_t imidichan, uint_t omidichan, aubio_process_func_t callback)
+new_aubio_jack (uint_t hop_size, uint_t ichan, uint_t ochan,
+    uint_t imidichan, uint_t omidichan)
 {
   aubio_jack_t *jack_setup = aubio_jack_alloc (ichan, ochan,
       imidichan, omidichan);
@@ -148,8 +152,13 @@ new_aubio_jack (uint_t ichan, uint_t ochan,
     AUBIO_DBG ("%s:%s\n", client_name, name);
   }
 
-  /* set processing callback */
-  jack_setup->callback = callback;
+  /* get sample rate */
+  jack_setup->samplerate = jack_get_sample_rate (jack_setup->client);
+
+  jack_setup->hop_size = hop_size;
+  jack_setup->ibuf = new_fvec(hop_size);
+  jack_setup->obuf = new_fvec(hop_size);
+  jack_setup->pos = 0;
   return jack_setup;
 
 beach:
@@ -159,10 +168,15 @@ beach:
 }
 
 uint_t
-aubio_jack_activate (aubio_jack_t * jack_setup)
+aubio_jack_get_samplerate (aubio_jack_t * jack_setup) {
+  return jack_setup->samplerate;
+}
+
+uint_t
+aubio_jack_activate (aubio_jack_t * jack_setup, aubio_process_func_t callback)
 {
-  /* get sample rate */
-  jack_setup->samplerate = jack_get_sample_rate (jack_setup->client);
+  /* set processing callback */
+  jack_setup->callback = callback;
   /* actual jack process activation */
   if (jack_activate (jack_setup->client)) {
     AUBIO_ERR ("jack client activation failed");
@@ -176,7 +190,6 @@ aubio_jack_close (aubio_jack_t * jack_setup)
 {
   /* bug : should disconnect all ports first */
   jack_client_close (jack_setup->client);
-  aubio_jack_free (jack_setup);
 }
 
 /* memory management */
@@ -208,18 +221,19 @@ aubio_jack_alloc (uint_t ichan, uint_t ochan,
   return jack_setup;
 }
 
-static uint_t
-aubio_jack_free (aubio_jack_t * jack_setup)
+void
+del_aubio_jack (aubio_jack_t * jack_setup)
 {
   if (jack_setup->omidichan && jack_setup->midi_out_ring) {
     jack_ringbuffer_free (jack_setup->midi_out_ring);
   }
+  del_fvec (jack_setup->ibuf);
+  del_fvec (jack_setup->obuf);
   AUBIO_FREE (jack_setup->oports);
   AUBIO_FREE (jack_setup->iports);
   AUBIO_FREE (jack_setup->ibufs);
   AUBIO_FREE (jack_setup->obufs);
   AUBIO_FREE (jack_setup);
-  return AUBIO_OK;
 }
 
 /* jack callback functions */
@@ -232,6 +246,26 @@ aubio_jack_shutdown (void *arg UNUSED)
 
 static void process_midi_output (aubio_jack_t * dev, jack_nframes_t nframes);
 
+static int block_process(aubio_jack_t *dev,
+    smpl_t **input, smpl_t **output, int nframes) {
+  unsigned int j;       /*frames*/
+  for (j=0;j<(unsigned)nframes;j++) {
+    /* put synthnew in output */
+    output[0][j] = fvec_read_sample(dev->obuf, dev->pos);
+    /* write input to datanew */
+    fvec_write_sample(dev->ibuf, input[0][j], dev->pos);
+    /*time for fft*/
+    if (dev->pos == (int)(dev->hop_size) - 1) {
+      /* block loop */
+      dev->callback(dev->ibuf, dev->obuf);
+      /* end of block loop */
+      dev->pos = -1; /* so it will be zero next j loop */
+    }
+    dev->pos++;
+  }
+  return 1;
+}
+
 static int
 aubio_jack_process (jack_nframes_t nframes, void *arg)
 {
@@ -248,7 +282,7 @@ aubio_jack_process (jack_nframes_t nframes, void *arg)
         (jack_sample_t *) jack_port_get_buffer (dev->oports[i], nframes);
   }
 #ifndef AUBIO_JACK_NEEDS_CONVERSION
-  dev->callback (dev->ibufs, dev->obufs, nframes);
+  block_process(dev, dev->ibufs, dev->obufs, nframes);
 #else
   uint_t j;
   for (j = 0; j < MIN (nframes, AUBIO_JACK_MAX_FRAMES); j++) {
@@ -256,7 +290,7 @@ aubio_jack_process (jack_nframes_t nframes, void *arg)
       dev->sibufs[i][j] = (smpl_t) dev->ibufs[i][j];
     }
   }
-  dev->callback (dev->sibufs, dev->sobufs, nframes);
+  block_process(dev, dev->sibufs, dev->sobufs, nframes);
   for (j = 0; j < MIN (nframes, AUBIO_JACK_MAX_FRAMES); j++) {
     for (i = 0; i < dev->ochan; i++) {
       dev->obufs[i][j] = (jack_sample_t) dev->sobufs[i][j];
index dcb6fb2..994e829 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
+  Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
 
   This file is part of aubio.
 
 #ifndef JACKIO_H
 #define JACKIO_H
 
-/** 
+/**
  * @file
  *
  * Jack driver for aubio
- * 
+ *
  */
 
 #ifdef __cplusplus
@@ -40,17 +40,20 @@ extern "C"
 /** jack object */
 typedef struct _aubio_jack_t aubio_jack_t;
 /** jack process function */
-typedef int (*aubio_process_func_t) (smpl_t ** input,
-    smpl_t ** output, int nframes);
+typedef int (*aubio_process_func_t) (fvec_t * input, fvec_t * output);
 
 /** jack device creation function */
-aubio_jack_t *new_aubio_jack (uint_t inchannels, uint_t outchannels,
-    uint_t imidichan, uint_t omidichan,
-    aubio_process_func_t callback);
+aubio_jack_t *new_aubio_jack (uint_t hop_size,
+    uint_t inchannels, uint_t outchannels,
+    uint_t imidichan, uint_t omidichan);
 /** activate jack client (run jackprocess function) */
-uint_t aubio_jack_activate (aubio_jack_t * jack_setup);
+uint_t aubio_jack_activate (aubio_jack_t * jack_setup,
+    aubio_process_func_t callback);
 /** close and delete jack client */
 void aubio_jack_close (aubio_jack_t * jack_setup);
+void del_aubio_jack (aubio_jack_t * jack_setup);
+/** get samplerate */
+uint_t aubio_jack_get_samplerate (aubio_jack_t * jack_setup);
 
 /** write a jack_midi_event_t to the midi output ringbuffer */
 void aubio_jack_midi_event_write (aubio_jack_t * jack_setup,
index 42a24ce..003f32f 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
+  Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
 
   This file is part of aubio.
 
@@ -26,7 +26,7 @@ extern char_t *sink_uri;
 // general stuff
 extern uint_t samplerate;
 extern uint_t buffer_size;
-extern uint_t overlap_size;
+extern uint_t hop_size;
 // onset stuff
 extern char_t * onset_method;
 extern smpl_t onset_threshold;
@@ -47,7 +47,7 @@ extern void examples_common_process (aubio_process_func_t process_func,
     aubio_print_func_t print);
 
 // internal stuff
-extern int frames;
+extern int blocks;
 
 extern fvec_t *ibuf;
 extern fvec_t *obuf;
@@ -155,7 +155,7 @@ parse_args (int argc, char **argv)
         buffer_size = atoi (optarg);
         break;
       case 'H':
-        overlap_size = atoi (optarg);
+        hop_size = atoi (optarg);
         break;
       case 'O':                /*onset type */
         onset_method = optarg;
index b3311cc..f014f85 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
+  Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
 
   This file is part of aubio.
 
 #endif /* HAVE_JACK */
 
 int verbose = 0;
+int usejack = 0;
 // input / output
 char_t *sink_uri = NULL;
 char_t *source_uri = NULL;
 // general stuff
 uint_t samplerate = 0;
 uint_t buffer_size = 512;
-uint_t overlap_size = 256;
+uint_t hop_size = 256;
 // onset stuff
 char_t * onset_method = "default";
 smpl_t onset_threshold = 0.0; // will be set if != 0.
@@ -59,15 +60,16 @@ aubio_sink_t *this_sink = NULL;
 fvec_t *ibuf;
 fvec_t *obuf;
 
-
 /* settings */
-int frames = 0;
-int usejack = 0;
-int frames_delay = 0;
+int blocks = 0;
 
 extern void usage (FILE * stream, int exit_code);
 extern int parse_args (int argc, char **argv);
 
+#if HAVE_JACK
+aubio_jack_t *jack_setup;
+#endif
+
 void
 examples_common_init (int argc, char **argv)
 {
@@ -77,12 +79,14 @@ examples_common_init (int argc, char **argv)
 
   if (!usejack) {
     debug ("Opening files ...\n");
-    this_source = new_aubio_source ((char_t*)source_uri, 0, overlap_size);
+    this_source = new_aubio_source ((char_t*)source_uri, samplerate, hop_size);
     if (this_source == NULL) {
       outmsg ("Could not open input file %s.\n", source_uri);
       exit (1);
     }
-    samplerate = aubio_source_get_samplerate(this_source);
+    if (samplerate == 0) {
+      samplerate = aubio_source_get_samplerate(this_source);
+    }
     if (sink_uri != NULL) {
       this_sink = new_aubio_sink ((char_t*)sink_uri, samplerate);
       if (this_sink == NULL) {
@@ -90,9 +94,16 @@ examples_common_init (int argc, char **argv)
         exit (1);
       }
     }
+#ifdef HAVE_JACK
+  } else {
+    debug ("Jack init ...\n");
+    jack_setup = new_aubio_jack (hop_size, 1, 1, 0, 1);
+    samplerate = aubio_jack_get_samplerate (jack_setup);
+    source_uri = "jack";
+#endif
   }
-  ibuf = new_fvec (overlap_size);
-  obuf = new_fvec (overlap_size);
+  ibuf = new_fvec (hop_size);
+  obuf = new_fvec (hop_size);
 
 }
 
@@ -102,12 +113,10 @@ examples_common_del (void)
   del_fvec (ibuf);
   del_fvec (obuf);
   aubio_cleanup ();
+  fflush(stderr);
+  fflush(stdout);
 }
 
-#if HAVE_JACK
-aubio_jack_t *jack_setup;
-#endif
-
 void
 examples_common_process (aubio_process_func_t process_func,
     aubio_print_func_t print)
@@ -117,11 +126,8 @@ examples_common_process (aubio_process_func_t process_func,
   if (usejack) {
 
 #if HAVE_JACK
-    debug ("Jack init ...\n");
-    jack_setup = new_aubio_jack (1, 1,
-        0, 1, (aubio_process_func_t) process_func);
     debug ("Jack activation ...\n");
-    aubio_jack_activate (jack_setup);
+    aubio_jack_activate (jack_setup, process_func);
     debug ("Processing (Ctrl+C to quit) ...\n");
     pause ();
     aubio_jack_close (jack_setup);
@@ -132,21 +138,25 @@ examples_common_process (aubio_process_func_t process_func,
 
   } else {
     /* phasevoc */
-    debug ("Processing ...\n");
-
-    frames = 0;
+    blocks = 0;
+    uint_t total_read = 0;
 
     do {
       aubio_source_do (this_source, ibuf, &read);
-      process_func (&ibuf->data, &obuf->data, overlap_size);
-      print ();
+      process_func (ibuf, obuf);
+      // print to console if verbose or no output given
+      if (verbose || sink_uri == NULL) {
+        print();
+      }
       if (this_sink) {
-        aubio_sink_do (this_sink, obuf, overlap_size);
+        aubio_sink_do (this_sink, obuf, hop_size);
       }
-      frames++;
-    } while (read == overlap_size);
+      blocks++;
+      total_read += read;
+    } while (read == hop_size);
 
-    debug ("Processed %d frames of %d samples.\n", frames, buffer_size);
+    verbmsg ("read %d samples (%d blocks of %d) from %s at %dHz\n",
+        total_read, blocks, hop_size, source_uri, samplerate);
 
     del_aubio_source (this_source);
     del_aubio_sink   (this_sink);
@@ -174,12 +184,10 @@ send_noteon (int pitch, int velo)
     aubio_jack_midi_event_write (jack_setup, (jack_midi_event_t *) & ev);
   } else
 #endif
-  if (!verbose) {
-    if (velo == 0) {
-      outmsg ("%f\n", frames * overlap_size / (float) samplerate);
-    } else {
-      outmsg ("%f\t%f\t", mpitch, frames * overlap_size / (float) samplerate);
-    }
+  if (velo == 0) {
+    outmsg ("%f\n", blocks * hop_size / (float) samplerate);
+  } else {
+    outmsg ("%f\t%f\t", mpitch, blocks * hop_size / (float) samplerate);
   }
 }
 
index be92681..d85388c 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
+  Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
 
   This file is part of aubio.
 
 #include "config.h"
 
 #ifdef HAVE_C99_VARARGS_MACROS
-#define debug(...)              if (verbose) fprintf (stderr, __VA_ARGS__)
-#define errmsg(...)             fprintf (stderr, __VA_ARGS__)
-#define outmsg(...)             fprintf (stdout, __VA_ARGS__)
+#ifdef HAVE_DEBUG
+#define debug(...)                fprintf (stderr, __VA_ARGS__)
 #else
-#define debug(format, args...)  if (verbose) fprintf(stderr, format , ##args)
-#define errmsg(format, args...) fprintf(stderr, format , ##args)
-#define outmsg(format, args...) fprintf(stdout, format , ##args)
+#define debug(...)
+#endif
+#define verbmsg(...)              if (verbose) fprintf (stderr, __VA_ARGS__)
+#define errmsg(...)               fprintf (stderr, __VA_ARGS__)
+#define outmsg(...)               fprintf (stdout, __VA_ARGS__)
+#else
+#ifdef HAVE_DEBUG
+#define debug(...)                fprintf (stderr, format , **args)
+#else
+#define debug(...)                ()
+#endif
+#define verbmsg(format, args...)  if (verbose) fprintf(stderr, format , ##args)
+#define errmsg(format, args...)   fprintf(stderr, format , ##args)
+#define outmsg(format, args...)   fprintf(stdout, format , ##args)
 #endif
 
 typedef void (aubio_print_func_t) (void);
-#ifndef HAVE_JACK
-typedef int (*aubio_process_func_t)
-  (smpl_t ** input, smpl_t ** output, int nframes);
-#endif
+typedef int (*aubio_process_func_t)(fvec_t * input, fvec_t * output);
 void send_noteon (int pitch, int velo);
 
-