Changeset 155cc10 for src/spectral
- Timestamp:
- Mar 10, 2017, 2:26:32 PM (8 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, sampler
- Children:
- ee8a57c
- Parents:
- 00d0275 (diff), 67b6618 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/spectral
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
src/spectral/fft.c
r00d0275 r155cc10 65 65 #ifdef HAVE_FFTW3F 66 66 #if HAVE_AUBIO_DOUBLE 67 # warning"Using aubio in double precision with fftw3 in single precision"67 #error "Using aubio in double precision with fftw3 in single precision" 68 68 #endif /* HAVE_AUBIO_DOUBLE */ 69 69 #define real_t float 70 #el se/* HAVE_FFTW3F */70 #elif defined (HAVE_FFTW3) /* HAVE_FFTW3F */ 71 71 #if !HAVE_AUBIO_DOUBLE 72 # warning"Using aubio in single precision with fftw3 in double precision"72 #error "Using aubio in single precision with fftw3 in double precision" 73 73 #endif /* HAVE_AUBIO_DOUBLE */ 74 74 #define real_t double … … 115 115 #else // using OOURA 116 116 // let's use ooura instead 117 extern void rdft(int, int, smpl_t *, int *, smpl_t *);117 extern void aubio_ooura_rdft(int, int, smpl_t *, int *, smpl_t *); 118 118 119 119 #endif /* HAVE_ACCELERATE */ … … 144 144 aubio_fft_t * new_aubio_fft (uint_t winsize) { 145 145 aubio_fft_t * s = AUBIO_NEW(aubio_fft_t); 146 if ((sint_t)winsize < 1) {147 AUBIO_ERR("fft: got winsize %d, but can not be < 1\n", winsize);146 if ((sint_t)winsize < 2) { 147 AUBIO_ERR("fft: got winsize %d, but can not be < 2\n", winsize); 148 148 goto beach; 149 149 } … … 189 189 #else // using OOURA 190 190 if (aubio_is_power_of_two(winsize) != 1) { 191 AUBIO_ERR("fft: can only create with sizes power of two, "192 " requested %d\n", winsize);191 AUBIO_ERR("fft: can only create with sizes power of two, requested %d," 192 " try recompiling aubio with --enable-fftw3\n", winsize); 193 193 goto beach; 194 194 } … … 213 213 del_fvec(s->compspec); 214 214 #ifdef HAVE_FFTW3 // using FFTW3 215 pthread_mutex_lock(&aubio_fftw_mutex); 215 216 fftw_destroy_plan(s->pfw); 216 217 fftw_destroy_plan(s->pbw); 217 218 fftw_free(s->specdata); 219 pthread_mutex_unlock(&aubio_fftw_mutex); 218 220 #else /* HAVE_FFTW3 */ 219 221 #ifdef HAVE_ACCELERATE // using ACCELERATE … … 231 233 } 232 234 233 void aubio_fft_do(aubio_fft_t * s, fvec_t * input, cvec_t * spectrum) {235 void aubio_fft_do(aubio_fft_t * s, const fvec_t * input, cvec_t * spectrum) { 234 236 aubio_fft_do_complex(s, input, s->compspec); 235 237 aubio_fft_get_spectrum(s->compspec, spectrum); 236 238 } 237 239 238 void aubio_fft_rdo(aubio_fft_t * s, c vec_t * spectrum, fvec_t * output) {240 void aubio_fft_rdo(aubio_fft_t * s, const cvec_t * spectrum, fvec_t * output) { 239 241 aubio_fft_get_realimag(spectrum, s->compspec); 240 242 aubio_fft_rdo_complex(s, s->compspec, output); 241 243 } 242 244 243 void aubio_fft_do_complex(aubio_fft_t * s, fvec_t * input, fvec_t * compspec) {245 void aubio_fft_do_complex(aubio_fft_t * s, const fvec_t * input, fvec_t * compspec) { 244 246 uint_t i; 245 247 #ifndef HAVE_MEMCPY_HACKS … … 281 283 aubio_vDSP_vsmul(compspec->data, 1, &scale, compspec->data, 1, s->fft_size); 282 284 #else // using OOURA 283 rdft(s->winsize, 1, s->in, s->ip, s->w);285 aubio_ooura_rdft(s->winsize, 1, s->in, s->ip, s->w); 284 286 compspec->data[0] = s->in[0]; 285 287 compspec->data[s->winsize / 2] = s->in[1]; … … 292 294 } 293 295 294 void aubio_fft_rdo_complex(aubio_fft_t * s, fvec_t * compspec, fvec_t * output) {296 void aubio_fft_rdo_complex(aubio_fft_t * s, const fvec_t * compspec, fvec_t * output) { 295 297 uint_t i; 296 298 #ifdef HAVE_FFTW3 … … 339 341 s->out[2 * i + 1] = - compspec->data[s->winsize - i]; 340 342 } 341 rdft(s->winsize, -1, s->out, s->ip, s->w);343 aubio_ooura_rdft(s->winsize, -1, s->out, s->ip, s->w); 342 344 for (i=0; i < s->winsize; i++) { 343 345 output->data[i] = s->out[i] * scale; … … 347 349 } 348 350 349 void aubio_fft_get_spectrum( fvec_t * compspec, cvec_t * spectrum) {351 void aubio_fft_get_spectrum(const fvec_t * compspec, cvec_t * spectrum) { 350 352 aubio_fft_get_phas(compspec, spectrum); 351 353 aubio_fft_get_norm(compspec, spectrum); 352 354 } 353 355 354 void aubio_fft_get_realimag(c vec_t * spectrum, fvec_t * compspec) {356 void aubio_fft_get_realimag(const cvec_t * spectrum, fvec_t * compspec) { 355 357 aubio_fft_get_imag(spectrum, compspec); 356 358 aubio_fft_get_real(spectrum, compspec); 357 359 } 358 360 359 void aubio_fft_get_phas( fvec_t * compspec, cvec_t * spectrum) {361 void aubio_fft_get_phas(const fvec_t * compspec, cvec_t * spectrum) { 360 362 uint_t i; 361 363 if (compspec->data[0] < 0) { … … 375 377 } 376 378 377 void aubio_fft_get_norm( fvec_t * compspec, cvec_t * spectrum) {379 void aubio_fft_get_norm(const fvec_t * compspec, cvec_t * spectrum) { 378 380 uint_t i = 0; 379 381 spectrum->norm[0] = ABS(compspec->data[0]); … … 386 388 } 387 389 388 void aubio_fft_get_imag(c vec_t * spectrum, fvec_t * compspec) {390 void aubio_fft_get_imag(const cvec_t * spectrum, fvec_t * compspec) { 389 391 uint_t i; 390 392 for (i = 1; i < ( compspec->length + 1 ) / 2 /*- 1 + 1*/; i++) { … … 394 396 } 395 397 396 void aubio_fft_get_real(c vec_t * spectrum, fvec_t * compspec) {398 void aubio_fft_get_real(const cvec_t * spectrum, fvec_t * compspec) { 397 399 uint_t i; 398 400 for (i = 0; i < compspec->length / 2 + 1; i++) { -
src/spectral/fft.h
r00d0275 r155cc10 28 28 - [vDSP](https://developer.apple.com/library/mac/#documentation/Accelerate/Reference/vDSPRef/Reference/reference.html) 29 29 30 \example s rc/spectral/test-fft.c30 \example spectral/test-fft.c 31 31 32 32 */ 33 33 34 #ifndef _AUBIO_FFT_H35 #define _AUBIO_FFT_H34 #ifndef AUBIO_FFT_H 35 #define AUBIO_FFT_H 36 36 37 37 #ifdef __cplusplus … … 66 66 67 67 */ 68 void aubio_fft_do (aubio_fft_t *s, fvec_t * input, cvec_t * spectrum);68 void aubio_fft_do (aubio_fft_t *s, const fvec_t * input, cvec_t * spectrum); 69 69 /** compute backward (inverse) FFT 70 70 … … 74 74 75 75 */ 76 void aubio_fft_rdo (aubio_fft_t *s, c vec_t * spectrum, fvec_t * output);76 void aubio_fft_rdo (aubio_fft_t *s, const cvec_t * spectrum, fvec_t * output); 77 77 78 78 /** compute forward FFT … … 83 83 84 84 */ 85 void aubio_fft_do_complex (aubio_fft_t *s, fvec_t * input, fvec_t * compspec);85 void aubio_fft_do_complex (aubio_fft_t *s, const fvec_t * input, fvec_t * compspec); 86 86 /** compute backward (inverse) FFT from real/imag 87 87 … … 91 91 92 92 */ 93 void aubio_fft_rdo_complex (aubio_fft_t *s, fvec_t * compspec, fvec_t * output);93 void aubio_fft_rdo_complex (aubio_fft_t *s, const fvec_t * compspec, fvec_t * output); 94 94 95 95 /** convert real/imag spectrum to norm/phas spectrum … … 99 99 100 100 */ 101 void aubio_fft_get_spectrum( fvec_t * compspec, cvec_t * spectrum);101 void aubio_fft_get_spectrum(const fvec_t * compspec, cvec_t * spectrum); 102 102 /** convert real/imag spectrum to norm/phas spectrum 103 103 … … 106 106 107 107 */ 108 void aubio_fft_get_realimag(c vec_t * spectrum, fvec_t * compspec);108 void aubio_fft_get_realimag(const cvec_t * spectrum, fvec_t * compspec); 109 109 110 110 /** compute phas spectrum from real/imag parts … … 114 114 115 115 */ 116 void aubio_fft_get_phas( fvec_t * compspec, cvec_t * spectrum);116 void aubio_fft_get_phas(const fvec_t * compspec, cvec_t * spectrum); 117 117 /** compute imaginary part from the norm/phas cvec 118 118 … … 121 121 122 122 */ 123 void aubio_fft_get_imag(c vec_t * spectrum, fvec_t * compspec);123 void aubio_fft_get_imag(const cvec_t * spectrum, fvec_t * compspec); 124 124 125 125 /** compute norm component from real/imag parts … … 129 129 130 130 */ 131 void aubio_fft_get_norm( fvec_t * compspec, cvec_t * spectrum);131 void aubio_fft_get_norm(const fvec_t * compspec, cvec_t * spectrum); 132 132 /** compute real part from norm/phas components 133 133 … … 136 136 137 137 */ 138 void aubio_fft_get_real(c vec_t * spectrum, fvec_t * compspec);138 void aubio_fft_get_real(const cvec_t * spectrum, fvec_t * compspec); 139 139 140 140 #ifdef __cplusplus … … 142 142 #endif 143 143 144 #endif /* _AUBIO_FFT_H */144 #endif /* AUBIO_FFT_H */ -
src/spectral/filterbank.c
r00d0275 r155cc10 57 57 58 58 void 59 aubio_filterbank_do (aubio_filterbank_t * f, c vec_t * in, fvec_t * out)59 aubio_filterbank_do (aubio_filterbank_t * f, const cvec_t * in, fvec_t * out) 60 60 { 61 uint_t j, fn; 61 /* apply filter to all input channel, provided out has enough channels */ 62 //uint_t max_filters = MIN (f->n_filters, out->length); 63 //uint_t max_length = MIN (in->length, f->filters->length); 62 64 63 /* apply filter to all input channel, provided out has enough channels */ 64 uint_t max_filters = MIN (f->n_filters, out->length); 65 uint_t max_length = MIN (in->length, f->filters->length); 65 // view cvec->norm as fvec->data 66 fvec_t tmp; 67 tmp.length = in->length; 68 tmp.data = in->norm; 66 69 67 /* reset all values in output vector */ 68 fvec_zeros (out); 69 70 /* for each filter */ 71 for (fn = 0; fn < max_filters; fn++) { 72 /* for each sample */ 73 for (j = 0; j < max_length; j++) { 74 out->data[fn] += in->norm[j] * f->filters->data[fn][j]; 75 } 76 } 70 fmat_vecmul(f->filters, &tmp, out); 77 71 78 72 return; … … 80 74 81 75 fmat_t * 82 aubio_filterbank_get_coeffs ( aubio_filterbank_t * f)76 aubio_filterbank_get_coeffs (const aubio_filterbank_t * f) 83 77 { 84 78 return f->filters; … … 86 80 87 81 uint_t 88 aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fmat_t * filter_coeffs)82 aubio_filterbank_set_coeffs (aubio_filterbank_t * f, const fmat_t * filter_coeffs) 89 83 { 90 84 fmat_copy(filter_coeffs, f->filters); -
src/spectral/filterbank.h
r00d0275 r155cc10 30 30 */ 31 31 32 #ifndef _AUBIO_FILTERBANK_H33 #define _AUBIO_FILTERBANK_H32 #ifndef AUBIO_FILTERBANK_H 33 #define AUBIO_FILTERBANK_H 34 34 35 35 #ifdef __cplusplus … … 67 67 68 68 */ 69 void aubio_filterbank_do (aubio_filterbank_t * f, c vec_t * in, fvec_t * out);69 void aubio_filterbank_do (aubio_filterbank_t * f, const cvec_t * in, fvec_t * out); 70 70 71 71 /** return a pointer to the matrix object containing all filter coefficients … … 74 74 75 75 */ 76 fmat_t *aubio_filterbank_get_coeffs ( aubio_filterbank_t * f);76 fmat_t *aubio_filterbank_get_coeffs (const aubio_filterbank_t * f); 77 77 78 78 /** copy filter coefficients to the filterbank … … 82 82 83 83 */ 84 uint_t aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fmat_t * filters);84 uint_t aubio_filterbank_set_coeffs (aubio_filterbank_t * f, const fmat_t * filters); 85 85 86 86 #ifdef __cplusplus … … 88 88 #endif 89 89 90 #endif /* _AUBIO_FILTERBANK_H */90 #endif /* AUBIO_FILTERBANK_H */ -
src/spectral/filterbank_mel.c
r00d0275 r155cc10 30 30 uint_t 31 31 aubio_filterbank_set_triangle_bands (aubio_filterbank_t * fb, 32 fvec_t * freqs, smpl_t samplerate)32 const fvec_t * freqs, smpl_t samplerate) 33 33 { 34 34 -
src/spectral/filterbank_mel.h
r00d0275 r155cc10 32 32 */ 33 33 34 #ifndef _AUBIO_FILTERBANK_MEL_H35 #define _AUBIO_FILTERBANK_MEL_H34 #ifndef AUBIO_FILTERBANK_MEL_H 35 #define AUBIO_FILTERBANK_MEL_H 36 36 37 37 #ifdef __cplusplus … … 51 51 */ 52 52 uint_t aubio_filterbank_set_triangle_bands (aubio_filterbank_t * fb, 53 fvec_t * freqs, smpl_t samplerate);53 const fvec_t * freqs, smpl_t samplerate); 54 54 55 55 /** filterbank initialization for Mel filters using Slaney's coefficients … … 70 70 #endif 71 71 72 #endif /* _AUBIO_FILTERBANK_MEL_H */72 #endif /* AUBIO_FILTERBANK_MEL_H */ -
src/spectral/mfcc.c
r00d0275 r155cc10 68 68 mfcc->in_dct = new_fvec (n_filters); 69 69 70 mfcc->dct_coeffs = new_fmat (n_ filters, n_coefs);70 mfcc->dct_coeffs = new_fmat (n_coefs, n_filters); 71 71 72 /* compute DCT transform dct_coeffs[ i][j] as72 /* compute DCT transform dct_coeffs[j][i] as 73 73 cos ( j * (i+.5) * PI / n_filters ) */ 74 74 scaling = 1. / SQRT (n_filters / 2.); 75 75 for (i = 0; i < n_filters; i++) { 76 76 for (j = 0; j < n_coefs; j++) { 77 mfcc->dct_coeffs->data[ i][j] =77 mfcc->dct_coeffs->data[j][i] = 78 78 scaling * COS (j * (i + 0.5) * PI / n_filters); 79 79 } 80 mfcc->dct_coeffs->data[ i][0] *= SQRT (2.) / 2.;80 mfcc->dct_coeffs->data[0][i] *= SQRT (2.) / 2.; 81 81 } 82 82 83 83 return mfcc; 84 } ;84 } 85 85 86 86 void … … 101 101 102 102 void 103 aubio_mfcc_do (aubio_mfcc_t * mf, c vec_t * in, fvec_t * out)103 aubio_mfcc_do (aubio_mfcc_t * mf, const cvec_t * in, fvec_t * out) 104 104 { 105 uint_t j, k;106 107 105 /* compute filterbank */ 108 106 aubio_filterbank_do (mf->fb, in, mf->in_dct); … … 114 112 //fvec_pow (mf->in_dct, 3.); 115 113 116 /* zeros output */ 117 fvec_zeros(out); 118 119 /* compute discrete cosine transform */ 120 for (j = 0; j < mf->n_filters; j++) { 121 for (k = 0; k < mf->n_coefs; k++) { 122 out->data[k] += mf->in_dct->data[j] 123 * mf->dct_coeffs->data[j][k]; 124 } 125 } 114 /* compute mfccs */ 115 fmat_vecmul(mf->dct_coeffs, mf->in_dct, out); 126 116 127 117 return; -
src/spectral/mfcc.h
r00d0275 r155cc10 35 35 */ 36 36 37 #ifndef _AUBIO_MFCC_H38 #define _AUBIO_MFCC_H37 #ifndef AUBIO_MFCC_H 38 #define AUBIO_MFCC_H 39 39 40 40 #ifdef __cplusplus … … 71 71 72 72 */ 73 void aubio_mfcc_do (aubio_mfcc_t * mf, c vec_t * in, fvec_t * out);73 void aubio_mfcc_do (aubio_mfcc_t * mf, const cvec_t * in, fvec_t * out); 74 74 75 75 #ifdef __cplusplus … … 77 77 #endif 78 78 79 #endif /* _AUBIO_MFCC_H */79 #endif /* AUBIO_MFCC_H */ -
src/spectral/ooura_fft8g.c
r00d0275 r155cc10 3 3 // - include "aubio_priv.h" (for config.h and types.h) 4 4 // - add missing prototypes 5 // - use COS and SIN macros 5 // - use COS, SIN, and ATAN macros 6 // - add cast to (smpl_t) to avoid float conversion warnings 7 // - declare initialization as static 8 // - prefix public function with aubio_ooura_ 6 9 7 10 #include "aubio_priv.h" 8 11 9 void cdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);10 void rdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);11 void ddct(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);12 void ddst(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);13 void dfct(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w);14 void dfst(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w);15 void makewt(int nw, int *ip, smpl_t *w);16 void makect(int nc, int *ip, smpl_t *c);17 void bitrv2(int n, int *ip, smpl_t *a);18 void bitrv2conj(int n, int *ip, smpl_t *a);19 void cftfsub(int n, smpl_t *a, smpl_t *w);20 void cftbsub(int n, smpl_t *a, smpl_t *w);21 void cft1st(int n, smpl_t *a, smpl_t *w);22 void cftmdl(int n, int l, smpl_t *a, smpl_t *w);23 void rftfsub(int n, smpl_t *a, int nc, smpl_t *c);24 void rftbsub(int n, smpl_t *a, int nc, smpl_t *c);25 void dctsub(int n, smpl_t *a, int nc, smpl_t *c);26 void dstsub(int n, smpl_t *a, int nc, smpl_t *c);12 void aubio_ooura_cdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w); 13 void aubio_ooura_rdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w); 14 void aubio_ooura_ddct(int n, int isgn, smpl_t *a, int *ip, smpl_t *w); 15 void aubio_ooura_ddst(int n, int isgn, smpl_t *a, int *ip, smpl_t *w); 16 void aubio_ooura_dfct(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w); 17 void aubio_ooura_dfst(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w); 18 static void makewt(int nw, int *ip, smpl_t *w); 19 static void makect(int nc, int *ip, smpl_t *c); 20 static void bitrv2(int n, int *ip, smpl_t *a); 21 static void bitrv2conj(int n, int *ip, smpl_t *a); 22 static void cftfsub(int n, smpl_t *a, smpl_t *w); 23 static void cftbsub(int n, smpl_t *a, smpl_t *w); 24 static void cft1st(int n, smpl_t *a, smpl_t *w); 25 static void cftmdl(int n, int l, smpl_t *a, smpl_t *w); 26 static void rftfsub(int n, smpl_t *a, int nc, smpl_t *c); 27 static void rftbsub(int n, smpl_t *a, int nc, smpl_t *c); 28 static void dctsub(int n, smpl_t *a, int nc, smpl_t *c); 29 static void dstsub(int n, smpl_t *a, int nc, smpl_t *c); 27 30 28 31 /* … … 303 306 304 307 305 void cdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)308 void aubio_ooura_cdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w) 306 309 { 307 310 void makewt(int nw, int *ip, smpl_t *w); … … 328 331 329 332 330 void rdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)333 void aubio_ooura_rdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w) 331 334 { 332 335 void makewt(int nw, int *ip, smpl_t *w); … … 362 365 a[1] = xi; 363 366 } else { 364 a[1] = 0.5 * (a[0] - a[1]);367 a[1] = (smpl_t)0.5 * (a[0] - a[1]); 365 368 a[0] -= a[1]; 366 369 if (n > 4) { … … 375 378 376 379 377 void ddct(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)380 void aubio_ooura_ddct(int n, int isgn, smpl_t *a, int *ip, smpl_t *w) 378 381 { 379 382 void makewt(int nw, int *ip, smpl_t *w); … … 434 437 435 438 436 void ddst(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)439 void aubio_ooura_ddst(int n, int isgn, smpl_t *a, int *ip, smpl_t *w) 437 440 { 438 441 void makewt(int nw, int *ip, smpl_t *w); … … 493 496 494 497 495 void dfct(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w)498 void aubio_ooura_dfct(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w) 496 499 { 497 500 void makewt(int nw, int *ip, smpl_t *w); … … 589 592 590 593 591 void dfst(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w)594 void aubio_ooura_dfst(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w) 592 595 { 593 596 void makewt(int nw, int *ip, smpl_t *w); … … 691 694 if (nw > 2) { 692 695 nwh = nw >> 1; 693 delta = atan(1.0) / nwh;696 delta = ATAN(1.0) / nwh; 694 697 w[0] = 1; 695 698 w[1] = 0; … … 725 728 if (nc > 1) { 726 729 nch = nc >> 1; 727 delta = atan(1.0) / nch;728 c[0] = cos(delta * nch);729 c[nch] = 0.5 * c[0];730 delta = ATAN(1.0) / nch; 731 c[0] = COS(delta * nch); 732 c[nch] = (smpl_t)0.5 * c[0]; 730 733 for (j = 1; j < nch; j++) { 731 c[j] = 0.5 * cos(delta * j);732 c[nc - j] = 0.5 * sin(delta * j);734 c[j] = (smpl_t)0.5 * COS(delta * j); 735 c[nc - j] = (smpl_t)0.5 * SIN(delta * j); 733 736 } 734 737 } … … 1586 1589 k = n - j; 1587 1590 kk += ks; 1588 wkr = 0.5 - c[nc - kk];1591 wkr = (smpl_t)0.5 - c[nc - kk]; 1589 1592 wki = c[kk]; 1590 1593 xr = a[j] - a[k]; … … 1612 1615 k = n - j; 1613 1616 kk += ks; 1614 wkr = 0.5 - c[nc - kk];1617 wkr = (smpl_t)0.5 - c[nc - kk]; 1615 1618 wki = c[kk]; 1616 1619 xr = a[j] - a[k]; -
src/spectral/phasevoc.c
r00d0275 r155cc10 45 45 46 46 /** returns data and dataold slided by hop_s */ 47 static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, fvec_t *new);47 static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, const fvec_t *new); 48 48 49 49 /** do additive synthesis from 'old' and 'cur' */ 50 50 static void aubio_pvoc_addsynth(aubio_pvoc_t *pv, fvec_t * synthnew); 51 51 52 void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t * datanew, cvec_t *fftgrain) {52 void aubio_pvoc_do(aubio_pvoc_t *pv, const fvec_t * datanew, cvec_t *fftgrain) { 53 53 /* slide */ 54 54 aubio_pvoc_swapbuffers(pv, datanew); … … 65 65 aubio_fft_rdo(pv->fft,fftgrain,pv->synth); 66 66 /* unshift */ 67 fvec_shift(pv->synth); 67 fvec_ishift(pv->synth); 68 /* windowing */ 69 // if overlap = 50%, do not apply window (identity) 70 if (pv->hop_s * 2 < pv->win_s) { 71 fvec_weight(pv->synth, pv->w); 72 } 68 73 /* additive synthesis */ 69 74 aubio_pvoc_addsynth(pv, synthnew); … … 80 85 AUBIO_ERR("pvoc: got hop_size %d, but can not be < 1\n", hop_s); 81 86 goto beach; 82 } else if ((sint_t)win_s < 1) {83 AUBIO_ERR("pvoc: got buffer_size %d, but can not be < 1\n", win_s);87 } else if ((sint_t)win_s < 2) { 88 AUBIO_ERR("pvoc: got buffer_size %d, but can not be < 2\n", win_s); 84 89 goto beach; 85 90 } else if (win_s < hop_s) { 86 AUBIO_ERR("pvoc: hop size (%d) is larger than win size (%d)\n", win_s, hop_s);91 AUBIO_ERR("pvoc: hop size (%d) is larger than win size (%d)\n", hop_s, win_s); 87 92 goto beach; 88 93 } 89 94 90 95 pv->fft = new_aubio_fft (win_s); 96 if (pv->fft == NULL) { 97 goto beach; 98 } 91 99 92 100 /* remember old */ … … 118 126 pv->hop_datasize = pv->hop_s * sizeof(smpl_t); 119 127 120 pv->scale = pv->hop_s * 2. / pv->win_s; 128 // for reconstruction with 75% overlap 129 if (win_s == hop_s * 4) { 130 pv->scale = 2./3.; 131 } else if (win_s == hop_s * 8) { 132 pv->scale = 1./3.; 133 } else if (win_s == hop_s * 2) { 134 pv->scale = 1.; 135 } else { 136 pv->scale = .5; 137 } 121 138 122 139 return pv; … … 137 154 } 138 155 139 static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, fvec_t *new)156 static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, const fvec_t *new) 140 157 { 141 158 /* some convenience pointers */ … … 143 160 smpl_t * dataold = pv->dataold->data; 144 161 smpl_t * datanew = new->data; 145 #if !HAVE_MEMCPY_HACKS162 #ifndef HAVE_MEMCPY_HACKS 146 163 uint_t i; 147 164 for (i = 0; i < pv->end; i++) -
src/spectral/phasevoc.h
r00d0275 r155cc10 32 32 */ 33 33 34 #ifndef _AUBIO_PHASEVOC_H35 #define _AUBIO_PHASEVOC_H34 #ifndef AUBIO_PHASEVOC_H 35 #define AUBIO_PHASEVOC_H 36 36 37 37 #ifdef __cplusplus … … 68 68 69 69 */ 70 void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t *in, cvec_t * fftgrain);70 void aubio_pvoc_do(aubio_pvoc_t *pv, const fvec_t *in, cvec_t * fftgrain); 71 71 /** compute signal from spectral frame 72 72 … … 100 100 #endif 101 101 102 #endif /* _AUBIO_PHASEVOC_H */102 #endif /* AUBIO_PHASEVOC_H */ -
src/spectral/specdesc.c
r00d0275 r155cc10 27 27 #include "utils/hist.h" 28 28 29 void aubio_specdesc_energy(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset);30 void aubio_specdesc_hfc(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset);31 void aubio_specdesc_complex(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset);32 void aubio_specdesc_phase(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset);33 void aubio_specdesc_specdiff(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset);34 void aubio_specdesc_kl(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset);35 void aubio_specdesc_mkl(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset);36 void aubio_specdesc_specflux(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset);37 38 extern void aubio_specdesc_centroid (aubio_specdesc_t * o, c vec_t * spec,39 fvec_t * desc); 40 extern void aubio_specdesc_spread (aubio_specdesc_t * o, c vec_t * spec,41 fvec_t * desc); 42 extern void aubio_specdesc_skewness (aubio_specdesc_t * o, c vec_t * spec,43 fvec_t * desc); 44 extern void aubio_specdesc_kurtosis (aubio_specdesc_t * o, c vec_t * spec,45 fvec_t * desc); 46 extern void aubio_specdesc_slope (aubio_specdesc_t * o, c vec_t * spec,47 fvec_t * desc); 48 extern void aubio_specdesc_decrease (aubio_specdesc_t * o, c vec_t * spec,49 fvec_t * desc); 50 extern void aubio_specdesc_rolloff (aubio_specdesc_t * o, c vec_t * spec,29 void aubio_specdesc_energy(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); 30 void aubio_specdesc_hfc(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); 31 void aubio_specdesc_complex(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); 32 void aubio_specdesc_phase(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); 33 void aubio_specdesc_specdiff(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); 34 void aubio_specdesc_kl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); 35 void aubio_specdesc_mkl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); 36 void aubio_specdesc_specflux(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); 37 38 extern void aubio_specdesc_centroid (aubio_specdesc_t * o, const cvec_t * spec, 39 fvec_t * desc); 40 extern void aubio_specdesc_spread (aubio_specdesc_t * o, const cvec_t * spec, 41 fvec_t * desc); 42 extern void aubio_specdesc_skewness (aubio_specdesc_t * o, const cvec_t * spec, 43 fvec_t * desc); 44 extern void aubio_specdesc_kurtosis (aubio_specdesc_t * o, const cvec_t * spec, 45 fvec_t * desc); 46 extern void aubio_specdesc_slope (aubio_specdesc_t * o, const cvec_t * spec, 47 fvec_t * desc); 48 extern void aubio_specdesc_decrease (aubio_specdesc_t * o, const cvec_t * spec, 49 fvec_t * desc); 50 extern void aubio_specdesc_rolloff (aubio_specdesc_t * o, const cvec_t * spec, 51 51 fvec_t * desc); 52 52 … … 76 76 /** Pointer to aubio_specdesc_<type> function */ 77 77 void (*funcpointer)(aubio_specdesc_t *o, 78 c vec_t * fftgrain, fvec_t * onset);78 const cvec_t * fftgrain, fvec_t * onset); 79 79 smpl_t threshold; /**< minimum norm threshold for phase and specdiff */ 80 80 fvec_t *oldmag; /**< previous norm vector */ … … 88 88 /* Energy based onset detection function */ 89 89 void aubio_specdesc_energy (aubio_specdesc_t *o UNUSED, 90 c vec_t * fftgrain, fvec_t * onset) {90 const cvec_t * fftgrain, fvec_t * onset) { 91 91 uint_t j; 92 92 onset->data[0] = 0.; … … 98 98 /* High Frequency Content onset detection function */ 99 99 void aubio_specdesc_hfc(aubio_specdesc_t *o UNUSED, 100 c vec_t * fftgrain, fvec_t * onset){100 const cvec_t * fftgrain, fvec_t * onset){ 101 101 uint_t j; 102 102 onset->data[0] = 0.; … … 108 108 109 109 /* Complex Domain Method onset detection function */ 110 void aubio_specdesc_complex (aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset) {110 void aubio_specdesc_complex (aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset) { 111 111 uint_t j; 112 112 uint_t nbins = fftgrain->length; … … 132 132 /* Phase Based Method onset detection function */ 133 133 void aubio_specdesc_phase(aubio_specdesc_t *o, 134 c vec_t * fftgrain, fvec_t * onset){134 const cvec_t * fftgrain, fvec_t * onset){ 135 135 uint_t j; 136 136 uint_t nbins = fftgrain->length; … … 162 162 /* Spectral difference method onset detection function */ 163 163 void aubio_specdesc_specdiff(aubio_specdesc_t *o, 164 c vec_t * fftgrain, fvec_t * onset){164 const cvec_t * fftgrain, fvec_t * onset){ 165 165 uint_t j; 166 166 uint_t nbins = fftgrain->length; … … 189 189 * note we use ln(1+Xn/(Xn-1+0.0001)) to avoid 190 190 * negative (1.+) and infinite values (+1.e-10) */ 191 void aubio_specdesc_kl(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset){191 void aubio_specdesc_kl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset){ 192 192 uint_t j; 193 193 onset->data[0] = 0.; … … 203 203 * note we use ln(1+Xn/(Xn-1+0.0001)) to avoid 204 204 * negative (1.+) and infinite values (+1.e-10) */ 205 void aubio_specdesc_mkl(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset){205 void aubio_specdesc_mkl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset){ 206 206 uint_t j; 207 207 onset->data[0] = 0.; … … 214 214 215 215 /* Spectral flux */ 216 void aubio_specdesc_specflux(aubio_specdesc_t *o, c vec_t * fftgrain, fvec_t * onset){216 void aubio_specdesc_specflux(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset){ 217 217 uint_t j; 218 218 onset->data[0] = 0.; … … 226 226 /* Generic function pointing to the choosen one */ 227 227 void 228 aubio_specdesc_do (aubio_specdesc_t *o, c vec_t * fftgrain,228 aubio_specdesc_do (aubio_specdesc_t *o, const cvec_t * fftgrain, 229 229 fvec_t * onset) { 230 230 o->funcpointer(o,fftgrain,onset); … … 235 235 */ 236 236 aubio_specdesc_t * 237 new_aubio_specdesc (c har_t * onset_mode, uint_t size){237 new_aubio_specdesc (const char_t * onset_mode, uint_t size){ 238 238 aubio_specdesc_t * o = AUBIO_NEW(aubio_specdesc_t); 239 239 uint_t rsize = size/2+1; … … 274 274 onset_type = aubio_onset_default; 275 275 else { 276 AUBIO_ERR("unknown spectral descriptor type %s, using default.\n", onset_mode); 277 onset_type = aubio_onset_default; 276 AUBIO_ERR("unknown spectral descriptor type %s\n", onset_mode); 277 AUBIO_FREE(o); 278 return NULL; 278 279 } 279 280 switch(onset_type) { 280 281 /* for both energy and hfc, only fftgrain->norm is required */ 281 case aubio_onset_energy: 282 case aubio_onset_energy: 282 283 break; 283 284 case aubio_onset_hfc: … … 367 368 void del_aubio_specdesc (aubio_specdesc_t *o){ 368 369 switch(o->onset_type) { 369 case aubio_onset_energy: 370 case aubio_onset_energy: 370 371 break; 371 372 case aubio_onset_hfc: -
src/spectral/specdesc.h
r00d0275 r155cc10 146 146 147 147 148 #ifndef _AUBIO_SPECDESC_H149 #define _AUBIO_SPECDESC_H148 #ifndef AUBIO_SPECDESC_H 149 #define AUBIO_SPECDESC_H 150 150 151 151 #ifdef __cplusplus … … 165 165 166 166 */ 167 void aubio_specdesc_do (aubio_specdesc_t * o, c vec_t * fftgrain,167 void aubio_specdesc_do (aubio_specdesc_t * o, const cvec_t * fftgrain, 168 168 fvec_t * desc); 169 169 … … 179 179 180 180 */ 181 aubio_specdesc_t *new_aubio_specdesc (c har_t * method, uint_t buf_size);181 aubio_specdesc_t *new_aubio_specdesc (const char_t * method, uint_t buf_size); 182 182 183 183 /** deletion of a spectral descriptor … … 192 192 #endif 193 193 194 #endif /* _AUBIO_SPECDESC_H */194 #endif /* AUBIO_SPECDESC_H */ -
src/spectral/statistics.c
r00d0275 r155cc10 23 23 #include "spectral/specdesc.h" 24 24 25 void aubio_specdesc_centroid (aubio_specdesc_t * o, c vec_t * spec,26 fvec_t * desc); 27 void aubio_specdesc_spread (aubio_specdesc_t * o, c vec_t * spec,28 fvec_t * desc); 29 void aubio_specdesc_skewness (aubio_specdesc_t * o, c vec_t * spec,30 fvec_t * desc); 31 void aubio_specdesc_kurtosis (aubio_specdesc_t * o, c vec_t * spec,32 fvec_t * desc); 33 void aubio_specdesc_slope (aubio_specdesc_t * o, c vec_t * spec,34 fvec_t * desc); 35 void aubio_specdesc_decrease (aubio_specdesc_t * o, c vec_t * spec,36 fvec_t * desc); 37 void aubio_specdesc_rolloff (aubio_specdesc_t * o, c vec_t * spec,38 fvec_t * desc); 39 40 41 smpl_t cvec_sum (c vec_t * s);42 smpl_t cvec_mean (c vec_t * s);43 smpl_t cvec_centroid (c vec_t * s);44 smpl_t cvec_moment (c vec_t * s, uint_t moment);45 46 smpl_t 47 cvec_sum (c vec_t * s)25 void aubio_specdesc_centroid (aubio_specdesc_t * o, const cvec_t * spec, 26 fvec_t * desc); 27 void aubio_specdesc_spread (aubio_specdesc_t * o, const cvec_t * spec, 28 fvec_t * desc); 29 void aubio_specdesc_skewness (aubio_specdesc_t * o, const cvec_t * spec, 30 fvec_t * desc); 31 void aubio_specdesc_kurtosis (aubio_specdesc_t * o, const cvec_t * spec, 32 fvec_t * desc); 33 void aubio_specdesc_slope (aubio_specdesc_t * o, const cvec_t * spec, 34 fvec_t * desc); 35 void aubio_specdesc_decrease (aubio_specdesc_t * o, const cvec_t * spec, 36 fvec_t * desc); 37 void aubio_specdesc_rolloff (aubio_specdesc_t * o, const cvec_t * spec, 38 fvec_t * desc); 39 40 41 smpl_t cvec_sum (const cvec_t * s); 42 smpl_t cvec_mean (const cvec_t * s); 43 smpl_t cvec_centroid (const cvec_t * s); 44 smpl_t cvec_moment (const cvec_t * s, uint_t moment); 45 46 smpl_t 47 cvec_sum (const cvec_t * s) 48 48 { 49 49 uint_t j; … … 56 56 57 57 smpl_t 58 cvec_mean (c vec_t * s)58 cvec_mean (const cvec_t * s) 59 59 { 60 60 return cvec_sum (s) / (smpl_t) (s->length); … … 62 62 63 63 smpl_t 64 cvec_centroid (c vec_t * spec)64 cvec_centroid (const cvec_t * spec) 65 65 { 66 66 smpl_t sum = 0., sc = 0.; … … 78 78 79 79 smpl_t 80 cvec_moment (c vec_t * spec, uint_t order)80 cvec_moment (const cvec_t * spec, uint_t order) 81 81 { 82 82 smpl_t sum = 0., centroid = 0., sc = 0.; … … 95 95 96 96 void 97 aubio_specdesc_centroid (aubio_specdesc_t * o UNUSED, c vec_t * spec,97 aubio_specdesc_centroid (aubio_specdesc_t * o UNUSED, const cvec_t * spec, 98 98 fvec_t * desc) 99 99 { … … 102 102 103 103 void 104 aubio_specdesc_spread (aubio_specdesc_t * o UNUSED, c vec_t * spec,104 aubio_specdesc_spread (aubio_specdesc_t * o UNUSED, const cvec_t * spec, 105 105 fvec_t * desc) 106 106 { … … 109 109 110 110 void 111 aubio_specdesc_skewness (aubio_specdesc_t * o UNUSED, c vec_t * spec,111 aubio_specdesc_skewness (aubio_specdesc_t * o UNUSED, const cvec_t * spec, 112 112 fvec_t * desc) 113 113 { … … 123 123 124 124 void 125 aubio_specdesc_kurtosis (aubio_specdesc_t * o UNUSED, c vec_t * spec,125 aubio_specdesc_kurtosis (aubio_specdesc_t * o UNUSED, const cvec_t * spec, 126 126 fvec_t * desc) 127 127 { … … 137 137 138 138 void 139 aubio_specdesc_slope (aubio_specdesc_t * o UNUSED, c vec_t * spec,139 aubio_specdesc_slope (aubio_specdesc_t * o UNUSED, const cvec_t * spec, 140 140 fvec_t * desc) 141 141 { … … 165 165 166 166 void 167 aubio_specdesc_decrease (aubio_specdesc_t *o UNUSED, c vec_t * spec,167 aubio_specdesc_decrease (aubio_specdesc_t *o UNUSED, const cvec_t * spec, 168 168 fvec_t * desc) 169 169 { … … 183 183 184 184 void 185 aubio_specdesc_rolloff (aubio_specdesc_t *o UNUSED, c vec_t * spec,185 aubio_specdesc_rolloff (aubio_specdesc_t *o UNUSED, const cvec_t * spec, 186 186 fvec_t *desc) 187 187 { -
src/spectral/tss.c
r00d0275 r155cc10 41 41 }; 42 42 43 void aubio_tss_do(aubio_tss_t *o, c vec_t * input,43 void aubio_tss_do(aubio_tss_t *o, const cvec_t * input, 44 44 cvec_t * trans, cvec_t * stead) 45 45 { -
src/spectral/tss.h
r00d0275 r155cc10 37 37 */ 38 38 39 #ifndef _AUBIO_TSS_H40 #define _AUBIO_TSS_H39 #ifndef AUBIO_TSS_H 40 #define AUBIO_TSS_H 41 41 42 42 #ifdef __cplusplus … … 70 70 71 71 */ 72 void aubio_tss_do (aubio_tss_t * o, c vec_t * input, cvec_t * trans,72 void aubio_tss_do (aubio_tss_t * o, const cvec_t * input, cvec_t * trans, 73 73 cvec_t * stead); 74 74 … … 101 101 #endif 102 102 103 #endif /* _AUBIO_TSS_H */103 #endif /* AUBIO_TSS_H */
Note: See TracChangeset
for help on using the changeset viewer.