Changeset 466dff3


Ignore:
Timestamp:
Dec 7, 2013, 4:09:00 AM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
Children:
3da8187
Parents:
44e94f3c
Message:

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

Location:
examples
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • examples/aubiomfcc.c

    r44e94f3c r466dff3  
    11/*
    2   Copyright (C) 2007-2009 Paul Brossier <piem@aubio.org>
     2  Copyright (C) 2007-2013 Paul Brossier <piem@aubio.org>
    33
    44  This file is part of aubio.
     
    2222#include "parse_args.h"
    2323
    24 /* mfcc objects */
    25 fvec_t * mfcc_out;
    26 aubio_mfcc_t * mfcc;
    27 aubio_pvoc_t *pv;
    28 cvec_t *fftgrain;
     24aubio_pvoc_t *pv;    // a phase vocoder
     25cvec_t *fftgrain;    // outputs a spectrum
     26aubio_mfcc_t * mfcc; // which the mfcc will process
     27fvec_t * mfcc_out;   // to get the output coefficients
    2928
    3029uint_t n_filters = 40;
    3130uint_t n_coefs = 13;
    3231
    33 unsigned int pos = 0; /*frames%dspblocksize*/
    34 
    35 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
    36   unsigned int j;       /*frames*/
    37  
    38   for (j=0;j<(unsigned)nframes;j++) {
    39     if(usejack) {
    40       /* write input to datanew */
    41       fvec_write_sample(ibuf, input[0][j], pos);
    42       /* put synthnew in output */
    43       output[0][j] = fvec_read_sample(obuf, pos);
    44     }
    45     /*time for fft*/
    46     if (pos == overlap_size-1) {         
    47       /* block loop */
    48      
    49       //compute mag spectrum
    50       aubio_pvoc_do (pv, ibuf, fftgrain);
    51      
    52       //compute mfccs
    53       aubio_mfcc_do(mfcc, fftgrain, mfcc_out);
    54      
    55       /* end of block loop */
    56       pos = -1; /* so it will be zero next j loop */
    57     }
    58     pos++;
    59   }
    60   return 1;
     32static void
     33process_block(fvec_t *ibuf, fvec_t *obuf) {
     34  fvec_zeros(obuf);
     35  //compute mag spectrum
     36  aubio_pvoc_do (pv, ibuf, fftgrain);
     37  //compute mfccs
     38  aubio_mfcc_do(mfcc, fftgrain, mfcc_out);
    6139}
    6240
    6341static void process_print (void) {
    6442  /* output times in seconds and extracted mfccs */
    65   if (sink_uri == NULL) {
    66     outmsg("%f\t",frames*overlap_size/(float)samplerate);
    67     fvec_print(mfcc_out);
    68   }
     43  outmsg("%f\t",blocks*hop_size/(float)samplerate);
     44  fvec_print(mfcc_out);
    6945}
    7046
    7147int main(int argc, char **argv) {
    72   // params
     48  // change some default params
    7349  buffer_size  = 512;
    74   overlap_size = 256;
    75  
     50  hop_size = 256;
     51
    7652  examples_common_init(argc,argv);
    7753
    78   /* phase vocoder */
    79   pv = new_aubio_pvoc (buffer_size, overlap_size);
     54  verbmsg ("using source: %s at %dHz\n", source_uri, samplerate);
     55  verbmsg ("buffer_size: %d, ", buffer_size);
     56  verbmsg ("hop_size: %d\n", hop_size);
    8057
     58  pv = new_aubio_pvoc (buffer_size, hop_size);
    8159  fftgrain = new_cvec (buffer_size);
     60  mfcc = new_aubio_mfcc(buffer_size, n_filters, n_coefs, samplerate);
     61  mfcc_out = new_fvec(n_coefs);
    8262
    83   //populating the filter
    84   mfcc = new_aubio_mfcc(buffer_size, n_filters, n_coefs, samplerate);
    85  
    86   mfcc_out = new_fvec(n_coefs);
    87  
    88   //process
    89   examples_common_process(aubio_process,process_print);
    90  
    91   //destroying mfcc
     63  examples_common_process((aubio_process_func_t)process_block, process_print);
     64
    9265  del_aubio_pvoc (pv);
    9366  del_cvec (fftgrain);
     
    9669
    9770  examples_common_del();
    98   debug("End of program.\n");
    99   fflush(stderr);
    100  
    10171  return 0;
    10272}
  • examples/aubionotes.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.
     
    2525#include "parse_args.h"
    2626
    27 /* pitch objects */
    28 smpl_t pitch = 0.;
     27uint_t median = 6;
    2928
    30 uint_t median = 6;
    31 smpl_t curlevel = 0.;
    32 
    33 aubio_pitch_t *pitchdet;
    34 
    35 fvec_t *note_buffer = NULL;
    36 fvec_t *note_buffer2 = NULL;
     29fvec_t *note_buffer;
     30fvec_t *note_buffer2;
    3731
    3832smpl_t curnote = 0.;
    3933smpl_t newnote = 0.;
    4034uint_t isready = 0;
    41 unsigned int pos = 0; /*frames%dspblocksize*/
    4235
    43 aubio_pitch_t *pitchdet;
     36aubio_pitch_t *pitch;
    4437aubio_onset_t *o;
    4538fvec_t *onset;
     
    5144uint_t get_note (fvec_t * note_buffer, fvec_t * note_buffer2);
    5245
    53 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
    54   unsigned int j;       /*frames*/
    55   for (j=0;j<(unsigned)nframes;j++) {
    56     if(usejack) {
    57       /* write input to datanew */
    58       fvec_write_sample(ibuf, input[0][j], pos);
    59       /* put synthnew in output */
    60       output[0][j] = fvec_read_sample(obuf, pos);
     46static void
     47process_block(fvec_t *ibuf, fvec_t *obuf) {
     48  fvec_zeros(obuf);
     49  aubio_onset_do(o, ibuf, onset);
     50
     51  aubio_pitch_do (pitch, ibuf, pitch_obuf);
     52  smpl_t new_pitch = fvec_read_sample(pitch_obuf, 0);
     53  if(median){
     54    note_append(note_buffer, new_pitch);
     55  }
     56
     57  /* curlevel is negatif or 1 if silence */
     58  smpl_t curlevel = aubio_level_detection(ibuf, silence);
     59  if (fvec_read_sample(onset, 0)) {
     60    /* test for silence */
     61    if (curlevel == 1.) {
     62      if (median) isready = 0;
     63      /* send note off */
     64      send_noteon(curnote,0);
     65    } else {
     66      if (median) {
     67        isready = 1;
     68      } else {
     69        /* kill old note */
     70        send_noteon(curnote,0);
     71        /* get and send new one */
     72        send_noteon(new_pitch,127+(int)floor(curlevel));
     73        curnote = new_pitch;
     74      }
    6175    }
    62     /*time for fft*/
    63     if (pos == overlap_size-1) {         
    64       /* block loop */
    65       aubio_onset_do(o, ibuf, onset);
    66      
    67       aubio_pitch_do (pitchdet, ibuf, pitch_obuf);
    68       pitch = fvec_read_sample(pitch_obuf, 0);
    69       if(median){
    70               note_append(note_buffer, pitch);
     76  } else {
     77    if (median) {
     78      if (isready > 0)
     79        isready++;
     80      if (isready == median)
     81      {
     82        /* kill old note */
     83        send_noteon(curnote,0);
     84        newnote = get_note(note_buffer, note_buffer2);
     85        curnote = newnote;
     86        /* get and send new one */
     87        if (curnote>45){
     88          send_noteon(curnote,127+(int)floor(curlevel));
     89        }
    7190      }
    72 
    73       /* curlevel is negatif or 1 if silence */
    74       curlevel = aubio_level_detection(ibuf, silence);
    75       if (fvec_read_sample(onset, 0)) {
    76               /* test for silence */
    77               if (curlevel == 1.) {
    78                       if (median) isready = 0;
    79                       /* send note off */
    80                       send_noteon(curnote,0);
    81               } else {
    82                       if (median) {
    83                               isready = 1;
    84                       } else {
    85                               /* kill old note */
    86                               send_noteon(curnote,0);
    87                               /* get and send new one */
    88                               send_noteon(pitch,127+(int)floor(curlevel));
    89                               curnote = pitch;
    90                       }
    91 
    92                       for (pos = 0; pos < overlap_size; pos++){
    93                               //obuf->data[pos] = woodblock->data[pos];
    94                       }
    95               }
    96       } else {
    97               if (median) {
    98                       if (isready > 0)
    99                               isready++;
    100                       if (isready == median)
    101                       {
    102                               /* kill old note */
    103                               send_noteon(curnote,0);
    104                               newnote = get_note(note_buffer, note_buffer2);
    105                               curnote = newnote;
    106                               /* get and send new one */
    107                               if (curnote>45){
    108                                       send_noteon(curnote,127+(int)floor(curlevel));
    109                               }
    110                       }
    111               } // if median
    112         for (pos = 0; pos < overlap_size; pos++)
    113           obuf->data[pos] = 0.;
    114       }
    115       /* end of block loop */
    116       pos = -1; /* so it will be zero next j loop */
    117     }
    118     pos++;
     91    } // if median
    11992  }
    120   return 1;
    12193}
    12294
    123 static void process_print (void) {
    124       if (verbose) outmsg("%f\n",pitch);
     95static void
     96process_print (void) {
     97  //if (verbose) outmsg("%f\n",pitch_obuf->data[0]);
    12598}
    12699
     
    149122  examples_common_init(argc,argv);
    150123
    151   o = new_aubio_onset (onset_method, buffer_size, overlap_size, samplerate);
     124  verbmsg ("using source: %s at %dHz\n", source_uri, samplerate);
     125
     126  verbmsg ("onset method: %s, ", onset_method);
     127  verbmsg ("buffer_size: %d, ", buffer_size);
     128  verbmsg ("hop_size: %d, ", hop_size);
     129  verbmsg ("threshold: %f\n", onset_threshold);
     130
     131  verbmsg ("pitch method: %s, ", pitch_method);
     132  verbmsg ("buffer_size: %d, ", buffer_size * 4);
     133  verbmsg ("hop_size: %d, ", hop_size);
     134  verbmsg ("tolerance: %f\n", pitch_tolerance);
     135
     136  o = new_aubio_onset (onset_method, buffer_size, hop_size, samplerate);
    152137  if (onset_threshold != 0.) aubio_onset_set_threshold (o, onset_threshold);
    153138  onset = new_fvec (1);
    154139
    155   pitchdet = new_aubio_pitch (pitch_method, buffer_size * 4,
    156           overlap_size, samplerate);
    157   aubio_pitch_set_tolerance (pitchdet, 0.7);
     140  pitch = new_aubio_pitch (pitch_method, buffer_size * 4, hop_size, samplerate);
     141  if (pitch_tolerance != 0.) aubio_pitch_set_tolerance (pitch, pitch_tolerance);
    158142  pitch_obuf = new_fvec (1);
     143
    159144  if (median) {
    160145      note_buffer = new_fvec (median);
     
    162147  }
    163148
    164   examples_common_process(aubio_process, process_print);
     149  examples_common_process((aubio_process_func_t)process_block, process_print);
    165150
     151  // send a last note off
    166152  send_noteon (curnote, 0);
    167   del_aubio_pitch (pitchdet);
     153
     154  del_aubio_pitch (pitch);
    168155  if (median) {
    169156      del_fvec (note_buffer);
     
    173160
    174161  examples_common_del();
    175   debug("End of program.\n");
    176   fflush(stderr);
    177162  return 0;
    178163}
  • examples/aubioonset.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.
     
    2020
    2121#include "utils.h"
    22 #define PROG_HAS_ONSET
     22#define PROG_HAS_ONSET 1
    2323#include "parse_args.h"
    24 
    25 uint_t pos = 0; /*frames%dspblocksize*/
    2624
    2725aubio_onset_t *o;
     
    2927fvec_t *onset;
    3028
    31 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
    32   unsigned int j;       /*frames*/
    33   for (j=0;j<(unsigned)nframes;j++) {
    34     if(usejack) {
    35       /* write input to datanew */
    36       fvec_write_sample(ibuf, input[0][j], pos);
    37       /* put synthnew in output */
    38       output[0][j] = fvec_read_sample(obuf, pos);
    39     }
    40     /*time for fft*/
    41     if (pos == overlap_size-1) {
    42       /* block loop */
    43       fvec_zeros(obuf);
    44       aubio_onset_do (o, ibuf, onset);
    45       if ( fvec_read_sample(onset, 0) ) {
    46         aubio_wavetable_play ( wavetable );
    47       } else {
    48         aubio_wavetable_stop ( wavetable );
    49       }
    50       aubio_wavetable_do (wavetable, obuf, obuf);
    51       /* end of block loop */
    52       pos = -1; /* so it will be zero next j loop */
    53     }
    54     pos++;
     29void
     30process_block(fvec_t *ibuf, fvec_t *obuf) {
     31  fvec_zeros(obuf);
     32  aubio_onset_do (o, ibuf, onset);
     33  if ( fvec_read_sample(onset, 0) ) {
     34    aubio_wavetable_play ( wavetable );
     35  } else {
     36    aubio_wavetable_stop ( wavetable );
    5537  }
    56   return 1;
     38  aubio_wavetable_do (wavetable, obuf, obuf);
    5739}
    5840
    59 static void
     41void
    6042process_print (void)
    6143{
    62   /* output times in seconds, taking back some delay to ensure the label is
    63    * _before_ the actual onset */
    64   if (!verbose && usejack)
    65     return;
    6644  smpl_t onset_found = fvec_read_sample (onset, 0);
    6745  if (onset_found) {
     
    7351  examples_common_init(argc,argv);
    7452
    75   o = new_aubio_onset (onset_method, buffer_size, overlap_size, samplerate);
     53  verbmsg ("using source: %s at %dHz\n", source_uri, samplerate);
     54  verbmsg ("onset method: %s, ", onset_method);
     55  verbmsg ("buffer_size: %d, ", buffer_size);
     56  verbmsg ("hop_size: %d, ", hop_size);
     57  verbmsg ("threshold: %f\n", onset_threshold);
     58
     59  o = new_aubio_onset (onset_method, buffer_size, hop_size, samplerate);
    7660  if (onset_threshold != 0.) aubio_onset_set_threshold (o, onset_threshold);
    7761  onset = new_fvec (1);
    7862
    79   wavetable = new_aubio_wavetable (samplerate, overlap_size);
     63  wavetable = new_aubio_wavetable (samplerate, hop_size);
    8064  aubio_wavetable_set_freq ( wavetable, 2450.);
    8165  //aubio_sampler_load (sampler, "/archives/sounds/woodblock.aiff");
    8266
    83   examples_common_process(aubio_process,process_print);
     67  examples_common_process((aubio_process_func_t)process_block, process_print);
    8468
    8569  del_aubio_onset (o);
     
    8872
    8973  examples_common_del();
    90   debug("End of program.\n");
    91   fflush(stderr);
    9274  return 0;
    9375}
    94 
  • examples/aubiopitch.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 unsigned int pos = 0; /*frames%dspblocksize*/
    26 
    2725aubio_pitch_t *o;
    2826aubio_wavetable_t *wavetable;
    2927fvec_t *pitch;
    3028
    31 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
    32   unsigned int j;       /*frames*/
    33   for (j=0;j<(unsigned)nframes;j++) {
    34     if(usejack) {
    35       /* write input to datanew */
    36       fvec_write_sample(ibuf, input[0][j], pos);
    37       /* put synthnew in output */
    38       output[0][j] = fvec_read_sample(obuf, pos);
    39     }
    40     /*time for fft*/
    41     if (pos == overlap_size-1) {         
    42       /* block loop */
    43       aubio_pitch_do (o, ibuf, pitch);
    44       smpl_t freq = fvec_read_sample(pitch, 0);
    45       aubio_wavetable_set_amp ( wavetable, aubio_level_lin (ibuf) );
    46       if (freq != 0.0) {
    47         aubio_wavetable_set_freq ( wavetable, freq );
    48       } else {
    49         aubio_wavetable_set_freq ( wavetable, 0.0 );
    50       }
    51       aubio_wavetable_do (wavetable, obuf, obuf);
    52       /* end of block loop */
    53       pos = -1; /* so it will be zero next j loop */
    54     }
    55     pos++;
     29void
     30process_block(fvec_t * ibuf, fvec_t * obuf) {
     31  fvec_zeros(obuf);
     32  aubio_pitch_do (o, ibuf, pitch);
     33  smpl_t freq = fvec_read_sample(pitch, 0);
     34  aubio_wavetable_set_amp ( wavetable, aubio_level_lin (ibuf) );
     35  if (freq != 0.0) {
     36    aubio_wavetable_set_freq ( wavetable, freq );
     37  } else {
     38    aubio_wavetable_set_freq ( wavetable, 0.0 );
    5639  }
    57   return 1;
     40  aubio_wavetable_do (wavetable, obuf, obuf);
    5841}
    5942
    60 static void process_print (void) {
    61       if (!verbose && usejack) return;
    62       smpl_t pitch_found = fvec_read_sample(pitch, 0);
    63       outmsg("%f %f\n",(frames)
    64               *overlap_size/(float)samplerate, pitch_found);
     43void
     44process_print (void) {
     45  smpl_t pitch_found = fvec_read_sample(pitch, 0);
     46  outmsg("%f %f\n",(blocks)
     47      *hop_size/(float)samplerate, pitch_found);
    6548}
    6649
     
    6851  examples_common_init(argc,argv);
    6952
    70   o = new_aubio_pitch (pitch_method, buffer_size, overlap_size, samplerate);
     53  verbmsg ("using source: %s at %dHz\n", source_uri, samplerate);
     54  verbmsg ("pitch method: %s, ", pitch_method);
     55  verbmsg ("buffer_size: %d, ", buffer_size);
     56  verbmsg ("hop_size: %d, ", hop_size);
     57  verbmsg ("tolerance: %f\n", pitch_tolerance);
     58
     59  o = new_aubio_pitch (pitch_method, buffer_size, hop_size, samplerate);
     60  if (pitch_tolerance != 0.) aubio_pitch_set_tolerance (o, pitch_tolerance);
    7161  pitch = new_fvec (1);
    7262
    73   wavetable = new_aubio_wavetable (samplerate, overlap_size);
     63  wavetable = new_aubio_wavetable (samplerate, hop_size);
    7464  aubio_wavetable_play ( wavetable );
    7565
    76   examples_common_process(aubio_process,process_print);
     66  examples_common_process((aubio_process_func_t)process_block,process_print);
    7767
    7868  del_aubio_pitch (o);
     
    8171
    8272  examples_common_del();
    83   debug("End of program.\n");
    84   fflush(stderr);
    8573  return 0;
    8674}
  • examples/aubioquiet.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.
     
    2222#include "parse_args.h"
    2323
    24 unsigned int pos = 0; /*frames%dspblocksize*/
    2524sint_t wassilence = 1, issilence;
    2625
    27 int aubio_process(smpl_t **input, smpl_t **output, int nframes);
    28 int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
    29   unsigned int j;       /*frames*/
    30   for (j=0;j<(unsigned)nframes;j++) {
    31     if(usejack) {
    32       /* write input to datanew */
    33       fvec_write_sample(ibuf, input[0][j], pos);
    34       /* put synthnew in output */
    35       output[0][j] = fvec_read_sample(obuf, pos);
    36     }
    37     /*time for fft*/
    38     if (pos == overlap_size-1) {         
    39       /* test for silence */
    40       if (aubio_silence_detection(ibuf, silence)==1) {
    41         if (wassilence==1) issilence = 1;
    42         else issilence = 2;
    43         wassilence=1;
    44       } else {
    45         if (wassilence<=0) issilence = 0;
    46         else issilence = -1;
    47         wassilence=0;
    48       }
    49       /* end of block loop */
    50       pos = -1; /* so it will be zero next j loop */
    51     }
    52     pos++;
     26void process_block(fvec_t * ibuf, fvec_t * obuf) {
     27  fvec_zeros (obuf);
     28  if (aubio_silence_detection(ibuf, silence)==1) {
     29    if (wassilence==1) issilence = 1;
     30    else issilence = 2;
     31    wassilence=1;
     32  } else {
     33    if (wassilence<=0) issilence = 0;
     34    else issilence = -1;
     35    wassilence=0;
    5336  }
    54   return 1;
    5537}
    5638
    5739static void process_print (void) {
    58       int curframes = (frames - 4) > 0 ? frames -4 : 0;
    59       if (issilence == -1) {
    60           outmsg("NOISY: %f\n",curframes*overlap_size/(float)samplerate);
    61       } else if (issilence == 2) {
    62           outmsg("QUIET: %f\n",curframes*overlap_size/(float)samplerate);
    63       }
     40  int curblocks = (blocks - 4) > 0 ? blocks - 4 : 0;
     41  if (issilence == -1) {
     42    outmsg("NOISY: %f\n",curblocks*hop_size/(float)samplerate);
     43  } else if (issilence == 2) {
     44    outmsg("QUIET: %f\n",curblocks*hop_size/(float)samplerate);
     45  }
    6446}
    6547
    6648int main(int argc, char **argv) {
    6749  examples_common_init(argc,argv);
    68   examples_common_process(aubio_process,process_print);
     50  verbmsg ("using source: %s at %dHz\n", source_uri, samplerate);
     51  verbmsg ("buffer_size: %d, ", buffer_size);
     52  verbmsg ("hop_size: %d\n", hop_size);
     53  examples_common_process((aubio_process_func_t)process_block,process_print);
    6954  examples_common_del();
    70   debug("End of program.\n");
    71   fflush(stderr);
    7255  return 0;
    7356}
  • 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}
  • examples/jackio.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.
     
    3636
    3737/**
    38  * jack device structure 
     38 * jack device structure
    3939 */
    4040struct _aubio_jack_t
     
    7070  /** jack processing function */
    7171  aubio_process_func_t callback;
     72  /** internal fvec */
     73  fvec_t *ibuf;
     74  fvec_t *obuf;
     75  uint_t hop_size;
     76  int pos;
    7277};
    7378
     
    7580static aubio_jack_t *aubio_jack_alloc (uint_t ichan, uint_t ochan,
    7681    uint_t imidichan, uint_t omidichan);
    77 static uint_t aubio_jack_free (aubio_jack_t * jack_setup);
    7882/* jack callback functions */
    7983static int aubio_jack_process (jack_nframes_t nframes, void *arg);
     
    8185
    8286aubio_jack_t *
    83 new_aubio_jack (uint_t ichan, uint_t ochan,
    84     uint_t imidichan, uint_t omidichan, aubio_process_func_t callback)
     87new_aubio_jack (uint_t hop_size, uint_t ichan, uint_t ochan,
     88    uint_t imidichan, uint_t omidichan)
    8589{
    8690  aubio_jack_t *jack_setup = aubio_jack_alloc (ichan, ochan,
     
    149153  }
    150154
    151   /* set processing callback */
    152   jack_setup->callback = callback;
     155  /* get sample rate */
     156  jack_setup->samplerate = jack_get_sample_rate (jack_setup->client);
     157
     158  jack_setup->hop_size = hop_size;
     159  jack_setup->ibuf = new_fvec(hop_size);
     160  jack_setup->obuf = new_fvec(hop_size);
     161  jack_setup->pos = 0;
    153162  return jack_setup;
    154163
     
    160169
    161170uint_t
    162 aubio_jack_activate (aubio_jack_t * jack_setup)
    163 {
    164   /* get sample rate */
    165   jack_setup->samplerate = jack_get_sample_rate (jack_setup->client);
     171aubio_jack_get_samplerate (aubio_jack_t * jack_setup) {
     172  return jack_setup->samplerate;
     173}
     174
     175uint_t
     176aubio_jack_activate (aubio_jack_t * jack_setup, aubio_process_func_t callback)
     177{
     178  /* set processing callback */
     179  jack_setup->callback = callback;
    166180  /* actual jack process activation */
    167181  if (jack_activate (jack_setup->client)) {
     
    177191  /* bug : should disconnect all ports first */
    178192  jack_client_close (jack_setup->client);
    179   aubio_jack_free (jack_setup);
    180193}
    181194
     
    209222}
    210223
    211 static uint_t
    212 aubio_jack_free (aubio_jack_t * jack_setup)
     224void
     225del_aubio_jack (aubio_jack_t * jack_setup)
    213226{
    214227  if (jack_setup->omidichan && jack_setup->midi_out_ring) {
    215228    jack_ringbuffer_free (jack_setup->midi_out_ring);
    216229  }
     230  del_fvec (jack_setup->ibuf);
     231  del_fvec (jack_setup->obuf);
    217232  AUBIO_FREE (jack_setup->oports);
    218233  AUBIO_FREE (jack_setup->iports);
     
    220235  AUBIO_FREE (jack_setup->obufs);
    221236  AUBIO_FREE (jack_setup);
    222   return AUBIO_OK;
    223237}
    224238
     
    232246
    233247static void process_midi_output (aubio_jack_t * dev, jack_nframes_t nframes);
     248
     249static int block_process(aubio_jack_t *dev,
     250    smpl_t **input, smpl_t **output, int nframes) {
     251  unsigned int j;       /*frames*/
     252  for (j=0;j<(unsigned)nframes;j++) {
     253    /* put synthnew in output */
     254    output[0][j] = fvec_read_sample(dev->obuf, dev->pos);
     255    /* write input to datanew */
     256    fvec_write_sample(dev->ibuf, input[0][j], dev->pos);
     257    /*time for fft*/
     258    if (dev->pos == (int)(dev->hop_size) - 1) {
     259      /* block loop */
     260      dev->callback(dev->ibuf, dev->obuf);
     261      /* end of block loop */
     262      dev->pos = -1; /* so it will be zero next j loop */
     263    }
     264    dev->pos++;
     265  }
     266  return 1;
     267}
    234268
    235269static int
     
    249283  }
    250284#ifndef AUBIO_JACK_NEEDS_CONVERSION
    251   dev->callback (dev->ibufs, dev->obufs, nframes);
     285  block_process(dev, dev->ibufs, dev->obufs, nframes);
    252286#else
    253287  uint_t j;
     
    257291    }
    258292  }
    259   dev->callback (dev->sibufs, dev->sobufs, nframes);
     293  block_process(dev, dev->sibufs, dev->sobufs, nframes);
    260294  for (j = 0; j < MIN (nframes, AUBIO_JACK_MAX_FRAMES); j++) {
    261295    for (i = 0; i < dev->ochan; i++) {
  • examples/jackio.h

    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.
     
    2222#define JACKIO_H
    2323
    24 /** 
     24/**
    2525 * @file
    2626 *
    2727 * Jack driver for aubio
    28  * 
     28 *
    2929 */
    3030
     
    4141typedef struct _aubio_jack_t aubio_jack_t;
    4242/** jack process function */
    43 typedef int (*aubio_process_func_t) (smpl_t ** input,
    44     smpl_t ** output, int nframes);
     43typedef int (*aubio_process_func_t) (fvec_t * input, fvec_t * output);
    4544
    4645/** jack device creation function */
    47 aubio_jack_t *new_aubio_jack (uint_t inchannels, uint_t outchannels,
    48     uint_t imidichan, uint_t omidichan,
     46aubio_jack_t *new_aubio_jack (uint_t hop_size,
     47    uint_t inchannels, uint_t outchannels,
     48    uint_t imidichan, uint_t omidichan);
     49/** activate jack client (run jackprocess function) */
     50uint_t aubio_jack_activate (aubio_jack_t * jack_setup,
    4951    aubio_process_func_t callback);
    50 /** activate jack client (run jackprocess function) */
    51 uint_t aubio_jack_activate (aubio_jack_t * jack_setup);
    5252/** close and delete jack client */
    5353void aubio_jack_close (aubio_jack_t * jack_setup);
     54void del_aubio_jack (aubio_jack_t * jack_setup);
     55/** get samplerate */
     56uint_t aubio_jack_get_samplerate (aubio_jack_t * jack_setup);
    5457
    5558/** write a jack_midi_event_t to the midi output ringbuffer */
  • examples/parse_args.h

    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.
     
    2727extern uint_t samplerate;
    2828extern uint_t buffer_size;
    29 extern uint_t overlap_size;
     29extern uint_t hop_size;
    3030// onset stuff
    3131extern char_t * onset_method;
     
    4848
    4949// internal stuff
    50 extern int frames;
     50extern int blocks;
    5151
    5252extern fvec_t *ibuf;
     
    156156        break;
    157157      case 'H':
    158         overlap_size = atoi (optarg);
     158        hop_size = atoi (optarg);
    159159        break;
    160160      case 'O':                /*onset type */
  • examples/utils.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.
     
    3333
    3434int verbose = 0;
     35int usejack = 0;
    3536// input / output
    3637char_t *sink_uri = NULL;
     
    3940uint_t samplerate = 0;
    4041uint_t buffer_size = 512;
    41 uint_t overlap_size = 256;
     42uint_t hop_size = 256;
    4243// onset stuff
    4344char_t * onset_method = "default";
     
    6061fvec_t *obuf;
    6162
    62 
    6363/* settings */
    64 int frames = 0;
    65 int usejack = 0;
    66 int frames_delay = 0;
     64int blocks = 0;
    6765
    6866extern void usage (FILE * stream, int exit_code);
    6967extern int parse_args (int argc, char **argv);
     68
     69#if HAVE_JACK
     70aubio_jack_t *jack_setup;
     71#endif
    7072
    7173void
     
    7880  if (!usejack) {
    7981    debug ("Opening files ...\n");
    80     this_source = new_aubio_source ((char_t*)source_uri, 0, overlap_size);
     82    this_source = new_aubio_source ((char_t*)source_uri, samplerate, hop_size);
    8183    if (this_source == NULL) {
    8284      outmsg ("Could not open input file %s.\n", source_uri);
    8385      exit (1);
    8486    }
    85     samplerate = aubio_source_get_samplerate(this_source);
     87    if (samplerate == 0) {
     88      samplerate = aubio_source_get_samplerate(this_source);
     89    }
    8690    if (sink_uri != NULL) {
    8791      this_sink = new_aubio_sink ((char_t*)sink_uri, samplerate);
     
    9195      }
    9296    }
     97#ifdef HAVE_JACK
     98  } else {
     99    debug ("Jack init ...\n");
     100    jack_setup = new_aubio_jack (hop_size, 1, 1, 0, 1);
     101    samplerate = aubio_jack_get_samplerate (jack_setup);
     102    source_uri = "jack";
     103#endif
    93104  }
    94   ibuf = new_fvec (overlap_size);
    95   obuf = new_fvec (overlap_size);
     105  ibuf = new_fvec (hop_size);
     106  obuf = new_fvec (hop_size);
    96107
    97108}
     
    103114  del_fvec (obuf);
    104115  aubio_cleanup ();
     116  fflush(stderr);
     117  fflush(stdout);
    105118}
    106 
    107 #if HAVE_JACK
    108 aubio_jack_t *jack_setup;
    109 #endif
    110119
    111120void
     
    118127
    119128#if HAVE_JACK
    120     debug ("Jack init ...\n");
    121     jack_setup = new_aubio_jack (1, 1,
    122         0, 1, (aubio_process_func_t) process_func);
    123129    debug ("Jack activation ...\n");
    124     aubio_jack_activate (jack_setup);
     130    aubio_jack_activate (jack_setup, process_func);
    125131    debug ("Processing (Ctrl+C to quit) ...\n");
    126132    pause ();
     
    133139  } else {
    134140    /* phasevoc */
    135     debug ("Processing ...\n");
    136 
    137     frames = 0;
     141    blocks = 0;
     142    uint_t total_read = 0;
    138143
    139144    do {
    140145      aubio_source_do (this_source, ibuf, &read);
    141       process_func (&ibuf->data, &obuf->data, overlap_size);
    142       print ();
     146      process_func (ibuf, obuf);
     147      // print to console if verbose or no output given
     148      if (verbose || sink_uri == NULL) {
     149        print();
     150      }
    143151      if (this_sink) {
    144         aubio_sink_do (this_sink, obuf, overlap_size);
     152        aubio_sink_do (this_sink, obuf, hop_size);
    145153      }
    146       frames++;
    147     } while (read == overlap_size);
     154      blocks++;
     155      total_read += read;
     156    } while (read == hop_size);
    148157
    149     debug ("Processed %d frames of %d samples.\n", frames, buffer_size);
     158    verbmsg ("read %d samples (%d blocks of %d) from %s at %dHz\n",
     159        total_read, blocks, hop_size, source_uri, samplerate);
    150160
    151161    del_aubio_source (this_source);
     
    175185  } else
    176186#endif
    177   if (!verbose) {
    178     if (velo == 0) {
    179       outmsg ("%f\n", frames * overlap_size / (float) samplerate);
    180     } else {
    181       outmsg ("%f\t%f\t", mpitch, frames * overlap_size / (float) samplerate);
    182     }
     187  if (velo == 0) {
     188    outmsg ("%f\n", blocks * hop_size / (float) samplerate);
     189  } else {
     190    outmsg ("%f\t%f\t", mpitch, blocks * hop_size / (float) samplerate);
    183191  }
    184192}
  • examples/utils.h

    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.
     
    3030
    3131#ifdef HAVE_C99_VARARGS_MACROS
    32 #define debug(...)              if (verbose) fprintf (stderr, __VA_ARGS__)
    33 #define errmsg(...)             fprintf (stderr, __VA_ARGS__)
    34 #define outmsg(...)             fprintf (stdout, __VA_ARGS__)
     32#ifdef HAVE_DEBUG
     33#define debug(...)                fprintf (stderr, __VA_ARGS__)
    3534#else
    36 #define debug(format, args...)  if (verbose) fprintf(stderr, format , ##args)
    37 #define errmsg(format, args...) fprintf(stderr, format , ##args)
    38 #define outmsg(format, args...) fprintf(stdout, format , ##args)
     35#define debug(...)
     36#endif
     37#define verbmsg(...)              if (verbose) fprintf (stderr, __VA_ARGS__)
     38#define errmsg(...)               fprintf (stderr, __VA_ARGS__)
     39#define outmsg(...)               fprintf (stdout, __VA_ARGS__)
     40#else
     41#ifdef HAVE_DEBUG
     42#define debug(...)                fprintf (stderr, format , **args)
     43#else
     44#define debug(...)                ()
     45#endif
     46#define verbmsg(format, args...)  if (verbose) fprintf(stderr, format , ##args)
     47#define errmsg(format, args...)   fprintf(stderr, format , ##args)
     48#define outmsg(format, args...)   fprintf(stdout, format , ##args)
    3949#endif
    4050
    4151typedef void (aubio_print_func_t) (void);
    42 #ifndef HAVE_JACK
    43 typedef int (*aubio_process_func_t)
    44   (smpl_t ** input, smpl_t ** output, int nframes);
    45 #endif
     52typedef int (*aubio_process_func_t)(fvec_t * input, fvec_t * output);
    4653void send_noteon (int pitch, int velo);
    4754
    48 
Note: See TracChangeset for help on using the changeset viewer.