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

File:
1 edited

Legend:

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