- Timestamp:
- Nov 21, 2007, 11:59:54 AM (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:
- fabb7cd
- Parents:
- 2a00568
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/onsetdetection.c
r2a00568 rec2fa2a 31 31 /** Pointer to aubio_onsetdetection_<type> function */ 32 32 void (*funcpointer)(aubio_onsetdetection_t *o, 33 cvec_t * fftgrain, fvec_t * onset);33 cvec_t * fftgrain, fvec_t * onset); 34 34 smpl_t threshold; /**< minimum norm threshold for phase and specdiff */ 35 35 fvec_t *oldmag; /**< previous norm vector */ … … 44 44 /* Energy based onset detection function */ 45 45 void aubio_onsetdetection_energy (aubio_onsetdetection_t *o UNUSED, 46 47 48 49 50 51 52 53 46 cvec_t * fftgrain, fvec_t * onset) { 47 uint_t i,j; 48 for (i=0;i<fftgrain->channels;i++) { 49 onset->data[i][0] = 0.; 50 for (j=0;j<fftgrain->length;j++) { 51 onset->data[i][0] += SQR(fftgrain->norm[i][j]); 52 } 53 } 54 54 } 55 55 … … 57 57 void aubio_onsetdetection_hfc(aubio_onsetdetection_t *o UNUSED, 58 58 cvec_t * fftgrain, fvec_t * onset){ 59 60 61 62 63 64 65 59 uint_t i,j; 60 for (i=0;i<fftgrain->channels;i++) { 61 onset->data[i][0] = 0.; 62 for (j=0;j<fftgrain->length;j++) { 63 onset->data[i][0] += (j+1)*fftgrain->norm[i][j]; 64 } 65 } 66 66 } 67 67 … … 69 69 /* Complex Domain Method onset detection function */ 70 70 void aubio_onsetdetection_complex (aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset) { 71 72 73 for (i=0;i<fftgrain->channels; i++){74 75 for (j=0;j<nbins; j++){76 o->dev1->data[i][j]= aubio_unwrap2pi(77 78 79 71 uint_t i, j; 72 uint_t nbins = fftgrain->length; 73 for (i=0;i<fftgrain->channels; i++) { 74 onset->data[i][0] = 0.; 75 for (j=0;j<nbins; j++) { 76 o->dev1->data[i][j] = aubio_unwrap2pi( 77 fftgrain->phas[i][j] 78 -2.0*o->theta1->data[i][j]+ 79 o->theta2->data[i][j]); 80 80 #ifdef HAVE_COMPLEX_H 81 82 83 onset->data[i][0]+= //(fftgrain->norm[i][j]);84 85 86 81 o->meas[j] = fftgrain->norm[i][j]*CEXPC(I*o->dev1->data[i][j]); 82 /* sum on all bins */ 83 onset->data[i][0] += //(fftgrain->norm[i][j]); 84 SQRT(SQR( REAL(o->oldmag->data[i][j]-o->meas[j]) ) 85 + SQR( IMAG(o->oldmag->data[i][j]-o->meas[j]) ) 86 ); 87 87 #else 88 89 90 91 onset->data[i][0]+= //(fftgrain->norm[i][j]);92 93 94 88 o->meas[j] = (fftgrain->norm[i][j])*COS(o->dev1->data[i][j]); 89 o->meas[(nbins-1)*2-j] = (fftgrain->norm[i][j])*SIN(o->dev1->data[i][j]); 90 /* sum on all bins */ 91 onset->data[i][0] += //(fftgrain->norm[i][j]); 92 SQRT(SQR( (o->oldmag->data[i][j]-o->meas[j]) ) 93 + SQR( (-o->meas[(nbins-1)*2-j]) ) 94 ); 95 95 #endif 96 97 98 99 100 101 102 96 /* swap old phase data (need to remember 2 frames behind)*/ 97 o->theta2->data[i][j] = o->theta1->data[i][j]; 98 o->theta1->data[i][j] = fftgrain->phas[i][j]; 99 /* swap old magnitude data (1 frame is enough) */ 100 o->oldmag->data[i][j] = fftgrain->norm[i][j]; 101 } 102 } 103 103 } 104 104 … … 106 106 /* Phase Based Method onset detection function */ 107 107 void aubio_onsetdetection_phase(aubio_onsetdetection_t *o, 108 109 110 111 for (i=0;i<fftgrain->channels; i++){112 113 114 for ( j=0;j<nbins; j++ ){115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 onset->data[i][0] = aubio_hist_mean(o->histog); 134 135 108 cvec_t * fftgrain, fvec_t * onset){ 109 uint_t i, j; 110 uint_t nbins = fftgrain->length; 111 for (i=0;i<fftgrain->channels; i++) { 112 onset->data[i][0] = 0.0f; 113 o->dev1->data[i][0]=0.; 114 for ( j=0;j<nbins; j++ ) { 115 o->dev1->data[i][j] = 116 aubio_unwrap2pi( 117 fftgrain->phas[i][j] 118 -2.0*o->theta1->data[i][j] 119 +o->theta2->data[i][j]); 120 if ( o->threshold < fftgrain->norm[i][j] ) 121 o->dev1->data[i][j] = ABS(o->dev1->data[i][j]); 122 else 123 o->dev1->data[i][j] = 0.0f; 124 /* keep a track of the past frames */ 125 o->theta2->data[i][j] = o->theta1->data[i][j]; 126 o->theta1->data[i][j] = fftgrain->phas[i][j]; 127 } 128 /* apply o->histogram */ 129 aubio_hist_dyn_notnull(o->histog,o->dev1); 130 /* weight it */ 131 aubio_hist_weight(o->histog); 132 /* its mean is the result */ 133 onset->data[i][0] = aubio_hist_mean(o->histog); 134 //onset->data[i][0] = vec_mean(o->dev1); 135 } 136 136 } 137 137 138 138 /* Spectral difference method onset detection function */ 139 139 void aubio_onsetdetection_specdiff(aubio_onsetdetection_t *o, 140 141 142 143 for (i=0;i<fftgrain->channels; i++){144 145 for (j=0;j<nbins; j++){146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 onset->data[i][0] = aubio_hist_mean(o->histog); 163 164 140 cvec_t * fftgrain, fvec_t * onset){ 141 uint_t i, j; 142 uint_t nbins = fftgrain->length; 143 for (i=0;i<fftgrain->channels; i++) { 144 onset->data[i][0] = 0.0f; 145 for (j=0;j<nbins; j++) { 146 o->dev1->data[i][j] = SQRT( 147 ABS(SQR( fftgrain->norm[i][j]) 148 - SQR(o->oldmag->data[i][j]))); 149 if (o->threshold < fftgrain->norm[i][j] ) 150 o->dev1->data[i][j] = ABS(o->dev1->data[i][j]); 151 else 152 o->dev1->data[i][j] = 0.0f; 153 o->oldmag->data[i][j] = fftgrain->norm[i][j]; 154 } 155 156 /* apply o->histogram (act somewhat as a low pass on the 157 * overall function)*/ 158 aubio_hist_dyn_notnull(o->histog,o->dev1); 159 /* weight it */ 160 aubio_hist_weight(o->histog); 161 /* its mean is the result */ 162 onset->data[i][0] = aubio_hist_mean(o->histog); 163 164 } 165 165 } 166 166 … … 169 169 * negative (1.+) and infinite values (+1.e-10) */ 170 170 void aubio_onsetdetection_kl(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset){ 171 172 173 174 175 176 177 178 179 180 171 uint_t i,j; 172 for (i=0;i<fftgrain->channels;i++) { 173 onset->data[i][0] = 0.; 174 for (j=0;j<fftgrain->length;j++) { 175 onset->data[i][0] += fftgrain->norm[i][j] 176 *LOG(1.+fftgrain->norm[i][j]/(o->oldmag->data[i][j]+1.e-10)); 177 o->oldmag->data[i][j] = fftgrain->norm[i][j]; 178 } 179 if (isnan(onset->data[i][0])) onset->data[i][0] = 0.; 180 } 181 181 } 182 182 … … 185 185 * negative (1.+) and infinite values (+1.e-10) */ 186 186 void aubio_onsetdetection_mkl(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset){ 187 188 189 190 191 192 193 194 195 187 uint_t i,j; 188 for (i=0;i<fftgrain->channels;i++) { 189 onset->data[i][0] = 0.; 190 for (j=0;j<fftgrain->length;j++) { 191 onset->data[i][0] += LOG(1.+fftgrain->norm[i][j]/(o->oldmag->data[i][j]+1.e-10)); 192 o->oldmag->data[i][j] = fftgrain->norm[i][j]; 193 } 194 if (isnan(onset->data[i][0])) onset->data[i][0] = 0.; 195 } 196 196 } 197 197 … … 199 199 void 200 200 aubio_onsetdetection(aubio_onsetdetection_t *o, cvec_t * fftgrain, 201 202 201 fvec_t * onset) { 202 o->funcpointer(o,fftgrain,onset); 203 203 } 204 204 … … 208 208 aubio_onsetdetection_t * 209 209 new_aubio_onsetdetection (aubio_onsetdetection_type type, 210 211 212 210 uint_t size, uint_t channels){ 211 aubio_onsetdetection_t * o = AUBIO_NEW(aubio_onsetdetection_t); 212 uint_t rsize = size/2+1; 213 213 uint_t i; 214 switch(type) { 215 /* for both energy and hfc, only fftgrain->norm is required */ 216 case aubio_onset_energy: 217 break; 218 case aubio_onset_hfc: 219 break; 220 /* the other approaches will need some more memory spaces */ 221 case aubio_onset_complex: 222 o->oldmag = new_fvec(rsize,channels); 223 /** bug: must be complex array */ 224 o->meas = AUBIO_ARRAY(fft_data_t,size+1); 225 for (i=0; i<size+1; i++) o->meas[i] = 0; 226 o->dev1 = new_fvec(rsize,channels); 227 o->theta1 = new_fvec(rsize,channels); 228 o->theta2 = new_fvec(rsize,channels); 229 break; 230 case aubio_onset_phase: 231 o->dev1 = new_fvec(rsize,channels); 232 o->theta1 = new_fvec(rsize,channels); 233 o->theta2 = new_fvec(rsize,channels); 234 o->histog = new_aubio_hist(0.0f, PI, 10, channels); 235 o->threshold = 0.1; 236 break; 237 case aubio_onset_specdiff: 238 o->oldmag = new_fvec(rsize,channels); 239 o->dev1 = new_fvec(rsize,channels); 240 o->histog = new_aubio_hist(0.0f, PI, 10, channels); 241 o->threshold = 0.1; 242 break; 243 case aubio_onset_kl: 244 o->oldmag = new_fvec(rsize,channels); 245 break; 246 case aubio_onset_mkl: 247 o->oldmag = new_fvec(rsize,channels); 248 break; 249 default: 250 break; 251 } 252 253 /* this switch could be in its own function to change between 254 * detections on the fly. this would need getting rid of the switch 255 * above and always allocate all the structure */ 256 257 switch(type) { 258 case aubio_onset_energy: 259 o->funcpointer = aubio_onsetdetection_energy; 260 break; 261 case aubio_onset_hfc: 262 o->funcpointer = aubio_onsetdetection_hfc; 263 break; 264 case aubio_onset_complex: 265 o->funcpointer = aubio_onsetdetection_complex; 266 break; 267 case aubio_onset_phase: 268 o->funcpointer = aubio_onsetdetection_phase; 269 break; 270 case aubio_onset_specdiff: 271 o->funcpointer = aubio_onsetdetection_specdiff; 272 break; 273 case aubio_onset_kl: 274 o->funcpointer = aubio_onsetdetection_kl; 275 break; 276 case aubio_onset_mkl: 277 o->funcpointer = aubio_onsetdetection_mkl; 278 break; 279 default: 280 break; 281 } 282 o->type = type; 283 return o; 214 switch(type) { 215 /* for both energy and hfc, only fftgrain->norm is required */ 216 case aubio_onset_energy: 217 break; 218 case aubio_onset_hfc: 219 break; 220 /* the other approaches will need some more memory spaces */ 221 case aubio_onset_complex: 222 o->oldmag = new_fvec(rsize,channels); 223 /** bug: must be complex array */ 224 o->meas = AUBIO_ARRAY(fft_data_t,size+1); 225 for (i=0; i<size+1; i++) o->meas[i] = 0; 226 o->dev1 = new_fvec(rsize,channels); 227 o->theta1 = new_fvec(rsize,channels); 228 o->theta2 = new_fvec(rsize,channels); 229 break; 230 case aubio_onset_phase: 231 o->dev1 = new_fvec(rsize,channels); 232 o->theta1 = new_fvec(rsize,channels); 233 o->theta2 = new_fvec(rsize,channels); 234 o->histog = new_aubio_hist(0.0f, PI, 10, channels); 235 o->threshold = 0.1; 236 break; 237 case aubio_onset_specdiff: 238 o->oldmag = new_fvec(rsize,channels); 239 o->dev1 = new_fvec(rsize,channels); 240 o->histog = new_aubio_hist(0.0f, PI, 10, channels); 241 o->threshold = 0.1; 242 break; 243 case aubio_onset_kl: 244 case aubio_onset_mkl: 245 o->oldmag = new_fvec(rsize,channels); 246 break; 247 default: 248 break; 249 } 250 251 /* this switch could be in its own function to change between 252 * detections on the fly. this would need getting rid of the switch 253 * above and always allocate all the structure */ 254 255 switch(type) { 256 case aubio_onset_energy: 257 o->funcpointer = aubio_onsetdetection_energy; 258 break; 259 case aubio_onset_hfc: 260 o->funcpointer = aubio_onsetdetection_hfc; 261 break; 262 case aubio_onset_complex: 263 o->funcpointer = aubio_onsetdetection_complex; 264 break; 265 case aubio_onset_phase: 266 o->funcpointer = aubio_onsetdetection_phase; 267 break; 268 case aubio_onset_specdiff: 269 o->funcpointer = aubio_onsetdetection_specdiff; 270 break; 271 case aubio_onset_kl: 272 o->funcpointer = aubio_onsetdetection_kl; 273 break; 274 case aubio_onset_mkl: 275 o->funcpointer = aubio_onsetdetection_mkl; 276 break; 277 default: 278 break; 279 } 280 o->type = type; 281 return o; 284 282 } 285 283 286 284 void del_aubio_onsetdetection (aubio_onsetdetection_t *o){ 287 288 switch(o->type) { 289 /* for both energy and hfc, only fftgrain->norm is required */ 290 case aubio_onset_energy: 291 break; 292 case aubio_onset_hfc: 293 break; 294 /* the other approaches will need some more memory spaces */ 295 case aubio_onset_complex: 296 AUBIO_FREE(o->meas); 297 del_fvec(o->oldmag); 298 del_fvec(o->dev1); 299 del_fvec(o->theta1); 300 del_fvec(o->theta2); 301 break; 302 case aubio_onset_phase: 303 del_fvec(o->dev1); 304 del_fvec(o->theta1); 305 del_fvec(o->theta2); 306 del_aubio_hist(o->histog); 307 break; 308 case aubio_onset_specdiff: 309 del_fvec(o->oldmag); 310 del_fvec(o->dev1); 311 del_aubio_hist(o->histog); 312 break; 313 case aubio_onset_kl: 314 del_fvec(o->oldmag); 315 break; 316 case aubio_onset_mkl: 317 del_fvec(o->oldmag); 318 break; 319 default: 320 break; 321 } 322 AUBIO_FREE(o); 323 324 } 285 switch(o->type) { 286 /* for both energy and hfc, only fftgrain->norm is required */ 287 case aubio_onset_energy: 288 break; 289 case aubio_onset_hfc: 290 break; 291 /* the other approaches will need some more memory spaces */ 292 case aubio_onset_complex: 293 AUBIO_FREE(o->meas); 294 del_fvec(o->oldmag); 295 del_fvec(o->dev1); 296 del_fvec(o->theta1); 297 del_fvec(o->theta2); 298 break; 299 case aubio_onset_phase: 300 del_fvec(o->dev1); 301 del_fvec(o->theta1); 302 del_fvec(o->theta2); 303 del_aubio_hist(o->histog); 304 break; 305 case aubio_onset_specdiff: 306 del_fvec(o->oldmag); 307 del_fvec(o->dev1); 308 del_aubio_hist(o->histog); 309 break; 310 case aubio_onset_kl: 311 del_fvec(o->oldmag); 312 break; 313 case aubio_onset_mkl: 314 del_fvec(o->oldmag); 315 break; 316 default: 317 break; 318 } 319 AUBIO_FREE(o); 320 } -
src/onsetdetection.h
r2a00568 rec2fa2a 47 47 aubio_onset_phase, /**< phase fast */ 48 48 aubio_onset_kl, /**< Kullback Liebler */ 49 aubio_onset_mkl 49 aubio_onset_mkl, /**< modified Kullback Liebler */ 50 50 } aubio_onsetdetection_type; 51 51
Note: See TracChangeset
for help on using the changeset viewer.