Ignore:
Timestamp:
Dec 7, 2013, 4:09:00 AM (11 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/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}
Note: See TracChangeset for help on using the changeset viewer.