Ignore:
Timestamp:
Dec 7, 2013, 4:09:00 AM (10 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:
3da8187
Parents:
44e94f3c
Message:

examples/: large refactoring, improve option management, remove old stuff, move blocking logic to jackio

File:
1 edited

Legend:

Unmodified
Added
Removed
  • examples/aubiotrack.c

    r44e94f3c r466dff3  
    11/*
    2   Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
     2  Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
    33
    44  This file is part of aubio.
     
    2323#include "parse_args.h"
    2424
    25 uint_t pos = 0;    /* frames%dspblocksize */
    26 aubio_tempo_t * bt = NULL;
     25aubio_tempo_t * tempo;
    2726aubio_wavetable_t *wavetable;
    28 fvec_t * tempo_out = NULL;
     27fvec_t * tempo_out;
    2928smpl_t istactus = 0;
    3029smpl_t isonset = 0;
    3130
    32 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
    33   unsigned int j;       /*frames*/
    34   for (j=0;j<(unsigned)nframes;j++) {
    35     if(usejack) {
    36       /* write input to datanew */
    37       fvec_write_sample(ibuf, input[0][j], pos);
    38       /* put synthnew in output */
    39       output[0][j] = fvec_read_sample(obuf, pos);
    40     }
    41     /*time for fft*/
    42     if (pos == overlap_size-1) {
    43       /* block loop */
    44       aubio_tempo_do (bt,ibuf,tempo_out);
    45       istactus = fvec_read_sample (tempo_out, 0);
    46       isonset = fvec_read_sample (tempo_out, 1);
    47       fvec_zeros (obuf);
    48       if (istactus > 0.) {
    49         aubio_wavetable_play ( wavetable );
    50       } else {
    51         aubio_wavetable_stop ( wavetable );
    52       }
    53       aubio_wavetable_do (wavetable, obuf, obuf);
    54       /* end of block loop */
    55       pos = -1; /* so it will be zero next j loop */
    56     }
    57     pos++;
     31void process_block(fvec_t * ibuf, fvec_t *obuf) {
     32  aubio_tempo_do (tempo, ibuf, tempo_out);
     33  istactus = fvec_read_sample (tempo_out, 0);
     34  isonset = fvec_read_sample (tempo_out, 1);
     35  fvec_zeros (obuf);
     36  if (istactus > 0.) {
     37    aubio_wavetable_play ( wavetable );
     38  } else {
     39    aubio_wavetable_stop ( wavetable );
    5840  }
    59   return 1;
     41  aubio_wavetable_do (wavetable, obuf, obuf);
    6042}
    6143
    62 static void process_print (void) {
    63   if (sink_uri == NULL) {
    64     if (istactus) {
    65       outmsg("%f\n",((smpl_t)(frames*overlap_size)+(istactus-1.)*overlap_size)/(smpl_t)samplerate);
    66     }
    67     if (isonset && verbose)
    68       outmsg(" \t \t%f\n",(frames)*overlap_size/(float)samplerate);
     44void process_print (void) {
     45  if (istactus) {
     46    outmsg("%f\n", aubio_tempo_get_last_s(tempo) );
    6947  }
     48  //if (isonset && verbose)
     49  //  outmsg(" \t \t%f\n",(blocks)*hop_size/(float)samplerate);
    7050}
    7151
    7252int main(int argc, char **argv) {
    73  
     53  // override general settings from utils.c
    7454  buffer_size = 1024;
    75   overlap_size = 512;
    76   /* override default settings */
     55  hop_size = 512;
     56
    7757  examples_common_init(argc,argv);
    7858
     59  verbmsg ("using source: %s at %dHz\n", source_uri, samplerate);
     60
     61  verbmsg ("tempo method: %s, ", tempo_method);
     62  verbmsg ("buffer_size: %d, ", buffer_size);
     63  verbmsg ("hop_size: %d, ", hop_size);
     64  verbmsg ("threshold: %f\n", onset_threshold);
     65
    7966  tempo_out = new_fvec(2);
    80   bt = new_aubio_tempo(tempo_method,buffer_size,overlap_size, samplerate);
    81   if (onset_threshold != 0.) aubio_tempo_set_threshold (bt, onset_threshold);
     67  tempo = new_aubio_tempo(tempo_method, buffer_size, hop_size, samplerate);
     68  if (onset_threshold != 0.) aubio_tempo_set_threshold (tempo, onset_threshold);
    8269
    83   wavetable = new_aubio_wavetable (samplerate, overlap_size);
     70  wavetable = new_aubio_wavetable (samplerate, hop_size);
    8471  aubio_wavetable_set_freq ( wavetable, 2450.);
    8572  //aubio_sampler_load (sampler, "/archives/sounds/woodblock.aiff");
    8673
    87   examples_common_process(aubio_process,process_print);
     74  examples_common_process((aubio_process_func_t)process_block,process_print);
    8875
    89   del_aubio_tempo(bt);
     76  del_aubio_tempo(tempo);
    9077  del_aubio_wavetable (wavetable);
    9178  del_fvec(tempo_out);
    9279
    9380  examples_common_del();
    94 
    95   debug("End of program.\n");
    96 
    97   fflush(stderr);
    98 
    9981  return 0;
    10082}
Note: See TracChangeset for help on using the changeset viewer.