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

src/pitch: switch to mono

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/pitch/pitchfcomb.c

    rfc61225 r168337e  
    4949
    5050aubio_pitchfcomb_t *
    51 new_aubio_pitchfcomb (uint_t bufsize, uint_t hopsize, uint_t channels)
     51new_aubio_pitchfcomb (uint_t bufsize, uint_t hopsize)
    5252{
    5353  aubio_pitchfcomb_t *p = AUBIO_NEW (aubio_pitchfcomb_t);
    5454  p->fftSize = bufsize;
    5555  p->stepSize = hopsize;
    56   p->winput = new_fvec (bufsize, 1);
    57   p->fftOut = new_cvec (bufsize, 1);
    58   p->fftLastPhase = new_fvec (bufsize, channels);
    59   p->fft = new_aubio_fft (bufsize, 1);
     56  p->winput = new_fvec (bufsize);
     57  p->fftOut = new_cvec (bufsize);
     58  p->fftLastPhase = new_fvec (bufsize);
     59  p->fft = new_aubio_fft (bufsize);
    6060  p->win = new_aubio_window ("hanning", bufsize);
    6161  return p;
     
    6666aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, fvec_t * input, fvec_t * output)
    6767{
    68   uint_t i, k, l, maxharm = 0;
     68  uint_t k, l, maxharm = 0;
    6969  smpl_t phaseDifference = TWO_PI * (smpl_t) p->stepSize / (smpl_t) p->fftSize;
    7070  aubio_fpeak_t peaks[MAX_PEAKS];
    7171
    72   for (i = 0; i < input->channels; i++) {
     72  for (k = 0; k < MAX_PEAKS; k++) {
     73    peaks[k].db = -200.;
     74    peaks[k].bin = 0.;
     75  }
    7376
    74     for (k = 0; k < MAX_PEAKS; k++) {
    75       peaks[k].db = -200.;
    76       peaks[k].bin = 0.;
     77  for (k = 0; k < input->length; k++) {
     78    p->winput->data[k] = p->win->data[k] * input->data[k];
     79  }
     80  aubio_fft_do (p->fft, p->winput, p->fftOut);
     81
     82  for (k = 0; k <= p->fftSize / 2; k++) {
     83    smpl_t
     84        magnitude =
     85        20. * LOG10 (2. * p->fftOut->norm[k] / (smpl_t) p->fftSize),
     86        phase = p->fftOut->phas[k], tmp, bin;
     87
     88    /* compute phase difference */
     89    tmp = phase - p->fftLastPhase->data[k];
     90    p->fftLastPhase->data[k] = phase;
     91
     92    /* subtract expected phase difference */
     93    tmp -= (smpl_t) k *phaseDifference;
     94
     95    /* map delta phase into +/- Pi interval */
     96    tmp = aubio_unwrap2pi (tmp);
     97
     98    /* get deviation from bin frequency from the +/- Pi interval */
     99    tmp = p->fftSize / (smpl_t) p->stepSize * tmp / (TWO_PI);
     100
     101    /* compute the k-th partials' true bin */
     102    bin = (smpl_t) k + tmp;
     103
     104    if (bin > 0.0 && magnitude > peaks[0].db) {       // && magnitude < 0) {
     105      memmove (peaks + 1, peaks, sizeof (aubio_fpeak_t) * (MAX_PEAKS - 1));
     106      peaks[0].bin = bin;
     107      peaks[0].db = magnitude;
    77108    }
     109  }
    78110
    79     for (k = 0; k < input->length; k++) {
    80       p->winput->data[0][k] = p->win->data[0][k] * input->data[i][k];
    81     }
    82     aubio_fft_do (p->fft, p->winput, p->fftOut);
    83 
    84     for (k = 0; k <= p->fftSize / 2; k++) {
    85       smpl_t
    86           magnitude =
    87           20. * LOG10 (2. * p->fftOut->norm[0][k] / (smpl_t) p->fftSize),
    88           phase = p->fftOut->phas[0][k], tmp, bin;
    89 
    90       /* compute phase difference */
    91       tmp = phase - p->fftLastPhase->data[i][k];
    92       p->fftLastPhase->data[i][k] = phase;
    93 
    94       /* subtract expected phase difference */
    95       tmp -= (smpl_t) k *phaseDifference;
    96 
    97       /* map delta phase into +/- Pi interval */
    98       tmp = aubio_unwrap2pi (tmp);
    99 
    100       /* get deviation from bin frequency from the +/- Pi interval */
    101       tmp = p->fftSize / (smpl_t) p->stepSize * tmp / (TWO_PI);
    102 
    103       /* compute the k-th partials' true bin */
    104       bin = (smpl_t) k + tmp;
    105 
    106       if (bin > 0.0 && magnitude > peaks[0].db) {       // && magnitude < 0) {
    107         memmove (peaks + 1, peaks, sizeof (aubio_fpeak_t) * (MAX_PEAKS - 1));
    108         peaks[0].bin = bin;
    109         peaks[0].db = magnitude;
    110       }
    111     }
    112 
    113     k = 0;
    114     for (l = 1; l < MAX_PEAKS && peaks[l].bin > 0.0; l++) {
    115       sint_t harmonic;
    116       for (harmonic = 5; harmonic > 1; harmonic--) {
    117         if (peaks[0].bin / peaks[l].bin < harmonic + .02 &&
    118             peaks[0].bin / peaks[l].bin > harmonic - .02) {
    119           if (harmonic > (sint_t) maxharm && peaks[0].db < peaks[l].db / 2) {
    120             maxharm = harmonic;
    121             k = l;
    122           }
     111  k = 0;
     112  for (l = 1; l < MAX_PEAKS && peaks[l].bin > 0.0; l++) {
     113    sint_t harmonic;
     114    for (harmonic = 5; harmonic > 1; harmonic--) {
     115      if (peaks[0].bin / peaks[l].bin < harmonic + .02 &&
     116          peaks[0].bin / peaks[l].bin > harmonic - .02) {
     117        if (harmonic > (sint_t) maxharm && peaks[0].db < peaks[l].db / 2) {
     118          maxharm = harmonic;
     119          k = l;
    123120        }
    124121      }
    125122    }
    126     output->data[i][0] = peaks[k].bin;
    127     /* quick hack to clean output a bit */
    128     if (peaks[k].bin > 5000.)
    129       output->data[i][0] = 0.;
    130123  }
     124  output->data[0] = peaks[k].bin;
     125  /* quick hack to clean output a bit */
     126  if (peaks[k].bin > 5000.)
     127    output->data[0] = 0.;
    131128}
    132129
Note: See TracChangeset for help on using the changeset viewer.