Changeset 0b9a02a for src


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

Location:
src/onset
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/onset/onset.c

    r66fb3ea r0b9a02a  
    4848  smpl_t isonset = 0;
    4949  smpl_t wasonset = 0;
    50   uint_t i;
    5150  aubio_pvoc_do (o->pv,input, o->fftgrain);
    5251  aubio_specdesc_do (o->od,o->fftgrain, o->of);
    53   /*if (usedoubled) {
    54     aubio_specdesc_do (o2,fftgrain, onset2);
    55     onset->data[0][0] *= onset2->data[0][0];
    56   }*/
    5752  aubio_peakpicker_do(o->pp, o->of, onset);
    58   for (i = 0; i < input->channels; i++) {
    59   isonset = onset->data[i][0];
    60   wasonset = o->wasonset->data[i][0];
     53  isonset = onset->data[0];
     54  wasonset = o->wasonset->data[0];
    6155  if (isonset > 0.) {
    6256    if (aubio_silence_detection(input, o->silence)==1) {
     
    7468    wasonset++;
    7569  }
    76   o->wasonset->data[i][0] = wasonset;
    77   onset->data[i][0] = isonset;
    78   }
     70  o->wasonset->data[0] = wasonset;
     71  onset->data[0] = isonset;
    7972  return;
    8073}
     
    9891/* Allocate memory for an onset detection */
    9992aubio_onset_t * new_aubio_onset (char_t * onset_mode,
    100     uint_t buf_size, uint_t hop_size, uint_t channels, uint_t samplerate)
     93    uint_t buf_size, uint_t hop_size, uint_t samplerate)
    10194{
    10295  aubio_onset_t * o = AUBIO_NEW(aubio_onset_t);
     
    10598  o->minioi    = 4;
    10699  o->silence   = -70;
    107   o->wasonset  = new_fvec(1, channels);
     100  o->wasonset  = new_fvec(1);
    108101  o->samplerate = samplerate;
    109102  o->hop_size = hop_size;
    110   o->pv = new_aubio_pvoc(buf_size, hop_size, channels);
    111   o->pp = new_aubio_peakpicker(channels);
     103  o->pv = new_aubio_pvoc(buf_size, hop_size);
     104  o->pp = new_aubio_peakpicker();
    112105  aubio_peakpicker_set_threshold (o->pp, o->threshold);
    113   o->od = new_aubio_specdesc(onset_mode,buf_size,channels);
    114   o->fftgrain = new_cvec(buf_size,channels);
    115   o->of = new_fvec(1, channels);
     106  o->od = new_aubio_specdesc(onset_mode,buf_size);
     107  o->fftgrain = new_cvec(buf_size);
     108  o->of = new_fvec(1);
    116109  /*if (usedoubled)    {
    117     o2 = new_aubio_specdesc(onset_type2,buffer_size,channels);
    118     onset2 = new_fvec(1 , channels);
     110    o2 = new_aubio_specdesc(onset_type2,buffer_size);
     111    onset2 = new_fvec(1);
    119112  }*/
    120113  return o;
  • src/onset/onset.h

    r66fb3ea r0b9a02a  
    5050  \param buf_size buffer size for phase vocoder
    5151  \param hop_size hop size for phase vocoder
    52   \param channels number of channels
    5352  \param samplerate sampling rate of the input signal
    5453
    5554*/
    5655aubio_onset_t * new_aubio_onset (char_t * method,
    57     uint_t buf_size, uint_t hop_size, uint_t channels, uint_t samplerate);
     56    uint_t buf_size, uint_t hop_size, uint_t samplerate);
    5857
    5958/** execute onset detection
  • 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;
  • src/onset/peakpicker.h

    r66fb3ea r0b9a02a  
    3636
    3737/** peak-picker creation function */
    38 aubio_peakpicker_t * new_aubio_peakpicker(uint_t channels);
     38aubio_peakpicker_t * new_aubio_peakpicker();
    3939/** real time peak picking function */
    4040void aubio_peakpicker_do(aubio_peakpicker_t * p, fvec_t * in, fvec_t * out);
Note: See TracChangeset for help on using the changeset viewer.