Ignore:
Timestamp:
Dec 4, 2009, 1:34:44 AM (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:
d95ff38
Parents:
66fb3ea
Message:

src/onset: mono

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/onset/peakpicker.c

    r66fb3ea r0b9a02a  
    2828
    2929/** function pointer to thresholding function */
    30 typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input, uint_t channel);
     30typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input);
    3131/** function pointer to peak-picking function */
    3232typedef uint_t (*aubio_pickerfn_t)(fvec_t *input, uint_t pos);
     
    6969  fvec_t *scratch;
    7070
    71   /** number of channels to analyse */
    72   uint_t channels;
    73 
    7471        /** \bug should be used to calculate filter coefficients */
    7572  /* cutoff: low-pass filter cutoff [0.34, 1] */
     
    9794  smpl_t mean = 0., median = 0.;
    9895  uint_t length = p->win_post + p->win_pre + 1;
    99   uint_t i, j = 0;
    100 
    101   for (i = 0; i < p->channels; i++) {
    102     /* store onset in onset_keep */
    103     /* shift all elements but last, then write last */
    104     for (j = 0; j < length - 1; j++) {
    105       onset_keep->data[i][j] = onset_keep->data[i][j + 1];
    106       onset_proc->data[i][j] = onset_keep->data[i][j];
    107     }
    108     onset_keep->data[i][length - 1] = onset->data[i][0];
    109     onset_proc->data[i][length - 1] = onset->data[i][0];
     96  uint_t j = 0;
     97
     98  /* store onset in onset_keep */
     99  /* shift all elements but last, then write last */
     100  for (j = 0; j < length - 1; j++) {
     101    onset_keep->data[j] = onset_keep->data[j + 1];
     102    onset_proc->data[j] = onset_keep->data[j];
    110103  }
     104  onset_keep->data[length - 1] = onset->data[0];
     105  onset_proc->data[length - 1] = onset->data[0];
    111106
    112107  /* filter onset_proc */
     
    114109  aubio_filter_do_filtfilt (p->biquad, onset_proc, scratch);
    115110
    116   for (i = 0; i < p->channels; i++) {
    117     /* calculate mean and median for onset_proc */
    118     mean = fvec_mean_channel (onset_proc, i);
    119     /* copy to scratch */
    120     for (j = 0; j < length; j++)
    121       scratch->data[i][j] = onset_proc->data[i][j];
    122     median = p->thresholdfn (scratch, i);
    123 
    124     /* shift peek array */
    125     for (j = 0; j < 3 - 1; j++)
    126       onset_peek->data[i][j] = onset_peek->data[i][j + 1];
    127     /* calculate new tresholded value */
    128     thresholded->data[i][0] =
    129         onset_proc->data[i][p->win_post] - median - mean * p->threshold;
    130     onset_peek->data[i][2] = thresholded->data[i][0];
    131     out->data[i][0] = (p->pickerfn) (onset_peek, 1);
    132     if (out->data[i][0]) {
    133       out->data[i][0] = fvec_quadint (onset_peek, 1, i);
    134     }
     111  /* calculate mean and median for onset_proc */
     112  mean = fvec_mean (onset_proc);
     113  /* copy to scratch */
     114  for (j = 0; j < length; j++)
     115    scratch->data[j] = onset_proc->data[j];
     116  median = p->thresholdfn (scratch);
     117
     118  /* shift peek array */
     119  for (j = 0; j < 3 - 1; j++)
     120    onset_peek->data[j] = onset_peek->data[j + 1];
     121  /* calculate new tresholded value */
     122  thresholded->data[0] =
     123      onset_proc->data[p->win_post] - median - mean * p->threshold;
     124  onset_peek->data[2] = thresholded->data[0];
     125  out->data[0] = (p->pickerfn) (onset_peek, 1);
     126  if (out->data[0]) {
     127    out->data[0] = fvec_quadint (onset_peek, 1);
    135128  }
    136129}
     
    173166
    174167aubio_peakpicker_t *
    175 new_aubio_peakpicker (uint_t channels)
     168new_aubio_peakpicker ()
    176169{
    177170  aubio_peakpicker_t *t = AUBIO_NEW (aubio_peakpicker_t);
     
    179172  t->win_post = 5;
    180173  t->win_pre = 1;
    181   //channels = 1;
    182   t->channels = channels;
    183 
    184   t->thresholdfn = (aubio_thresholdfn_t) (fvec_median_channel); /* (fvec_mean); */
     174
     175  t->thresholdfn = (aubio_thresholdfn_t) (fvec_median); /* (fvec_mean); */
    185176  t->pickerfn = (aubio_pickerfn_t) (fvec_peakpick);
    186177
    187   t->scratch = new_fvec (t->win_post + t->win_pre + 1, channels);
    188   t->onset_keep = new_fvec (t->win_post + t->win_pre + 1, channels);
    189   t->onset_proc = new_fvec (t->win_post + t->win_pre + 1, channels);
    190   t->onset_peek = new_fvec (3, channels);
    191   t->thresholded = new_fvec (1, channels);
     178  t->scratch = new_fvec (t->win_post + t->win_pre + 1);
     179  t->onset_keep = new_fvec (t->win_post + t->win_pre + 1);
     180  t->onset_proc = new_fvec (t->win_post + t->win_pre + 1);
     181  t->onset_peek = new_fvec (3);
     182  t->thresholded = new_fvec (1);
    192183
    193184  /* cutoff: low-pass filter with cutoff reduced frequency at 0.34
     
    195186   */
    196187  t->biquad = new_aubio_filter_biquad (0.15998789, 0.31997577, 0.15998789,
    197       -0.59488894, 0.23484048, channels);
     188      -0.59488894, 0.23484048);
    198189
    199190  return t;
Note: See TracChangeset for help on using the changeset viewer.