Changeset 8040cca


Ignore:
Timestamp:
Oct 8, 2009, 7:46:46 PM (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:
e5757cf
Parents:
6fc103d
Message:

src/pitch/pitchfcomb.c: update prototypes, make multichannel, remove unneeded samplerate parameter, now returns bin

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/pitch/pitchfcomb.c

    r6fc103d r8040cca  
    2828
    2929typedef struct {
    30   smpl_t freq;
     30  smpl_t bin;
    3131  smpl_t db;
    3232} aubio_fpeak_t;
     
    4141  fvec_t * fftLastPhase;
    4242  aubio_fft_t * fft;
    43   //aubio_pvoc_t * pvoc;
    4443};
    4544
    46 aubio_pitchfcomb_t * new_aubio_pitchfcomb (uint_t bufsize, uint_t hopsize, uint_t samplerate)
     45aubio_pitchfcomb_t * new_aubio_pitchfcomb (uint_t bufsize, uint_t hopsize, uint_t channels)
    4746{
    4847  aubio_pitchfcomb_t * p = AUBIO_NEW(aubio_pitchfcomb_t);
    49   p->rate         = samplerate;
    5048  p->fftSize      = bufsize;
    5149  p->stepSize     = hopsize;
    5250  p->winput       = new_fvec(bufsize,1);
    5351  p->fftOut       = new_cvec(bufsize,1);
    54   p->fftLastPhase = new_fvec(bufsize,1);
     52  p->fftLastPhase = new_fvec(bufsize, channels);
    5553  p->fft = new_aubio_fft(bufsize, 1);
    5654  p->win = new_aubio_window(bufsize, aubio_win_hanning);
     
    5957
    6058/* input must be stepsize long */
    61 smpl_t aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, fvec_t * input)
     59void aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, fvec_t * input, fvec_t * output)
    6260{
    63   uint_t k, l, maxharm = 0;
    64   smpl_t freqPerBin = p->rate/(smpl_t)p->fftSize,
    65     phaseDifference = TWO_PI*(smpl_t)p->stepSize/(smpl_t)p->fftSize;
     61  uint_t i, k, l, maxharm = 0;
     62  smpl_t phaseDifference = TWO_PI*(smpl_t)p->stepSize/(smpl_t)p->fftSize;
    6663  aubio_fpeak_t peaks[MAX_PEAKS];
     64
     65  for (i = 0; i < input->channels; i++) {
    6766
    6867  for (k=0; k<MAX_PEAKS; k++) {
    6968    peaks[k].db = -200.;
    70     peaks[k].freq = 0.;
     69    peaks[k].bin = 0.;
    7170  }
    7271
    7372  for (k=0; k < input->length; k++){
    74     p->winput->data[0][k] = p->win->data[0][k] * input->data[0][k];
     73    p->winput->data[0][k] = p->win->data[0][k] * input->data[i][k];
    7574  }
    7675  aubio_fft_do(p->fft,p->winput,p->fftOut);
     
    8079      magnitude = 20.*LOG10(2.*p->fftOut->norm[0][k]/(smpl_t)p->fftSize),
    8180      phase     = p->fftOut->phas[0][k],
    82       tmp, freq;
     81      tmp, bin;
    8382
    8483    /* compute phase difference */
    85     tmp = phase - p->fftLastPhase->data[0][k];
    86     p->fftLastPhase->data[0][k] = phase;
     84    tmp = phase - p->fftLastPhase->data[i][k];
     85    p->fftLastPhase->data[i][k] = phase;
    8786
    8887    /* subtract expected phase difference */
     
    9594    tmp = p->fftSize/(smpl_t)p->stepSize*tmp/(TWO_PI);
    9695
    97     /* compute the k-th partials' true frequency */
    98     freq = (smpl_t)k*freqPerBin + tmp*freqPerBin;
     96    /* compute the k-th partials' true bin */
     97    bin = (smpl_t)k + tmp;
    9998
    100     if (freq > 0.0 && magnitude > peaks[0].db) { // && magnitude < 0) {
     99    if (bin > 0.0 && magnitude > peaks[0].db) { // && magnitude < 0) {
    101100      memmove(peaks+1, peaks, sizeof(aubio_fpeak_t)*(MAX_PEAKS-1));
    102       peaks[0].freq = freq;
     101      peaks[0].bin = bin;
    103102      peaks[0].db = magnitude;
    104103    }
     
    106105
    107106  k = 0;
    108   for (l=1; l<MAX_PEAKS && peaks[l].freq > 0.0; l++) {
     107  for (l=1; l<MAX_PEAKS && peaks[l].bin > 0.0; l++) {
    109108    sint_t harmonic;
    110109    for (harmonic=5; harmonic>1; harmonic--) {
    111       if (peaks[0].freq / peaks[l].freq < harmonic+.02 &&
    112           peaks[0].freq / peaks[l].freq > harmonic-.02) {
     110      if (peaks[0].bin / peaks[l].bin < harmonic+.02 &&
     111          peaks[0].bin / peaks[l].bin > harmonic-.02) {
    113112        if (harmonic > (sint_t)maxharm &&
    114113            peaks[0].db < peaks[l].db/2) {
     
    119118    }
    120119  }
     120  output->data[i][0] = peaks[k].bin;
    121121  /* quick hack to clean output a bit */
    122   if (peaks[k].freq > 5000.) return 0.;
    123   return peaks[k].freq;
     122  if (peaks[k].bin > 5000.) output->data[i][0] = 0.;
     123  }
    124124}
    125125
  • src/pitch/pitchfcomb.h

    r6fc103d r8040cca  
    4646  \param p pitch detection object as returned by new_aubio_pitchfcomb
    4747  \param input input signal window (length as specified at creation time)
     48  \param output pitch candidates in bins
    4849 
    4950*/
    50 smpl_t aubio_pitchfcomb_do (aubio_pitchfcomb_t *p, fvec_t * input);
     51void aubio_pitchfcomb_do (aubio_pitchfcomb_t *p, fvec_t * input, fvec_t * output);
    5152/** creation of the pitch detection object
    5253 
    5354  \param bufsize size of the input buffer to analyse
    5455  \param hopsize step size between two consecutive analysis instant
    55   \param samplerate sampling rate of the signal
     56  \param channels number of channels to detect pitch on
    5657 
    5758*/
    58 aubio_pitchfcomb_t * new_aubio_pitchfcomb (uint_t bufsize, uint_t hopsize, uint_t samplerate);
     59aubio_pitchfcomb_t * new_aubio_pitchfcomb (uint_t bufsize, uint_t hopsize, uint_t channels);
    5960/** deletion of the pitch detection object
    6061 
  • tests/src/test-pitchfcomb.c

    r6fc103d r8040cca  
    55        uint_t win_s      = 1024;                       /* window size */
    66        uint_t hop_s      = win_s/4;                    /* hop size */
    7         uint_t samplerate = 44100;                      /* samplerate */
    8         uint_t channels   = 1;                          /* number of channel */
     7        uint_t channels   = 3;                          /* number of channel */
    98        fvec_t * in       = new_fvec (hop_s, channels); /* input buffer */
     9        fvec_t * out      = new_fvec (1, channels);
    1010        aubio_pitchfcomb_t * o  = new_aubio_pitchfcomb (
    11           win_s, hop_s, samplerate
    12           );
     11          win_s, hop_s, channels);
    1312        uint_t i = 0;
    1413
    15         while (i < 1000) {
    16           aubio_pitchfcomb_do (o,in);
     14        while (i < 2) {
     15          aubio_pitchfcomb_do (o,in, out);
    1716          i++;
    1817        };
Note: See TracChangeset for help on using the changeset viewer.