Changeset 18a82b3 for src


Ignore:
Timestamp:
Nov 7, 2007, 5:21:00 PM (17 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:
8701ec3
Parents:
4b6937b (diff), b050e8e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge from rhubarb

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/pitchfcomb.c

    r4b6937b r18a82b3  
    3232
    3333struct _aubio_pitchfcomb_t {
    34         uint_t fftSize;
    35         uint_t stepSize;
    36         uint_t rate;
    37         fvec_t * winput;
    38         fvec_t * win;
    39         cvec_t * fftOut;
    40         fvec_t * fftLastPhase;
    41         aubio_fft_t * fft;
    42         //aubio_pvoc_t * pvoc;
     34  uint_t fftSize;
     35  uint_t stepSize;
     36  uint_t rate;
     37  fvec_t * winput;
     38  fvec_t * win;
     39  cvec_t * fftOut;
     40  fvec_t * fftLastPhase;
     41  aubio_fft_t * fft;
     42  //aubio_pvoc_t * pvoc;
    4343};
    4444
     
    4848  p->rate         = samplerate;
    4949  p->fftSize      = bufsize;
    50   p->stepSize     = hopsize; 
     50  p->stepSize     = hopsize;
    5151  p->winput       = new_fvec(bufsize,1);
    5252  p->fftOut       = new_cvec(bufsize,1);
     
    7272
    7373  for (k=0; k < input->length; k++){
    74           p->winput->data[0][k] = p->win->data[0][k] * input->data[0][k];
     74    p->winput->data[0][k] = p->win->data[0][k] * input->data[0][k];
    7575  }
    7676  aubio_fft_do(p->fft,p->winput,p->fftOut);
     
    104104    }
    105105  }
    106  
     106
    107107  k = 0;
    108108  for (l=1; l<MAX_PEAKS && peaks[l].freq > 0.0; l++) {
     
    110110    for (harmonic=5; harmonic>1; harmonic--) {
    111111      if (peaks[0].freq / peaks[l].freq < harmonic+.02 &&
    112         peaks[0].freq / peaks[l].freq > harmonic-.02) {
     112          peaks[0].freq / peaks[l].freq > harmonic-.02) {
    113113        if (harmonic > (sint_t)maxharm &&
    114           peaks[0].db < peaks[l].db/2) {
     114            peaks[0].db < peaks[l].db/2) {
    115115          maxharm = harmonic;
    116           k = l;
     116          k = l;
    117117        }
    118118      }
  • src/pitchmcomb.c

    r4b6937b r18a82b3  
    9797  for (j=0; j< newmag->length; j++)
    9898    newmag->data[i][j]=fftgrain->norm[i][j];
    99   /* detect only if local energy > 10. */ 
     99  /* detect only if local energy > 10. */
    100100  //if (vec_local_energy(newmag)>10.) {
    101101    //hfc = vec_local_hfc(newmag); //not used
     
    106106  j = (uint_t)FLOOR(p->candidates[p->goodcandidate]->ebin+.5);
    107107  instfreq  = aubio_unwrap2pi(fftgrain->phas[0][j]
    108                   - p->theta->data[0][j] - j*p->phasediff);
     108      - p->theta->data[0][j] - j*p->phasediff);
    109109  instfreq *= p->phasefreq;
    110110  /* store phase for next run */
     
    119119}
    120120
    121 uint_t aubio_pitch_cands(aubio_pitchmcomb_t * p, cvec_t * fftgrain, 
     121uint_t aubio_pitch_cands(aubio_pitchmcomb_t * p, cvec_t * fftgrain,
    122122    smpl_t * cands) {
    123123  uint_t i=0,j;
    124124  uint_t k;
    125125  fvec_t * newmag = (fvec_t *)p->newmag;
    126   aubio_spectralcandidate_t ** scands = 
     126  aubio_spectralcandidate_t ** scands =
    127127    (aubio_spectralcandidate_t **)(p->candidates);
    128128  //smpl_t hfc; //fe=instfreq(theta1,theta,ops); //theta1=theta;
     
    130130  for (j=0; j< newmag->length; j++)
    131131    newmag->data[i][j]=fftgrain->norm[i][j];
    132   /* detect only if local energy > 10. */ 
    133   if (vec_local_energy(newmag)>10.)     {
     132  /* detect only if local energy > 10. */
     133  if (vec_local_energy(newmag)>10.) {
    134134    /* hfc = vec_local_hfc(newmag); do not use */
    135135    aubio_pitchmcomb_spectral_pp(p, newmag);
    136136    aubio_pitchmcomb_combdet(p,newmag);
    137137    aubio_pitchmcomb_sort_cand_freq(scands,p->ncand);
    138     /* store ncand comb energies in cands[1:ncand] */ 
    139     for (k = 0; k<p->ncand; k++) 
     138    /* store ncand comb energies in cands[1:ncand] */
     139    for (k = 0; k<p->ncand; k++)
    140140      cands[k] = p->candidates[k]->ene;
    141     /* store ncand[end] freq in cands[end] */ 
     141    /* store ncand[end] freq in cands[end] */
    142142    cands[p->ncand] = p->candidates[p->ncand-1]->ebin;
    143143    return 1;
     
    156156  /* copy newmag to mag (scracth) */
    157157  for (j=0;j<length;j++) {
    158     mag->data[i][j] = newmag->data[i][j]; 
     158    mag->data[i][j] = newmag->data[i][j];
    159159  }
    160160  vec_dc_removal(mag);               /* dc removal           */
     
    169169    /*  return bin and ebin */
    170170    count = aubio_pitchmcomb_quadpick(peaks,mag);
    171     for (j=0;j<count;j++) 
     171    for (j=0;j<count;j++)
    172172      peaks[j].mag = newmag->data[i][peaks[j].bin];
    173173    /* reset non peaks */
     
    181181void aubio_pitchmcomb_combdet(aubio_pitchmcomb_t * p, fvec_t * newmag) {
    182182  aubio_spectralpeak_t * peaks = (aubio_spectralpeak_t *)p->peaks;
    183   aubio_spectralcandidate_t ** candidate = 
     183  aubio_spectralcandidate_t ** candidate =
    184184    (aubio_spectralcandidate_t **)p->candidates;
    185185
     
    224224    for (k=0;k<curlen;k++) {
    225225      xx = 100000.;
    226       /** get the candidate->ecomb the closer to peaks.ebin 
     226      /** get the candidate->ecomb the closer to peaks.ebin
    227227       * (to cope with the inharmonicity)*/
    228       for (d=0;d<count;d++) { 
     228      for (d=0;d<count;d++) {
    229229        delta2 = ABS(candidate[l]->ecomb[k]-peaks[d].ebin);
    230230        if (delta2 <= xx) {
     
    233233        }
    234234      }
    235       /* for a Q factor of 17, maintaining "constant Q filtering", 
     235      /* for a Q factor of 17, maintaining "constant Q filtering",
    236236       * and sum energy and length over non null combs */
    237237      if ( 17. * xx < candidate[l]->ecomb[k] ) {
     
    261261 * exact peak positions are retrieved by quadratic interpolation
    262262 *
    263  * \bug peak-picking too picky, sometimes counts too many peaks ? 
     263 * \bug peak-picking too picky, sometimes counts too many peaks ?
    264264 */
    265265uint_t aubio_pitchmcomb_quadpick(aubio_spectralpeak_t * spectral_peaks, fvec_t * X){
    266266  uint_t i, j, ispeak, count = 0;
    267267  for (i=0;i<X->channels;i++)
    268     for (j=1;j<X->length-1;j++) {
     268    for (j=1;j<X->length-1;j++) {
    269269      ispeak = vec_peakpick(X,j);
    270270      if (ispeak) {
     
    290290
    291291void aubio_pitchmcomb_sort_peak(aubio_spectralpeak_t * peaks, uint_t nbins) {
    292   qsort(peaks, nbins, sizeof(aubio_spectralpeak_t), 
     292  qsort(peaks, nbins, sizeof(aubio_spectralpeak_t),
    293293      aubio_pitchmcomb_sort_peak_comp);
    294294}
  • src/pitchyinfft.c

    r4b6937b r18a82b3  
    3636
    3737static const smpl_t freqs[] = {0., 20., 25., 31.5, 40., 50., 63., 80., 100.,
    38         125., 160., 200., 250., 315., 400., 500., 630., 800., 1000., 1250.,
    39         1600., 2000., 2500., 3150., 4000., 5000., 6300., 8000., 9000., 10000.,
    40         12500., 15000., 20000.,  25100};
     38  125., 160., 200., 250., 315., 400., 500., 630., 800., 1000., 1250.,
     39  1600., 2000., 2500., 3150., 4000., 5000., 6300., 8000., 9000., 10000.,
     40  12500., 15000., 20000.,  25100};
    4141
    4242static const smpl_t weight[] = {-75.8, -70.1, -60.8, -52.1, -44.2, -37.5,
    43         -31.3, -25.6, -20.9, -16.5, -12.6, -9.6, -7.0, -4.7, -3.0, -1.8, -0.8,
    44         -0.2, -0.0, 0.5, 1.6, 3.2, 5.4, 7.8, 8.1, 5.3, -2.4, -11.1, -12.8,
    45         -12.2, -7.4, -17.8, -17.8, -17.8};
     43  -31.3, -25.6, -20.9, -16.5, -12.6, -9.6, -7.0, -4.7, -3.0, -1.8, -0.8,
     44  -0.2, -0.0, 0.5, 1.6, 3.2, 5.4, 7.8, 8.1, 5.3, -2.4, -11.1, -12.8,
     45  -12.2, -7.4, -17.8, -17.8, -17.8};
    4646
    4747aubio_pitchyinfft_t * new_aubio_pitchyinfft (uint_t bufsize)
    4848{
    4949  aubio_pitchyinfft_t * p = AUBIO_NEW(aubio_pitchyinfft_t);
    50   p->winput       = new_fvec(bufsize,1);
    51   p->fft          = new_aubio_fft(bufsize, 1);
    52   p->fftout       = new_cvec(bufsize,1);
    53   p->sqrmag       = new_fvec(bufsize,1);
    54   p->res          = new_cvec(bufsize,1);
    55   p->yinfft       = new_fvec(bufsize/2+1,1);
    56   p->win          = new_fvec(bufsize,1);
     50  p->winput = new_fvec(bufsize,1);
     51  p->fft    = new_aubio_fft(bufsize, 1);
     52  p->fftout = new_cvec(bufsize,1);
     53  p->sqrmag = new_fvec(bufsize,1);
     54  p->res    = new_cvec(bufsize,1);
     55  p->yinfft = new_fvec(bufsize/2+1,1);
     56  p->win    = new_fvec(bufsize,1);
    5757  aubio_window(p->win->data[0], bufsize, aubio_win_hanningz);
    5858  p->weight      = new_fvec(bufsize/2+1,1);
    5959  {
    60           uint_t i = 0, j = 1;
    61           smpl_t freq = 0, a0 = 0, a1 = 0, f0 = 0, f1 = 0;
    62           for (i=0; i<p->weight->length; i++) {
    63                   freq = (smpl_t)i/(smpl_t)bufsize*(smpl_t)44100.;
    64                   while (freq > freqs[j]) {
    65                           j +=1;
    66                   }
    67                   a0 = weight[j-1];
    68                   f0 = freqs[j-1];
    69                   a1 = weight[j];
    70                   f1 = freqs[j];
    71                   if (f0 == f1) { // just in case
    72                           p->weight->data[0][i] = a0;
    73                   } else if (f0 == 0) { // y = ax+b
    74                           p->weight->data[0][i] = (a1-a0)/f1*freq + a0;
    75                   } else {
    76                           p->weight->data[0][i] = (a1-a0)/(f1-f0)*freq +
    77                                   (a0 - (a1 - a0)/(f1/f0 - 1.));
    78                   }
    79                   while (freq > freqs[j]) {
    80                           j +=1;
    81                   }
    82                   //AUBIO_DBG("%f\n",p->weight->data[0][i]);
    83                   p->weight->data[0][i] = DB2LIN(p->weight->data[0][i]);
    84                   //p->weight->data[0][i] = SQRT(DB2LIN(p->weight->data[0][i]));
    85           }
     60    uint_t i = 0, j = 1;
     61    smpl_t freq = 0, a0 = 0, a1 = 0, f0 = 0, f1 = 0;
     62    for (i=0; i<p->weight->length; i++) {
     63      freq = (smpl_t)i/(smpl_t)bufsize*(smpl_t)44100.;
     64      while (freq > freqs[j]) {
     65        j +=1;
     66            }
     67      a0 = weight[j-1];
     68      f0 = freqs[j-1];
     69            a1 = weight[j];
     70      f1 = freqs[j];
     71      if (f0 == f1) { // just in case
     72        p->weight->data[0][i] = a0;
     73      } else if (f0 == 0) { // y = ax+b
     74        p->weight->data[0][i] = (a1-a0)/f1*freq + a0;
     75      } else {
     76        p->weight->data[0][i] = (a1-a0)/(f1-f0)*freq +
     77          (a0 - (a1 - a0)/(f1/f0 - 1.));
     78      }
     79      while (freq > freqs[j]) {
     80        j +=1;
     81      }
     82      //AUBIO_DBG("%f\n",p->weight->data[0][i]);
     83      p->weight->data[0][i] = DB2LIN(p->weight->data[0][i]);
     84      //p->weight->data[0][i] = SQRT(DB2LIN(p->weight->data[0][i]));
     85    }
    8686  }
    8787  return p;
     
    9595  fvec_t * yin = (fvec_t *)p->yinfft;
    9696  for (l=0; l < input->length; l++){
    97           p->winput->data[0][l] = p->win->data[0][l] * input->data[0][l];
     97    p->winput->data[0][l] = p->win->data[0][l] * input->data[0][l];
    9898  }
    9999  aubio_fft_do(p->fft,p->winput,p->fftout);
    100100  for (l=0; l < p->fftout->length; l++){
    101           p->sqrmag->data[0][l] = SQR(p->fftout->norm[0][l]);
    102           p->sqrmag->data[0][l] *= p->weight->data[0][l];
     101    p->sqrmag->data[0][l] = SQR(p->fftout->norm[0][l]);
     102    p->sqrmag->data[0][l] *= p->weight->data[0][l];
    103103  }
    104104  for (l=1; l < p->fftout->length; l++){
    105           p->sqrmag->data[0][(p->fftout->length-1)*2-l] =
    106            SQR(p->fftout->norm[0][l]);
    107           p->sqrmag->data[0][(p->fftout->length-1)*2-l] *=
    108                 p->weight->data[0][l];
     105    p->sqrmag->data[0][(p->fftout->length-1)*2-l] =
     106     SQR(p->fftout->norm[0][l]);
     107    p->sqrmag->data[0][(p->fftout->length-1)*2-l] *=
     108    p->weight->data[0][l];
    109109  }
    110110  for (l=0; l < p->sqrmag->length/2+1; l++) {
    111           sum += p->sqrmag->data[0][l];
     111    sum += p->sqrmag->data[0][l];
    112112  }
    113113  sum *= 2.;
    114114  aubio_fft_do(p->fft,p->sqrmag,res);
    115   yin->data[0][0] = 1.; 
     115  yin->data[0][0] = 1.;
    116116  for (tau=1; tau < yin->length; tau++) {
    117           yin->data[0][tau] = sum -
    118                   res->norm[0][tau]*COS(res->phas[0][tau]);
    119           tmp += yin->data[0][tau];
    120           yin->data[0][tau] *= tau/tmp;
     117    yin->data[0][tau] = sum -
     118      res->norm[0][tau]*COS(res->phas[0][tau]);
     119    tmp += yin->data[0][tau];
     120    yin->data[0][tau] *= tau/tmp;
    121121  }
    122   tau = vec_min_elem(yin); 
     122  tau = vec_min_elem(yin);
    123123  if (yin->data[0][tau] < tol) {
    124           /* no interpolation */
    125           //return tau;
    126           /* 3 point quadratic interpolation */
    127           //return vec_quadint_min(yin,tau,1);
    128           /* additional check for (unlikely) octave doubling in higher frequencies */
    129           if (tau>35) {
    130                   return vec_quadint_min(yin,tau,1);
    131           } else {
    132                   /* should compare the minimum value of each interpolated peaks */
    133                   halfperiod = FLOOR(tau/2+.5);
    134                   if (yin->data[0][halfperiod] < tol)
    135                           return vec_quadint_min(yin,halfperiod,1);
    136                   else
    137                           return vec_quadint_min(yin,tau,1);
    138           }
     124    /* no interpolation */
     125    //return tau;
     126    /* 3 point quadratic interpolation */
     127    //return vec_quadint_min(yin,tau,1);
     128    /* additional check for (unlikely) octave doubling in higher frequencies */
     129    if (tau>35) {
     130      return vec_quadint_min(yin,tau,1);
     131    } else {
     132      /* should compare the minimum value of each interpolated peaks */
     133      halfperiod = FLOOR(tau/2+.5);
     134      if (yin->data[0][halfperiod] < tol)
     135        return vec_quadint_min(yin,halfperiod,1);
     136      else
     137        return vec_quadint_min(yin,tau,1);
     138    }
    139139  } else
    140           return 0;
     140    return 0;
    141141}
    142142
    143143void del_aubio_pitchyinfft(aubio_pitchyinfft_t *p){
    144         del_fvec(p->win);
    145         del_aubio_fft(p->fft);
    146         del_fvec(p->yinfft);
    147         del_fvec(p->sqrmag);
    148         del_cvec(p->res);
    149         del_cvec(p->fftout);
    150         del_fvec(p->winput);
    151         del_fvec(p->weight);
    152         AUBIO_FREE(p);
     144  del_fvec(p->win);
     145  del_aubio_fft(p->fft);
     146  del_fvec(p->yinfft);
     147  del_fvec(p->sqrmag);
     148  del_cvec(p->res);
     149  del_cvec(p->fftout);
     150  del_fvec(p->winput);
     151  del_fvec(p->weight);
     152  AUBIO_FREE(p);
    153153}
Note: See TracChangeset for help on using the changeset viewer.