Changeset 0b9a02a for src/onset/peakpicker.c
- Timestamp:
- Dec 4, 2009, 1:34:44 AM (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:
- d95ff38
- Parents:
- 66fb3ea
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/onset/peakpicker.c
r66fb3ea r0b9a02a 28 28 29 29 /** function pointer to thresholding function */ 30 typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input , uint_t channel);30 typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input); 31 31 /** function pointer to peak-picking function */ 32 32 typedef uint_t (*aubio_pickerfn_t)(fvec_t *input, uint_t pos); … … 69 69 fvec_t *scratch; 70 70 71 /** number of channels to analyse */72 uint_t channels;73 74 71 /** \bug should be used to calculate filter coefficients */ 75 72 /* cutoff: low-pass filter cutoff [0.34, 1] */ … … 97 94 smpl_t mean = 0., median = 0.; 98 95 uint_t length = p->win_post + p->win_pre + 1; 99 uint_t i, j = 0; 100 101 for (i = 0; i < p->channels; i++) { 102 /* store onset in onset_keep */ 103 /* shift all elements but last, then write last */ 104 for (j = 0; j < length - 1; j++) { 105 onset_keep->data[i][j] = onset_keep->data[i][j + 1]; 106 onset_proc->data[i][j] = onset_keep->data[i][j]; 107 } 108 onset_keep->data[i][length - 1] = onset->data[i][0]; 109 onset_proc->data[i][length - 1] = onset->data[i][0]; 96 uint_t j = 0; 97 98 /* store onset in onset_keep */ 99 /* shift all elements but last, then write last */ 100 for (j = 0; j < length - 1; j++) { 101 onset_keep->data[j] = onset_keep->data[j + 1]; 102 onset_proc->data[j] = onset_keep->data[j]; 110 103 } 104 onset_keep->data[length - 1] = onset->data[0]; 105 onset_proc->data[length - 1] = onset->data[0]; 111 106 112 107 /* filter onset_proc */ … … 114 109 aubio_filter_do_filtfilt (p->biquad, onset_proc, scratch); 115 110 116 for (i = 0; i < p->channels; i++) { 117 /* calculate mean and median for onset_proc */ 118 mean = fvec_mean_channel (onset_proc, i); 119 /* copy to scratch */ 120 for (j = 0; j < length; j++) 121 scratch->data[i][j] = onset_proc->data[i][j]; 122 median = p->thresholdfn (scratch, i); 123 124 /* shift peek array */ 125 for (j = 0; j < 3 - 1; j++) 126 onset_peek->data[i][j] = onset_peek->data[i][j + 1]; 127 /* calculate new tresholded value */ 128 thresholded->data[i][0] = 129 onset_proc->data[i][p->win_post] - median - mean * p->threshold; 130 onset_peek->data[i][2] = thresholded->data[i][0]; 131 out->data[i][0] = (p->pickerfn) (onset_peek, 1); 132 if (out->data[i][0]) { 133 out->data[i][0] = fvec_quadint (onset_peek, 1, i); 134 } 111 /* calculate mean and median for onset_proc */ 112 mean = fvec_mean (onset_proc); 113 /* copy to scratch */ 114 for (j = 0; j < length; j++) 115 scratch->data[j] = onset_proc->data[j]; 116 median = p->thresholdfn (scratch); 117 118 /* shift peek array */ 119 for (j = 0; j < 3 - 1; j++) 120 onset_peek->data[j] = onset_peek->data[j + 1]; 121 /* calculate new tresholded value */ 122 thresholded->data[0] = 123 onset_proc->data[p->win_post] - median - mean * p->threshold; 124 onset_peek->data[2] = thresholded->data[0]; 125 out->data[0] = (p->pickerfn) (onset_peek, 1); 126 if (out->data[0]) { 127 out->data[0] = fvec_quadint (onset_peek, 1); 135 128 } 136 129 } … … 173 166 174 167 aubio_peakpicker_t * 175 new_aubio_peakpicker ( uint_t channels)168 new_aubio_peakpicker () 176 169 { 177 170 aubio_peakpicker_t *t = AUBIO_NEW (aubio_peakpicker_t); … … 179 172 t->win_post = 5; 180 173 t->win_pre = 1; 181 //channels = 1; 182 t->channels = channels; 183 184 t->thresholdfn = (aubio_thresholdfn_t) (fvec_median_channel); /* (fvec_mean); */ 174 175 t->thresholdfn = (aubio_thresholdfn_t) (fvec_median); /* (fvec_mean); */ 185 176 t->pickerfn = (aubio_pickerfn_t) (fvec_peakpick); 186 177 187 t->scratch = new_fvec (t->win_post + t->win_pre + 1 , channels);188 t->onset_keep = new_fvec (t->win_post + t->win_pre + 1 , channels);189 t->onset_proc = new_fvec (t->win_post + t->win_pre + 1 , channels);190 t->onset_peek = new_fvec (3 , channels);191 t->thresholded = new_fvec (1 , channels);178 t->scratch = new_fvec (t->win_post + t->win_pre + 1); 179 t->onset_keep = new_fvec (t->win_post + t->win_pre + 1); 180 t->onset_proc = new_fvec (t->win_post + t->win_pre + 1); 181 t->onset_peek = new_fvec (3); 182 t->thresholded = new_fvec (1); 192 183 193 184 /* cutoff: low-pass filter with cutoff reduced frequency at 0.34 … … 195 186 */ 196 187 t->biquad = new_aubio_filter_biquad (0.15998789, 0.31997577, 0.15998789, 197 -0.59488894, 0.23484048 , channels);188 -0.59488894, 0.23484048); 198 189 199 190 return t;
Note: See TracChangeset
for help on using the changeset viewer.