- Timestamp:
- Mar 18, 2013, 4:34:01 PM (12 years ago)
- 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:
- b209eda
- Parents:
- ac20c85 (diff), a5f4b7d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/pitch/pitchyinfft.c
rac20c85 rbb42f65 1 1 /* 2 Copyright (C) 2003-20 09Paul Brossier <piem@aubio.org>2 Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org> 3 3 4 4 This file is part of aubio. … … 31 31 fvec_t *win; /**< temporal weighting window */ 32 32 fvec_t *winput; /**< windowed spectrum */ 33 cvec_t *res; /**< complex vector to compute square difference function */34 33 fvec_t *sqrmag; /**< square difference function */ 35 34 fvec_t *weight; /**< spectral weighting window (psychoacoustic model) */ 36 cvec_t *fftout; /**< Fourier transform output */35 fvec_t *fftout; /**< Fourier transform output */ 37 36 aubio_fft_t *fft; /**< fft object to compute square difference function */ 38 37 fvec_t *yinfft; /**< Yin function */ … … 59 58 p->winput = new_fvec (bufsize); 60 59 p->fft = new_aubio_fft (bufsize); 61 p->fftout = new_ cvec (bufsize);60 p->fftout = new_fvec (bufsize); 62 61 p->sqrmag = new_fvec (bufsize); 63 p->res = new_cvec (bufsize);64 62 p->yinfft = new_fvec (bufsize / 2 + 1); 65 63 p->tol = 0.85; … … 99 97 { 100 98 uint_t tau, l; 99 uint_t length = p->fftout->length; 101 100 uint_t halfperiod; 102 smpl_t tmp, sum; 103 cvec_t *res = (cvec_t *) p->res; 104 fvec_t *yin = (fvec_t *) p->yinfft; 105 l = 0; 106 tmp = 0.; 107 sum = 0.; 101 fvec_t *fftout = p->fftout; 102 fvec_t *yin = p->yinfft; 103 smpl_t tmp = 0., sum = 0.; 104 // window the input 108 105 for (l = 0; l < input->length; l++) { 109 106 p->winput->data[l] = p->win->data[l] * input->data[l]; 110 107 } 111 aubio_fft_do (p->fft, p->winput, p->fftout); 112 for (l = 0; l < p->fftout->length; l++) { 113 p->sqrmag->data[l] = SQR (p->fftout->norm[l]); 108 // get the real / imag parts of its fft 109 aubio_fft_do_complex (p->fft, p->winput, fftout); 110 // get the squared magnitude spectrum, applying some weight 111 p->sqrmag->data[0] = SQR(fftout->data[0]); 112 p->sqrmag->data[0] *= p->weight->data[0]; 113 for (l = 1; l < length / 2; l++) { 114 p->sqrmag->data[l] = SQR(fftout->data[l]) + SQR(fftout->data[length - l]); 114 115 p->sqrmag->data[l] *= p->weight->data[l]; 116 p->sqrmag->data[length - l] = p->sqrmag->data[l]; 115 117 } 116 for (l = 1; l < p->fftout->length; l++) { 117 p->sqrmag->data[(p->fftout->length - 1) * 2 - l] = 118 SQR (p->fftout->norm[l]); 119 p->sqrmag->data[(p->fftout->length - 1) * 2 - l] *= 120 p->weight->data[l]; 121 } 122 for (l = 0; l < p->sqrmag->length / 2 + 1; l++) { 118 p->sqrmag->data[length / 2] = SQR(fftout->data[length / 2]); 119 p->sqrmag->data[length / 2] *= p->weight->data[length / 2]; 120 // get sum of weighted squared mags 121 for (l = 0; l < length / 2 + 1; l++) { 123 122 sum += p->sqrmag->data[l]; 124 123 } 125 124 sum *= 2.; 126 aubio_fft_do (p->fft, p->sqrmag, res); 125 // get the real / imag parts of the fft of the squared magnitude 126 aubio_fft_do_complex (p->fft, p->sqrmag, fftout); 127 127 yin->data[0] = 1.; 128 128 for (tau = 1; tau < yin->length; tau++) { 129 yin->data[tau] = sum - res->norm[tau] * COS (res->phas[tau]); 129 // compute the square differences 130 yin->data[tau] = sum - fftout->data[tau]; 131 // and the cumulative mean normalized difference function 130 132 tmp += yin->data[tau]; 131 133 yin->data[tau] *= tau / tmp; 132 134 } 135 // find best candidates 133 136 tau = fvec_min_elem (yin); 134 137 if (yin->data[tau] < p->tol) { 135 /* no interpolation */ 136 //return tau; 137 /* 3 point quadratic interpolation */ 138 // no interpolation, directly return the period as an integer 139 //output->data[0] = tau; 140 //return; 141 142 // 3 point quadratic interpolation 138 143 //return fvec_quadint_min(yin,tau,1); 139 144 /* additional check for (unlikely) octave doubling in higher frequencies */ … … 160 165 del_fvec (p->yinfft); 161 166 del_fvec (p->sqrmag); 162 del_cvec (p->res); 163 del_cvec (p->fftout); 167 del_fvec (p->fftout); 164 168 del_fvec (p->winput); 165 169 del_fvec (p->weight);
Note: See TracChangeset
for help on using the changeset viewer.