Changeset d4c5de7 for examples


Ignore:
Timestamp:
Oct 16, 2009, 11:03:08 PM (15 years ago)
Author:
Paul Brossier <piem@piem.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:
6107f4c
Parents:
2828382
Message:

examples/: make use of aubio_onset in aubioonset and aubionotes, simplify, keep only general stuff in utils

Location:
examples
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • examples/aubiomfcc.c

    r2828382 rd4c5de7  
    2323fvec_t * mfcc_out;
    2424aubio_mfcc_t * mfcc;
     25aubio_pvoc_t *pv;
     26cvec_t *fftgrain;
    2527
    2628uint_t n_filters = 40;
     
    2830
    2931unsigned int pos = 0; /*frames%dspblocksize*/
    30 uint_t usepitch = 0;
    3132
    32 int aubio_process(smpl_t **input, smpl_t **output, int nframes);
    33 int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
     33static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
    3434  unsigned int i;       /*channels*/
    3535  unsigned int j;       /*frames*/
     
    6262}
    6363
    64 void process_print (void);
    65 void process_print (void) {
     64static void process_print (void) {
    6665      /* output times in seconds
    6766         write extracted mfccs
     
    8483 
    8584  examples_common_init(argc,argv);
     85
     86  /* phase vocoder */
     87  pv = new_aubio_pvoc (buffer_size, overlap_size, channels);
     88
     89  fftgrain = new_cvec (buffer_size, channels);
     90
     91  //populating the filter
     92  mfcc = new_aubio_mfcc(buffer_size, n_filters, n_coefs, samplerate);
     93 
    8694  mfcc_out = new_fvec(n_coefs,channels);
    87  
    88  
    89   //populating the filter
    90   mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, n_coefs);
    9195 
    9296  //process
     
    9498 
    9599  //destroying mfcc
     100  del_aubio_pvoc (pv);
     101  del_cvec (fftgrain);
    96102  del_aubio_mfcc(mfcc);
    97103  del_fvec(mfcc_out);
  • examples/aubionotes.c

    r2828382 rd4c5de7  
    1919#include "utils.h"
    2020
     21/* pitch objects */
     22smpl_t pitch = 0.;
     23
     24uint_t median = 6;
     25smpl_t curlevel = 0.;
     26
     27aubio_pitchdetection_t *pitchdet;
     28
     29fvec_t *note_buffer = NULL;
     30fvec_t *note_buffer2 = NULL;
     31
     32smpl_t curnote = 0.;
     33smpl_t newnote = 0.;
     34uint_t isready = 0;
    2135unsigned int pos = 0; /*frames%dspblocksize*/
    22 uint_t usepitch = 1;
    2336
    24 int aubio_process(smpl_t **input, smpl_t **output, int nframes);
    25 int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
     37aubio_pitchdetection_t *pitchdet;
     38aubio_onset_t *o;
     39fvec_t *onset;
     40fvec_t *pitch_obuf;
     41
     42/** append new note candidate to the note_buffer and return filtered value. we
     43 * need to copy the input array as fvec_median destroy its input data.*/
     44void note_append (fvec_t * note_buffer, smpl_t curnote);
     45uint_t get_note (fvec_t * note_buffer, fvec_t * note_buffer2);
     46
     47static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
    2648  unsigned int i;       /*channels*/
    2749  unsigned int j;       /*frames*/
     
    3860    if (pos == overlap_size-1) {         
    3961      /* block loop */
    40       aubio_pvoc_do (pv,ibuf, fftgrain);
    41       aubio_onsetdetection_do(o,fftgrain, onset);
    42       isonset = aubio_peakpicker_do(parms, onset);
     62      aubio_onset_do(o, ibuf, onset);
    4363     
    4464      aubio_pitchdetection_do (pitchdet, ibuf, pitch_obuf);
     
    5070      /* curlevel is negatif or 1 if silence */
    5171      curlevel = aubio_level_detection(ibuf, silence);
    52       if (isonset) {
     72      if (fvec_read_sample(onset, 0, 0)) {
    5373              /* test for silence */
    5474              if (curlevel == 1.) {
    55                       isonset=0;
    5675                      if (median) isready = 0;
    5776                      /* send note off */
     
    99118}
    100119
    101 void process_print (void);
    102 void process_print (void) {
     120static void process_print (void) {
    103121      if (verbose) outmsg("%f\n",pitch);
     122}
     123
     124void
     125note_append (fvec_t * note_buffer, smpl_t curnote)
     126{
     127  uint_t i = 0;
     128  for (i = 0; i < note_buffer->length - 1; i++) {
     129    note_buffer->data[0][i] = note_buffer->data[0][i + 1];
     130  }
     131  note_buffer->data[0][note_buffer->length - 1] = curnote;
     132  return;
     133}
     134
     135uint_t
     136get_note (fvec_t * note_buffer, fvec_t * note_buffer2)
     137{
     138  uint_t i = 0;
     139  for (i = 0; i < note_buffer->length; i++) {
     140    note_buffer2->data[0][i] = note_buffer->data[0][i];
     141  }
     142  return fvec_median (note_buffer2);
    104143}
    105144
    106145int main(int argc, char **argv) {
    107146  examples_common_init(argc,argv);
     147
     148  o = new_aubio_onset (onset_mode, buffer_size, overlap_size, channels,
     149          samplerate);
     150  onset = new_fvec (1, channels);
     151
     152  pitchdet = new_aubio_pitchdetection (pitch_mode, buffer_size * 4,
     153          overlap_size, channels, samplerate);
     154  aubio_pitchdetection_set_tolerance (pitchdet, 0.7);
     155  pitch_obuf = new_fvec (1, channels);
     156  if (median) {
     157      note_buffer = new_fvec (median, 1);
     158      note_buffer2 = new_fvec (median, 1);
     159  }
     160
    108161  examples_common_process(aubio_process, process_print);
     162
     163  send_noteon (curnote, 0);
     164  del_aubio_pitchdetection (pitchdet);
     165  if (median) {
     166      del_fvec (note_buffer);
     167      del_fvec (note_buffer2);
     168  }
     169  del_fvec (pitch_obuf);
     170
    109171  examples_common_del();
    110172  debug("End of program.\n");
  • examples/aubioonset.c

    r2828382 rd4c5de7  
    2020
    2121unsigned int pos = 0; /*frames%dspblocksize*/
    22 uint_t usepitch = 0;
    2322
    24 int aubio_process(smpl_t **input, smpl_t **output, int nframes);
    25 int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
     23aubio_onset_t *o;
     24fvec_t *onset;
     25
     26static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
    2627  unsigned int i;       /*channels*/
    2728  unsigned int j;       /*frames*/
     
    3839    if (pos == overlap_size-1) {         
    3940      /* block loop */
    40       aubio_pvoc_do (pv,ibuf, fftgrain);
    41       aubio_onsetdetection_do (o,fftgrain, onset);
    42       isonset = aubio_peakpicker_do(parms, onset);
    43       if (isonset) {
    44         /* test for silence */
    45         if (aubio_silence_detection(ibuf, silence)==1)
    46           isonset=0.;
    47         else
    48           for (pos = 0; pos < overlap_size; pos++){
    49             obuf->data[0][pos] = woodblock->data[0][pos];
    50           }
     41      aubio_onset_do (o, ibuf, onset);
     42      if (fvec_read_sample(onset, 0, 0)) {
     43        for (pos = 0; pos < overlap_size; pos++){
     44          obuf->data[0][pos] = woodblock->data[0][pos];
     45        }
    5146      } else {
    52         for (pos = 0; pos < overlap_size; pos++)
     47        for (pos = 0; pos < overlap_size; pos++) {
    5348          obuf->data[0][pos] = 0.;
     49        }
    5450      }
    5551      /* end of block loop */
     
    6157}
    6258
    63 void process_print (void);
    64 void process_print (void) {
     59static void process_print (void) {
    6560      /* output times in seconds, taking back some
    6661       * delay to ensure the label is _before_ the
    6762       * actual onset */
    68       if (isonset && output_filename == NULL) {
     63      if (!verbose && usejack) return;
     64      smpl_t onset_found = fvec_read_sample(onset, 0, 0);
     65      if (onset_found) {
    6966        if(frames >= 4) {
    70           outmsg("%f\n",(frames - frames_delay + isonset)*overlap_size/(float)samplerate);
     67          outmsg("%f\n",(frames - frames_delay + onset_found)
     68                  *overlap_size/(float)samplerate);
    7169        } else if (frames < frames_delay) {
    7270          outmsg("%f\n",0.);
     
    7876  frames_delay = 3;
    7977  examples_common_init(argc,argv);
     78
     79  o = new_aubio_onset (onset_mode, buffer_size, overlap_size, channels,
     80          samplerate);
     81  onset = new_fvec (1, channels);
     82
    8083  examples_common_process(aubio_process,process_print);
     84
     85  del_aubio_onset (o);
     86  del_fvec (onset);
     87
    8188  examples_common_del();
    8289  debug("End of program.\n");
  • examples/aubioquiet.c

    r2828382 rd4c5de7  
    2121unsigned int pos = 0; /*frames%dspblocksize*/
    2222sint_t wassilence = 1, issilence;
    23 uint_t usepitch = 0;
    2423
    2524int aubio_process(smpl_t **input, smpl_t **output, int nframes);
     
    5655}
    5756
    58 void process_print (void);
    59 void process_print (void) {
     57static void process_print (void) {
    6058      int curframes = (frames - 4) > 0 ? frames -4 : 0;
    6159      if (issilence == -1) {
  • examples/aubiotrack.c

    r2828382 rd4c5de7  
    2020#include "utils.h"
    2121
    22 unsigned int pos          = 0;    /* frames%dspblocksize */
    23 uint_t usepitch           = 0;
    24 fvec_t * out              = NULL;
    25 aubio_tempo_t * bt        = NULL;
    26 smpl_t istactus          = 0;
     22uint_t pos = 0;    /* frames%dspblocksize */
     23fvec_t * tempo_out = NULL;
     24aubio_tempo_t * bt = NULL;
     25smpl_t istactus = 0;
     26smpl_t isonset = 0;
    2727
    28 int aubio_process(smpl_t **input, smpl_t **output, int nframes);
    29 int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
     28static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
    3029  unsigned int i;       /*channels*/
    3130  unsigned int j;       /*frames*/
     
    4241    if (pos == overlap_size-1) {         
    4342      /* block loop */
    44       aubio_tempo_do (bt,ibuf,out);
    45       if (out->data[0][0]>=1)
    46         istactus = out->data[0][0];
     43      aubio_tempo_do (bt,ibuf,tempo_out);
     44      if (tempo_out->data[0][0]>0)
     45        istactus = tempo_out->data[0][0];
    4746      else
    4847        istactus = 0;
     48      if (tempo_out->data[0][1]>0)
     49        isonset = tempo_out->data[0][0];
     50      else
     51        isonset = 0;
    4952      if (istactus) {
    5053              for (pos = 0; pos < overlap_size; pos++)
     
    6265}
    6366
    64 void process_print (void);
    65 void process_print (void) {
     67static void process_print (void) {
    6668        if (output_filename == NULL) {
    6769                if (istactus) {
     
    8082  examples_common_init(argc,argv);
    8183
    82   out = new_fvec(2,channels);
    83   bt  = new_aubio_tempo(onset_mode,buffer_size,overlap_size,channels);
     84  tempo_out = new_fvec(2,channels);
     85  bt = new_aubio_tempo(onset_mode,buffer_size,overlap_size,channels, samplerate);
    8486
    8587  examples_common_process(aubio_process,process_print);
    8688
    8789  del_aubio_tempo(bt);
    88   del_fvec(out);
     90  del_fvec(tempo_out);
    8991
    9092  examples_common_del();
  • examples/utils.c

    r2828382 rd4c5de7  
    1616  You should have received a copy of the GNU General Public License
    1717  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
     18
     19*/
     20
     21/**
     22
     23  This file includes some tools common to all examples. Code specific to the
     24  algorithm performed by each program should go in the source file of that
     25  program instead.
    1826
    1927*/
     
    4149int verbose = 0;
    4250int usejack = 0;
    43 int usedoubled = 1;
    4451int frames_delay = 0;
    4552
     53
     54char_t * pitch_unit = "default";
     55char_t * pitch_mode = "default";
    4656
    4757/* energy,specdiff,hfc,complexdomain,phase */
     
    5868aubio_sndfile_t *fileout = NULL;
    5969
    60 aubio_pvoc_t *pv;
    6170fvec_t *ibuf;
    6271fvec_t *obuf;
    63 fvec_t *pitch_obuf;
    64 cvec_t *fftgrain;
    6572fvec_t *woodblock;
    66 aubio_onsetdetection_t *o;
    67 fvec_t *onset;
    68 fvec_t *onset2;
    69 smpl_t isonset = 0;
    70 aubio_peakpicker_t *parms;
    71 
    72 
    73 /* pitch objects */
    74 smpl_t pitch = 0.;
    75 aubio_pitchdetection_t *pitchdet;
    76 char_t * pitch_unit = "default";
    77 char_t * pitch_mode = "default";
    78 uint_t median = 6;
    79 
    80 fvec_t *note_buffer = NULL;
    81 fvec_t *note_buffer2 = NULL;
    82 smpl_t curlevel = 0.;
    83 smpl_t maxonset = 0.;
    84 
    85 smpl_t curnote = 0.;
    86 smpl_t newnote = 0.;
    87 uint_t isready = 0;
    88 
    89 
    9073
    9174/* badly redeclare some things */
     
    9376smpl_t averaging;
    9477const char *prog_name;
     78
     79void flush_process (aubio_process_func_t process_func,
     80    aubio_print_func_t print);
    9581
    9682void
     
    222208{
    223209
     210  uint_t found_wood = 0;
    224211
    225212  aubio_sndfile_t *onsetfile = NULL;
     
    230217  if (output_filename || usejack) {
    231218    /* dummy assignement to keep egcs happy */
    232     isonset = (onsetfile = new_aubio_sndfile_ro (onset_filename)) ||
     219    found_wood = (onsetfile = new_aubio_sndfile_ro (onset_filename)) ||
    233220        (onsetfile = new_aubio_sndfile_ro ("sounds/woodblock.aiff")) ||
    234221        (onsetfile = new_aubio_sndfile_ro ("../sounds/woodblock.aiff"));
     
    277264  ibuf = new_fvec (overlap_size, channels);
    278265  obuf = new_fvec (overlap_size, channels);
    279   fftgrain = new_cvec (buffer_size, channels);
    280 
    281   if (usepitch) {
    282     pitchdet = new_aubio_pitchdetection (pitch_mode, buffer_size * 4,
    283         overlap_size, channels, samplerate);
    284     aubio_pitchdetection_set_tolerance (pitchdet, 0.7);
    285     pitch_obuf = new_fvec (1, channels);
    286 
    287     if (median) {
    288       note_buffer = new_fvec (median, 1);
    289       note_buffer2 = new_fvec (median, 1);
    290     }
    291   }
    292   /* phase vocoder */
    293   pv = new_aubio_pvoc (buffer_size, overlap_size, channels);
    294   /* onsets */
    295   parms = new_aubio_peakpicker (threshold);
    296   o = new_aubio_onsetdetection (onset_mode, buffer_size, channels);
    297   onset = new_fvec (1, channels);
    298266
    299267}
     
    303271examples_common_del (void)
    304272{
    305   if (usepitch) {
    306     send_noteon (curnote, 0);
    307     del_aubio_pitchdetection (pitchdet);
    308     if (median) {
    309       del_fvec (note_buffer);
    310       del_fvec (note_buffer2);
    311     }
    312     del_fvec (pitch_obuf);
    313   }
    314   del_aubio_onsetdetection (o);
    315   del_aubio_peakpicker (parms);
    316   del_aubio_pvoc (pv);
     273  del_fvec (ibuf);
    317274  del_fvec (obuf);
    318   del_fvec (ibuf);
    319   del_cvec (fftgrain);
    320   del_fvec (onset);
    321275  del_fvec (woodblock);
    322276  aubio_cleanup ();
     
    355309    while ((signed) overlap_size == aubio_sndfile_read (file, overlap_size,
    356310            ibuf)) {
    357       isonset = 0;
    358311      process_func (ibuf->data, obuf->data, overlap_size);
    359312      print ();
     
    416369
    417370
    418 void
    419 note_append (fvec_t * note_buffer, smpl_t curnote)
    420 {
    421   uint_t i = 0;
    422   for (i = 0; i < note_buffer->length - 1; i++) {
    423     note_buffer->data[0][i] = note_buffer->data[0][i + 1];
    424   }
    425   note_buffer->data[0][note_buffer->length - 1] = curnote;
    426   return;
    427 }
    428 
    429 uint_t
    430 get_note (fvec_t * note_buffer, fvec_t * note_buffer2)
    431 {
    432   uint_t i = 0;
    433   for (i = 0; i < note_buffer->length; i++) {
    434     note_buffer2->data[0][i] = note_buffer->data[0][i];
    435   }
    436   return fvec_median (note_buffer2);
    437 }
    438 
    439371#if HAVE_LASH
    440372
  • examples/utils.h

    r2828382 rd4c5de7  
    4343extern int verbose;
    4444extern int usejack;
    45 extern int usedoubled;
    4645extern int frames_delay;
    47 extern unsigned int median;
    48 extern const char *output_filename;
    49 extern const char *input_filename;
    5046/* defined in utils.c */
    5147void usage (FILE * stream, int exit_code);
     
    6056void examples_common_process (aubio_process_func_t process_func,
    6157    aubio_print_func_t print);
    62 void flush_process (aubio_process_func_t process_func,
    63     aubio_print_func_t print);
    6458
     59extern char_t * pitch_unit;
     60extern char_t * pitch_mode;
    6561
    6662void send_noteon (int pitch, int velo);
    67 /** append new note candidate to the note_buffer and return filtered value. we
    68  * need to copy the input array as fvec_median destroy its input data.*/
    69 void note_append (fvec_t * note_buffer, smpl_t curnote);
    70 uint_t get_note (fvec_t * note_buffer, fvec_t * note_buffer2);
    7163
    7264extern const char *output_filename;
    73 extern const char *input_filename;
    74 extern const char *onset_filename;
    75 extern int verbose;
    76 extern int usejack;
    77 extern int usedoubled;
    78 
    79 
    80 /* energy,specdiff,hfc,complexdomain,phase */
    8165extern char_t * onset_mode;
    8266extern smpl_t threshold;
    8367extern smpl_t silence;
     68extern int verbose;
     69extern int usejack;
    8470extern uint_t buffer_size;
    8571extern uint_t overlap_size;
     
    8773extern uint_t samplerate;
    8874
    89 
    90 extern aubio_sndfile_t *file;
    91 extern aubio_sndfile_t *fileout;
    92 
    93 extern aubio_pvoc_t *pv;
    9475extern fvec_t *ibuf;
    9576extern fvec_t *obuf;
    96 extern fvec_t *pitch_obuf;
    97 extern cvec_t *fftgrain;
    9877extern fvec_t *woodblock;
    99 extern aubio_onsetdetection_t *o;
    100 extern aubio_onsetdetection_t *o2;
    101 extern fvec_t *onset;
    102 extern fvec_t *onset2;
    103 extern smpl_t isonset;
    104 extern aubio_peakpicker_t *parms;
    105 
    106 
    107 /* pitch objects */
    108 extern smpl_t pitch;
    109 extern aubio_pitchdetection_t *pitchdet;
    110 extern uint_t median;
    111 
    112 extern fvec_t *note_buffer;
    113 extern fvec_t *note_buffer2;
    114 extern smpl_t curlevel;
    115 extern smpl_t maxonset;
    116 
    117 extern smpl_t curnote;
    118 extern smpl_t newnote;
    119 extern uint_t isready;
    120 
    121 /* per example param */
    122 extern uint_t usepitch;
Note: See TracChangeset for help on using the changeset viewer.