merged commmon code between aubionotes.c and aubioonset.c into utils.c
authorPaul Brossier <piem@altern.org>
Mon, 11 Apr 2005 16:37:51 +0000 (16:37 +0000)
committerPaul Brossier <piem@altern.org>
Mon, 11 Apr 2005 16:37:51 +0000 (16:37 +0000)
examples/aubionotes.c
examples/aubioonset.c
examples/utils.c
examples/utils.h

index 7a9e786..9780b95 100644 (file)
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <getopt.h>
-#include <unistd.h>
-#include <math.h>
-#include "aubio.h"
-#include "aubioext.h"
 #include "utils.h"
 
-/* settings */
-const char * output_filename = NULL;
-const char * input_filename  = NULL;
-const char * onset_filename  = "/usr/share/sounds/aubio/woodblock.aiff";
-int verbose = 0;
-int usejack = 0;
-int usedoubled = 1;
-int usemidi = 1;
-int median = 0;
-
-/* energy,specdiff,hfc,complexdomain,phase */
-aubio_onsetdetection_type type_onset  = hfc;
-aubio_onsetdetection_type type_onset2 = complexdomain;
-smpl_t threshold                      = 0.3;
-smpl_t threshold2                     = -90.;
-uint_t buffer_size                    = 1024;
-uint_t overlap_size                   = 512;
-uint_t channels                       = 1;
-uint_t samplerate                     = 44100;
-
-/* global objects */
-int frames;
-aubio_pvoc_t * pv;
-fvec_t * ibuf;
-fvec_t * obuf;
-cvec_t * fftgrain;
-fvec_t * woodblock;
-aubio_onsetdetection_t *o;
-aubio_onsetdetection_t *o2;
-fvec_t *onset;
-fvec_t *onset2;
-int isonset = 0;
-aubio_pickpeak_t * parms;
-
-/* pitch objects */
-smpl_t pitch               = 0.;
-aubio_pitchdetection_t * pitchdet;
-
-fvec_t * note_buffer = NULL;
-fvec_t * note_buffer2 = NULL;
-uint_t medianfiltlen = 6;
-smpl_t curlevel = 0.;
-smpl_t maxonset = 0.;
-
-/* midi objects */
-aubio_midi_player_t * mplay; 
-aubio_midi_driver_t * mdriver; 
-aubio_midi_event_t  * event;
-
 unsigned int pos = 0; /*frames%dspblocksize*/
-
-void send_noteon(aubio_midi_driver_t * d, int pitch, int velo);
-void send_noteon(aubio_midi_driver_t * d, int pitch, int velo)
-{
-    /* we should check if we use midi here, not jack */
-#if ALSA_SUPPORT
-    if (usejack) {
-        if (velo==0) {
-            aubio_midi_event_set_type(event,NOTE_OFF);
-        } else {
-            aubio_midi_event_set_type(event,NOTE_ON);
-        }
-        aubio_midi_event_set_channel(event,0);
-        aubio_midi_event_set_pitch(event,pitch);
-        aubio_midi_event_set_velocity(event,velo);
-        aubio_midi_direct_output(mdriver,event);
-    } else 
-#endif
-    {
-        if (velo==0) {
-            outmsg("%f\n",frames*overlap_size/(float)samplerate);
-        } else {
-            outmsg("%d\t%f\t",pitch,frames*overlap_size/(float)samplerate);
-        }
-    }
-}
-
-
-/** append new note candidate to the note_buffer and return filtered value. we
- * need to copy the input array as vec_median destroy its input data.*/
-
-void note_append(fvec_t * note_buffer, smpl_t curnote); 
-void note_append(fvec_t * note_buffer, smpl_t curnote) {
-  uint_t i = 0;
-  for (i = 0; i < note_buffer->length - 1; i++) { 
-      note_buffer->data[0][i] = note_buffer->data[0][i+1];
-  }
-  note_buffer->data[0][note_buffer->length - 1] = curnote;
-  return;
-}
-
-uint_t get_note(fvec_t *note_buffer, fvec_t *note_buffer2);
-uint_t get_note(fvec_t *note_buffer, fvec_t *note_buffer2){
-  uint_t i = 0;
-  for (i = 0; i < note_buffer->length; i++) { 
-      note_buffer2->data[0][i] = note_buffer->data[0][i];
-  }
-  return vec_median(note_buffer2);
-}
-
-
-smpl_t curnote = 0.;
-smpl_t newnote = 0.;
-uint_t isready = 0;
+uint_t usepitch = 1;
 
 int aubio_process(float **input, float **output, int nframes);
 int aubio_process(float **input, float **output, int nframes) {
@@ -157,65 +47,49 @@ int aubio_process(float **input, float **output, int nframes) {
       
       pitch = aubio_pitchdetection(pitchdet,ibuf);
       if(median){
-      newnote = (FLOOR)(bintomidi(pitch,samplerate,buffer_size*4)+.5);
-      note_append(note_buffer, newnote);
+              note_append(note_buffer, pitch);
       }
 
       /* curlevel is negatif or 1 if silence */
       curlevel = aubio_level_detection(ibuf, threshold2);
       if (isonset) {
-        /* test for silence */
-        if (curlevel == 1.) {
-          isonset=0;
-          if (median) isready = 0;
-          /* send note off */
-          send_noteon(mdriver,curnote,0);
-        } else {
-          if (median) {
-                  isready = 1;
-          } else {
-          /* kill old note */
-          send_noteon(mdriver,curnote,0);
-          //curnote = (int)FLOOR(bintomidi(pitch,samplerate,buffer_size*4) + .5);
-          curnote = (int)FLOOR(freqtomidi(pitch) + .5);
-          /* get and send new one */
-          /*if (curnote<45){
-            send_noteon(mdriver,curnote,0);
-          } else {*/
-          if (curnote>45){
-            send_noteon(mdriver,curnote,127+(int)FLOOR(curlevel));
-          }
-          }
-          
-          for (pos = 0; pos < overlap_size; pos++){
-            obuf->data[0][pos] = woodblock->data[0][pos];
-          }
-        }
+              /* test for silence */
+              if (curlevel == 1.) {
+                      isonset=0;
+                      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[0][pos] = woodblock->data[0][pos];
+                      }
+              }
       } else {
               if (median) {
-//        if (curlevel != 1) {
-//          if (bufpos == note_buffer->length)
-//            curnote = aubio_getnote(note_buffer);
-//        }
-//
-        if (isready > 0)
-            isready++;
-        if (isready == note_buffer->length)
-        {
-            //outmsg("%d, %f\n", isready, curnote);
-            send_noteon(mdriver,curnote,0);
-        /* kill old note */
-            newnote = get_note(note_buffer, note_buffer2);
-            curnote = newnote;
-        /* get and send new one */
-        /*if (curnote<45){
-          send_noteon(mdriver,curnote,0);
-        } else {*/
-            if (curnote>45){
-                send_noteon(mdriver,curnote,127+(int)FLOOR(curlevel));
-            }
-        }
-        } // 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[0][pos] = 0.;
       }
@@ -227,114 +101,15 @@ int aubio_process(float **input, float **output, int nframes) {
   return 1;
 }
 
-int main(int argc, char **argv) {
-
-  aubio_file_t * file = NULL;
-  aubio_file_t * fileout = NULL;
-
-  aubio_file_t * onsetfile = new_file_ro(onset_filename);
-  /* parse command line arguments */
-  parse_args(argc, argv);
-
-  if(!usejack)
-  {
-    debug("Opening files ...\n");
-    file = new_file_ro (input_filename);
-    file_info(file);
-    samplerate = aubio_file_samplerate(file);
-    channels = aubio_file_channels(file);
-    if (output_filename != NULL)
-      fileout = new_file_wo(file, output_filename);
-  }
-
-  ibuf        = new_fvec(overlap_size, channels);
-  obuf        = new_fvec(overlap_size, channels);
-  woodblock   = new_fvec(buffer_size,1);
-  fftgrain    = new_cvec(buffer_size, channels);
-
-  aubio_pitchdetection_type mode = yin; // mcomb
-  pitchdet = new_aubio_pitchdetection(buffer_size*4, overlap_size, channels, samplerate, mode, freq);
-  
-if (median) {
-  note_buffer = new_fvec(medianfiltlen, 1);
-  note_buffer2= new_fvec(medianfiltlen, 1);
+void process_print (void);
+void process_print (void) {
+      if (verbose) outmsg("%f\n",pitch);
 }
-  /* read the output sound once */
-  file_read(onsetfile, overlap_size, woodblock);
-  /* phase vocoder */
-  pv = new_aubio_pvoc(buffer_size, overlap_size, channels);
-  /* onsets */
-  parms = new_aubio_peakpicker(threshold);
-  o = new_aubio_onsetdetection(type_onset,buffer_size,channels);
-  onset = new_fvec(1, channels);
-  if (usedoubled)    {
-    o2 = new_aubio_onsetdetection(type_onset2,buffer_size,channels);
-    onset2 = new_fvec(1 , channels);
-  }
-
-  if(usejack) {
-#ifdef JACK_SUPPORT
-    aubio_jack_t * jack_setup;
-    debug("Midi init ...\n");
-    debug("Jack init ...\n");
-    jack_setup = new_aubio_jack(channels, channels,
-          (aubio_process_func_t)aubio_process);
-
-    mplay = new_aubio_midi_player();
-
-    mdriver = new_aubio_midi_driver("alsa_seq",
-        (handle_midi_event_func_t)aubio_midi_send_event, mplay);
-
-    event = new_aubio_midi_event();
-    
-    debug("Jack activation ...\n");
-    aubio_jack_activate(jack_setup);
-    debug("Processing (Ctrl+C to quit) ...\n");
-    pause();
-    send_noteon(mdriver,curnote,0);
-    aubio_jack_close(jack_setup);
-    del_aubio_midi_driver(mdriver);
-#else
-    usage(stderr, 1);
-    outmsg("Compiled without jack output, exiting.\n");
-#endif
-
-  } else {
-    /* phasevoc */
-    debug("Processing ...\n");
-
-    frames = 0;
-
-    while (overlap_size == file_read(file, overlap_size, ibuf))
-    {
-      isonset=0;
-      aubio_process(ibuf->data, obuf->data, overlap_size);
-      if (output_filename != NULL) {
-        file_write(fileout,overlap_size,obuf);
-      }
-      frames++;
-    }
-    send_noteon(mdriver,curnote,0);
-
-    debug("Processed %d frames of %d samples.\n", frames, buffer_size);
-    del_file(file);
-
-    if (output_filename != NULL)
-      del_file(fileout);
-
-  }
-
-  del_aubio_pvoc(pv);
-  del_fvec(obuf);
-  del_fvec(ibuf);
-  del_cvec(fftgrain);
-  del_aubio_pitchdetection(pitchdet);
-  del_fvec(onset);
-  if (median) {
-  del_fvec(note_buffer);
-  del_fvec(note_buffer2);
-  }
 
+int main(int argc, char **argv) {
+  examples_common_init(argc,argv);
+  examples_common_process(aubio_process, process_print);
+  examples_common_del();
   debug("End of program.\n");
   fflush(stderr);
   return 0;
index adfe1e9..bd8f627 100644 (file)
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <getopt.h>
-#include <unistd.h>
-#include "aubio.h"
-#include "aubioext.h"
 #include "utils.h"
 
-int aubio_process(float **input, float **output, int nframes);
-
-const char * output_filename = NULL;
-const char * input_filename  = NULL;
-const char * onset_filename  = "/usr/share/sounds/aubio/woodblock.aiff";
-
-/* settings */
-int verbose = 0;
-int usejack = 0;
-int usedoubled = 1;
-
-
-/* energy,specdiff,hfc,complexdomain,phase */
-aubio_onsetdetection_type type_onset  = hfc;
-aubio_onsetdetection_type type_onset2 = complexdomain;
-smpl_t threshold                      = 0.1;
-smpl_t threshold2                     = -90.;
-uint_t buffer_size                    = 1024;
-uint_t overlap_size                   = 512;
-uint_t channels                       = 1;
-uint_t samplerate                     = 44100;
-
-/* global objects */
-aubio_pvoc_t * pv;
-fvec_t * ibuf;
-fvec_t * obuf;
-cvec_t * fftgrain;
-fvec_t * woodblock;
-aubio_onsetdetection_t *o;
-aubio_onsetdetection_t *o2;
-fvec_t *onset;
-fvec_t *onset2;
-int isonset = 0;
-aubio_pickpeak_t * parms;
 unsigned int pos = 0; /*frames%dspblocksize*/
+uint_t usepitch = 0;
 
+int aubio_process(float **input, float **output, int nframes);
 int aubio_process(float **input, float **output, int nframes) {
   unsigned int i;       /*channels*/
   unsigned int j;       /*frames*/
@@ -95,7 +56,6 @@ int aubio_process(float **input, float **output, int nframes) {
         for (pos = 0; pos < overlap_size; pos++)
           obuf->data[0][pos] = 0.;
       }
-      //aubio_pvoc_rdo(pv,fftgrain, obuf);
       /* end of block loop */
       pos = -1; /* so it will be zero next j loop */
     }
@@ -104,72 +64,8 @@ int aubio_process(float **input, float **output, int nframes) {
   return 1;
 }
 
-int main(int argc, char **argv) {
-  int frames;
-
-  aubio_file_t * file = NULL;
-  aubio_file_t * fileout = NULL;
-
-  aubio_file_t * onsetfile = new_file_ro(onset_filename);
-  parse_args(argc, argv);
-
-  if(!usejack)
-  {
-    debug("Opening files ...\n");
-    file = new_file_ro (input_filename);
-    if (verbose) file_info(file);
-    channels = aubio_file_channels(file);
-    samplerate = aubio_file_samplerate(file);
-    if (output_filename != NULL)
-      fileout = new_file_wo(file, output_filename);
-  }
-
-  ibuf      = new_fvec(overlap_size, channels);
-  obuf      = new_fvec(overlap_size, channels);
-  woodblock = new_fvec(buffer_size,1);
-  fftgrain  = new_cvec(buffer_size, channels);
-
-  /* read the output sound once */
-  file_read(onsetfile, overlap_size, woodblock);
-
-  /* phase vocoder */
-  debug("Phase voc init ... \n");
-  pv = new_aubio_pvoc(buffer_size, overlap_size, channels);
-
-  /* onsets */
-  parms = new_aubio_peakpicker(threshold);
-  o = new_aubio_onsetdetection(type_onset,buffer_size,channels);
-  onset = new_fvec(1, channels);
-  if (usedoubled)    {
-    o2 = new_aubio_onsetdetection(type_onset2,buffer_size,channels);
-    onset2 = new_fvec(1 , channels);
-  }
-
-  if(usejack) {
-#ifdef JACK_SUPPORT
-    aubio_jack_t * jack_setup;
-    debug("Jack init ...\n");
-    jack_setup = new_aubio_jack(channels, channels,
-          (aubio_process_func_t)aubio_process);
-    debug("Jack activation ...\n");
-    aubio_jack_activate(jack_setup);
-    debug("Processing (Ctrl+C to quit) ...\n");
-    pause();
-    aubio_jack_close(jack_setup);
-#else
-    outmsg("Compiled without jack output, exiting.");
-#endif
-
-  } else {
-    /* phasevoc */
-    debug("Processing ...\n");
-
-    frames = 0;
-
-    while (overlap_size == file_read(file, overlap_size, ibuf))
-    {
-      isonset=0;
-      aubio_process(ibuf->data, obuf->data, overlap_size);
+void process_print (void);
+void process_print (void) {
       /* output times in seconds, taking back some 
        * delay to ensure the label is _before_ the
        * actual onset */
@@ -180,26 +76,12 @@ int main(int argc, char **argv) {
           outmsg("%f\n",0.);
         }
       }
-      if (output_filename != NULL) {
-        file_write(fileout,overlap_size,obuf);
-      }
-      frames++;
-    }
-
-    debug("Processed %d frames of %d samples.\n", frames, buffer_size);
-    del_file(file);
-
-    if (output_filename != NULL)
-      del_file(fileout);
-
-  }
-
-  del_aubio_pvoc(pv);
-  del_fvec(obuf);
-  del_fvec(ibuf);
-  del_cvec(fftgrain);
-  del_fvec(onset);
+}
 
+int main(int argc, char **argv) {
+  examples_common_init(argc,argv);
+  examples_common_process(aubio_process,process_print);
+  examples_common_del();
   debug("End of program.\n");
   fflush(stderr);
   return 0;
index 27836aa..6741840 100644 (file)
 cca_client_t * aubio_cca_client;
 #endif /* LADCCA_SUPPORT */
 
+/* settings */
+const char * output_filename = NULL;
+const char * input_filename  = NULL;
+const char * onset_filename  = "/usr/share/sounds/aubio/woodblock.aiff";
+int frames = 0;
+int verbose = 0;
+int usejack = 0;
+int usedoubled = 1;
+
+
+/* energy,specdiff,hfc,complexdomain,phase */
+aubio_onsetdetection_type type_onset  = hfc;
+aubio_onsetdetection_type type_onset2 = complexdomain;
+smpl_t threshold                      = 0.3;
+smpl_t threshold2                     = -90.;
+uint_t buffer_size                    = 1024;
+uint_t overlap_size                   = 512;
+uint_t channels                       = 1;
+uint_t samplerate                     = 44100;
+
+
+aubio_file_t * file = NULL;
+aubio_file_t * fileout = NULL;
+
+aubio_pvoc_t * pv;
+fvec_t * ibuf;
+fvec_t * obuf;
+cvec_t * fftgrain;
+fvec_t * woodblock;
+aubio_onsetdetection_t *o;
+aubio_onsetdetection_t *o2;
+fvec_t *onset;
+fvec_t *onset2;
+int isonset = 0;
+aubio_pickpeak_t * parms;
+
+
+/* pitch objects */
+smpl_t pitch               = 0.;
+aubio_pitchdetection_t * pitchdet;
+aubio_pitchdetection_type mode = yin; // mcomb
+uint_t median         = 6;
+
+fvec_t * note_buffer  = NULL;
+fvec_t * note_buffer2 = NULL;
+smpl_t curlevel       = 0.;
+smpl_t maxonset       = 0.;
+
+/* midi objects */
+aubio_midi_player_t * mplay; 
+aubio_midi_driver_t * mdriver; 
+aubio_midi_event_t  * event;
+
+smpl_t curnote = 0.;
+smpl_t newnote = 0.;
+uint_t isready = 0;
+
+
 
 /* badly redeclare some things */
 aubio_onsetdetection_type type_onset;
@@ -135,3 +193,168 @@ int parse_args (int argc, char **argv) {
        return 0;
 }
 
+void examples_common_init(int argc,char ** argv) {
+
+
+  aubio_file_t * onsetfile = new_file_ro(onset_filename);
+  /* parse command line arguments */
+  parse_args(argc, argv);
+
+  if(!usejack)
+  {
+    debug("Opening files ...\n");
+    file = new_file_ro (input_filename);
+    if (verbose) file_info(file);
+    channels = aubio_file_channels(file);
+    samplerate = aubio_file_samplerate(file);
+    if (output_filename != NULL)
+      fileout = new_file_wo(file, output_filename);
+  }
+
+  ibuf      = new_fvec(overlap_size, channels);
+  obuf      = new_fvec(overlap_size, channels);
+  woodblock = new_fvec(buffer_size,1);
+  fftgrain  = new_cvec(buffer_size, channels);
+
+  if (usepitch) {
+    pitchdet = new_aubio_pitchdetection(buffer_size*4, overlap_size, channels, samplerate, mode, freq);
+  
+  if (median) {
+          note_buffer = new_fvec(median, 1);
+          note_buffer2= new_fvec(median, 1);
+  }
+  }
+  /* read the output sound once */
+  file_read(onsetfile, overlap_size, woodblock);
+  /* phase vocoder */
+  pv = new_aubio_pvoc(buffer_size, overlap_size, channels);
+  /* onsets */
+  parms = new_aubio_peakpicker(threshold);
+  o = new_aubio_onsetdetection(type_onset,buffer_size,channels);
+  onset = new_fvec(1, channels);
+  if (usedoubled)    {
+    o2 = new_aubio_onsetdetection(type_onset2,buffer_size,channels);
+    onset2 = new_fvec(1 , channels);
+  }
+
+}
+
+
+void examples_common_del(void){
+  if (usepitch) {
+          send_noteon(curnote,0);
+          del_aubio_pitchdetection(pitchdet);
+          if (median) {
+                  del_fvec(note_buffer);
+                  del_fvec(note_buffer2);
+          }
+  }
+  del_aubio_pvoc(pv);
+  del_fvec(obuf);
+  del_fvec(ibuf);
+  del_cvec(fftgrain);
+  del_fvec(onset);
+}
+
+void examples_common_process(aubio_process_func_t process_func, aubio_print_func_t print ){
+  if(usejack) {
+#ifdef JACK_SUPPORT
+    aubio_jack_t * jack_setup;
+    debug("Jack init ...\n");
+    jack_setup = new_aubio_jack(channels, channels,
+          (aubio_process_func_t)process_func);
+    if (usepitch) {
+            debug("Midi init ...\n");
+            mplay = new_aubio_midi_player();
+            mdriver = new_aubio_midi_driver("alsa_seq",
+                            (handle_midi_event_func_t)aubio_midi_send_event, mplay);
+            event = new_aubio_midi_event();
+    }
+    debug("Jack activation ...\n");
+    aubio_jack_activate(jack_setup);
+    debug("Processing (Ctrl+C to quit) ...\n");
+    pause();
+    aubio_jack_close(jack_setup);
+    if (usepitch) {
+            send_noteon(curnote,0);
+            del_aubio_midi_driver(mdriver);
+    }
+#else
+    usage(stderr, 1);
+    outmsg("Compiled without jack output, exiting.\n");
+#endif
+
+  } else {
+    /* phasevoc */
+    debug("Processing ...\n");
+
+    frames = 0;
+
+    while (overlap_size == file_read(file, overlap_size, ibuf))
+    {
+      isonset=0;
+      process_func(ibuf->data, obuf->data, overlap_size);
+      print(); 
+      if (output_filename != NULL) {
+        file_write(fileout,overlap_size,obuf);
+      }
+      frames++;
+    }
+
+    debug("Processed %d frames of %d samples.\n", frames, buffer_size);
+    del_file(file);
+
+    if (output_filename != NULL)
+      del_file(fileout);
+
+  }
+}
+
+
+
+void send_noteon(int pitch, int velo)
+{
+    smpl_t mpitch = (FLOOR)(freqtomidi(pitch)+.5);
+    /* we should check if we use midi here, not jack */
+#if ALSA_SUPPORT
+    if (usejack) {
+        if (velo==0) {
+            aubio_midi_event_set_type(event,NOTE_OFF);
+        } else {
+            aubio_midi_event_set_type(event,NOTE_ON);
+        }
+        aubio_midi_event_set_channel(event,0);
+        aubio_midi_event_set_pitch(event,mpitch);
+        aubio_midi_event_set_velocity(event,velo);
+        aubio_midi_direct_output(mdriver,event);
+    } 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);
+        }
+    }
+}
+
+
+void note_append(fvec_t * note_buffer, smpl_t curnote) {
+  uint_t i = 0;
+  for (i = 0; i < note_buffer->length - 1; i++) { 
+      note_buffer->data[0][i] = note_buffer->data[0][i+1];
+  }
+  note_buffer->data[0][note_buffer->length - 1] = curnote;
+  return;
+}
+
+uint_t get_note(fvec_t *note_buffer, fvec_t *note_buffer2){
+  uint_t i = 0;
+  for (i = 0; i < note_buffer->length; i++) { 
+      note_buffer2->data[0][i] = note_buffer->data[0][i];
+  }
+  return vec_median(note_buffer2);
+}
+
index 50ac100..1e3d4c8 100644 (file)
         
 */
 
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <getopt.h>
+#include <unistd.h>
+#include <math.h>
+#include <aubio.h>
+#include <aubioext.h>
+
 #define debug(...) if (verbose) fprintf (stderr, __VA_ARGS__)
 #define errmsg(...) fprintf (stderr, __VA_ARGS__)
 #define outmsg(...) fprintf (stdout, __VA_ARGS__)
 
+extern int frames;
 extern int verbose;
 extern int usejack;
 extern int usedoubled;
-extern int median;
+extern unsigned int median;
 extern const char * output_filename;
 extern const char * input_filename;
 /* defined in utils.c */
 void usage (FILE * stream, int exit_code);
 int parse_args (int argc, char **argv);
+void examples_common_init(int argc, char **argv);
+void examples_common_del(void);
+typedef void (aubio_print_func_t)(void);
+void examples_common_process(aubio_process_func_t process_func, aubio_print_func_t print);
+
+
+void send_noteon(int pitch, int velo);
+/** append new note candidate to the note_buffer and return filtered value. we
+ * need to copy the input array as vec_median destroy its input data.*/
+void note_append(fvec_t * note_buffer, smpl_t curnote); 
+uint_t get_note(fvec_t *note_buffer, fvec_t *note_buffer2);
+
+extern const char * output_filename;
+extern const char * input_filename;
+extern const char * onset_filename;
+extern int verbose;
+extern int usejack;
+extern int usedoubled;
+
+
+/* energy,specdiff,hfc,complexdomain,phase */
+extern aubio_onsetdetection_type type_onset;
+extern aubio_onsetdetection_type type_onset2;
+extern smpl_t threshold;
+extern smpl_t threshold2;
+extern uint_t buffer_size;
+extern uint_t overlap_size;
+extern uint_t channels;
+extern uint_t samplerate;
+
+
+extern aubio_file_t * file;
+extern aubio_file_t * fileout;
+
+extern aubio_pvoc_t * pv;
+extern fvec_t * ibuf;
+extern fvec_t * obuf;
+extern cvec_t * fftgrain;
+extern fvec_t * woodblock;
+extern aubio_onsetdetection_t *o;
+extern aubio_onsetdetection_t *o2;
+extern fvec_t *onset;
+extern fvec_t *onset2;
+extern int isonset;
+extern aubio_pickpeak_t * parms;
+
+
+/* pitch objects */
+extern smpl_t pitch;
+extern aubio_pitchdetection_t * pitchdet;
+extern aubio_pitchdetection_type mode;
+extern uint_t median;
+
+extern fvec_t * note_buffer;
+extern fvec_t * note_buffer2;
+extern smpl_t curlevel;
+extern smpl_t maxonset;
+
+/* midi objects */
+extern aubio_midi_player_t * mplay; 
+extern aubio_midi_driver_t * mdriver; 
+extern aubio_midi_event_t  * event;
+
+extern smpl_t curnote;
+extern smpl_t newnote;
+extern uint_t isready;
+
+/* per example param */
+extern uint_t usepitch;