Changeset 168337e for src/pitch


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

Location:
src/pitch
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • src/pitch/pitch.c

    rfc61225 r168337e  
    114114aubio_pitch_t *
    115115new_aubio_pitch (char_t * pitch_mode,
    116     uint_t bufsize, uint_t hopsize, uint_t channels, uint_t samplerate)
     116    uint_t bufsize, uint_t hopsize, uint_t samplerate)
    117117{
    118118  aubio_pitch_t *p = AUBIO_NEW (aubio_pitch_t);
     
    142142  switch (p->type) {
    143143    case aubio_pitcht_yin:
    144       p->buf = new_fvec (bufsize, channels);
     144      p->buf = new_fvec (bufsize);
    145145      p->yin = new_aubio_pitchyin (bufsize);
    146146      p->callback = aubio_pitch_do_yin;
     
    148148      break;
    149149    case aubio_pitcht_mcomb:
    150       p->pv = new_aubio_pvoc (bufsize, hopsize, channels);
    151       p->fftgrain = new_cvec (bufsize, channels);
    152       p->mcomb = new_aubio_pitchmcomb (bufsize, hopsize, channels);
    153       p->filter = new_aubio_filter_c_weighting (samplerate, channels);
     150      p->pv = new_aubio_pvoc (bufsize, hopsize);
     151      p->fftgrain = new_cvec (bufsize);
     152      p->mcomb = new_aubio_pitchmcomb (bufsize, hopsize);
     153      p->filter = new_aubio_filter_c_weighting (samplerate);
    154154      p->callback = aubio_pitch_do_mcomb;
    155155      break;
    156156    case aubio_pitcht_fcomb:
    157       p->buf = new_fvec (bufsize, channels);
    158       p->fcomb = new_aubio_pitchfcomb (bufsize, hopsize, channels);
     157      p->buf = new_fvec (bufsize);
     158      p->fcomb = new_aubio_pitchfcomb (bufsize, hopsize);
    159159      p->callback = aubio_pitch_do_fcomb;
    160160      break;
    161161    case aubio_pitcht_schmitt:
    162       p->buf = new_fvec (bufsize, channels);
     162      p->buf = new_fvec (bufsize);
    163163      p->schmitt = new_aubio_pitchschmitt (bufsize);
    164164      p->callback = aubio_pitch_do_schmitt;
    165165      break;
    166166    case aubio_pitcht_yinfft:
    167       p->buf = new_fvec (bufsize, channels);
     167      p->buf = new_fvec (bufsize);
    168168      p->yinfft = new_aubio_pitchyinfft (bufsize);
    169169      p->callback = aubio_pitch_do_yinfft;
     
    211211aubio_pitch_slideblock (aubio_pitch_t * p, fvec_t * ibuf)
    212212{
    213   uint_t i, j = 0, overlap_size = 0;
     213  uint_t j = 0, overlap_size = 0;
    214214  overlap_size = p->buf->length - ibuf->length;
    215   for (i = 0; i < p->buf->channels; i++) {
    216     for (j = 0; j < overlap_size; j++) {
    217       p->buf->data[i][j] = p->buf->data[i][j + ibuf->length];
    218     }
    219   }
    220   for (i = 0; i < ibuf->channels; i++) {
    221     for (j = 0; j < ibuf->length; j++) {
    222       p->buf->data[i][j + overlap_size] = ibuf->data[i][j];
    223     }
     215  for (j = 0; j < overlap_size; j++) {
     216    p->buf->data[j] = p->buf->data[j + ibuf->length];
     217  }
     218  for (j = 0; j < ibuf->length; j++) {
     219    p->buf->data[j + overlap_size] = ibuf->data[j];
    224220  }
    225221}
     
    283279aubio_pitch_do (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
    284280{
    285   uint_t i;
    286281  p->callback (p, ibuf, obuf);
    287   for (i = 0; i < obuf->channels; i++) {
    288     p->freqconv (obuf->data[i][0], p->srate, p->bufsize);
    289   }
     282  obuf->data[0] = p->freqconv (obuf->data[0], p->srate, p->bufsize);
    290283}
    291284
     
    293286aubio_pitch_do_mcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
    294287{
    295   uint_t i;
    296288  aubio_filter_do (p->filter, ibuf);
    297289  aubio_pvoc_do (p->pv, ibuf, p->fftgrain);
    298290  aubio_pitchmcomb_do (p->mcomb, p->fftgrain, obuf);
    299   for (i = 0; i < obuf->channels; i++) {
    300     obuf->data[i][0] = aubio_bintofreq (obuf->data[i][0], p->srate, p->bufsize);
    301   }
     291  obuf->data[0] = aubio_bintofreq (obuf->data[0], p->srate, p->bufsize);
    302292}
    303293
     
    306296{
    307297  smpl_t pitch = 0.;
    308   uint_t i;
    309298  aubio_pitch_slideblock (p, ibuf);
    310299  aubio_pitchyin_do (p->yin, p->buf, obuf);
    311   for (i = 0; i < obuf->channels; i++) {
    312     pitch = obuf->data[i][0];
    313     if (pitch > 0) {
    314       pitch = p->srate / (pitch + 0.);
    315     } else {
    316       pitch = 0.;
    317     }
    318     obuf->data[i][0] = pitch;
    319   }
     300  pitch = obuf->data[0];
     301  if (pitch > 0) {
     302    pitch = p->srate / (pitch + 0.);
     303  } else {
     304    pitch = 0.;
     305  }
     306  obuf->data[0] = pitch;
    320307}
    321308
     
    325312{
    326313  smpl_t pitch = 0.;
    327   uint_t i;
    328314  aubio_pitch_slideblock (p, ibuf);
    329315  aubio_pitchyinfft_do (p->yinfft, p->buf, obuf);
    330   for (i = 0; i < obuf->channels; i++) {
    331     pitch = obuf->data[i][0];
    332     if (pitch > 0) {
    333       pitch = p->srate / (pitch + 0.);
    334     } else {
    335       pitch = 0.;
    336     }
    337     obuf->data[i][0] = pitch;
    338   }
     316  pitch = obuf->data[0];
     317  if (pitch > 0) {
     318    pitch = p->srate / (pitch + 0.);
     319  } else {
     320    pitch = 0.;
     321  }
     322  obuf->data[0] = pitch;
    339323}
    340324
     
    342326aubio_pitch_do_fcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out)
    343327{
    344   uint_t i;
    345328  aubio_pitch_slideblock (p, ibuf);
    346329  aubio_pitchfcomb_do (p->fcomb, p->buf, out);
    347   for (i = 0; i < out->channels; i++) {
    348     out->data[i][0] = aubio_bintofreq (out->data[i][0], p->srate, p->bufsize);
    349   }
     330  out->data[0] = aubio_bintofreq (out->data[0], p->srate, p->bufsize);
    350331}
    351332
     
    354335{
    355336  smpl_t period, pitch = 0.;
    356   uint_t i;
    357337  aubio_pitch_slideblock (p, ibuf);
    358338  aubio_pitchschmitt_do (p->schmitt, p->buf, out);
    359   for (i = 0; i < out->channels; i++) {
    360     period = out->data[i][0];
    361     if (period > 0) {
    362       pitch = p->srate / period;
    363     } else {
    364       pitch = 0.;
    365     }
    366     out->data[i][0] = pitch;
    367   }
    368 }
     339  period = out->data[0];
     340  if (period > 0) {
     341    pitch = p->srate / period;
     342  } else {
     343    pitch = 0.;
     344  }
     345  out->data[0] = pitch;
     346}
  • src/pitch/pitch.h

    rfc61225 r168337e  
    4141
    4242  \param o pitch detection object as returned by new_aubio_pitch()
    43   \param in input signal of size [hop_size x channels]
    44   \param out output pitch candidates of size [1 x channels]
     43  \param in input signal of size [hop_size]
     44  \param out output pitch candidates of size [1]
    4545
    4646*/
     
    6767  \param buf_size size of the input buffer to analyse
    6868  \param hop_size step size between two consecutive analysis instant
    69   \param channels number of channels to analyse
    7069  \param samplerate sampling rate of the signal
    7170
    7271*/
    7372aubio_pitch_t *new_aubio_pitch (char_t * method,
    74     uint_t buf_size, uint_t hop_size, uint_t channels, uint_t samplerate);
     73    uint_t buf_size, uint_t hop_size, uint_t samplerate);
    7574
    7675/** set the output unit of the pitch detection object
  • 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
  • src/pitch/pitchfcomb.h

    rfc61225 r168337e  
    5757  \param buf_size size of the input buffer to analyse
    5858  \param hop_size step size between two consecutive analysis instant
    59   \param channels number of channels to detect pitch on
    6059 
    6160*/
    62 aubio_pitchfcomb_t *new_aubio_pitchfcomb (uint_t buf_size, uint_t hop_size,
    63     uint_t channels);
     61aubio_pitchfcomb_t *new_aubio_pitchfcomb (uint_t buf_size, uint_t hop_size);
    6462
    6563/** deletion of the pitch detection object
  • 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);
  • src/pitch/pitchmcomb.h

    rfc61225 r168337e  
    5757  \param buf_size size of the input buffer to analyse
    5858  \param hop_size step size between two consecutive analysis instant
    59   \param channels number of channels to analyse
    6059  \param samplerate sampling rate of the signal
    6160 
    6261*/
    63 aubio_pitchmcomb_t *new_aubio_pitchmcomb (uint_t buf_size, uint_t hop_size,
    64     uint_t channels);
     62aubio_pitchmcomb_t *new_aubio_pitchmcomb (uint_t buf_size, uint_t hop_size);
    6563
    6664/** deletion of the pitch detection object
  • src/pitch/pitchschmitt.c

    rfc61225 r168337e  
    5151    fvec_t * output)
    5252{
    53   uint_t i, j;
    54   for (i = 0; i < input->channels; i++) {
    55     for (j = 0; j < input->length; j++) {
    56       p->buf[j] = input->data[i][j] * 32768.;
    57     }
    58     output->data[i][0] = aubio_schmittS16LE (p, input->length, p->buf);
     53  uint_t j;
     54  for (j = 0; j < input->length; j++) {
     55    p->buf[j] = input->data[j] * 32768.;
    5956  }
     57  output->data[0] = aubio_schmittS16LE (p, input->length, p->buf);
    6058}
    6159
  • src/pitch/pitchyin.c

    rfc61225 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
  • src/pitch/pitchyinfft.c

    rfc61225 r168337e  
    5656{
    5757  aubio_pitchyinfft_t *p = AUBIO_NEW (aubio_pitchyinfft_t);
    58   p->winput = new_fvec (bufsize, 1);
    59   p->fft = new_aubio_fft (bufsize, 1);
    60   p->fftout = new_cvec (bufsize, 1);
    61   p->sqrmag = new_fvec (bufsize, 1);
    62   p->res = new_cvec (bufsize, 1);
    63   p->yinfft = new_fvec (bufsize / 2 + 1, 1);
     58  p->winput = new_fvec (bufsize);
     59  p->fft = new_aubio_fft (bufsize);
     60  p->fftout = new_cvec (bufsize);
     61  p->sqrmag = new_fvec (bufsize);
     62  p->res = new_cvec (bufsize);
     63  p->yinfft = new_fvec (bufsize / 2 + 1);
    6464  p->tol = 0.85;
    6565  p->win = new_aubio_window ("hanningz", bufsize);
    66   p->weight = new_fvec (bufsize / 2 + 1, 1);
    67   {
    68     uint_t i = 0, j = 1;
    69     smpl_t freq = 0, a0 = 0, a1 = 0, f0 = 0, f1 = 0;
    70     for (i = 0; i < p->weight->length; i++) {
    71       freq = (smpl_t) i / (smpl_t) bufsize *(smpl_t) 44100.;
    72       while (freq > freqs[j]) {
    73         j += 1;
    74       }
    75       a0 = weight[j - 1];
    76       f0 = freqs[j - 1];
    77       a1 = weight[j];
    78       f1 = freqs[j];
    79       if (f0 == f1) {           // just in case
    80         p->weight->data[0][i] = a0;
    81       } else if (f0 == 0) {     // y = ax+b
    82         p->weight->data[0][i] = (a1 - a0) / f1 * freq + a0;
    83       } else {
    84         p->weight->data[0][i] = (a1 - a0) / (f1 - f0) * freq +
    85             (a0 - (a1 - a0) / (f1 / f0 - 1.));
    86       }
    87       while (freq > freqs[j]) {
    88         j += 1;
    89       }
    90       //AUBIO_DBG("%f\n",p->weight->data[0][i]);
    91       p->weight->data[0][i] = DB2LIN (p->weight->data[0][i]);
    92       //p->weight->data[0][i] = SQRT(DB2LIN(p->weight->data[0][i]));
     66  p->weight = new_fvec (bufsize / 2 + 1);
     67  uint_t i = 0, j = 1;
     68  smpl_t freq = 0, a0 = 0, a1 = 0, f0 = 0, f1 = 0;
     69  for (i = 0; i < p->weight->length; i++) {
     70    freq = (smpl_t) i / (smpl_t) bufsize *(smpl_t) 44100.;
     71    while (freq > freqs[j]) {
     72      j += 1;
    9373    }
     74    a0 = weight[j - 1];
     75    f0 = freqs[j - 1];
     76    a1 = weight[j];
     77    f1 = freqs[j];
     78    if (f0 == f1) {           // just in case
     79      p->weight->data[i] = a0;
     80    } else if (f0 == 0) {     // y = ax+b
     81      p->weight->data[i] = (a1 - a0) / f1 * freq + a0;
     82    } else {
     83      p->weight->data[i] = (a1 - a0) / (f1 - f0) * freq +
     84          (a0 - (a1 - a0) / (f1 / f0 - 1.));
     85    }
     86    while (freq > freqs[j]) {
     87      j += 1;
     88    }
     89    //AUBIO_DBG("%f\n",p->weight->data[i]);
     90    p->weight->data[i] = DB2LIN (p->weight->data[i]);
     91    //p->weight->data[i] = SQRT(DB2LIN(p->weight->data[i]));
    9492  }
    9593  return p;
     
    9997aubio_pitchyinfft_do (aubio_pitchyinfft_t * p, fvec_t * input, fvec_t * output)
    10098{
    101   uint_t i, tau, l;
     99  uint_t tau, l;
    102100  uint_t halfperiod;
    103101  smpl_t tmp, sum;
    104102  cvec_t *res = (cvec_t *) p->res;
    105103  fvec_t *yin = (fvec_t *) p->yinfft;
    106   for (i = 0; i < input->channels; i++) {
    107     l = 0;
    108     tmp = 0.;
    109     sum = 0.;
    110     for (l = 0; l < input->length; l++) {
    111       p->winput->data[0][l] = p->win->data[0][l] * input->data[i][l];
     104  l = 0;
     105  tmp = 0.;
     106  sum = 0.;
     107  for (l = 0; l < input->length; l++) {
     108    p->winput->data[l] = p->win->data[l] * input->data[l];
     109  }
     110  aubio_fft_do (p->fft, p->winput, p->fftout);
     111  for (l = 0; l < p->fftout->length; l++) {
     112    p->sqrmag->data[l] = SQR (p->fftout->norm[l]);
     113    p->sqrmag->data[l] *= p->weight->data[l];
     114  }
     115  for (l = 1; l < p->fftout->length; l++) {
     116    p->sqrmag->data[(p->fftout->length - 1) * 2 - l] =
     117        SQR (p->fftout->norm[l]);
     118    p->sqrmag->data[(p->fftout->length - 1) * 2 - l] *=
     119        p->weight->data[l];
     120  }
     121  for (l = 0; l < p->sqrmag->length / 2 + 1; l++) {
     122    sum += p->sqrmag->data[l];
     123  }
     124  sum *= 2.;
     125  aubio_fft_do (p->fft, p->sqrmag, res);
     126  yin->data[0] = 1.;
     127  for (tau = 1; tau < yin->length; tau++) {
     128    yin->data[tau] = sum - res->norm[tau] * COS (res->phas[tau]);
     129    tmp += yin->data[tau];
     130    yin->data[tau] *= tau / tmp;
     131  }
     132  tau = fvec_min_elem (yin);
     133  if (yin->data[tau] < p->tol) {
     134    /* no interpolation */
     135    //return tau;
     136    /* 3 point quadratic interpolation */
     137    //return fvec_quadint_min(yin,tau,1);
     138    /* additional check for (unlikely) octave doubling in higher frequencies */
     139    if (tau > 35) {
     140      output->data[0] = fvec_quadint (yin, tau);
     141    } else {
     142      /* should compare the minimum value of each interpolated peaks */
     143      halfperiod = FLOOR (tau / 2 + .5);
     144      if (yin->data[halfperiod] < p->tol)
     145        output->data[0] = fvec_quadint (yin, halfperiod);
     146      else
     147        output->data[0] = fvec_quadint (yin, tau);
    112148    }
    113     aubio_fft_do (p->fft, p->winput, p->fftout);
    114     for (l = 0; l < p->fftout->length; l++) {
    115       p->sqrmag->data[0][l] = SQR (p->fftout->norm[0][l]);
    116       p->sqrmag->data[0][l] *= p->weight->data[0][l];
    117     }
    118     for (l = 1; l < p->fftout->length; l++) {
    119       p->sqrmag->data[0][(p->fftout->length - 1) * 2 - l] =
    120           SQR (p->fftout->norm[0][l]);
    121       p->sqrmag->data[0][(p->fftout->length - 1) * 2 - l] *=
    122           p->weight->data[0][l];
    123     }
    124     for (l = 0; l < p->sqrmag->length / 2 + 1; l++) {
    125       sum += p->sqrmag->data[0][l];
    126     }
    127     sum *= 2.;
    128     aubio_fft_do (p->fft, p->sqrmag, res);
    129     yin->data[0][0] = 1.;
    130     for (tau = 1; tau < yin->length; tau++) {
    131       yin->data[0][tau] = sum - res->norm[0][tau] * COS (res->phas[0][tau]);
    132       tmp += yin->data[0][tau];
    133       yin->data[0][tau] *= tau / tmp;
    134     }
    135     tau = fvec_min_elem (yin);
    136     if (yin->data[0][tau] < p->tol) {
    137       /* no interpolation */
    138       //return tau;
    139       /* 3 point quadratic interpolation */
    140       //return fvec_quadint_min(yin,tau,1);
    141       /* additional check for (unlikely) octave doubling in higher frequencies */
    142       if (tau > 35) {
    143         output->data[i][0] = fvec_quadint (yin, tau, i);
    144       } else {
    145         /* should compare the minimum value of each interpolated peaks */
    146         halfperiod = FLOOR (tau / 2 + .5);
    147         if (yin->data[0][halfperiod] < p->tol)
    148           output->data[i][0] = fvec_quadint (yin, halfperiod, i);
    149         else
    150           output->data[i][0] = fvec_quadint (yin, tau, i);
    151       }
    152     } else {
    153       output->data[i][0] = 0.;
    154     }
     149  } else {
     150    output->data[0] = 0.;
    155151  }
    156152}
Note: See TracChangeset for help on using the changeset viewer.