- Timestamp:
- Oct 8, 2009, 8:51:06 PM (15 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:
- 05773a2c
- Parents:
- 22d33e2
- Location:
- src/pitch
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/pitch/pitchdetection.c
r22d33e2 r7a6cbbe 32 32 #include "pitch/pitchdetection.h" 33 33 34 typedef smpl_t(*aubio_pitchdetection_func_t)35 (aubio_pitchdetection_t *p, fvec_t * ibuf );34 typedef void (*aubio_pitchdetection_func_t) 35 (aubio_pitchdetection_t *p, fvec_t * ibuf, fvec_t *obuf); 36 36 typedef smpl_t (*aubio_pitchdetection_conv_t) 37 37 (smpl_t value, uint_t srate, uint_t bufsize); … … 39 39 void aubio_pitchdetection_slideblock(aubio_pitchdetection_t *p, fvec_t *ibuf); 40 40 41 smpl_t aubio_pitchdetection_mcomb (aubio_pitchdetection_t *p, fvec_t *ibuf);42 smpl_t aubio_pitchdetection_yin (aubio_pitchdetection_t *p, fvec_t *ibuf);43 smpl_t aubio_pitchdetection_schmitt (aubio_pitchdetection_t *p, fvec_t *ibuf);44 smpl_t aubio_pitchdetection_fcomb (aubio_pitchdetection_t *p, fvec_t *ibuf);45 smpl_t aubio_pitchdetection_yinfft (aubio_pitchdetection_t *p, fvec_t *ibuf);41 void aubio_pitchdetection_mcomb (aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t *obuf); 42 void aubio_pitchdetection_yin (aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t *obuf); 43 void aubio_pitchdetection_schmitt (aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t *obuf); 44 void aubio_pitchdetection_fcomb (aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t *obuf); 45 void aubio_pitchdetection_yinfft (aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t *obuf); 46 46 47 47 /** generic pitch detection structure */ … … 55 55 aubio_pitchschmitt_t * schmitt; /**< schmitt object */ 56 56 aubio_pitchyinfft_t * yinfft; /**< yinfft object */ 57 aubio_pitchyin_t * yin; /**< yinfft object */ 57 58 aubio_filter_t * filter; /**< filter */ 58 59 aubio_pvoc_t * pv; /**< phase vocoder for mcomb */ 59 60 cvec_t * fftgrain; /**< spectral frame for mcomb */ 60 61 fvec_t * buf; /**< temporary buffer for yin */ 61 fvec_t * yin; /**< yin function */62 smpl_t yinthres; /**< yin peak picking threshold parameter */63 62 aubio_pitchdetection_func_t callback; /**< pointer to current pitch detection method */ 64 63 aubio_pitchdetection_conv_t freqconv; /**< pointer to current pitch conversion method */ … … 97 96 case aubio_pitch_yin: 98 97 p->buf = new_fvec(bufsize,channels); 99 p->yin = new_ fvec(bufsize/2,channels);98 p->yin = new_aubio_pitchyin(bufsize); 100 99 p->callback = aubio_pitchdetection_yin; 101 p->yinthres = 0.15;100 aubio_pitchyin_set_tolerance (p->yin, 0.15); 102 101 break; 103 102 case aubio_pitch_mcomb: 104 103 p->pv = new_aubio_pvoc(bufsize, hopsize, channels); 105 104 p->fftgrain = new_cvec(bufsize, channels); 106 p->mcomb = new_aubio_pitchmcomb(bufsize,hopsize,channels ,samplerate);105 p->mcomb = new_aubio_pitchmcomb(bufsize,hopsize,channels); 107 106 p->filter = new_aubio_filter_c_weighting (samplerate, channels); 108 107 p->callback = aubio_pitchdetection_mcomb; … … 110 109 case aubio_pitch_fcomb: 111 110 p->buf = new_fvec(bufsize,channels); 112 p->fcomb = new_aubio_pitchfcomb(bufsize,hopsize, samplerate);111 p->fcomb = new_aubio_pitchfcomb(bufsize,hopsize,channels); 113 112 p->callback = aubio_pitchdetection_fcomb; 114 113 break; 115 114 case aubio_pitch_schmitt: 116 115 p->buf = new_fvec(bufsize,channels); 117 p->schmitt = new_aubio_pitchschmitt(bufsize ,samplerate);116 p->schmitt = new_aubio_pitchschmitt(bufsize); 118 117 p->callback = aubio_pitchdetection_schmitt; 119 118 break; … … 122 121 p->yinfft = new_aubio_pitchyinfft(bufsize); 123 122 p->callback = aubio_pitchdetection_yinfft; 124 p->yinthres = 0.85;123 aubio_pitchyinfft_set_tolerance (p->yinfft, 0.85); 125 124 break; 126 125 default: … … 150 149 switch(p->type) { 151 150 case aubio_pitch_yin: 152 del_fvec(p-> yin);153 del_ fvec(p->buf);151 del_fvec(p->buf); 152 del_aubio_pitchyin(p->yin); 154 153 break; 155 154 case aubio_pitch_mcomb: … … 192 191 } 193 192 194 void aubio_pitchdetection_set_yinthresh(aubio_pitchdetection_t *p, smpl_t thres) { 195 p->yinthres = thres; 196 } 197 198 smpl_t aubio_pitchdetection_do (aubio_pitchdetection_t *p, fvec_t * ibuf) { 199 return p->freqconv(p->callback(p,ibuf),p->srate,p->bufsize); 200 } 201 202 smpl_t aubio_pitchdetection_mcomb(aubio_pitchdetection_t *p, fvec_t *ibuf) { 203 smpl_t pitch = 0.; 193 void aubio_pitchdetection_set_tolerance(aubio_pitchdetection_t *p, smpl_t tol) { 194 switch(p->type) { 195 case aubio_pitch_yin: 196 aubio_pitchyin_set_tolerance (p->yin, tol); 197 break; 198 case aubio_pitch_yinfft: 199 aubio_pitchyinfft_set_tolerance (p->yinfft, tol); 200 break; 201 default: 202 break; 203 } 204 } 205 206 void aubio_pitchdetection_do (aubio_pitchdetection_t *p, fvec_t * ibuf, fvec_t *obuf) { 207 uint_t i; 208 p->callback(p, ibuf, obuf); 209 for (i = 0; i < obuf->channels; i++) { 210 p->freqconv(obuf->data[i][0],p->srate,p->bufsize); 211 } 212 } 213 214 void aubio_pitchdetection_mcomb(aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t * obuf) { 215 uint_t i; 204 216 aubio_filter_do(p->filter,ibuf); 205 217 aubio_pvoc_do(p->pv,ibuf,p->fftgrain); 206 pitch = aubio_pitchmcomb_do(p->mcomb,p->fftgrain); 207 /** \bug should move the >0 check within aubio_bintofreq */ 208 if (pitch>0.) { 209 pitch = aubio_bintofreq(pitch,p->srate,p->bufsize); 210 } else { 211 pitch = 0.; 212 } 213 return pitch; 214 } 215 216 smpl_t aubio_pitchdetection_yin(aubio_pitchdetection_t *p, fvec_t *ibuf) { 218 aubio_pitchmcomb_do(p->mcomb,p->fftgrain, obuf); 219 for (i = 0; i < obuf->channels; i++) { 220 obuf->data[i][0] = aubio_bintofreq (obuf->data[i][0], p->srate, p->bufsize); 221 } 222 } 223 224 void aubio_pitchdetection_yin(aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t * obuf) { 217 225 smpl_t pitch = 0.; 218 aubio_pitchdetection_slideblock(p,ibuf); 219 pitch = aubio_pitchyin_getpitchfast(p->buf,p->yin, p->yinthres); 220 if (pitch>0) { 221 pitch = p->srate/(pitch+0.); 222 } else { 223 pitch = 0.; 224 } 225 return pitch; 226 } 227 228 229 smpl_t aubio_pitchdetection_yinfft(aubio_pitchdetection_t *p, fvec_t *ibuf){ 226 uint_t i; 227 aubio_pitchdetection_slideblock(p,ibuf); 228 aubio_pitchyin_do(p->yin,p->buf, obuf); 229 for (i = 0; i < obuf->channels; i++) { 230 pitch = obuf->data[i][0]; 231 if (pitch>0) { 232 pitch = p->srate/(pitch+0.); 233 } else { 234 pitch = 0.; 235 } 236 obuf->data[i][0] = pitch; 237 } 238 } 239 240 241 void aubio_pitchdetection_yinfft(aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t * obuf){ 230 242 smpl_t pitch = 0.; 231 aubio_pitchdetection_slideblock(p,ibuf); 232 pitch = aubio_pitchyinfft_do(p->yinfft,p->buf,p->yinthres); 233 if (pitch>0) { 234 pitch = p->srate/(pitch+0.); 235 } else { 236 pitch = 0.; 237 } 238 return pitch; 239 } 240 241 smpl_t aubio_pitchdetection_fcomb(aubio_pitchdetection_t *p, fvec_t *ibuf){ 242 aubio_pitchdetection_slideblock(p,ibuf); 243 return aubio_pitchfcomb_do(p->fcomb,p->buf); 244 } 245 246 smpl_t aubio_pitchdetection_schmitt(aubio_pitchdetection_t *p, fvec_t *ibuf){ 247 aubio_pitchdetection_slideblock(p,ibuf); 248 return aubio_pitchschmitt_do(p->schmitt,p->buf); 249 } 243 uint_t i; 244 aubio_pitchdetection_slideblock(p,ibuf); 245 aubio_pitchyinfft_do(p->yinfft,p->buf,obuf); 246 for (i = 0; i < obuf->channels; i++) { 247 pitch = obuf->data[i][0]; 248 if (pitch>0) { 249 pitch = p->srate/(pitch+0.); 250 } else { 251 pitch = 0.; 252 } 253 obuf->data[i][0] = pitch; 254 } 255 } 256 257 void aubio_pitchdetection_fcomb(aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t * out){ 258 uint_t i; 259 aubio_pitchdetection_slideblock(p,ibuf); 260 aubio_pitchfcomb_do(p->fcomb,p->buf, out); 261 for (i = 0; i < out->channels; i++) { 262 out->data[i][0] = aubio_bintofreq (out->data[i][0], p->srate, p->bufsize); 263 } 264 } 265 266 void aubio_pitchdetection_schmitt(aubio_pitchdetection_t *p, fvec_t *ibuf, fvec_t *out){ 267 smpl_t period, pitch = 0.; 268 uint_t i; 269 aubio_pitchdetection_slideblock(p,ibuf); 270 aubio_pitchschmitt_do(p->schmitt,p->buf, out); 271 for (i = 0; i < out->channels; i++) { 272 period = out->data[i][0]; 273 if (period>0) { 274 pitch = p->srate/period; 275 } else { 276 pitch = 0.; 277 } 278 out->data[i][0] = pitch; 279 } 280 } -
src/pitch/pitchdetection.h
r22d33e2 r7a6cbbe 59 59 60 60 */ 61 smpl_t aubio_pitchdetection_do (aubio_pitchdetection_t * p, fvec_t * ibuf);61 void aubio_pitchdetection_do (aubio_pitchdetection_t * p, fvec_t * ibuf, fvec_t * obuf); 62 62 63 63 /** change yin or yinfft tolerance threshold … … 66 66 67 67 */ 68 void aubio_pitchdetection_set_ yinthresh(aubio_pitchdetection_t *p, smpl_t thres);68 void aubio_pitchdetection_set_tolerance(aubio_pitchdetection_t *p, smpl_t tol); 69 69 70 70 /** deletion of the pitch detection object
Note: See TracChangeset
for help on using the changeset viewer.