Changeset 56ef7e1 for src/onset


Ignore:
Timestamp:
Oct 18, 2009, 3:08:59 PM (11 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:
e5f49af
Parents:
74516f7
Message:

Change peakpicker to match API specs, make quadint per channel

  • src/mathutils.c
    • add per channel mean and median
    • update moving thres and adapt_thres accordingly
    • change quadint unused span argument to a channel argument
  • src/onset/onset.c:
    • make wasonset a vector for multi channel, use new peakpicker
  • src/onset/peakpick.c:
    • update peakpicker do for multi channeling
  • src/pitch/: update use to fvec_quadint
  • src/tempo/beattracking.c: update calls to fvec_quadint
  • src/tempo/tempo.c: update peakpicker usage
  • tests/src/test-peakpick.c: update peakpicker usage
Location:
src/onset
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/onset/onset.c

    r74516f7 r56ef7e1  
    3737  smpl_t silence;               /**< silence threhsold */
    3838  uint_t minioi;                /**< minimum inter onset interval */
    39   uint_t wasonset;              /**< number of frames since last onset */
     39  fvec_t * wasonset;            /**< number of frames since last onset */
    4040  uint_t samplerate;            /**< sampling rate of the input signal */
    4141};
     
    4444void aubio_onset_do (aubio_onset_t *o, fvec_t * input, fvec_t * onset)
    4545{
    46   uint_t isonset = 0;
    47   uint_t wasonset = o->wasonset;
     46  smpl_t isonset = 0;
     47  smpl_t wasonset = 0;
     48  uint_t i;
    4849  aubio_pvoc_do (o->pv,input, o->fftgrain);
    4950  aubio_onsetdetection_do (o->od,o->fftgrain, o->of);
     
    5253    onset->data[0][0] *= onset2->data[0][0];
    5354  }*/
    54   isonset = aubio_peakpicker_do(o->pp, o->of);
     55  aubio_peakpicker_do(o->pp, o->of, onset);
     56  for (i = 0; i < input->channels; i++) {
     57  isonset = onset->data[i][0];
     58  wasonset = o->wasonset->data[i][0];
    5559  if (isonset > 0.) {
    5660    if (aubio_silence_detection(input, o->silence)==1) {
     
    6872    wasonset++;
    6973  }
    70   o->wasonset = wasonset;
    71   onset->data[0][0] = isonset;
     74  o->wasonset->data[i][0] = wasonset;
     75  onset->data[i][0] = isonset;
     76  }
    7277  return;
    7378}
     
    98103  o->minioi    = 4;
    99104  o->silence   = -70;
    100   o->wasonset  = 0;
     105  o->wasonset  = new_fvec(1, channels);
    101106  o->samplerate = samplerate;
    102107  o->pv = new_aubio_pvoc(buf_size, hop_size, channels);
    103   o->pp = new_aubio_peakpicker(o->threshold);
     108  o->pp = new_aubio_peakpicker(channels);
     109  aubio_peakpicker_set_threshold (o->pp, o->threshold);
    104110  o->od = new_aubio_onsetdetection(onset_mode,buf_size,channels);
    105111  o->fftgrain = new_cvec(buf_size,channels);
     
    118124  del_aubio_pvoc(o->pv);
    119125  del_fvec(o->of);
     126  del_fvec(o->wasonset);
    120127  del_cvec(o->fftgrain);
    121128  AUBIO_FREE(o);
  • src/onset/peakpick.c

    r74516f7 r56ef7e1  
    5353        fvec_t * scratch;
    5454
     55  /** number of channels to analyse */
     56  uint_t channels;
     57
    5558        /** \bug should be used to calculate filter coefficients */
    5659        /* cutoff: low-pass filter cutoff [0.34, 1] */
     
    6871 * is slightly more permissive than the offline one, and yelds to an increase
    6972 * of false positives. best  */
    70 smpl_t aubio_peakpicker_do(aubio_peakpicker_t * p, fvec_t * onset) {
    71         fvec_t * onset_keep = (fvec_t *)p->onset_keep;
    72         fvec_t * onset_proc = (fvec_t *)p->onset_proc;
    73         fvec_t * onset_peek = (fvec_t *)p->onset_peek;
    74         fvec_t * scratch    = (fvec_t *)p->scratch;
    75         smpl_t mean = 0., median = 0.;
    76   smpl_t isonset = 0.;
    77         uint_t length = p->win_post + p->win_pre + 1;
    78         uint_t i = 0, j;
     73void
     74aubio_peakpicker_do (aubio_peakpicker_t * p, fvec_t * onset, fvec_t * out)
     75{
     76  fvec_t *onset_keep = p->onset_keep;
     77  fvec_t *onset_proc = p->onset_proc;
     78  fvec_t *onset_peek = p->onset_peek;
     79  fvec_t *scratch = p->scratch;
     80  smpl_t mean = 0., median = 0.;
     81  uint_t length = p->win_post + p->win_pre + 1;
     82  uint_t i, j = 0;
    7983
    80         /* store onset in onset_keep */
    81         /* shift all elements but last, then write last */
    82         /* for (i=0;i<channels;i++) { */
    83         for (j=0;j<length-1;j++) {
    84                 onset_keep->data[i][j] = onset_keep->data[i][j+1];
    85                 onset_proc->data[i][j] = onset_keep->data[i][j];
    86         }
    87         onset_keep->data[i][length-1] = onset->data[i][0];
    88         onset_proc->data[i][length-1] = onset->data[i][0];
    89         /* } */
     84  for (i = 0; i < p->channels; i++) {
     85    /* store onset in onset_keep */
     86    /* shift all elements but last, then write last */
     87    for (j = 0; j < length - 1; j++) {
     88      onset_keep->data[i][j] = onset_keep->data[i][j + 1];
     89      onset_proc->data[i][j] = onset_keep->data[i][j];
     90    }
     91    onset_keep->data[i][length - 1] = onset->data[i][0];
     92    onset_proc->data[i][length - 1] = onset->data[i][0];
     93  }
    9094
    91         /* filter onset_proc */
    92         /** \bug filtfilt calculated post+pre times, should be only once !? */
    93         aubio_biquad_do_filtfilt(p->biquad,onset_proc,scratch);
     95  /* filter onset_proc */
     96  /** \bug filtfilt calculated post+pre times, should be only once !? */
     97  //aubio_biquad_do_filtfilt(p->biquad,onset_proc,scratch);
    9498
    95         /* calculate mean and median for onset_proc */
    96         /* for (i=0;i<onset_proc->channels;i++) { */
    97         mean = fvec_mean(onset_proc);
    98         /* copy to scratch */
    99         for (j = 0; j < length; j++)
    100                 scratch->data[i][j] = onset_proc->data[i][j];
    101         median = p->thresholdfn(scratch);
    102         /* } */
     99  for (i = 0; i < p->channels; i++) {
     100    /* calculate mean and median for onset_proc */
     101    mean = fvec_mean_channel (onset_proc, i);
     102    /* copy to scratch */
     103    for (j = 0; j < length; j++)
     104      scratch->data[i][j] = onset_proc->data[i][j];
     105    median = p->thresholdfn (scratch, i);
    103106
    104         /* for (i=0;i<onset->channels;i++) { */
    105         /* shift peek array */
    106         for (j=0;j<3-1;j++)
    107                 onset_peek->data[i][j] = onset_peek->data[i][j+1];
    108         /* calculate new peek value */
    109         onset_peek->data[i][2] =
    110                 onset_proc->data[i][p->win_post] - median - mean * p->threshold;
    111         /* } */
    112         //AUBIO_DBG("%f\n", onset_peek->data[0][2]);
    113   isonset = (p->pickerfn)(onset_peek,1);
    114   if (isonset) { //(isonset) {
    115     isonset = fvec_quadint(onset_peek, 1, 1);
     107    /* shift peek array */
     108    for (j = 0; j < 3 - 1; j++)
     109      onset_peek->data[i][j] = onset_peek->data[i][j + 1];
     110    /* calculate new peek value */
     111    onset_peek->data[i][2] =
     112        onset_proc->data[i][p->win_post] - median - mean * p->threshold;
     113    out->data[i][0] = (p->pickerfn) (onset_peek, 1);
     114    if (out->data[i][0]) {
     115      out->data[i][0] = fvec_quadint (onset_peek, 1, i);
     116    }
    116117  }
    117         return isonset;
    118118}
    119119
     
    126126}
    127127
    128 /** function added by Miguel Ramirez to return the onset detection amplitude in peakval */
    129128uint_t aubio_peakpicker_set_threshold(aubio_peakpicker_t * p, smpl_t threshold) {
    130         p->threshold = threshold;
     129    p->threshold = threshold;
    131130        return AUBIO_OK;
    132131}
     
    145144}
    146145
    147 aubio_peakpicker_t * new_aubio_peakpicker(smpl_t threshold) {
     146aubio_peakpicker_t * new_aubio_peakpicker(uint_t channels) {
    148147        aubio_peakpicker_t * t = AUBIO_NEW(aubio_peakpicker_t);
    149148        t->threshold = 0.1; /* 0.0668; 0.33; 0.082; 0.033; */
    150         if (threshold > 0. && threshold < 10.)
    151                 t->threshold = threshold;
    152149        t->win_post  = 5;
    153150        t->win_pre   = 1;
     151  //channels = 1;
     152  t->channels = channels;
    154153
    155         t->thresholdfn = (aubio_thresholdfn_t)(fvec_median); /* (fvec_mean); */
     154        t->thresholdfn = (aubio_thresholdfn_t)(fvec_median_channel); /* (fvec_mean); */
    156155        t->pickerfn = (aubio_pickerfn_t)(fvec_peakpick);
    157156
    158         t->scratch = new_fvec(t->win_post+t->win_pre+1,1);
    159         t->onset_keep = new_fvec(t->win_post+t->win_pre+1,1);
    160         t->onset_proc = new_fvec(t->win_post+t->win_pre+1,1);
    161         t->onset_peek = new_fvec(3,1);
     157        t->scratch = new_fvec(t->win_post+t->win_pre+1, channels);
     158        t->onset_keep = new_fvec(t->win_post+t->win_pre+1, channels);
     159        t->onset_proc = new_fvec(t->win_post+t->win_pre+1, channels);
     160        t->onset_peek = new_fvec(3, channels);
    162161
    163162        /* cutoff: low-pass filter cutoff [0.34, 1] */
  • src/onset/peakpick.h

    r74516f7 r56ef7e1  
    3232
    3333/** function pointer to thresholding function */
    34 typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input);
     34typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input, uint_t channel);
    3535/** function pointer to peak-picking function */
    3636typedef uint_t (*aubio_pickerfn_t)(fvec_t *input, uint_t pos);
     
    3939
    4040/** peak-picker creation function */
    41 aubio_peakpicker_t * new_aubio_peakpicker(smpl_t threshold);
     41aubio_peakpicker_t * new_aubio_peakpicker(uint_t channels);
    4242/** real time peak picking function */
    43 smpl_t aubio_peakpicker_do(aubio_peakpicker_t * p, fvec_t * DF);
     43void aubio_peakpicker_do(aubio_peakpicker_t * p, fvec_t * in, fvec_t * out);
    4444/** get current peak value */
    4545smpl_t aubio_peakpicker_get_thresholded_input(aubio_peakpicker_t * p);
Note: See TracChangeset for help on using the changeset viewer.