Changeset c5c0c98


Ignore:
Timestamp:
Sep 12, 2009, 12:08:54 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:
fbe2cd2
Parents:
68a3fc9
Message:

src/mathutils.c: merge and fix vec_quadint_min and _max into simpler and more exact vec_quadint, use in src/pitch algorithms

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/mathutils.c

    r68a3fc9 rc5c0c98  
    286286}
    287287
    288 smpl_t vec_quadint(fvec_t * x,uint_t pos) {
    289   uint_t span = 2;
    290   smpl_t step = 1./200.;
    291   /* hack : init resold to - something (in case x[pos+-span]<0)) */
    292   smpl_t res, frac, s0, s1, s2, exactpos = (smpl_t)pos, resold = -1000.;
    293   if ((pos > span) && (pos < x->length-span)) {
    294     s0 = x->data[0][pos-span];
    295     s1 = x->data[0][pos]     ;
    296     s2 = x->data[0][pos+span];
    297     /* increase frac */
    298     for (frac = 0.; frac < 2.; frac = frac + step) {
    299       res = aubio_quadfrac(s0, s1, s2, frac);
    300       if (res > resold)
    301         resold = res;
    302       else {
    303         exactpos += (frac-step)*2. - 1.;
    304         break;
    305       }
    306     }
    307   }
    308   return exactpos;
    309 }
    310 
    311 smpl_t vec_quadint_min(fvec_t * x,uint_t pos, uint_t span) {
    312   smpl_t step = 1./200.;
    313   /* init resold to - something (in case x[pos+-span]<0)) */
    314   smpl_t res, frac, s0, s1, s2, exactpos = (smpl_t)pos, resold = 100000.;
    315   if ((pos > span) && (pos < x->length-span)) {
    316     s0 = x->data[0][pos-span];
    317     s1 = x->data[0][pos]     ;
    318     s2 = x->data[0][pos+span];
    319     /* increase frac */
    320     for (frac = 0.; frac < 2.; frac = frac + step) {
    321       res = aubio_quadfrac(s0, s1, s2, frac);
    322       if (res < resold) {
    323         resold = res;
    324       } else {
    325         exactpos += (frac-step)*span - span/2.;
    326         break;
    327       }
    328     }
    329   }
    330   return exactpos;
     288smpl_t vec_quadint(fvec_t * x,uint_t pos, uint_t span) {
     289  smpl_t s0, s1, s2;
     290  uint_t x0 = (pos < span) ? pos : pos - span;
     291  uint_t x2 = (pos + span < x->length) ? pos + span : pos;
     292  if (x0 == pos) return (x->data[0][pos] <= x->data[0][x2]) ? pos : x2;
     293  if (x2 == pos) return (x->data[0][pos] <= x->data[0][x0]) ? pos : x0;
     294  s0 = x->data[0][x0];
     295  s1 = x->data[0][pos]     ;
     296  s2 = x->data[0][x2];
     297  return pos + 0.5 * (s2 - s0 ) / (s2 - 2.* s1 + s0);
    331298}
    332299
  • src/mathutils.h

    r68a3fc9 rc5c0c98  
    162162smpl_t vec_median(fvec_t * input);
    163163
    164 /** finds exact maximum position by quadratic interpolation*/
    165 smpl_t vec_quadint(fvec_t * x,uint_t pos);
    166 
    167 /** finds exact minimum position by quadratic interpolation*/
    168 smpl_t vec_quadint_min(fvec_t * x,uint_t pos, uint_t span);
     164/** finds exact peak index by quadratic interpolation*/
     165smpl_t vec_quadint(fvec_t * x, uint_t pos, uint_t span);
    169166
    170167/** Quadratic interpolation using Lagrange polynomial.
  • src/pitch/pitchmcomb.c

    r68a3fc9 rc5c0c98  
    273273        count += ispeak;
    274274        spectral_peaks[count-1].bin = j;
    275         spectral_peaks[count-1].ebin = vec_quadint(X,j) - 1.;
     275        spectral_peaks[count-1].ebin = vec_quadint(X, j, 1) - 1.;
    276276      }
    277277    }
  • src/pitch/pitchyin.c

    r68a3fc9 rc5c0c98  
    107107    if(tau > 4 && (yin->data[c][period] < tol) &&
    108108        (yin->data[c][period] < yin->data[c][period+1])) {
    109       return vec_quadint_min(yin,period,1);
     109      return vec_quadint(yin,period,1);
    110110    }
    111111  }
    112   return vec_quadint_min(yin,vec_min_elem(yin),1);
     112  return vec_quadint(yin,vec_min_elem(yin),1);
    113113  //return 0;
    114114}
  • src/pitch/pitchyinfft.c

    r68a3fc9 rc5c0c98  
    129129    /* additional check for (unlikely) octave doubling in higher frequencies */
    130130    if (tau>35) {
    131       return vec_quadint_min(yin,tau,1);
     131      return vec_quadint(yin,tau,1);
    132132    } else {
    133133      /* should compare the minimum value of each interpolated peaks */
    134134      halfperiod = FLOOR(tau/2+.5);
    135135      if (yin->data[0][halfperiod] < tol)
    136         return vec_quadint_min(yin,halfperiod,1);
     136        return vec_quadint(yin,halfperiod,1);
    137137      else
    138         return vec_quadint_min(yin,tau,1);
     138        return vec_quadint(yin,tau,1);
    139139    }
    140140  } else
Note: See TracChangeset for help on using the changeset viewer.