Changeset 8040cca for src/pitch/pitchfcomb.c
- Timestamp:
- Oct 8, 2009, 7:46:46 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:
- e5757cf
- Parents:
- 6fc103d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/pitch/pitchfcomb.c
r6fc103d r8040cca 28 28 29 29 typedef struct { 30 smpl_t freq;30 smpl_t bin; 31 31 smpl_t db; 32 32 } aubio_fpeak_t; … … 41 41 fvec_t * fftLastPhase; 42 42 aubio_fft_t * fft; 43 //aubio_pvoc_t * pvoc;44 43 }; 45 44 46 aubio_pitchfcomb_t * new_aubio_pitchfcomb (uint_t bufsize, uint_t hopsize, uint_t samplerate)45 aubio_pitchfcomb_t * new_aubio_pitchfcomb (uint_t bufsize, uint_t hopsize, uint_t channels) 47 46 { 48 47 aubio_pitchfcomb_t * p = AUBIO_NEW(aubio_pitchfcomb_t); 49 p->rate = samplerate;50 48 p->fftSize = bufsize; 51 49 p->stepSize = hopsize; 52 50 p->winput = new_fvec(bufsize,1); 53 51 p->fftOut = new_cvec(bufsize,1); 54 p->fftLastPhase = new_fvec(bufsize, 1);52 p->fftLastPhase = new_fvec(bufsize, channels); 55 53 p->fft = new_aubio_fft(bufsize, 1); 56 54 p->win = new_aubio_window(bufsize, aubio_win_hanning); … … 59 57 60 58 /* input must be stepsize long */ 61 smpl_t aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, fvec_t * input)59 void aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, fvec_t * input, fvec_t * output) 62 60 { 63 uint_t k, l, maxharm = 0; 64 smpl_t freqPerBin = p->rate/(smpl_t)p->fftSize, 65 phaseDifference = TWO_PI*(smpl_t)p->stepSize/(smpl_t)p->fftSize; 61 uint_t i, k, l, maxharm = 0; 62 smpl_t phaseDifference = TWO_PI*(smpl_t)p->stepSize/(smpl_t)p->fftSize; 66 63 aubio_fpeak_t peaks[MAX_PEAKS]; 64 65 for (i = 0; i < input->channels; i++) { 67 66 68 67 for (k=0; k<MAX_PEAKS; k++) { 69 68 peaks[k].db = -200.; 70 peaks[k]. freq= 0.;69 peaks[k].bin = 0.; 71 70 } 72 71 73 72 for (k=0; k < input->length; k++){ 74 p->winput->data[0][k] = p->win->data[0][k] * input->data[ 0][k];73 p->winput->data[0][k] = p->win->data[0][k] * input->data[i][k]; 75 74 } 76 75 aubio_fft_do(p->fft,p->winput,p->fftOut); … … 80 79 magnitude = 20.*LOG10(2.*p->fftOut->norm[0][k]/(smpl_t)p->fftSize), 81 80 phase = p->fftOut->phas[0][k], 82 tmp, freq;81 tmp, bin; 83 82 84 83 /* compute phase difference */ 85 tmp = phase - p->fftLastPhase->data[ 0][k];86 p->fftLastPhase->data[ 0][k] = phase;84 tmp = phase - p->fftLastPhase->data[i][k]; 85 p->fftLastPhase->data[i][k] = phase; 87 86 88 87 /* subtract expected phase difference */ … … 95 94 tmp = p->fftSize/(smpl_t)p->stepSize*tmp/(TWO_PI); 96 95 97 /* compute the k-th partials' true frequency*/98 freq = (smpl_t)k*freqPerBin + tmp*freqPerBin;96 /* compute the k-th partials' true bin */ 97 bin = (smpl_t)k + tmp; 99 98 100 if ( freq> 0.0 && magnitude > peaks[0].db) { // && magnitude < 0) {99 if (bin > 0.0 && magnitude > peaks[0].db) { // && magnitude < 0) { 101 100 memmove(peaks+1, peaks, sizeof(aubio_fpeak_t)*(MAX_PEAKS-1)); 102 peaks[0]. freq = freq;101 peaks[0].bin = bin; 103 102 peaks[0].db = magnitude; 104 103 } … … 106 105 107 106 k = 0; 108 for (l=1; l<MAX_PEAKS && peaks[l]. freq> 0.0; l++) {107 for (l=1; l<MAX_PEAKS && peaks[l].bin > 0.0; l++) { 109 108 sint_t harmonic; 110 109 for (harmonic=5; harmonic>1; harmonic--) { 111 if (peaks[0]. freq / peaks[l].freq< harmonic+.02 &&112 peaks[0]. freq / peaks[l].freq> harmonic-.02) {110 if (peaks[0].bin / peaks[l].bin < harmonic+.02 && 111 peaks[0].bin / peaks[l].bin > harmonic-.02) { 113 112 if (harmonic > (sint_t)maxharm && 114 113 peaks[0].db < peaks[l].db/2) { … … 119 118 } 120 119 } 120 output->data[i][0] = peaks[k].bin; 121 121 /* quick hack to clean output a bit */ 122 if (peaks[k]. freq > 5000.) return0.;123 return peaks[k].freq;122 if (peaks[k].bin > 5000.) output->data[i][0] = 0.; 123 } 124 124 } 125 125
Note: See TracChangeset
for help on using the changeset viewer.