Changeset d4c5de7 for examples/utils.c


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.