Changeset 56ef7e1 for src/mathutils.c


Ignore:
Timestamp:
Oct 18, 2009, 3:08:59 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:
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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mathutils.c

    r74516f7 r56ef7e1  
    142142
    143143smpl_t
     144fvec_mean_channel (fvec_t * s, uint_t i)
     145{
     146  uint_t j;
     147  smpl_t tmp = 0.0;
     148  for (j = 0; j < s->length; j++)
     149      tmp += s->data[i][j];
     150  return tmp / (smpl_t) (s->length);
     151}
     152
     153smpl_t
    144154fvec_sum (fvec_t * s)
    145155{
     
    289299
    290300void fvec_adapt_thres(fvec_t * vec, fvec_t * tmp,
    291     uint_t post, uint_t pre) {
    292   uint_t length = vec->length, i=0, j;
     301    uint_t post, uint_t pre, uint_t channel) {
     302  uint_t length = vec->length, i=channel, j;
    293303  for (j=0;j<length;j++) {
    294     vec->data[i][j] -= fvec_moving_thres(vec, tmp, post, pre, j);
     304    vec->data[i][j] -= fvec_moving_thres(vec, tmp, post, pre, j, i);
    295305  }
    296306}
     
    298308smpl_t
    299309fvec_moving_thres (fvec_t * vec, fvec_t * tmpvec,
    300     uint_t post, uint_t pre, uint_t pos)
    301 {
    302   smpl_t *medar = (smpl_t *) tmpvec->data[0];
    303   uint_t k;
     310    uint_t post, uint_t pre, uint_t pos, uint_t channel)
     311{
     312  uint_t i = channel, k;
     313  smpl_t *medar = (smpl_t *) tmpvec->data[i];
    304314  uint_t win_length = post + pre + 1;
    305315  uint_t length = vec->length;
     
    321331      medar[k] = 0.;            /* 0-padding at the end */
    322332  }
    323   return fvec_median (tmpvec);
    324 }
    325 
    326 smpl_t fvec_median(fvec_t * input) {
     333  return fvec_median_channel (tmpvec, i);
     334}
     335
     336smpl_t fvec_median_channel (fvec_t * input, uint_t channel) {
    327337  uint_t n = input->length;
    328   smpl_t * arr = (smpl_t *) input->data[0];
     338  smpl_t * arr = (smpl_t *) input->data[channel];
    329339  uint_t low, high ;
    330340  uint_t median;
     
    375385}
    376386
    377 smpl_t fvec_quadint(fvec_t * x,uint_t pos, uint_t span) {
     387smpl_t fvec_quadint (fvec_t * x, uint_t pos, uint_t i) {
    378388  smpl_t s0, s1, s2;
    379   uint_t x0 = (pos < span) ? pos : pos - span;
    380   uint_t x2 = (pos + span < x->length) ? pos + span : pos;
    381   if (x0 == pos) return (x->data[0][pos] <= x->data[0][x2]) ? pos : x2;
    382   if (x2 == pos) return (x->data[0][pos] <= x->data[0][x0]) ? pos : x0;
    383   s0 = x->data[0][x0];
    384   s1 = x->data[0][pos];
    385   s2 = x->data[0][x2];
     389  uint_t x0 = (pos < 1) ? pos : pos - 1;
     390  uint_t x2 = (pos + 1 < x->length) ? pos + 1 : pos;
     391  if (x0 == pos) return (x->data[i][pos] <= x->data[i][x2]) ? pos : x2;
     392  if (x2 == pos) return (x->data[i][pos] <= x->data[i][x0]) ? pos : x0;
     393  s0 = x->data[i][x0];
     394  s1 = x->data[i][pos];
     395  s2 = x->data[i][x2];
    386396  return pos + 0.5 * (s2 - s0 ) / (s2 - 2.* s1 + s0);
    387397}
Note: See TracChangeset for help on using the changeset viewer.