Changeset 2ba3440
- Timestamp:
- Oct 8, 2009, 8:24:43 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:
- 22d33e2
- Parents:
- f162cf9
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/pitch/pitchyin.c
rf162cf9 r2ba3440 30 30 #include "mathutils.h" 31 31 #include "pitch/pitchyin.h" 32 33 struct _aubio_pitchyin_t { 34 fvec_t * yin; 35 smpl_t tol; 36 }; 37 38 /** compute difference function 39 40 \param input input signal 41 \param yinbuf output buffer to store difference function (half shorter than input) 42 43 */ 44 void aubio_pitchyin_diff(fvec_t * input, fvec_t * yinbuf); 45 46 /** in place computation of the YIN cumulative normalised function 47 48 \param yinbuf input signal (a square difference function), also used to store function 49 50 */ 51 void aubio_pitchyin_getcum(fvec_t * yinbuf); 52 53 /** detect pitch in a YIN function 54 55 \param yinbuf input buffer as computed by aubio_pitchyin_getcum 56 57 */ 58 uint_t aubio_pitchyin_getpitch(fvec_t *yinbuf); 59 60 aubio_pitchyin_t * new_aubio_pitchyin (uint_t bufsize) { 61 aubio_pitchyin_t * o = AUBIO_NEW(aubio_pitchyin_t); 62 o->yin = new_fvec (bufsize/2, 1); 63 o->tol = 0.15; 64 return o; 65 } 66 67 void del_aubio_pitchyin (aubio_pitchyin_t *o) { 68 del_fvec(o->yin); 69 AUBIO_FREE(o); 70 } 32 71 33 72 /* outputs the difference function */ … … 89 128 90 129 /* all the above in one */ 91 smpl_t aubio_pitchyin_getpitchfast(fvec_t * input, fvec_t * yin, smpl_t tol){ 92 uint_t c=0,j,tau = 0; 130 void aubio_pitchyin_do(aubio_pitchyin_t *o, fvec_t * input, fvec_t * out){ 131 smpl_t tol = o->tol; 132 fvec_t * yin = o->yin; 133 uint_t c , j,tau = 0; 93 134 sint_t period; 94 135 smpl_t tmp = 0., tmp2 = 0.; 95 yin->data[c][0] = 1.; 96 for (tau=1;tau<yin->length;tau++) 97 { 98 yin->data[c][tau] = 0.; 99 for (j=0;j<yin->length;j++) 136 for (c = 0; c < input->channels; c++) { 137 yin->data[c][0] = 1.; 138 for (tau=1;tau<yin->length;tau++) 100 139 { 101 tmp = input->data[c][j] - input->data[c][j+tau]; 102 yin->data[c][tau] += SQR(tmp); 140 yin->data[c][tau] = 0.; 141 for (j=0;j<yin->length;j++) 142 { 143 tmp = input->data[c][j] - input->data[c][j+tau]; 144 yin->data[c][tau] += SQR(tmp); 145 } 146 tmp2 += yin->data[c][tau]; 147 yin->data[c][tau] *= tau/tmp2; 148 period = tau-3; 149 if(tau > 4 && (yin->data[c][period] < tol) && 150 (yin->data[c][period] < yin->data[c][period+1])) { 151 out->data[c][0] = fvec_quadint(yin,period,1); 152 goto beach; 153 } 103 154 } 104 tmp2 += yin->data[c][tau]; 105 yin->data[c][tau] *= tau/tmp2; 106 period = tau-3; 107 if(tau > 4 && (yin->data[c][period] < tol) && 108 (yin->data[c][period] < yin->data[c][period+1])) { 109 return fvec_quadint(yin,period,1); 110 } 155 out->data[c][0] = fvec_quadint(yin,fvec_min_elem(yin),1); 156 beach: 157 continue; 111 158 } 112 return fvec_quadint(yin,fvec_min_elem(yin),1);113 159 //return 0; 114 160 } 115 161 162 uint_t aubio_pitchyin_set_tolerance (aubio_pitchyin_t *o, smpl_t tol) { 163 o->tol = tol; 164 return 0; 165 } 166 167 smpl_t aubio_pitchyin_get_tolerance (aubio_pitchyin_t *o) { 168 return o->tol; 169 } -
src/pitch/pitchyin.h
rf162cf9 r2ba3440 38 38 #endif 39 39 40 /** compute difference function 40 /** pitch detection object */ 41 typedef struct _aubio_pitchyin_t aubio_pitchyin_t; 42 43 /** creation of the pitch detection object 44 45 \param bufsize size of the input buffer to analyse 46 47 */ 48 aubio_pitchyin_t * new_aubio_pitchyin (uint_t bufsize); 49 50 /** deletion of the pitch detection object 51 52 \param p pitch detection object as returned by new_aubio_pitchyin() 53 54 */ 55 void del_aubio_pitchyin (aubio_pitchyin_t * o); 56 57 /** execute pitch detection on an input buffer 58 59 \param p pitch detection object as returned by new_aubio_pitchyin() 60 \param input input signal window (length as specified at creation time) 61 \param tol tolerance parameter for minima selection [default 0.85] 62 63 */ 64 void aubio_pitchyin_do (aubio_pitchyin_t * o, fvec_t *in, fvec_t *out); 65 66 67 /** set tolerance parameter for YIN algorithm 41 68 42 \param input input signal 43 \param yinbuf output buffer to store difference function (half shorter than input) 44 45 */ 46 void aubio_pitchyin_diff(fvec_t * input, fvec_t * yinbuf); 47 48 /** in place computation of the YIN cumulative normalised function 49 50 \param yinbuf input signal (a square difference function), also used to store function 51 52 */ 53 void aubio_pitchyin_getcum(fvec_t * yinbuf); 54 55 /** detect pitch in a YIN function 56 57 \param yinbuf input buffer as computed by aubio_pitchyin_getcum 58 59 */ 60 uint_t aubio_pitchyin_getpitch(fvec_t *yinbuf); 61 62 /** fast implementation of the YIN algorithm 63 64 \param input input signal 65 \param yinbuf input buffer used to compute the YIN function 69 \param o YIN pitch detection object 66 70 \param tol tolerance parameter for minima selection [default 0.15] 67 71 68 72 */ 69 smpl_t aubio_pitchyin_getpitchfast(fvec_t * input, fvec_t *yinbuf, smpl_t tol); 73 uint_t aubio_pitchyin_set_tolerance (aubio_pitchyin_t *o, smpl_t tol); 74 75 /** get tolerance parameter for YIN algorithm 76 77 \param o YIN pitch detection object 78 \return tolerance parameter for minima selection [default 0.15] 79 80 */ 81 smpl_t aubio_pitchyin_get_tolerance (aubio_pitchyin_t *o); 70 82 71 83 #ifdef __cplusplus -
tests/src/test-pitchyin.c
rf162cf9 r2ba3440 7 7 fvec_t * in = new_fvec (win_s, channels); /* input buffer */ 8 8 fvec_t * out = new_fvec (win_s/2, channels); /* input buffer */ 9 aubio_pitchyin_t *p = new_aubio_pitchyin (win_s); 9 10 uint_t i = 0; 10 11 11 12 while (i < 10) { 12 aubio_pitchyin_diff (in,out); 13 aubio_pitchyin_getcum (out); 14 aubio_pitchyin_getpitch (out); 15 aubio_pitchyin_getpitchfast (in,out,0.2); 13 aubio_pitchyin_do (p, in,out); 16 14 i++; 17 15 };
Note: See TracChangeset
for help on using the changeset viewer.