Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/pitch/pitchyin.c

    rfddfa64 r168337e  
    6565{
    6666  aubio_pitchyin_t *o = AUBIO_NEW (aubio_pitchyin_t);
    67   o->yin = new_fvec (bufsize / 2, 1);
     67  o->yin = new_fvec (bufsize / 2);
    6868  o->tol = 0.15;
    6969  return o;
     
    8181aubio_pitchyin_diff (fvec_t * input, fvec_t * yin)
    8282{
    83   uint_t c, j, tau;
     83  uint_t j, tau;
    8484  smpl_t tmp;
    85   for (c = 0; c < input->channels; c++) {
    86     for (tau = 0; tau < yin->length; tau++) {
    87       yin->data[c][tau] = 0.;
    88     }
    89     for (tau = 1; tau < yin->length; tau++) {
    90       for (j = 0; j < yin->length; j++) {
    91         tmp = input->data[c][j] - input->data[c][j + tau];
    92         yin->data[c][tau] += SQR (tmp);
    93       }
     85  for (tau = 0; tau < yin->length; tau++) {
     86    yin->data[tau] = 0.;
     87  }
     88  for (tau = 1; tau < yin->length; tau++) {
     89    for (j = 0; j < yin->length; j++) {
     90      tmp = input->data[j] - input->data[j + tau];
     91      yin->data[tau] += SQR (tmp);
    9492    }
    9593  }
     
    10098aubio_pitchyin_getcum (fvec_t * yin)
    10199{
    102   uint_t c, tau;
     100  uint_t tau;
    103101  smpl_t tmp;
    104   for (c = 0; c < yin->channels; c++) {
    105     tmp = 0.;
    106     yin->data[c][0] = 1.;
    107     //AUBIO_DBG("%f\t",yin->data[c][0]);
    108     for (tau = 1; tau < yin->length; tau++) {
    109       tmp += yin->data[c][tau];
    110       yin->data[c][tau] *= tau / tmp;
    111       //AUBIO_DBG("%f\t",yin->data[c][tau]);
    112     }
    113     //AUBIO_DBG("\n");
     102  tmp = 0.;
     103  yin->data[0] = 1.;
     104  //AUBIO_DBG("%f\t",yin->data[0]);
     105  for (tau = 1; tau < yin->length; tau++) {
     106    tmp += yin->data[tau];
     107    yin->data[tau] *= tau / tmp;
     108    //AUBIO_DBG("%f\t",yin->data[tau]);
    114109  }
     110  //AUBIO_DBG("\n");
    115111}
    116112
     
    118114aubio_pitchyin_getpitch (fvec_t * yin)
    119115{
    120   uint_t c = 0, tau = 1;
     116  uint_t tau = 1;
    121117  do {
    122     if (yin->data[c][tau] < 0.1) {
    123       while (yin->data[c][tau + 1] < yin->data[c][tau]) {
     118    if (yin->data[tau] < 0.1) {
     119      while (yin->data[tau + 1] < yin->data[tau]) {
    124120        tau++;
    125121      }
     
    139135  smpl_t tol = o->tol;
    140136  fvec_t *yin = o->yin;
    141   uint_t c, j, tau = 0;
     137  uint_t j, tau = 0;
    142138  sint_t period;
    143139  smpl_t tmp = 0., tmp2 = 0.;
    144   for (c = 0; c < input->channels; c++) {
    145     yin->data[c][0] = 1.;
    146     for (tau = 1; tau < yin->length; tau++) {
    147       yin->data[c][tau] = 0.;
    148       for (j = 0; j < yin->length; j++) {
    149         tmp = input->data[c][j] - input->data[c][j + tau];
    150         yin->data[c][tau] += SQR (tmp);
    151       }
    152       tmp2 += yin->data[c][tau];
    153       yin->data[c][tau] *= tau / tmp2;
    154       period = tau - 3;
    155       if (tau > 4 && (yin->data[c][period] < tol) &&
    156           (yin->data[c][period] < yin->data[c][period + 1])) {
    157         out->data[c][0] = fvec_quadint (yin, period, c);
    158         goto beach;
    159       }
     140  yin->data[0] = 1.;
     141  for (tau = 1; tau < yin->length; tau++) {
     142    yin->data[tau] = 0.;
     143    for (j = 0; j < yin->length; j++) {
     144      tmp = input->data[j] - input->data[j + tau];
     145      yin->data[tau] += SQR (tmp);
    160146    }
    161     out->data[c][0] = fvec_quadint (yin, fvec_min_elem (yin), c);
    162   beach:
    163     continue;
     147    tmp2 += yin->data[tau];
     148    yin->data[tau] *= tau / tmp2;
     149    period = tau - 3;
     150    if (tau > 4 && (yin->data[period] < tol) &&
     151        (yin->data[period] < yin->data[period + 1])) {
     152      out->data[0] = fvec_quadint (yin, period);
     153      goto beach;
     154    }
    164155  }
    165   //return 0;
     156  out->data[0] = fvec_quadint (yin, fvec_min_elem (yin));
     157beach:
     158  return;
    166159}
    167160
Note: See TracChangeset for help on using the changeset viewer.