Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/notes/notes.c

    r790b6d7 r1f6a9f8  
    2525#include "notes/notes.h"
    2626
     27#define AUBIO_DEFAULT_NOTES_SILENCE -70.
     28// increase to 10. for .1  cent precision
     29//      or to 100. for .01 cent precision
     30#define AUBIO_DEFAULT_CENT_PRECISION 1.
     31#define AUBIO_DEFAULT_NOTES_MINIOI_MS 30.
     32
    2733struct _aubio_notes_t {
    2834
     
    7985  o->pitch = new_aubio_pitch (pitch_method, o->pitch_buf_size, o->hop_size, o->samplerate);
    8086  if (o->pitch_tolerance != 0.) aubio_pitch_set_tolerance (o->pitch, o->pitch_tolerance);
     87  aubio_pitch_set_unit (o->pitch, "midi");
    8188  o->pitch_output = new_fvec (1);
    8289
     
    9198  o->newnote = 0.;
    9299
    93   o->silence_threshold = -90.;
     100  aubio_notes_set_silence(o, AUBIO_DEFAULT_NOTES_SILENCE);
     101  aubio_notes_set_minioi_ms (o, AUBIO_DEFAULT_NOTES_MINIOI_MS);
    94102
    95103  return o;
     
    98106  del_aubio_notes(o);
    99107  return NULL;
     108}
     109
     110uint_t aubio_notes_set_silence(aubio_notes_t *o, smpl_t silence)
     111{
     112  uint_t err = AUBIO_OK;
     113  if (aubio_pitch_set_silence(o->pitch, silence) != AUBIO_OK) {
     114    err = AUBIO_FAIL;
     115  }
     116  if (aubio_onset_set_silence(o->onset, silence) != AUBIO_OK) {
     117    err = AUBIO_FAIL;
     118  }
     119  o->silence_threshold = silence;
     120  return err;
     121}
     122
     123smpl_t aubio_notes_get_silence(const aubio_notes_t *o)
     124{
     125  return aubio_pitch_get_silence(o->pitch);
     126}
     127
     128uint_t aubio_notes_set_minioi_ms (aubio_notes_t *o, smpl_t minioi_ms)
     129{
     130  uint_t err = AUBIO_OK;
     131  if (!o->onset || (aubio_onset_set_minioi_ms(o->onset, minioi_ms) != 0)) {
     132    err = AUBIO_FAIL;
     133  }
     134  return err;
     135}
     136
     137smpl_t aubio_notes_get_minioi_ms(const aubio_notes_t *o)
     138{
     139  return aubio_onset_get_minioi_ms(o->onset);
    100140}
    101141
     
    109149    note_buffer->data[i] = note_buffer->data[i + 1];
    110150  }
    111   note_buffer->data[note_buffer->length - 1] = curnote;
     151  //note_buffer->data[note_buffer->length - 1] = ROUND(10.*curnote)/10.;
     152  note_buffer->data[note_buffer->length - 1] = ROUND(AUBIO_DEFAULT_CENT_PRECISION*curnote);
    112153  return;
    113154}
    114155
    115 static uint_t
     156static smpl_t
    116157aubio_notes_get_latest_note (aubio_notes_t *o)
    117158{
    118   uint_t i;
    119   for (i = 0; i < o->note_buffer->length; i++) {
    120     o->note_buffer2->data[i] = o->note_buffer->data[i];
    121   }
    122   return fvec_median (o->note_buffer2);
     159  fvec_copy(o->note_buffer, o->note_buffer2);
     160  return fvec_median (o->note_buffer2) / AUBIO_DEFAULT_CENT_PRECISION;
    123161}
    124162
Note: See TracChangeset for help on using the changeset viewer.