Ignore:
Timestamp:
Dec 4, 2009, 1:44:41 AM (14 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:
02a01dd
Parents:
fc61225
Message:

src/pitch: switch to mono

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/pitch/pitchmcomb.c

    rfc61225 r168337e  
    104104aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, cvec_t * fftgrain, fvec_t * output)
    105105{
    106   uint_t i, j;
     106  uint_t j;
    107107  smpl_t instfreq;
    108108  fvec_t *newmag = (fvec_t *) p->newmag;
    109109  //smpl_t hfc; //fe=instfreq(theta1,theta,ops); //theta1=theta;
    110110  /* copy incoming grain to newmag */
    111   for (i = 0; i < fftgrain->channels; i++) {
    112     for (j = 0; j < newmag->length; j++)
    113       newmag->data[0][j] = fftgrain->norm[i][j];
    114     /* detect only if local energy > 10. */
    115     //if (fvec_local_energy(newmag)>10.) {
    116     //hfc = fvec_local_hfc(newmag); //not used
    117     aubio_pitchmcomb_spectral_pp (p, newmag);
    118     aubio_pitchmcomb_combdet (p, newmag);
    119     //aubio_pitchmcomb_sort_cand_freq(p->candidates,p->ncand);
    120     //return p->candidates[p->goodcandidate]->ebin;
    121     j = (uint_t) FLOOR (p->candidates[p->goodcandidate]->ebin + .5);
    122     instfreq = aubio_unwrap2pi (fftgrain->phas[i][j]
    123         - p->theta->data[i][j] - j * p->phasediff);
    124     instfreq *= p->phasefreq;
    125     /* store phase for next run */
    126     for (j = 0; j < p->theta->length; j++) {
    127       p->theta->data[i][j] = fftgrain->phas[i][j];
    128     }
    129     //return p->candidates[p->goodcandidate]->ebin;
    130     output->data[i][0] =
    131         FLOOR (p->candidates[p->goodcandidate]->ebin + .5) + instfreq;
    132     /*} else {
    133        return -1.;
    134        } */
    135   }
     111  for (j = 0; j < newmag->length; j++)
     112    newmag->data[j] = fftgrain->norm[j];
     113  /* detect only if local energy > 10. */
     114  //if (fvec_local_energy(newmag)>10.) {
     115  //hfc = fvec_local_hfc(newmag); //not used
     116  aubio_pitchmcomb_spectral_pp (p, newmag);
     117  aubio_pitchmcomb_combdet (p, newmag);
     118  //aubio_pitchmcomb_sort_cand_freq(p->candidates,p->ncand);
     119  //return p->candidates[p->goodcandidate]->ebin;
     120  j = (uint_t) FLOOR (p->candidates[p->goodcandidate]->ebin + .5);
     121  instfreq = aubio_unwrap2pi (fftgrain->phas[j]
     122      - p->theta->data[j] - j * p->phasediff);
     123  instfreq *= p->phasefreq;
     124  /* store phase for next run */
     125  for (j = 0; j < p->theta->length; j++) {
     126    p->theta->data[j] = fftgrain->phas[j];
     127  }
     128  //return p->candidates[p->goodcandidate]->ebin;
     129  output->data[0] =
     130      FLOOR (p->candidates[p->goodcandidate]->ebin + .5) + instfreq;
     131  /*} else {
     132     return -1.;
     133     } */
    136134}
    137135
     
    139137aubio_pitch_cands (aubio_pitchmcomb_t * p, cvec_t * fftgrain, smpl_t * cands)
    140138{
    141   uint_t i = 0, j;
     139  uint_t j;
    142140  uint_t k;
    143141  fvec_t *newmag = (fvec_t *) p->newmag;
     
    147145  /* copy incoming grain to newmag */
    148146  for (j = 0; j < newmag->length; j++)
    149     newmag->data[i][j] = fftgrain->norm[i][j];
     147    newmag->data[j] = fftgrain->norm[j];
    150148  /* detect only if local energy > 10. */
    151149  if (fvec_local_energy (newmag) > 10.) {
     
    172170  fvec_t *mag = (fvec_t *) p->scratch;
    173171  fvec_t *tmp = (fvec_t *) p->scratch2;
    174   uint_t i = 0, j;
     172  uint_t j;
    175173  uint_t length = mag->length;
    176174  /* copy newmag to mag (scracth) */
    177175  for (j = 0; j < length; j++) {
    178     mag->data[i][j] = newmag->data[i][j];
     176    mag->data[j] = newmag->data[j];
    179177  }
    180178  fvec_min_removal (mag);       /* min removal          */
     
    182180  /* skipped *//* low pass filtering   */
    183181  /** \bug fvec_moving_thres may write out of bounds */
    184   fvec_adapt_thres (mag, tmp, p->win_post, p->win_pre, i);      /* adaptative threshold */
     182  fvec_adapt_thres (mag, tmp, p->win_post, p->win_pre);      /* adaptative threshold */
    185183  fvec_add (mag, -p->threshold);        /* fixed threshold      */
    186184  {
     
    190188    count = aubio_pitchmcomb_quadpick (peaks, mag);
    191189    for (j = 0; j < count; j++)
    192       peaks[j].mag = newmag->data[i][peaks[j].bin];
     190      peaks[j].mag = newmag->data[peaks[j].bin];
    193191    /* reset non peaks */
    194192    for (j = count; j < length; j++)
     
    261259        candidate[l]->ecomb[k] = peaks[position].ebin;
    262260        candidate[l]->ene +=    /* ecomb rounded to nearest int */
    263             POW (newmag->data[0][(uint_t) FLOOR (candidate[l]->ecomb[k] + .5)],
     261            POW (newmag->data[(uint_t) FLOOR (candidate[l]->ecomb[k] + .5)],
    264262            0.25);
    265263        candidate[l]->len += 1. / curlen;
     
    290288aubio_pitchmcomb_quadpick (aubio_spectralpeak_t * spectral_peaks, fvec_t * X)
    291289{
    292   uint_t i, j, ispeak, count = 0;
    293   for (i = 0; i < X->channels; i++)
    294     for (j = 1; j < X->length - 1; j++) {
    295       ispeak = fvec_peakpick (X, j);
    296       if (ispeak) {
    297         count += ispeak;
    298         spectral_peaks[count - 1].bin = j;
    299         spectral_peaks[count - 1].ebin = fvec_quadint (X, j, i) - 1.;
    300       }
    301     }
     290  uint_t j, ispeak, count = 0;
     291  for (j = 1; j < X->length - 1; j++) {
     292    ispeak = fvec_peakpick (X, j);
     293    if (ispeak) {
     294      count += ispeak;
     295      spectral_peaks[count - 1].bin = j;
     296      spectral_peaks[count - 1].ebin = fvec_quadint (X, j) - 1.;
     297    }
     298  }
    302299  return count;
    303300}
     
    364361
    365362aubio_pitchmcomb_t *
    366 new_aubio_pitchmcomb (uint_t bufsize, uint_t hopsize, uint_t channels)
     363new_aubio_pitchmcomb (uint_t bufsize, uint_t hopsize)
    367364{
    368365  aubio_pitchmcomb_t *p = AUBIO_NEW (aubio_pitchmcomb_t);
     
    386383  //p->biquad = new_biquad(0.1600,0.3200,0.1600, -0.5949, 0.2348);
    387384  /* allocate temp memory */
    388   p->newmag = new_fvec (spec_size, 1);
     385  p->newmag = new_fvec (spec_size);
    389386  /* array for median */
    390   p->scratch = new_fvec (spec_size, 1);
     387  p->scratch = new_fvec (spec_size);
    391388  /* array for phase */
    392   p->theta = new_fvec (spec_size, channels);
     389  p->theta = new_fvec (spec_size);
    393390  /* array for adaptative threshold */
    394   p->scratch2 = new_fvec (p->win_post + p->win_pre + 1, 1);
     391  p->scratch2 = new_fvec (p->win_post + p->win_pre + 1);
    395392  /* array of spectral peaks */
    396393  p->peaks = AUBIO_ARRAY (aubio_spectralpeak_t, spec_size);
Note: See TracChangeset for help on using the changeset viewer.