Changeset 10cf306
- Timestamp:
- Nov 7, 2007, 5:13:27 PM (17 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:
- c8cbf3c
- Parents:
- f218f29
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/pitchyinfft.c
rf218f29 r10cf306 36 36 37 37 static const smpl_t freqs[] = {0., 20., 25., 31.5, 40., 50., 63., 80., 100., 38 39 40 38 125., 160., 200., 250., 315., 400., 500., 630., 800., 1000., 1250., 39 1600., 2000., 2500., 3150., 4000., 5000., 6300., 8000., 9000., 10000., 40 12500., 15000., 20000., 25100}; 41 41 42 42 static const smpl_t weight[] = {-75.8, -70.1, -60.8, -52.1, -44.2, -37.5, 43 44 45 43 -31.3, -25.6, -20.9, -16.5, -12.6, -9.6, -7.0, -4.7, -3.0, -1.8, -0.8, 44 -0.2, -0.0, 0.5, 1.6, 3.2, 5.4, 7.8, 8.1, 5.3, -2.4, -11.1, -12.8, 45 -12.2, -7.4, -17.8, -17.8, -17.8}; 46 46 47 47 aubio_pitchyinfft_t * new_aubio_pitchyinfft (uint_t bufsize) 48 48 { 49 49 aubio_pitchyinfft_t * p = AUBIO_NEW(aubio_pitchyinfft_t); 50 p->winput 51 p->fft 52 p->fftout 53 p->sqrmag 54 p->res 55 p->yinfft 56 p->win 50 p->winput = new_fvec(bufsize,1); 51 p->fft = new_aubio_fft(bufsize, 1); 52 p->fftout = new_cvec(bufsize,1); 53 p->sqrmag = new_fvec(bufsize,1); 54 p->res = new_cvec(bufsize,1); 55 p->yinfft = new_fvec(bufsize/2+1,1); 56 p->win = new_fvec(bufsize,1); 57 57 aubio_window(p->win->data[0], bufsize, aubio_win_hanningz); 58 58 p->weight = new_fvec(bufsize/2+1,1); 59 59 { 60 61 62 63 64 65 66 67 68 69 70 71 if (f0 == f1) { // just in case 72 73 74 75 76 p->weight->data[0][i] = (a1-a0)/(f1-f0)*freq + 77 78 79 80 81 82 83 84 85 60 uint_t i = 0, j = 1; 61 smpl_t freq = 0, a0 = 0, a1 = 0, f0 = 0, f1 = 0; 62 for (i=0; i<p->weight->length; i++) { 63 freq = (smpl_t)i/(smpl_t)bufsize*(smpl_t)44100.; 64 while (freq > freqs[j]) { 65 j +=1; 66 } 67 a0 = weight[j-1]; 68 f0 = freqs[j-1]; 69 a1 = weight[j]; 70 f1 = freqs[j]; 71 if (f0 == f1) { // just in case 72 p->weight->data[0][i] = a0; 73 } else if (f0 == 0) { // y = ax+b 74 p->weight->data[0][i] = (a1-a0)/f1*freq + a0; 75 } else { 76 p->weight->data[0][i] = (a1-a0)/(f1-f0)*freq + 77 (a0 - (a1 - a0)/(f1/f0 - 1.)); 78 } 79 while (freq > freqs[j]) { 80 j +=1; 81 } 82 //AUBIO_DBG("%f\n",p->weight->data[0][i]); 83 p->weight->data[0][i] = DB2LIN(p->weight->data[0][i]); 84 //p->weight->data[0][i] = SQRT(DB2LIN(p->weight->data[0][i])); 85 } 86 86 } 87 87 return p; … … 95 95 fvec_t * yin = (fvec_t *)p->yinfft; 96 96 for (l=0; l < input->length; l++){ 97 97 p->winput->data[0][l] = p->win->data[0][l] * input->data[0][l]; 98 98 } 99 99 aubio_fft_do(p->fft,p->winput,p->fftout); 100 100 for (l=0; l < p->fftout->length; l++){ 101 102 p->sqrmag->data[0][l] *= p->weight->data[0][l]; 101 p->sqrmag->data[0][l] = SQR(p->fftout->norm[0][l]); 102 p->sqrmag->data[0][l] *= p->weight->data[0][l]; 103 103 } 104 104 for (l=1; l < p->fftout->length; l++){ 105 p->sqrmag->data[0][(p->fftout->length-1)*2-l] = 106 107 108 105 p->sqrmag->data[0][(p->fftout->length-1)*2-l] = 106 SQR(p->fftout->norm[0][l]); 107 p->sqrmag->data[0][(p->fftout->length-1)*2-l] *= 108 p->weight->data[0][l]; 109 109 } 110 110 for (l=0; l < p->sqrmag->length/2+1; l++) { 111 111 sum += p->sqrmag->data[0][l]; 112 112 } 113 113 sum *= 2.; 114 114 aubio_fft_do(p->fft,p->sqrmag,res); 115 yin->data[0][0] = 1.; 115 yin->data[0][0] = 1.; 116 116 for (tau=1; tau < yin->length; tau++) { 117 118 res->norm[0][tau]*COS(res->phas[0][tau]); 119 120 117 yin->data[0][tau] = sum - 118 res->norm[0][tau]*COS(res->phas[0][tau]); 119 tmp += yin->data[0][tau]; 120 yin->data[0][tau] *= tau/tmp; 121 121 } 122 tau = vec_min_elem(yin); 122 tau = vec_min_elem(yin); 123 123 if (yin->data[0][tau] < tol) { 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 124 /* no interpolation */ 125 //return tau; 126 /* 3 point quadratic interpolation */ 127 //return vec_quadint_min(yin,tau,1); 128 /* additional check for (unlikely) octave doubling in higher frequencies */ 129 if (tau>35) { 130 return vec_quadint_min(yin,tau,1); 131 } else { 132 /* should compare the minimum value of each interpolated peaks */ 133 halfperiod = FLOOR(tau/2+.5); 134 if (yin->data[0][halfperiod] < tol) 135 return vec_quadint_min(yin,halfperiod,1); 136 else 137 return vec_quadint_min(yin,tau,1); 138 } 139 139 } else 140 140 return 0; 141 141 } 142 142 143 143 void del_aubio_pitchyinfft(aubio_pitchyinfft_t *p){ 144 145 146 147 148 149 150 151 152 144 del_fvec(p->win); 145 del_aubio_fft(p->fft); 146 del_fvec(p->yinfft); 147 del_fvec(p->sqrmag); 148 del_cvec(p->res); 149 del_cvec(p->fftout); 150 del_fvec(p->winput); 151 del_fvec(p->weight); 152 AUBIO_FREE(p); 153 153 }
Note: See TracChangeset
for help on using the changeset viewer.