Changeset bd2f2ab


Ignore:
Timestamp:
Apr 11, 2005, 6:37:51 PM (20 years ago)
Author:
Paul Brossier <piem@altern.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
dc27a81
Parents:
84941cb
Message:

merged commmon code between aubionotes.c and aubioonset.c into utils.c

Location:
examples
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • examples/aubionotes.c

    r84941cb rbd2f2ab  
    1717*/
    1818
    19 #include <stdio.h>
    20 #include <stdlib.h>
    21 #include <stdarg.h>
    22 #include <getopt.h>
    23 #include <unistd.h>
    24 #include <math.h>
    25 #include "aubio.h"
    26 #include "aubioext.h"
    2719#include "utils.h"
    2820
    29 /* settings */
    30 const char * output_filename = NULL;
    31 const char * input_filename  = NULL;
    32 const char * onset_filename  = "/usr/share/sounds/aubio/woodblock.aiff";
    33 int verbose = 0;
    34 int usejack = 0;
    35 int usedoubled = 1;
    36 int usemidi = 1;
    37 int median = 0;
    38 
    39 /* energy,specdiff,hfc,complexdomain,phase */
    40 aubio_onsetdetection_type type_onset  = hfc;
    41 aubio_onsetdetection_type type_onset2 = complexdomain;
    42 smpl_t threshold                      = 0.3;
    43 smpl_t threshold2                     = -90.;
    44 uint_t buffer_size                    = 1024;
    45 uint_t overlap_size                   = 512;
    46 uint_t channels                       = 1;
    47 uint_t samplerate                     = 44100;
    48 
    49 /* global objects */
    50 int frames;
    51 aubio_pvoc_t * pv;
    52 fvec_t * ibuf;
    53 fvec_t * obuf;
    54 cvec_t * fftgrain;
    55 fvec_t * woodblock;
    56 aubio_onsetdetection_t *o;
    57 aubio_onsetdetection_t *o2;
    58 fvec_t *onset;
    59 fvec_t *onset2;
    60 int isonset = 0;
    61 aubio_pickpeak_t * parms;
    62 
    63 /* pitch objects */
    64 smpl_t pitch               = 0.;
    65 aubio_pitchdetection_t * pitchdet;
    66 
    67 fvec_t * note_buffer = NULL;
    68 fvec_t * note_buffer2 = NULL;
    69 uint_t medianfiltlen = 6;
    70 smpl_t curlevel = 0.;
    71 smpl_t maxonset = 0.;
    72 
    73 /* midi objects */
    74 aubio_midi_player_t * mplay;
    75 aubio_midi_driver_t * mdriver;
    76 aubio_midi_event_t  * event;
    77 
    7821unsigned int pos = 0; /*frames%dspblocksize*/
    79 
    80 void send_noteon(aubio_midi_driver_t * d, int pitch, int velo);
    81 void send_noteon(aubio_midi_driver_t * d, int pitch, int velo)
    82 {
    83     /* we should check if we use midi here, not jack */
    84 #if ALSA_SUPPORT
    85     if (usejack) {
    86         if (velo==0) {
    87             aubio_midi_event_set_type(event,NOTE_OFF);
    88         } else {
    89             aubio_midi_event_set_type(event,NOTE_ON);
    90         }
    91         aubio_midi_event_set_channel(event,0);
    92         aubio_midi_event_set_pitch(event,pitch);
    93         aubio_midi_event_set_velocity(event,velo);
    94         aubio_midi_direct_output(mdriver,event);
    95     } else
    96 #endif
    97     {
    98         if (velo==0) {
    99             outmsg("%f\n",frames*overlap_size/(float)samplerate);
    100         } else {
    101             outmsg("%d\t%f\t",pitch,frames*overlap_size/(float)samplerate);
    102         }
    103     }
    104 }
    105 
    106 
    107 /** append new note candidate to the note_buffer and return filtered value. we
    108  * need to copy the input array as vec_median destroy its input data.*/
    109 
    110 void note_append(fvec_t * note_buffer, smpl_t curnote);
    111 void note_append(fvec_t * note_buffer, smpl_t curnote) {
    112   uint_t i = 0;
    113   for (i = 0; i < note_buffer->length - 1; i++) {
    114       note_buffer->data[0][i] = note_buffer->data[0][i+1];
    115   }
    116   note_buffer->data[0][note_buffer->length - 1] = curnote;
    117   return;
    118 }
    119 
    120 uint_t get_note(fvec_t *note_buffer, fvec_t *note_buffer2);
    121 uint_t get_note(fvec_t *note_buffer, fvec_t *note_buffer2){
    122   uint_t i = 0;
    123   for (i = 0; i < note_buffer->length; i++) {
    124       note_buffer2->data[0][i] = note_buffer->data[0][i];
    125   }
    126   return vec_median(note_buffer2);
    127 }
    128 
    129 
    130 smpl_t curnote = 0.;
    131 smpl_t newnote = 0.;
    132 uint_t isready = 0;
     22uint_t usepitch = 1;
    13323
    13424int aubio_process(float **input, float **output, int nframes);
     
    15848      pitch = aubio_pitchdetection(pitchdet,ibuf);
    15949      if(median){
    160       newnote = (FLOOR)(bintomidi(pitch,samplerate,buffer_size*4)+.5);
    161       note_append(note_buffer, newnote);
     50              note_append(note_buffer, pitch);
    16251      }
    16352
     
    16554      curlevel = aubio_level_detection(ibuf, threshold2);
    16655      if (isonset) {
    167         /* test for silence */
    168         if (curlevel == 1.) {
    169           isonset=0;
    170           if (median) isready = 0;
    171           /* send note off */
    172           send_noteon(mdriver,curnote,0);
    173         } else {
    174           if (median) {
    175                   isready = 1;
    176           } else {
    177           /* kill old note */
    178           send_noteon(mdriver,curnote,0);
    179           //curnote = (int)FLOOR(bintomidi(pitch,samplerate,buffer_size*4) + .5);
    180           curnote = (int)FLOOR(freqtomidi(pitch) + .5);
    181           /* get and send new one */
    182           /*if (curnote<45){
    183             send_noteon(mdriver,curnote,0);
    184           } else {*/
    185           if (curnote>45){
    186             send_noteon(mdriver,curnote,127+(int)FLOOR(curlevel));
    187           }
    188           }
    189          
    190           for (pos = 0; pos < overlap_size; pos++){
    191             obuf->data[0][pos] = woodblock->data[0][pos];
    192           }
    193         }
     56              /* test for silence */
     57              if (curlevel == 1.) {
     58                      isonset=0;
     59                      if (median) isready = 0;
     60                      /* send note off */
     61                      send_noteon(curnote,0);
     62              } else {
     63                      if (median) {
     64                              isready = 1;
     65                      } else {
     66                              /* kill old note */
     67                              send_noteon(curnote,0);
     68                              /* get and send new one */
     69                              send_noteon(pitch,127+(int)FLOOR(curlevel));
     70                              curnote = pitch;
     71                      }
     72
     73                      for (pos = 0; pos < overlap_size; pos++){
     74                              obuf->data[0][pos] = woodblock->data[0][pos];
     75                      }
     76              }
    19477      } else {
    19578              if (median) {
    196 //        if (curlevel != 1) {
    197 //          if (bufpos == note_buffer->length)
    198 //            curnote = aubio_getnote(note_buffer);
    199 //        }
    200 //
    201         if (isready > 0)
    202             isready++;
    203         if (isready == note_buffer->length)
    204         {
    205             //outmsg("%d, %f\n", isready, curnote);
    206             send_noteon(mdriver,curnote,0);
    207         /* kill old note */
    208             newnote = get_note(note_buffer, note_buffer2);
    209             curnote = newnote;
    210         /* get and send new one */
    211         /*if (curnote<45){
    212           send_noteon(mdriver,curnote,0);
    213         } else {*/
    214             if (curnote>45){
    215                 send_noteon(mdriver,curnote,127+(int)FLOOR(curlevel));
    216             }
    217         }
    218         } // if median
     79                      if (isready > 0)
     80                              isready++;
     81                      if (isready == median)
     82                      {
     83                              /* kill old note */
     84                              send_noteon(curnote,0);
     85                              newnote = get_note(note_buffer, note_buffer2);
     86                              curnote = newnote;
     87                              /* get and send new one */
     88                              if (curnote>45){
     89                                      send_noteon(curnote,127+(int)FLOOR(curlevel));
     90                              }
     91                      }
     92              } // if median
    21993        for (pos = 0; pos < overlap_size; pos++)
    22094          obuf->data[0][pos] = 0.;
     
    228102}
    229103
     104void process_print (void);
     105void process_print (void) {
     106      if (verbose) outmsg("%f\n",pitch);
     107}
     108
    230109int main(int argc, char **argv) {
    231 
    232   aubio_file_t * file = NULL;
    233   aubio_file_t * fileout = NULL;
    234 
    235   aubio_file_t * onsetfile = new_file_ro(onset_filename);
    236   /* parse command line arguments */
    237   parse_args(argc, argv);
    238 
    239   if(!usejack)
    240   {
    241     debug("Opening files ...\n");
    242     file = new_file_ro (input_filename);
    243     file_info(file);
    244     samplerate = aubio_file_samplerate(file);
    245     channels = aubio_file_channels(file);
    246     if (output_filename != NULL)
    247       fileout = new_file_wo(file, output_filename);
    248   }
    249 
    250   ibuf        = new_fvec(overlap_size, channels);
    251   obuf        = new_fvec(overlap_size, channels);
    252   woodblock   = new_fvec(buffer_size,1);
    253   fftgrain    = new_cvec(buffer_size, channels);
    254 
    255   aubio_pitchdetection_type mode = yin; // mcomb
    256   pitchdet = new_aubio_pitchdetection(buffer_size*4, overlap_size, channels, samplerate, mode, freq);
    257  
    258 if (median) {
    259   note_buffer = new_fvec(medianfiltlen, 1);
    260   note_buffer2= new_fvec(medianfiltlen, 1);
    261 }
    262   /* read the output sound once */
    263   file_read(onsetfile, overlap_size, woodblock);
    264   /* phase vocoder */
    265   pv = new_aubio_pvoc(buffer_size, overlap_size, channels);
    266   /* onsets */
    267   parms = new_aubio_peakpicker(threshold);
    268   o = new_aubio_onsetdetection(type_onset,buffer_size,channels);
    269   onset = new_fvec(1, channels);
    270   if (usedoubled)    {
    271     o2 = new_aubio_onsetdetection(type_onset2,buffer_size,channels);
    272     onset2 = new_fvec(1 , channels);
    273   }
    274 
    275   if(usejack) {
    276 #ifdef JACK_SUPPORT
    277     aubio_jack_t * jack_setup;
    278     debug("Midi init ...\n");
    279     debug("Jack init ...\n");
    280     jack_setup = new_aubio_jack(channels, channels,
    281           (aubio_process_func_t)aubio_process);
    282 
    283     mplay = new_aubio_midi_player();
    284 
    285     mdriver = new_aubio_midi_driver("alsa_seq",
    286         (handle_midi_event_func_t)aubio_midi_send_event, mplay);
    287 
    288     event = new_aubio_midi_event();
    289    
    290     debug("Jack activation ...\n");
    291     aubio_jack_activate(jack_setup);
    292     debug("Processing (Ctrl+C to quit) ...\n");
    293     pause();
    294     send_noteon(mdriver,curnote,0);
    295     aubio_jack_close(jack_setup);
    296     del_aubio_midi_driver(mdriver);
    297 #else
    298     usage(stderr, 1);
    299     outmsg("Compiled without jack output, exiting.\n");
    300 #endif
    301 
    302   } else {
    303     /* phasevoc */
    304     debug("Processing ...\n");
    305 
    306     frames = 0;
    307 
    308     while (overlap_size == file_read(file, overlap_size, ibuf))
    309     {
    310       isonset=0;
    311       aubio_process(ibuf->data, obuf->data, overlap_size);
    312       if (output_filename != NULL) {
    313         file_write(fileout,overlap_size,obuf);
    314       }
    315       frames++;
    316     }
    317     send_noteon(mdriver,curnote,0);
    318 
    319     debug("Processed %d frames of %d samples.\n", frames, buffer_size);
    320     del_file(file);
    321 
    322     if (output_filename != NULL)
    323       del_file(fileout);
    324 
    325   }
    326 
    327   del_aubio_pvoc(pv);
    328   del_fvec(obuf);
    329   del_fvec(ibuf);
    330   del_cvec(fftgrain);
    331   del_aubio_pitchdetection(pitchdet);
    332   del_fvec(onset);
    333   if (median) {
    334   del_fvec(note_buffer);
    335   del_fvec(note_buffer2);
    336   }
    337 
     110  examples_common_init(argc,argv);
     111  examples_common_process(aubio_process, process_print);
     112  examples_common_del();
    338113  debug("End of program.\n");
    339114  fflush(stderr);
  • examples/aubioonset.c

    r84941cb rbd2f2ab  
    1717*/
    1818
    19 #include <stdio.h>
    20 #include <stdlib.h>
    21 #include <stdarg.h>
    22 #include <getopt.h>
    23 #include <unistd.h>
    24 #include "aubio.h"
    25 #include "aubioext.h"
    2619#include "utils.h"
    2720
     21unsigned int pos = 0; /*frames%dspblocksize*/
     22uint_t usepitch = 0;
     23
    2824int aubio_process(float **input, float **output, int nframes);
    29 
    30 const char * output_filename = NULL;
    31 const char * input_filename  = NULL;
    32 const char * onset_filename  = "/usr/share/sounds/aubio/woodblock.aiff";
    33 
    34 /* settings */
    35 int verbose = 0;
    36 int usejack = 0;
    37 int usedoubled = 1;
    38 
    39 
    40 /* energy,specdiff,hfc,complexdomain,phase */
    41 aubio_onsetdetection_type type_onset  = hfc;
    42 aubio_onsetdetection_type type_onset2 = complexdomain;
    43 smpl_t threshold                      = 0.1;
    44 smpl_t threshold2                     = -90.;
    45 uint_t buffer_size                    = 1024;
    46 uint_t overlap_size                   = 512;
    47 uint_t channels                       = 1;
    48 uint_t samplerate                     = 44100;
    49 
    50 /* global objects */
    51 aubio_pvoc_t * pv;
    52 fvec_t * ibuf;
    53 fvec_t * obuf;
    54 cvec_t * fftgrain;
    55 fvec_t * woodblock;
    56 aubio_onsetdetection_t *o;
    57 aubio_onsetdetection_t *o2;
    58 fvec_t *onset;
    59 fvec_t *onset2;
    60 int isonset = 0;
    61 aubio_pickpeak_t * parms;
    62 unsigned int pos = 0; /*frames%dspblocksize*/
    63 
    6425int aubio_process(float **input, float **output, int nframes) {
    6526  unsigned int i;       /*channels*/
     
    9657          obuf->data[0][pos] = 0.;
    9758      }
    98       //aubio_pvoc_rdo(pv,fftgrain, obuf);
    9959      /* end of block loop */
    10060      pos = -1; /* so it will be zero next j loop */
     
    10565}
    10666
    107 int main(int argc, char **argv) {
    108   int frames;
    109 
    110   aubio_file_t * file = NULL;
    111   aubio_file_t * fileout = NULL;
    112 
    113   aubio_file_t * onsetfile = new_file_ro(onset_filename);
    114   parse_args(argc, argv);
    115 
    116   if(!usejack)
    117   {
    118     debug("Opening files ...\n");
    119     file = new_file_ro (input_filename);
    120     if (verbose) file_info(file);
    121     channels = aubio_file_channels(file);
    122     samplerate = aubio_file_samplerate(file);
    123     if (output_filename != NULL)
    124       fileout = new_file_wo(file, output_filename);
    125   }
    126 
    127   ibuf      = new_fvec(overlap_size, channels);
    128   obuf      = new_fvec(overlap_size, channels);
    129   woodblock = new_fvec(buffer_size,1);
    130   fftgrain  = new_cvec(buffer_size, channels);
    131 
    132   /* read the output sound once */
    133   file_read(onsetfile, overlap_size, woodblock);
    134 
    135   /* phase vocoder */
    136   debug("Phase voc init ... \n");
    137   pv = new_aubio_pvoc(buffer_size, overlap_size, channels);
    138 
    139   /* onsets */
    140   parms = new_aubio_peakpicker(threshold);
    141   o = new_aubio_onsetdetection(type_onset,buffer_size,channels);
    142   onset = new_fvec(1, channels);
    143   if (usedoubled)    {
    144     o2 = new_aubio_onsetdetection(type_onset2,buffer_size,channels);
    145     onset2 = new_fvec(1 , channels);
    146   }
    147 
    148   if(usejack) {
    149 #ifdef JACK_SUPPORT
    150     aubio_jack_t * jack_setup;
    151     debug("Jack init ...\n");
    152     jack_setup = new_aubio_jack(channels, channels,
    153           (aubio_process_func_t)aubio_process);
    154     debug("Jack activation ...\n");
    155     aubio_jack_activate(jack_setup);
    156     debug("Processing (Ctrl+C to quit) ...\n");
    157     pause();
    158     aubio_jack_close(jack_setup);
    159 #else
    160     outmsg("Compiled without jack output, exiting.");
    161 #endif
    162 
    163   } else {
    164     /* phasevoc */
    165     debug("Processing ...\n");
    166 
    167     frames = 0;
    168 
    169     while (overlap_size == file_read(file, overlap_size, ibuf))
    170     {
    171       isonset=0;
    172       aubio_process(ibuf->data, obuf->data, overlap_size);
     67void process_print (void);
     68void process_print (void) {
    17369      /* output times in seconds, taking back some
    17470       * delay to ensure the label is _before_ the
     
    18177        }
    18278      }
    183       if (output_filename != NULL) {
    184         file_write(fileout,overlap_size,obuf);
    185       }
    186       frames++;
    187     }
     79}
    18880
    189     debug("Processed %d frames of %d samples.\n", frames, buffer_size);
    190     del_file(file);
    191 
    192     if (output_filename != NULL)
    193       del_file(fileout);
    194 
    195   }
    196 
    197   del_aubio_pvoc(pv);
    198   del_fvec(obuf);
    199   del_fvec(ibuf);
    200   del_cvec(fftgrain);
    201   del_fvec(onset);
    202 
     81int main(int argc, char **argv) {
     82  examples_common_init(argc,argv);
     83  examples_common_process(aubio_process,process_print);
     84  examples_common_del();
    20385  debug("End of program.\n");
    20486  fflush(stderr);
  • examples/utils.c

    r84941cb rbd2f2ab  
    1818cca_client_t * aubio_cca_client;
    1919#endif /* LADCCA_SUPPORT */
     20
     21/* settings */
     22const char * output_filename = NULL;
     23const char * input_filename  = NULL;
     24const char * onset_filename  = "/usr/share/sounds/aubio/woodblock.aiff";
     25int frames = 0;
     26int verbose = 0;
     27int usejack = 0;
     28int usedoubled = 1;
     29
     30
     31/* energy,specdiff,hfc,complexdomain,phase */
     32aubio_onsetdetection_type type_onset  = hfc;
     33aubio_onsetdetection_type type_onset2 = complexdomain;
     34smpl_t threshold                      = 0.3;
     35smpl_t threshold2                     = -90.;
     36uint_t buffer_size                    = 1024;
     37uint_t overlap_size                   = 512;
     38uint_t channels                       = 1;
     39uint_t samplerate                     = 44100;
     40
     41
     42aubio_file_t * file = NULL;
     43aubio_file_t * fileout = NULL;
     44
     45aubio_pvoc_t * pv;
     46fvec_t * ibuf;
     47fvec_t * obuf;
     48cvec_t * fftgrain;
     49fvec_t * woodblock;
     50aubio_onsetdetection_t *o;
     51aubio_onsetdetection_t *o2;
     52fvec_t *onset;
     53fvec_t *onset2;
     54int isonset = 0;
     55aubio_pickpeak_t * parms;
     56
     57
     58/* pitch objects */
     59smpl_t pitch               = 0.;
     60aubio_pitchdetection_t * pitchdet;
     61aubio_pitchdetection_type mode = yin; // mcomb
     62uint_t median         = 6;
     63
     64fvec_t * note_buffer  = NULL;
     65fvec_t * note_buffer2 = NULL;
     66smpl_t curlevel       = 0.;
     67smpl_t maxonset       = 0.;
     68
     69/* midi objects */
     70aubio_midi_player_t * mplay;
     71aubio_midi_driver_t * mdriver;
     72aubio_midi_event_t  * event;
     73
     74smpl_t curnote = 0.;
     75smpl_t newnote = 0.;
     76uint_t isready = 0;
     77
    2078
    2179
     
    136194}
    137195
     196void examples_common_init(int argc,char ** argv) {
     197
     198
     199  aubio_file_t * onsetfile = new_file_ro(onset_filename);
     200  /* parse command line arguments */
     201  parse_args(argc, argv);
     202
     203  if(!usejack)
     204  {
     205    debug("Opening files ...\n");
     206    file = new_file_ro (input_filename);
     207    if (verbose) file_info(file);
     208    channels = aubio_file_channels(file);
     209    samplerate = aubio_file_samplerate(file);
     210    if (output_filename != NULL)
     211      fileout = new_file_wo(file, output_filename);
     212  }
     213
     214  ibuf      = new_fvec(overlap_size, channels);
     215  obuf      = new_fvec(overlap_size, channels);
     216  woodblock = new_fvec(buffer_size,1);
     217  fftgrain  = new_cvec(buffer_size, channels);
     218
     219  if (usepitch) {
     220    pitchdet = new_aubio_pitchdetection(buffer_size*4, overlap_size, channels, samplerate, mode, freq);
     221 
     222  if (median) {
     223          note_buffer = new_fvec(median, 1);
     224          note_buffer2= new_fvec(median, 1);
     225  }
     226  }
     227  /* read the output sound once */
     228  file_read(onsetfile, overlap_size, woodblock);
     229  /* phase vocoder */
     230  pv = new_aubio_pvoc(buffer_size, overlap_size, channels);
     231  /* onsets */
     232  parms = new_aubio_peakpicker(threshold);
     233  o = new_aubio_onsetdetection(type_onset,buffer_size,channels);
     234  onset = new_fvec(1, channels);
     235  if (usedoubled)    {
     236    o2 = new_aubio_onsetdetection(type_onset2,buffer_size,channels);
     237    onset2 = new_fvec(1 , channels);
     238  }
     239
     240}
     241
     242
     243void examples_common_del(void){
     244  if (usepitch) {
     245          send_noteon(curnote,0);
     246          del_aubio_pitchdetection(pitchdet);
     247          if (median) {
     248                  del_fvec(note_buffer);
     249                  del_fvec(note_buffer2);
     250          }
     251  }
     252  del_aubio_pvoc(pv);
     253  del_fvec(obuf);
     254  del_fvec(ibuf);
     255  del_cvec(fftgrain);
     256  del_fvec(onset);
     257}
     258
     259void examples_common_process(aubio_process_func_t process_func, aubio_print_func_t print ){
     260  if(usejack) {
     261#ifdef JACK_SUPPORT
     262    aubio_jack_t * jack_setup;
     263    debug("Jack init ...\n");
     264    jack_setup = new_aubio_jack(channels, channels,
     265          (aubio_process_func_t)process_func);
     266    if (usepitch) {
     267            debug("Midi init ...\n");
     268            mplay = new_aubio_midi_player();
     269            mdriver = new_aubio_midi_driver("alsa_seq",
     270                            (handle_midi_event_func_t)aubio_midi_send_event, mplay);
     271            event = new_aubio_midi_event();
     272    }
     273    debug("Jack activation ...\n");
     274    aubio_jack_activate(jack_setup);
     275    debug("Processing (Ctrl+C to quit) ...\n");
     276    pause();
     277    aubio_jack_close(jack_setup);
     278    if (usepitch) {
     279            send_noteon(curnote,0);
     280            del_aubio_midi_driver(mdriver);
     281    }
     282#else
     283    usage(stderr, 1);
     284    outmsg("Compiled without jack output, exiting.\n");
     285#endif
     286
     287  } else {
     288    /* phasevoc */
     289    debug("Processing ...\n");
     290
     291    frames = 0;
     292
     293    while (overlap_size == file_read(file, overlap_size, ibuf))
     294    {
     295      isonset=0;
     296      process_func(ibuf->data, obuf->data, overlap_size);
     297      print();
     298      if (output_filename != NULL) {
     299        file_write(fileout,overlap_size,obuf);
     300      }
     301      frames++;
     302    }
     303
     304    debug("Processed %d frames of %d samples.\n", frames, buffer_size);
     305    del_file(file);
     306
     307    if (output_filename != NULL)
     308      del_file(fileout);
     309
     310  }
     311}
     312
     313
     314
     315void send_noteon(int pitch, int velo)
     316{
     317    smpl_t mpitch = (FLOOR)(freqtomidi(pitch)+.5);
     318    /* we should check if we use midi here, not jack */
     319#if ALSA_SUPPORT
     320    if (usejack) {
     321        if (velo==0) {
     322            aubio_midi_event_set_type(event,NOTE_OFF);
     323        } else {
     324            aubio_midi_event_set_type(event,NOTE_ON);
     325        }
     326        aubio_midi_event_set_channel(event,0);
     327        aubio_midi_event_set_pitch(event,mpitch);
     328        aubio_midi_event_set_velocity(event,velo);
     329        aubio_midi_direct_output(mdriver,event);
     330    } else
     331#endif
     332    if (!verbose)
     333    {
     334        if (velo==0) {
     335            outmsg("%f\n",frames*overlap_size/(float)samplerate);
     336        } else {
     337            outmsg("%f\t%f\t", mpitch,
     338                        frames*overlap_size/(float)samplerate);
     339        }
     340    }
     341}
     342
     343
     344void note_append(fvec_t * note_buffer, smpl_t curnote) {
     345  uint_t i = 0;
     346  for (i = 0; i < note_buffer->length - 1; i++) {
     347      note_buffer->data[0][i] = note_buffer->data[0][i+1];
     348  }
     349  note_buffer->data[0][note_buffer->length - 1] = curnote;
     350  return;
     351}
     352
     353uint_t get_note(fvec_t *note_buffer, fvec_t *note_buffer2){
     354  uint_t i = 0;
     355  for (i = 0; i < note_buffer->length; i++) {
     356      note_buffer2->data[0][i] = note_buffer->data[0][i];
     357  }
     358  return vec_median(note_buffer2);
     359}
     360
  • examples/utils.h

    r84941cb rbd2f2ab  
    1818*/
    1919
     20#include <stdio.h>
     21#include <stdlib.h>
     22#include <stdarg.h>
     23#include <getopt.h>
     24#include <unistd.h>
     25#include <math.h>
     26#include <aubio.h>
     27#include <aubioext.h>
     28
    2029#define debug(...) if (verbose) fprintf (stderr, __VA_ARGS__)
    2130#define errmsg(...) fprintf (stderr, __VA_ARGS__)
    2231#define outmsg(...) fprintf (stdout, __VA_ARGS__)
    2332
     33extern int frames;
    2434extern int verbose;
    2535extern int usejack;
    2636extern int usedoubled;
    27 extern int median;
     37extern unsigned int median;
    2838extern const char * output_filename;
    2939extern const char * input_filename;
     
    3141void usage (FILE * stream, int exit_code);
    3242int parse_args (int argc, char **argv);
     43void examples_common_init(int argc, char **argv);
     44void examples_common_del(void);
     45typedef void (aubio_print_func_t)(void);
     46void examples_common_process(aubio_process_func_t process_func, aubio_print_func_t print);
    3347
     48
     49void send_noteon(int pitch, int velo);
     50/** append new note candidate to the note_buffer and return filtered value. we
     51 * need to copy the input array as vec_median destroy its input data.*/
     52void note_append(fvec_t * note_buffer, smpl_t curnote);
     53uint_t get_note(fvec_t *note_buffer, fvec_t *note_buffer2);
     54
     55extern const char * output_filename;
     56extern const char * input_filename;
     57extern const char * onset_filename;
     58extern int verbose;
     59extern int usejack;
     60extern int usedoubled;
     61
     62
     63/* energy,specdiff,hfc,complexdomain,phase */
     64extern aubio_onsetdetection_type type_onset;
     65extern aubio_onsetdetection_type type_onset2;
     66extern smpl_t threshold;
     67extern smpl_t threshold2;
     68extern uint_t buffer_size;
     69extern uint_t overlap_size;
     70extern uint_t channels;
     71extern uint_t samplerate;
     72
     73
     74extern aubio_file_t * file;
     75extern aubio_file_t * fileout;
     76
     77extern aubio_pvoc_t * pv;
     78extern fvec_t * ibuf;
     79extern fvec_t * obuf;
     80extern cvec_t * fftgrain;
     81extern fvec_t * woodblock;
     82extern aubio_onsetdetection_t *o;
     83extern aubio_onsetdetection_t *o2;
     84extern fvec_t *onset;
     85extern fvec_t *onset2;
     86extern int isonset;
     87extern aubio_pickpeak_t * parms;
     88
     89
     90/* pitch objects */
     91extern smpl_t pitch;
     92extern aubio_pitchdetection_t * pitchdet;
     93extern aubio_pitchdetection_type mode;
     94extern uint_t median;
     95
     96extern fvec_t * note_buffer;
     97extern fvec_t * note_buffer2;
     98extern smpl_t curlevel;
     99extern smpl_t maxonset;
     100
     101/* midi objects */
     102extern aubio_midi_player_t * mplay;
     103extern aubio_midi_driver_t * mdriver;
     104extern aubio_midi_event_t  * event;
     105
     106extern smpl_t curnote;
     107extern smpl_t newnote;
     108extern uint_t isready;
     109
     110/* per example param */
     111extern uint_t usepitch;
     112
Note: See TracChangeset for help on using the changeset viewer.