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/aubionotes.c

    r2828382 rd4c5de7  
    1919#include "utils.h"
    2020
     21/* pitch objects */
     22smpl_t pitch = 0.;
     23
     24uint_t median = 6;
     25smpl_t curlevel = 0.;
     26
     27aubio_pitchdetection_t *pitchdet;
     28
     29fvec_t *note_buffer = NULL;
     30fvec_t *note_buffer2 = NULL;
     31
     32smpl_t curnote = 0.;
     33smpl_t newnote = 0.;
     34uint_t isready = 0;
    2135unsigned int pos = 0; /*frames%dspblocksize*/
    22 uint_t usepitch = 1;
    2336
    24 int aubio_process(smpl_t **input, smpl_t **output, int nframes);
    25 int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
     37aubio_pitchdetection_t *pitchdet;
     38aubio_onset_t *o;
     39fvec_t *onset;
     40fvec_t *pitch_obuf;
     41
     42/** append new note candidate to the note_buffer and return filtered value. we
     43 * need to copy the input array as fvec_median destroy its input data.*/
     44void note_append (fvec_t * note_buffer, smpl_t curnote);
     45uint_t get_note (fvec_t * note_buffer, fvec_t * note_buffer2);
     46
     47static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
    2648  unsigned int i;       /*channels*/
    2749  unsigned int j;       /*frames*/
     
    3860    if (pos == overlap_size-1) {         
    3961      /* block loop */
    40       aubio_pvoc_do (pv,ibuf, fftgrain);
    41       aubio_onsetdetection_do(o,fftgrain, onset);
    42       isonset = aubio_peakpicker_do(parms, onset);
     62      aubio_onset_do(o, ibuf, onset);
    4363     
    4464      aubio_pitchdetection_do (pitchdet, ibuf, pitch_obuf);
     
    5070      /* curlevel is negatif or 1 if silence */
    5171      curlevel = aubio_level_detection(ibuf, silence);
    52       if (isonset) {
     72      if (fvec_read_sample(onset, 0, 0)) {
    5373              /* test for silence */
    5474              if (curlevel == 1.) {
    55                       isonset=0;
    5675                      if (median) isready = 0;
    5776                      /* send note off */
     
    99118}
    100119
    101 void process_print (void);
    102 void process_print (void) {
     120static void process_print (void) {
    103121      if (verbose) outmsg("%f\n",pitch);
     122}
     123
     124void
     125note_append (fvec_t * note_buffer, smpl_t curnote)
     126{
     127  uint_t i = 0;
     128  for (i = 0; i < note_buffer->length - 1; i++) {
     129    note_buffer->data[0][i] = note_buffer->data[0][i + 1];
     130  }
     131  note_buffer->data[0][note_buffer->length - 1] = curnote;
     132  return;
     133}
     134
     135uint_t
     136get_note (fvec_t * note_buffer, fvec_t * note_buffer2)
     137{
     138  uint_t i = 0;
     139  for (i = 0; i < note_buffer->length; i++) {
     140    note_buffer2->data[0][i] = note_buffer->data[0][i];
     141  }
     142  return fvec_median (note_buffer2);
    104143}
    105144
    106145int main(int argc, char **argv) {
    107146  examples_common_init(argc,argv);
     147
     148  o = new_aubio_onset (onset_mode, buffer_size, overlap_size, channels,
     149          samplerate);
     150  onset = new_fvec (1, channels);
     151
     152  pitchdet = new_aubio_pitchdetection (pitch_mode, buffer_size * 4,
     153          overlap_size, channels, samplerate);
     154  aubio_pitchdetection_set_tolerance (pitchdet, 0.7);
     155  pitch_obuf = new_fvec (1, channels);
     156  if (median) {
     157      note_buffer = new_fvec (median, 1);
     158      note_buffer2 = new_fvec (median, 1);
     159  }
     160
    108161  examples_common_process(aubio_process, process_print);
     162
     163  send_noteon (curnote, 0);
     164  del_aubio_pitchdetection (pitchdet);
     165  if (median) {
     166      del_fvec (note_buffer);
     167      del_fvec (note_buffer2);
     168  }
     169  del_fvec (pitch_obuf);
     170
    109171  examples_common_del();
    110172  debug("End of program.\n");
Note: See TracChangeset for help on using the changeset viewer.