Changeset fddfa64 for src/pitch/pitchmcomb.c
- Timestamp:
- Nov 3, 2009, 4:14:03 PM (14 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:
- bafe71d
- Parents:
- 63f3c70
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/pitch/pitchmcomb.c
r63f3c70 rfddfa64 29 29 typedef struct _aubio_spectralpeak_t aubio_spectralpeak_t; 30 30 typedef struct _aubio_spectralcandidate_t aubio_spectralcandidate_t; 31 uint_t aubio_pitchmcomb_get_root_peak(aubio_spectralpeak_t * peaks, uint_t length); 32 uint_t aubio_pitchmcomb_quadpick(aubio_spectralpeak_t * spectral_peaks, fvec_t * X); 33 void aubio_pitchmcomb_spectral_pp(aubio_pitchmcomb_t * p, fvec_t * oldmag); 34 void aubio_pitchmcomb_combdet(aubio_pitchmcomb_t * p, fvec_t * newmag); 31 uint_t aubio_pitchmcomb_get_root_peak (aubio_spectralpeak_t * peaks, 32 uint_t length); 33 uint_t aubio_pitchmcomb_quadpick (aubio_spectralpeak_t * spectral_peaks, 34 fvec_t * X); 35 void aubio_pitchmcomb_spectral_pp (aubio_pitchmcomb_t * p, fvec_t * oldmag); 36 void aubio_pitchmcomb_combdet (aubio_pitchmcomb_t * p, fvec_t * newmag); 35 37 /* not used but useful : sort by amplitudes (or anything else) 36 38 * sort_pitchpeak(peaks, length); 37 39 */ 38 40 /** spectral_peak comparison function (must return signed int) */ 39 static sint_t aubio_pitchmcomb_sort_peak_comp (const void *x, const void *y);41 static sint_t aubio_pitchmcomb_sort_peak_comp (const void *x, const void *y); 40 42 /** sort spectral_peak against their mag */ 41 void aubio_pitchmcomb_sort_peak (aubio_spectralpeak_t * peaks, uint_t nbins);43 void aubio_pitchmcomb_sort_peak (aubio_spectralpeak_t * peaks, uint_t nbins); 42 44 /** select the best candidates */ 43 uint_t aubio_pitch_cands(aubio_pitchmcomb_t * p, cvec_t * fftgrain, smpl_t * cands); 45 uint_t aubio_pitch_cands (aubio_pitchmcomb_t * p, cvec_t * fftgrain, 46 smpl_t * cands); 44 47 45 48 /** sort spectral_candidate against their comb ene */ 46 void aubio_pitchmcomb_sort_cand_ene(aubio_spectralcandidate_t ** candidates, uint_t nbins); 49 void aubio_pitchmcomb_sort_cand_ene (aubio_spectralcandidate_t ** candidates, 50 uint_t nbins); 47 51 /** sort spectral_candidate against their frequency */ 48 void aubio_pitchmcomb_sort_cand_freq(aubio_spectralcandidate_t ** candidates, uint_t nbins); 49 50 struct _aubio_pitchmcomb_t { 52 void aubio_pitchmcomb_sort_cand_freq (aubio_spectralcandidate_t ** candidates, 53 uint_t nbins); 54 55 struct _aubio_pitchmcomb_t 56 { 51 57 smpl_t threshold; /**< offset threshold [0.033 or 0.01] */ 52 58 smpl_t alpha; /**< normalisation exponent [9] */ … … 61 67 uint_t goodcandidate; /**< best candidate */ 62 68 uint_t spec_partition; /**< spectrum partition to consider */ 63 aubio_spectralpeak_t * peaks;/**< up to length win/spec_partition */64 aubio_spectralcandidate_t ** candidates;/** up to five candidates */69 aubio_spectralpeak_t *peaks; /**< up to length win/spec_partition */ 70 aubio_spectralcandidate_t **candidates; /** up to five candidates */ 65 71 /* some scratch pads */ 66 72 /** \bug (unnecessary copied from fftgrain?) */ 67 fvec_t * newmag;/**< vec to store mag */68 fvec_t * scratch;/**< vec to store modified mag */69 fvec_t * scratch2;/**< vec to compute moving median */70 fvec_t * theta;/**< vec to store phase */73 fvec_t *newmag; /**< vec to store mag */ 74 fvec_t *scratch; /**< vec to store modified mag */ 75 fvec_t *scratch2; /**< vec to compute moving median */ 76 fvec_t *theta; /**< vec to store phase */ 71 77 smpl_t phasediff; 72 78 smpl_t phasefreq; … … 78 84 79 85 /** spectral peak object */ 80 struct _aubio_spectralpeak_t { 86 struct _aubio_spectralpeak_t 87 { 81 88 uint_t bin; /**< bin [0-(length-1)] */ 82 89 smpl_t ebin; /**< estimated bin */ … … 85 92 86 93 /** spectral candidates array object */ 87 struct _aubio_spectralcandidate_t { 94 struct _aubio_spectralcandidate_t 95 { 88 96 smpl_t ebin; /**< interpolated bin */ 89 smpl_t * ecomb;/**< comb */97 smpl_t *ecomb; /**< comb */ 90 98 smpl_t ene; /**< candidate energy */ 91 99 smpl_t len; /**< length */ … … 93 101 94 102 95 void aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, cvec_t * fftgrain, fvec_t * output) { 96 uint_t i,j; 103 void 104 aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, cvec_t * fftgrain, fvec_t * output) 105 { 106 uint_t i, j; 97 107 smpl_t instfreq; 98 fvec_t * newmag = (fvec_t *)p->newmag;108 fvec_t *newmag = (fvec_t *) p->newmag; 99 109 //smpl_t hfc; //fe=instfreq(theta1,theta,ops); //theta1=theta; 100 110 /* copy incoming grain to newmag */ 101 for (i =0; i< fftgrain->channels; i++) {102 for (j=0; j< newmag->length; j++)103 newmag->data[0][j]=fftgrain->norm[i][j];104 /* detect only if local energy > 10. */105 //if (fvec_local_energy(newmag)>10.) {111 for (i = 0; i < fftgrain->channels; i++) { 112 for (j = 0; j < newmag->length; j++) 113 newmag->data[0][j] = fftgrain->norm[i][j]; 114 /* detect only if local energy > 10. */ 115 //if (fvec_local_energy(newmag)>10.) { 106 116 //hfc = fvec_local_hfc(newmag); //not used 107 aubio_pitchmcomb_spectral_pp (p, newmag);108 aubio_pitchmcomb_combdet (p,newmag);117 aubio_pitchmcomb_spectral_pp (p, newmag); 118 aubio_pitchmcomb_combdet (p, newmag); 109 119 //aubio_pitchmcomb_sort_cand_freq(p->candidates,p->ncand); 110 120 //return p->candidates[p->goodcandidate]->ebin; 111 j = (uint_t)FLOOR(p->candidates[p->goodcandidate]->ebin+.5); 112 instfreq = aubio_unwrap2pi(fftgrain->phas[i][j] 113 - p->theta->data[i][j] - j*p->phasediff); 114 instfreq *= p->phasefreq; 115 /* store phase for next run */ 116 for (j=0; j< p->theta->length; j++) { 117 p->theta->data[i][j]=fftgrain->phas[i][j]; 118 } 119 //return p->candidates[p->goodcandidate]->ebin; 120 output->data[i][0] = FLOOR(p->candidates[p->goodcandidate]->ebin+.5) + instfreq; 121 /*} else { 122 return -1.; 123 }*/ 124 } 125 } 126 127 uint_t aubio_pitch_cands(aubio_pitchmcomb_t * p, cvec_t * fftgrain, 128 smpl_t * cands) { 129 uint_t i=0,j; 121 j = (uint_t) FLOOR (p->candidates[p->goodcandidate]->ebin + .5); 122 instfreq = aubio_unwrap2pi (fftgrain->phas[i][j] 123 - p->theta->data[i][j] - j * p->phasediff); 124 instfreq *= p->phasefreq; 125 /* store phase for next run */ 126 for (j = 0; j < p->theta->length; j++) { 127 p->theta->data[i][j] = fftgrain->phas[i][j]; 128 } 129 //return p->candidates[p->goodcandidate]->ebin; 130 output->data[i][0] = 131 FLOOR (p->candidates[p->goodcandidate]->ebin + .5) + instfreq; 132 /*} else { 133 return -1.; 134 } */ 135 } 136 } 137 138 uint_t 139 aubio_pitch_cands (aubio_pitchmcomb_t * p, cvec_t * fftgrain, smpl_t * cands) 140 { 141 uint_t i = 0, j; 130 142 uint_t k; 131 fvec_t * newmag = (fvec_t *)p->newmag;132 aubio_spectralcandidate_t ** 133 (aubio_spectralcandidate_t **)(p->candidates);143 fvec_t *newmag = (fvec_t *) p->newmag; 144 aubio_spectralcandidate_t **scands = 145 (aubio_spectralcandidate_t **) (p->candidates); 134 146 //smpl_t hfc; //fe=instfreq(theta1,theta,ops); //theta1=theta; 135 147 /* copy incoming grain to newmag */ 136 for (j =0; j< newmag->length; j++)137 newmag->data[i][j] =fftgrain->norm[i][j];148 for (j = 0; j < newmag->length; j++) 149 newmag->data[i][j] = fftgrain->norm[i][j]; 138 150 /* detect only if local energy > 10. */ 139 if (fvec_local_energy (newmag)>10.) {151 if (fvec_local_energy (newmag) > 10.) { 140 152 /* hfc = fvec_local_hfc(newmag); do not use */ 141 aubio_pitchmcomb_spectral_pp (p, newmag);142 aubio_pitchmcomb_combdet (p,newmag);143 aubio_pitchmcomb_sort_cand_freq (scands,p->ncand);153 aubio_pitchmcomb_spectral_pp (p, newmag); 154 aubio_pitchmcomb_combdet (p, newmag); 155 aubio_pitchmcomb_sort_cand_freq (scands, p->ncand); 144 156 /* store ncand comb energies in cands[1:ncand] */ 145 for (k = 0; k <p->ncand; k++)157 for (k = 0; k < p->ncand; k++) 146 158 cands[k] = p->candidates[k]->ene; 147 159 /* store ncand[end] freq in cands[end] */ 148 cands[p->ncand] = p->candidates[p->ncand -1]->ebin;160 cands[p->ncand] = p->candidates[p->ncand - 1]->ebin; 149 161 return 1; 150 162 } else { 151 for (k = 0; k <p->ncand; k++)163 for (k = 0; k < p->ncand; k++) 152 164 cands[k] = 0; 153 165 return 0; … … 155 167 } 156 168 157 void aubio_pitchmcomb_spectral_pp(aubio_pitchmcomb_t * p, fvec_t * newmag) { 158 fvec_t * mag = (fvec_t *)p->scratch; 159 fvec_t * tmp = (fvec_t *)p->scratch2; 160 uint_t i=0,j; 169 void 170 aubio_pitchmcomb_spectral_pp (aubio_pitchmcomb_t * p, fvec_t * newmag) 171 { 172 fvec_t *mag = (fvec_t *) p->scratch; 173 fvec_t *tmp = (fvec_t *) p->scratch2; 174 uint_t i = 0, j; 161 175 uint_t length = mag->length; 162 176 /* copy newmag to mag (scracth) */ 163 for (j =0;j<length;j++) {177 for (j = 0; j < length; j++) { 164 178 mag->data[i][j] = newmag->data[i][j]; 165 179 } 166 fvec_min_removal (mag);/* min removal */167 fvec_alpha_normalise (mag,p->alpha); /* alpha normalisation */168 /* skipped */ 180 fvec_min_removal (mag); /* min removal */ 181 fvec_alpha_normalise (mag, p->alpha); /* alpha normalisation */ 182 /* skipped *//* low pass filtering */ 169 183 /** \bug fvec_moving_thres may write out of bounds */ 170 fvec_adapt_thres (mag,tmp,p->win_post,p->win_pre,i);/* adaptative threshold */171 fvec_add (mag,-p->threshold); /* fixed threshold */184 fvec_adapt_thres (mag, tmp, p->win_post, p->win_pre, i); /* adaptative threshold */ 185 fvec_add (mag, -p->threshold); /* fixed threshold */ 172 186 { 173 aubio_spectralpeak_t * peaks = (aubio_spectralpeak_t *)p->peaks;187 aubio_spectralpeak_t *peaks = (aubio_spectralpeak_t *) p->peaks; 174 188 uint_t count; 175 189 /* return bin and ebin */ 176 count = aubio_pitchmcomb_quadpick (peaks,mag);177 for (j =0;j<count;j++)190 count = aubio_pitchmcomb_quadpick (peaks, mag); 191 for (j = 0; j < count; j++) 178 192 peaks[j].mag = newmag->data[i][peaks[j].bin]; 179 193 /* reset non peaks */ 180 for (j =count;j<length;j++)194 for (j = count; j < length; j++) 181 195 peaks[j].mag = 0.; 182 196 p->peaks = peaks; … … 185 199 } 186 200 187 void aubio_pitchmcomb_combdet(aubio_pitchmcomb_t * p, fvec_t * newmag) { 188 aubio_spectralpeak_t * peaks = (aubio_spectralpeak_t *)p->peaks; 189 aubio_spectralcandidate_t ** candidate = 190 (aubio_spectralcandidate_t **)p->candidates; 201 void 202 aubio_pitchmcomb_combdet (aubio_pitchmcomb_t * p, fvec_t * newmag) 203 { 204 aubio_spectralpeak_t *peaks = (aubio_spectralpeak_t *) p->peaks; 205 aubio_spectralcandidate_t **candidate = 206 (aubio_spectralcandidate_t **) p->candidates; 191 207 192 208 /* parms */ 193 uint_t N = p->npartials; /* maximum number of partials to be considered 10 */194 uint_t M = p->ncand; /* maximum number of combs to be considered 5 */209 uint_t N = p->npartials; /* maximum number of partials to be considered 10 */ 210 uint_t M = p->ncand; /* maximum number of combs to be considered 5 */ 195 211 uint_t length = newmag->length; 196 212 uint_t count = p->count; … … 209 225 210 226 /* get the biggest peak in the spectrum */ 211 root_peak = aubio_pitchmcomb_get_root_peak (peaks,count);227 root_peak = aubio_pitchmcomb_get_root_peak (peaks, count); 212 228 /* not enough partials in highest notes, could be forced */ 213 229 //if (peaks[root_peak].ebin >= aubio_miditofreq(85.)/p->tau) N=2; 214 230 //if (peaks[root_peak].ebin >= aubio_miditofreq(90.)/p->tau) N=1; 215 231 /* now calculate the energy of each of the 5 combs */ 216 for (l =0;l<M;l++) {217 smpl_t scaler = (1. /(l+1.));218 candidate[l]->ene = 0.; /* reset ene and len sums */232 for (l = 0; l < M; l++) { 233 smpl_t scaler = (1. / (l + 1.)); 234 candidate[l]->ene = 0.; /* reset ene and len sums */ 219 235 candidate[l]->len = 0.; 220 candidate[l]->ebin =scaler*peaks[root_peak].ebin;236 candidate[l]->ebin = scaler * peaks[root_peak].ebin; 221 237 /* if less than N peaks available, curlen < N */ 222 238 if (candidate[l]->ebin != 0.) 223 curlen = (uint_t) FLOOR(length/(candidate[l]->ebin));224 curlen = (N < curlen )? N : curlen;239 curlen = (uint_t) FLOOR (length / (candidate[l]->ebin)); 240 curlen = (N < curlen) ? N : curlen; 225 241 /* fill candidate[l]->ecomb[k] with (k+1)*candidate[l]->ebin */ 226 for (k =0;k<curlen;k++)227 candidate[l]->ecomb[k] =(candidate[l]->ebin)*(k+1.);228 for (k =curlen;k<length;k++)229 candidate[l]->ecomb[k] =0.;242 for (k = 0; k < curlen; k++) 243 candidate[l]->ecomb[k] = (candidate[l]->ebin) * (k + 1.); 244 for (k = curlen; k < length; k++) 245 candidate[l]->ecomb[k] = 0.; 230 246 /* for each in candidate[l]->ecomb[k] */ 231 for (k =0;k<curlen;k++) {247 for (k = 0; k < curlen; k++) { 232 248 xx = 100000.; 233 249 /** get the candidate->ecomb the closer to peaks.ebin 234 250 * (to cope with the inharmonicity)*/ 235 for (d =0;d<count;d++) {236 delta2 = ABS (candidate[l]->ecomb[k]-peaks[d].ebin);251 for (d = 0; d < count; d++) { 252 delta2 = ABS (candidate[l]->ecomb[k] - peaks[d].ebin); 237 253 if (delta2 <= xx) { 238 254 position = d; … … 242 258 /* for a Q factor of 17, maintaining "constant Q filtering", 243 259 * and sum energy and length over non null combs */ 244 if ( 17. * xx < candidate[l]->ecomb[k] ) { 245 candidate[l]->ecomb[k]=peaks[position].ebin; 246 candidate[l]->ene += /* ecomb rounded to nearest int */ 247 POW(newmag->data[0][(uint_t)FLOOR(candidate[l]->ecomb[k]+.5)],0.25); 248 candidate[l]->len += 1./curlen; 260 if (17. * xx < candidate[l]->ecomb[k]) { 261 candidate[l]->ecomb[k] = peaks[position].ebin; 262 candidate[l]->ene += /* ecomb rounded to nearest int */ 263 POW (newmag->data[0][(uint_t) FLOOR (candidate[l]->ecomb[k] + .5)], 264 0.25); 265 candidate[l]->len += 1. / curlen; 249 266 } else 250 candidate[l]->ecomb[k] =0.;267 candidate[l]->ecomb[k] = 0.; 251 268 } 252 269 /* punishment */ 253 270 /*if (candidate[l]->len<0.6) 254 candidate[l]->ene=0.; */271 candidate[l]->ene=0.; */ 255 272 /* remember best candidate energy (in polyphonic, could check for 256 273 * tmpene*1.1 < candidate->ene to reduce jumps towards low frequencies) */ … … 270 287 * \bug peak-picking too picky, sometimes counts too many peaks ? 271 288 */ 272 uint_t aubio_pitchmcomb_quadpick(aubio_spectralpeak_t * spectral_peaks, fvec_t * X){ 289 uint_t 290 aubio_pitchmcomb_quadpick (aubio_spectralpeak_t * spectral_peaks, fvec_t * X) 291 { 273 292 uint_t i, j, ispeak, count = 0; 274 for (i =0;i<X->channels;i++)275 for (j =1;j<X->length-1;j++) {276 ispeak = fvec_peakpick (X,j);293 for (i = 0; i < X->channels; i++) 294 for (j = 1; j < X->length - 1; j++) { 295 ispeak = fvec_peakpick (X, j); 277 296 if (ispeak) { 278 297 count += ispeak; 279 spectral_peaks[count -1].bin = j;280 spectral_peaks[count -1].ebin = fvec_quadint(X, j, i) - 1.;298 spectral_peaks[count - 1].bin = j; 299 spectral_peaks[count - 1].ebin = fvec_quadint (X, j, i) - 1.; 281 300 } 282 301 } … … 285 304 286 305 /* get predominant partial */ 287 uint_t aubio_pitchmcomb_get_root_peak(aubio_spectralpeak_t * peaks, uint_t length) { 288 uint_t i,pos=0; 306 uint_t 307 aubio_pitchmcomb_get_root_peak (aubio_spectralpeak_t * peaks, uint_t length) 308 { 309 uint_t i, pos = 0; 289 310 smpl_t tmp = 0.; 290 for (i =0;i<length;i++)311 for (i = 0; i < length; i++) 291 312 if (tmp <= peaks[i].mag) { 292 313 pos = i; … … 296 317 } 297 318 298 void aubio_pitchmcomb_sort_peak(aubio_spectralpeak_t * peaks, uint_t nbins) { 299 qsort(peaks, nbins, sizeof(aubio_spectralpeak_t), 319 void 320 aubio_pitchmcomb_sort_peak (aubio_spectralpeak_t * peaks, uint_t nbins) 321 { 322 qsort (peaks, nbins, sizeof (aubio_spectralpeak_t), 300 323 aubio_pitchmcomb_sort_peak_comp); 301 324 } 302 static sint_t aubio_pitchmcomb_sort_peak_comp(const void *x, const void *y) { 303 return (((aubio_spectralpeak_t *)y)->mag - ((aubio_spectralpeak_t *)x)->mag); 304 } 305 306 307 void aubio_pitchmcomb_sort_cand_ene(aubio_spectralcandidate_t ** candidates, uint_t nbins) { 325 326 static sint_t 327 aubio_pitchmcomb_sort_peak_comp (const void *x, const void *y) 328 { 329 return (((aubio_spectralpeak_t *) y)->mag - 330 ((aubio_spectralpeak_t *) x)->mag); 331 } 332 333 334 void 335 aubio_pitchmcomb_sort_cand_ene (aubio_spectralcandidate_t ** candidates, 336 uint_t nbins) 337 { 308 338 uint_t cur = 0; 309 339 uint_t run = 0; 310 for (cur =0;cur<nbins;cur++) {340 for (cur = 0; cur < nbins; cur++) { 311 341 run = cur + 1; 312 for (run=cur;run<nbins;run++) { 313 if(candidates[run]->ene > candidates[cur]->ene) 314 CAND_SWAP(candidates[run], candidates[cur]); 315 } 316 } 317 } 318 319 320 void aubio_pitchmcomb_sort_cand_freq(aubio_spectralcandidate_t ** candidates, uint_t nbins) { 342 for (run = cur; run < nbins; run++) { 343 if (candidates[run]->ene > candidates[cur]->ene) 344 CAND_SWAP (candidates[run], candidates[cur]); 345 } 346 } 347 } 348 349 350 void 351 aubio_pitchmcomb_sort_cand_freq (aubio_spectralcandidate_t ** candidates, 352 uint_t nbins) 353 { 321 354 uint_t cur = 0; 322 355 uint_t run = 0; 323 for (cur =0;cur<nbins;cur++) {356 for (cur = 0; cur < nbins; cur++) { 324 357 run = cur + 1; 325 for (run=cur;run<nbins;run++) { 326 if(candidates[run]->ebin < candidates[cur]->ebin) 327 CAND_SWAP(candidates[run], candidates[cur]); 328 } 329 } 330 } 331 332 aubio_pitchmcomb_t * new_aubio_pitchmcomb(uint_t bufsize, uint_t hopsize, uint_t channels) { 333 aubio_pitchmcomb_t * p = AUBIO_NEW(aubio_pitchmcomb_t); 358 for (run = cur; run < nbins; run++) { 359 if (candidates[run]->ebin < candidates[cur]->ebin) 360 CAND_SWAP (candidates[run], candidates[cur]); 361 } 362 } 363 } 364 365 aubio_pitchmcomb_t * 366 new_aubio_pitchmcomb (uint_t bufsize, uint_t hopsize, uint_t channels) 367 { 368 aubio_pitchmcomb_t *p = AUBIO_NEW (aubio_pitchmcomb_t); 334 369 /* bug: should check if size / 8 > post+pre+1 */ 335 370 uint_t i, j; 336 371 uint_t spec_size; 337 p->spec_partition 338 p->ncand 339 p->npartials 340 p->cutoff 341 p->threshold 342 p->win_post 343 p->win_pre 372 p->spec_partition = 4; 373 p->ncand = 5; 374 p->npartials = 5; 375 p->cutoff = 1.; 376 p->threshold = 0.01; 377 p->win_post = 8; 378 p->win_pre = 7; 344 379 // p->tau = samplerate/bufsize; 345 p->alpha 346 p->goodcandidate 347 p->phasefreq = bufsize/hopsize/TWO_PI;348 p->phasediff = TWO_PI*hopsize/bufsize;349 spec_size = bufsize /p->spec_partition;380 p->alpha = 9.; 381 p->goodcandidate = 0; 382 p->phasefreq = bufsize / hopsize / TWO_PI; 383 p->phasediff = TWO_PI * hopsize / bufsize; 384 spec_size = bufsize / p->spec_partition; 350 385 //p->pickerfn = quadpick; 351 386 //p->biquad = new_biquad(0.1600,0.3200,0.1600, -0.5949, 0.2348); 352 387 /* allocate temp memory */ 353 p->newmag = new_fvec(spec_size,1);388 p->newmag = new_fvec (spec_size, 1); 354 389 /* array for median */ 355 p->scratch = new_fvec(spec_size,1);390 p->scratch = new_fvec (spec_size, 1); 356 391 /* array for phase */ 357 p->theta = new_fvec(spec_size,channels);392 p->theta = new_fvec (spec_size, channels); 358 393 /* array for adaptative threshold */ 359 p->scratch2 = new_fvec(p->win_post+p->win_pre+1,1);394 p->scratch2 = new_fvec (p->win_post + p->win_pre + 1, 1); 360 395 /* array of spectral peaks */ 361 p->peaks = AUBIO_ARRAY(aubio_spectralpeak_t,spec_size);396 p->peaks = AUBIO_ARRAY (aubio_spectralpeak_t, spec_size); 362 397 for (i = 0; i < spec_size; i++) { 363 398 p->peaks[i].bin = 0.; … … 366 401 } 367 402 /* array of pointers to spectral candidates */ 368 p->candidates = AUBIO_ARRAY (aubio_spectralcandidate_t *,p->ncand);369 for (i =0;i<p->ncand;i++) {370 p->candidates[i] = AUBIO_NEW (aubio_spectralcandidate_t);371 p->candidates[i]->ecomb = AUBIO_ARRAY (smpl_t, spec_size);372 for (j =0; j < spec_size; j++) {403 p->candidates = AUBIO_ARRAY (aubio_spectralcandidate_t *, p->ncand); 404 for (i = 0; i < p->ncand; i++) { 405 p->candidates[i] = AUBIO_NEW (aubio_spectralcandidate_t); 406 p->candidates[i]->ecomb = AUBIO_ARRAY (smpl_t, spec_size); 407 for (j = 0; j < spec_size; j++) { 373 408 p->candidates[i]->ecomb[j] = 0.; 374 409 } … … 381 416 382 417 383 void del_aubio_pitchmcomb (aubio_pitchmcomb_t *p) { 418 void 419 del_aubio_pitchmcomb (aubio_pitchmcomb_t * p) 420 { 384 421 uint_t i; 385 del_fvec (p->newmag);386 del_fvec (p->scratch);387 del_fvec (p->theta);388 del_fvec (p->scratch2);389 AUBIO_FREE (p->peaks);390 for (i =0;i<p->ncand;i++) {391 AUBIO_FREE (p->candidates[i]->ecomb);392 AUBIO_FREE (p->candidates[i]);393 } 394 AUBIO_FREE (p->candidates);395 AUBIO_FREE (p);396 } 422 del_fvec (p->newmag); 423 del_fvec (p->scratch); 424 del_fvec (p->theta); 425 del_fvec (p->scratch2); 426 AUBIO_FREE (p->peaks); 427 for (i = 0; i < p->ncand; i++) { 428 AUBIO_FREE (p->candidates[i]->ecomb); 429 AUBIO_FREE (p->candidates[i]); 430 } 431 AUBIO_FREE (p->candidates); 432 AUBIO_FREE (p); 433 }
Note: See TracChangeset
for help on using the changeset viewer.