Changeset a5f4b7d
 Timestamp:
 Mar 18, 2013, 9:18:30 AM (7 years ago)
 Branches:
 feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
 Children:
 bb42f65
 Parents:
 53439af
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/pitch/pitchyinfft.c
r53439af ra5f4b7d 1 1 /* 2 Copyright (C) 200320 09Paul Brossier <piem@aubio.org>2 Copyright (C) 20032013 Paul Brossier <piem@aubio.org> 3 3 4 4 This file is part of aubio. … … 34 34 fvec_t *weight; /**< spectral weighting window (psychoacoustic model) */ 35 35 fvec_t *fftout; /**< Fourier transform output */ 36 fvec_t *res; /**< complex vector to compute square difference function */37 36 aubio_fft_t *fft; /**< fft object to compute square difference function */ 38 37 fvec_t *yinfft; /**< Yin function */ … … 60 59 p>fft = new_aubio_fft (bufsize); 61 60 p>fftout = new_fvec (bufsize); 62 p>res = new_fvec (bufsize);63 61 p>sqrmag = new_fvec (bufsize); 64 62 p>yinfft = new_fvec (bufsize / 2 + 1); … … 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 fvec_t *res = (fvec_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_complex (p>fft, p>winput, p>fftout); 112 uint_t length = p>fftout>length; 113 p>sqrmag>data[0] = SQR(p>fftout>data[0]); 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]); 114 112 p>sqrmag>data[0] *= p>weight>data[0]; 115 113 for (l = 1; l < length / 2; l++) { 116 p>sqrmag>data[l] = SQR( p>fftout>data[l]) + SQR(p>fftout>data[length  l]);114 p>sqrmag>data[l] = SQR(fftout>data[l]) + SQR(fftout>data[length  l]); 117 115 p>sqrmag>data[l] *= p>weight>data[l]; 118 p>sqrmag>data[ p>sqrmag>length  l] = p>sqrmag>data[l];116 p>sqrmag>data[length  l] = p>sqrmag>data[l]; 119 117 } 120 p>sqrmag>data[length / 2] = SQR( p>fftout>data[length / 2]);118 p>sqrmag>data[length / 2] = SQR(fftout>data[length / 2]); 121 119 p>sqrmag>data[length / 2] *= p>weight>data[length / 2]; 120 // get sum of weighted squared mags 122 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_complex (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>data[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 */ … … 161 166 del_fvec (p>sqrmag); 162 167 del_fvec (p>fftout); 163 del_fvec (p>res);164 168 del_fvec (p>winput); 165 169 del_fvec (p>weight);
Note: See TracChangeset
for help on using the changeset viewer.