Changeset d57d1de
- Timestamp:
- Nov 7, 2007, 4:51:42 PM (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:
- 4368223
- Parents:
- e00f769 (diff), 038852a (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. - Files:
-
- 1 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
src/fft.c
re00f769 rd57d1de 19 19 20 20 #include "aubio_priv.h" 21 #include "sample.h" 21 #include "fvec.h" 22 #include "cvec.h" 22 23 #include "mathutils.h" 23 24 #include "fft.h" … … 41 42 42 43 struct _aubio_fft_t { 44 uint_t winsize; 45 uint_t channels; 43 46 uint_t fft_size; 44 uint_t channels; 45 real_t *in, *out; 46 fft_data_t *specdata; 47 real_t *in, *out; 47 48 fftw_plan pfw, pbw; 49 fft_data_t * specdata; /* complex spectral data */ 50 fvec_t * compspec; 48 51 }; 49 52 50 static void aubio_fft_getspectrum(fft_data_t * spectrum, smpl_t *norm, smpl_t * phas, uint_t size); 51 52 aubio_fft_t * new_aubio_fft(uint_t size) { 53 aubio_fft_t * new_aubio_fft(uint_t winsize, uint_t channels) { 53 54 aubio_fft_t * s = AUBIO_NEW(aubio_fft_t); 55 s->winsize = winsize; 56 s->channels = channels; 54 57 /* allocate memory */ 55 s->in = AUBIO_ARRAY(real_t,size); 56 s->out = AUBIO_ARRAY(real_t,size); 58 s->in = AUBIO_ARRAY(real_t,winsize); 59 s->out = AUBIO_ARRAY(real_t,winsize); 60 s->compspec = new_fvec(winsize,channels); 57 61 /* create plans */ 58 62 #ifdef HAVE_COMPLEX_H 59 s->fft_size = size/2+1;63 s->fft_size = winsize/2+1; 60 64 s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*s->fft_size); 61 s->pfw = fftw_plan_dft_r2c_1d( size, s->in, s->specdata, FFTW_ESTIMATE);62 s->pbw = fftw_plan_dft_c2r_1d( size, s->specdata, s->out, FFTW_ESTIMATE);65 s->pfw = fftw_plan_dft_r2c_1d(winsize, s->in, s->specdata, FFTW_ESTIMATE); 66 s->pbw = fftw_plan_dft_c2r_1d(winsize, s->specdata, s->out, FFTW_ESTIMATE); 63 67 #else 64 s->fft_size = size;68 s->fft_size = winsize; 65 69 s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*s->fft_size); 66 s->pfw = fftw_plan_r2r_1d( size, s->in, s->specdata, FFTW_R2HC, FFTW_ESTIMATE);67 s->pbw = fftw_plan_r2r_1d( size, s->specdata, s->out, FFTW_HC2R, FFTW_ESTIMATE);70 s->pfw = fftw_plan_r2r_1d(winsize, s->in, s->specdata, FFTW_R2HC, FFTW_ESTIMATE); 71 s->pbw = fftw_plan_r2r_1d(winsize, s->specdata, s->out, FFTW_HC2R, FFTW_ESTIMATE); 68 72 #endif 69 73 return s; … … 72 76 void del_aubio_fft(aubio_fft_t * s) { 73 77 /* destroy data */ 78 del_fvec(s->compspec); 74 79 fftw_destroy_plan(s->pfw); 75 80 fftw_destroy_plan(s->pbw); … … 80 85 } 81 86 82 void aubio_fft_do(const aubio_fft_t * s, 83 const smpl_t * data, fft_data_t * spectrum, const uint_t size) { 84 uint_t i; 85 for (i=0;i<size;i++) s->in[i] = data[i]; 86 fftw_execute(s->pfw); 87 for (i=0; i < s->fft_size; i++) spectrum[i] = s->specdata[i]; 87 void aubio_fft_do(aubio_fft_t * s, fvec_t * input, cvec_t * spectrum) { 88 aubio_fft_do_complex(s, input, s->compspec); 89 aubio_fft_get_spectrum(s->compspec, spectrum); 88 90 } 89 91 90 void aubio_fft_rdo(const aubio_fft_t * s, 91 const fft_data_t * spectrum, smpl_t * data, const uint_t size) { 92 uint_t i; 93 const smpl_t renorm = 1./(smpl_t)size; 94 for (i=0; i < s->fft_size; i++) s->specdata[i] = spectrum[i]; 95 fftw_execute(s->pbw); 96 for (i=0;i<size;i++) data[i] = s->out[i]*renorm; 92 void aubio_fft_rdo(aubio_fft_t * s, cvec_t * spectrum, fvec_t * output) { 93 aubio_fft_get_realimag(spectrum, s->compspec); 94 aubio_fft_rdo_complex(s, s->compspec, output); 97 95 } 98 96 99 #ifdef HAVE_COMPLEX_H 100 101 void aubio_fft_getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size) { 102 uint_t i; 103 for (i=0;i<size/2+1;i++) norm[i] = ABSC(spectrum[i]); 104 } 105 106 void aubio_fft_getphas(smpl_t * phas, fft_data_t * spectrum, uint_t size) { 107 uint_t i; 108 for (i=0;i<size/2+1;i++) phas[i] = ARGC(spectrum[i]); 109 } 110 111 void aubio_fft_getspectrum(fft_data_t * spectrum, smpl_t *norm, smpl_t * phas, uint_t size) { 112 uint_t j; 113 for (j=0; j<size/2+1; j++) { 114 spectrum[j] = CEXPC(I*phas[j]); 115 spectrum[j] *= norm[j]; 97 void aubio_fft_do_complex(aubio_fft_t * s, fvec_t * input, fvec_t * compspec) { 98 uint_t i, j; 99 for (i = 0; i < s->channels; i++) { 100 for (j=0; j < s->winsize; j++) { 101 s->in[j] = input->data[i][j]; 102 } 103 fftw_execute(s->pfw); 104 #if HAVE_COMPLEX_H 105 compspec->data[i][0] = REAL(s->specdata[0]); 106 for (j = 1; j < s->fft_size -1 ; j++) { 107 compspec->data[i][j] = REAL(s->specdata[j]); 108 compspec->data[i][compspec->length - j] = IMAG(s->specdata[j]); 109 } 110 compspec->data[i][s->fft_size-1] = REAL(s->specdata[s->fft_size-1]); 111 #else 112 for (j = 0; j < s->fft_size; j++) { 113 compspec->data[i][j] = s->specdata[j]; 114 } 115 #endif 116 116 } 117 117 } 118 118 119 void aubio_fft_rdo_complex(aubio_fft_t * s, fvec_t * compspec, fvec_t * output) { 120 uint_t i, j; 121 const smpl_t renorm = 1./(smpl_t)s->winsize; 122 for (i = 0; i < compspec->channels; i++) { 123 #if HAVE_COMPLEX_H 124 s->specdata[0] = compspec->data[i][0]; 125 for (j=1; j < s->fft_size - 1; j++) { 126 s->specdata[j] = compspec->data[i][j] + 127 I * compspec->data[i][compspec->length - j]; 128 } 129 s->specdata[s->fft_size - 1] = compspec->data[i][s->fft_size - 1]; 119 130 #else 120 121 void aubio_fft_getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size) { 122 uint_t i; 123 norm[0] = spectrum[0]; 124 for (i=1;i<size/2;i++) norm[i] = SQRT((SQR(spectrum[i]) + SQR(spectrum[size-i]))); 125 norm[size/2] = spectrum[size/2]; 126 } 127 128 void aubio_fft_getphas(smpl_t * phas, fft_data_t * spectrum, uint_t size) { 129 uint_t i; 130 phas[0] = 0; 131 for (i=1;i<size/2+1;i++) phas[i] = atan2f(spectrum[size-i] , spectrum[i]); 132 phas[size/2] = 0; 133 } 134 135 void aubio_fft_getspectrum(fft_data_t * spectrum, smpl_t *norm, smpl_t * phas, uint_t size) { 136 uint_t j; 137 for (j=0; j<size/2+1; j++) { 138 spectrum[j] = norm[j]*COS(phas[j]); 139 } 140 for (j=1; j<size/2+1; j++) { 141 spectrum[size-j] = norm[j]*SIN(phas[j]); 131 for (j=0; j < s->fft_size; j++) { 132 s->specdata[j] = compspec->data[i][j]; 133 } 134 #endif 135 fftw_execute(s->pbw); 136 for (j = 0; j < output->length; j++) { 137 output->data[i][j] = s->out[j]*renorm; 138 } 142 139 } 143 140 } 144 141 145 #endif 146 147 /* new interface aubio_mfft */ 148 struct _aubio_mfft_t { 149 aubio_fft_t * fft; /* fftw interface */ 150 fft_data_t ** spec; /* complex spectral data */ 151 uint_t winsize; 152 uint_t channels; 153 }; 154 155 aubio_mfft_t * new_aubio_mfft(uint_t winsize, uint_t channels){ 156 uint_t i; 157 aubio_mfft_t * fft = AUBIO_NEW(aubio_mfft_t); 158 fft->winsize = winsize; 159 fft->channels = channels; 160 fft->fft = new_aubio_fft(winsize); 161 fft->spec = AUBIO_ARRAY(fft_data_t*,channels); 162 for (i=0; i < channels; i++) 163 fft->spec[i] = AUBIO_ARRAY(fft_data_t,winsize); 164 return fft; 142 void aubio_fft_get_spectrum(fvec_t * compspec, cvec_t * spectrum) { 143 aubio_fft_get_phas(compspec, spectrum); 144 aubio_fft_get_norm(compspec, spectrum); 165 145 } 166 146 167 /* execute stft */ 168 void aubio_mfft_do (aubio_mfft_t * fft,fvec_t * in,cvec_t * fftgrain){ 169 uint_t i=0; 170 /* execute stft */ 171 for (i=0; i < fft->channels; i++) { 172 aubio_fft_do (fft->fft,in->data[i],fft->spec[i],fft->winsize); 173 /* put norm and phase into fftgrain */ 174 aubio_fft_getnorm(fftgrain->norm[i], fft->spec[i], fft->winsize); 175 aubio_fft_getphas(fftgrain->phas[i], fft->spec[i], fft->winsize); 147 void aubio_fft_get_realimag(cvec_t * spectrum, fvec_t * compspec) { 148 aubio_fft_get_imag(spectrum, compspec); 149 aubio_fft_get_real(spectrum, compspec); 150 } 151 152 void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum) { 153 uint_t i, j; 154 for (i = 0; i < spectrum->channels; i++) { 155 spectrum->phas[i][0] = 0.; 156 for (j=1; j < spectrum->length - 1; j++) { 157 spectrum->phas[i][j] = atan2f(compspec->data[i][compspec->length-j], 158 compspec->data[i][j]); 159 } 160 spectrum->phas[i][spectrum->length-1] = 0.; 176 161 } 177 162 } 178 163 179 /* execute inverse fourier transform */ 180 void aubio_mfft_rdo(aubio_mfft_t * fft,cvec_t * fftgrain, fvec_t * out){ 181 uint_t i=0; 182 for (i=0; i < fft->channels; i++) { 183 aubio_fft_getspectrum(fft->spec[i],fftgrain->norm[i],fftgrain->phas[i],fft->winsize); 184 aubio_fft_rdo(fft->fft,fft->spec[i],out->data[i],fft->winsize); 164 void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum) { 165 uint_t i, j = 0; 166 for (i = 0; i < spectrum->channels; i++) { 167 spectrum->norm[i][0] = compspec->data[i][0]; 168 for (j=1; j < spectrum->length - 1; j++) { 169 spectrum->norm[i][j] = SQRT(SQR(compspec->data[i][j]) 170 + SQR(compspec->data[i][compspec->length - j]) ); 171 } 172 spectrum->norm[i][spectrum->length-1] = compspec->data[i][compspec->length/2]; 185 173 } 186 174 } 187 175 188 void del_aubio_mfft(aubio_mfft_t * fft) { 189 uint_t i; 190 for (i=0; i < fft->channels; i++) 191 AUBIO_FREE(fft->spec[i]); 192 AUBIO_FREE(fft->spec); 193 del_aubio_fft(fft->fft); 194 AUBIO_FREE(fft); 176 void aubio_fft_get_imag(cvec_t * spectrum, fvec_t * compspec) { 177 uint_t i, j; 178 for (i = 0; i < compspec->channels; i++) { 179 for (j = 1; j < compspec->length / 2 + 1; j++) { 180 compspec->data[i][compspec->length - j] = 181 spectrum->norm[i][j]*SIN(spectrum->phas[i][j]); 182 } 183 } 195 184 } 185 186 void aubio_fft_get_real(cvec_t * spectrum, fvec_t * compspec) { 187 uint_t i, j; 188 for (i = 0; i < compspec->channels; i++) { 189 for (j = 0; j< compspec->length / 2 + 1; j++) { 190 compspec->data[i][j] = 191 spectrum->norm[i][j]*COS(spectrum->phas[i][j]); 192 } 193 } 194 } -
src/fft.h
re00f769 rd57d1de 67 67 68 68 \param size length of the FFT 69 \param channels number of channels 69 70 70 71 */ 71 aubio_fft_t * new_aubio_fft(uint_t size );72 aubio_fft_t * new_aubio_fft(uint_t size, uint_t channels); 72 73 /** delete FFT object 73 74 … … 76 77 */ 77 78 void del_aubio_fft(aubio_fft_t * s); 79 78 80 /** compute forward FFT 79 81 80 82 \param s fft object as returned by new_aubio_fft 81 \param datainput signal83 \param input input signal 82 84 \param spectrum output spectrum 83 \param size length of the input vector84 85 85 86 */ 86 void aubio_fft_do (const aubio_fft_t *s, const smpl_t * data, 87 fft_data_t * spectrum, const uint_t size); 87 void aubio_fft_do (aubio_fft_t *s, fvec_t * input, cvec_t * spectrum); 88 88 /** compute backward (inverse) FFT 89 89 90 90 \param s fft object as returned by new_aubio_fft 91 91 \param spectrum input spectrum 92 \param data output signal 93 \param size length of the input vector 92 \param output output signal 94 93 95 94 */ 96 void aubio_fft_rdo(const aubio_fft_t *s, const fft_data_t * spectrum, 97 smpl_t * data, const uint_t size); 98 /** compute norm vector from input spectrum 95 void aubio_fft_rdo (aubio_fft_t *s, cvec_t * spectrum, fvec_t * output); 99 96 100 \param norm magnitude vector output 101 \param spectrum spectral data input 102 \param size size of the vectors 97 /** compute forward FFT 98 99 \param s fft object as returned by new_aubio_fft 100 \param input real input signal 101 \param compspec complex output fft real/imag 103 102 104 103 */ 105 void aubio_fft_ getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size);106 /** compute phase vector from input spectrum107 108 \param phase phase vector output109 \param spectrum spectral data input110 \param size size of the vectors104 void aubio_fft_do_complex (aubio_fft_t *s, fvec_t * input, fvec_t * compspec); 105 /** compute backward (inverse) FFT from real/imag 106 107 \param s fft object as returned by new_aubio_fft 108 \param compspec real/imag input fft array 109 \param output real output array 111 110 112 111 */ 113 void aubio_fft_ getphas(smpl_t * phase, fft_data_t * spectrum, uint_t size);112 void aubio_fft_rdo_complex (aubio_fft_t *s, fvec_t * compspec, fvec_t * output); 114 113 115 /** FFT object (using cvec)114 /** convert real/imag spectrum to norm/phas spectrum 116 115 117 This object works similarly as aubio_fft_t, except the spectral data is118 stored in a cvec_t as two vectors, magnitude and phase.116 \param compspec real/imag input fft array 117 \param spectrum cvec norm/phas output array 119 118 120 119 */ 121 typedef struct _aubio_mfft_t aubio_mfft_t; 120 void aubio_fft_get_spectrum(fvec_t * compspec, cvec_t * spectrum); 121 /** convert real/imag spectrum to norm/phas spectrum 122 122 123 /** create new FFT computation object 124 125 \param winsize length of the FFT 126 \param channels number of channels 123 \param compspec real/imag input fft array 124 \param spectrum cvec norm/phas output array 127 125 128 126 */ 129 aubio_mfft_t * new_aubio_mfft(uint_t winsize, uint_t channels); 130 /** compute forward FFT 127 void aubio_fft_get_realimag(cvec_t * spectrum, fvec_t * compspec); 131 128 132 \param fft fft object as returned by new_aubio_mfft 133 \param in input signal 134 \param fftgrain output spectrum 129 /** compute phas spectrum from real/imag parts 130 131 \param compspec real/imag input fft array 132 \param spectrum cvec norm/phas output array 135 133 136 134 */ 137 void aubio_ mfft_do (aubio_mfft_t * fft,fvec_t * in,cvec_t * fftgrain);138 /** compute backward (inverse) FFT135 void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum); 136 /** compute imaginary part from the norm/phas cvec 139 137 140 \param fft fft object as returned by new_aubio_mfft 141 \param fftgrain input spectrum (cvec) 142 \param out output signal 138 \param spectrum norm/phas input array 139 \param compspec real/imag output fft array 143 140 144 141 */ 145 void aubio_mfft_rdo(aubio_mfft_t * fft,cvec_t * fftgrain, fvec_t * out); 146 /** delete FFT object 142 void aubio_fft_get_imag(cvec_t * spectrum, fvec_t * compspec); 147 143 148 \param fft fft object as returned by new_aubio_mfft 144 /** compute norm component from real/imag parts 145 146 \param compspec real/imag input fft array 147 \param spectrum cvec norm/phas output array 149 148 150 149 */ 151 void del_aubio_mfft(aubio_mfft_t * fft); 150 void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum); 151 /** compute real part from norm/phas components 152 152 153 \param spectrum norm/phas input array 154 \param compspec real/imag output fft array 155 156 */ 157 void aubio_fft_get_real(cvec_t * spectrum, fvec_t * compspec); 153 158 154 159 #ifdef __cplusplus … … 156 161 #endif 157 162 158 #endif 163 #endif // FFT_H_ -
src/hist.c
re00f769 rd57d1de 1 1 /* 2 2 Copyright (C) 2003 Paul Brossier 3 3 4 5 6 7 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 8 9 10 11 12 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 13 14 15 16 17 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 */ 18 18 19 19 #include "aubio_priv.h" … … 28 28 29 29 struct _aubio_hist_t { 30 /*bug: move to a fvec */ 31 smpl_t ** hist; 32 uint_t nelems; 33 uint_t channels; 34 smpl_t * cent; 35 aubio_scale_t *scaler; 30 fvec_t * hist; 31 uint_t nelems; 32 uint_t channels; 33 fvec_t * cent; 34 aubio_scale_t *scaler; 36 35 }; 37 36 … … 40 39 */ 41 40 aubio_hist_t * new_aubio_hist (smpl_t ilow, smpl_t ihig, uint_t nelems, uint_t channels){ 42 aubio_hist_t * s = AUBIO_NEW(aubio_hist_t); 43 smpl_t step = (ihig-ilow)/(smpl_t)(nelems); 44 smpl_t accum = step; 45 uint_t i; 46 s->channels = channels; 47 s->nelems = nelems; 48 s->hist = AUBIO_ARRAY(smpl_t*, channels); 49 for (i=0; i< s->channels; i++) { 50 s->hist[i] = AUBIO_ARRAY(smpl_t, nelems); 51 } 52 s->cent = AUBIO_ARRAY(smpl_t, nelems); 53 54 /* use scale to map ilow/ihig -> 0/nelems */ 55 s->scaler = new_aubio_scale(ilow,ihig,0,nelems); 56 /* calculate centers now once */ 57 s->cent[0] = ilow + 0.5 * step; 58 for (i=1; i < s->nelems; i++, accum+=step ) 59 s->cent[i] = s->cent[0] + accum; 60 61 return s; 41 aubio_hist_t * s = AUBIO_NEW(aubio_hist_t); 42 smpl_t step = (ihig-ilow)/(smpl_t)(nelems); 43 smpl_t accum = step; 44 uint_t i; 45 s->channels = channels; 46 s->nelems = nelems; 47 s->hist = new_fvec(nelems, channels); 48 s->cent = new_fvec(nelems, 1); 49 50 /* use scale to map ilow/ihig -> 0/nelems */ 51 s->scaler = new_aubio_scale(ilow,ihig,0,nelems); 52 /* calculate centers now once */ 53 s->cent->data[0][0] = ilow + 0.5 * step; 54 for (i=1; i < s->nelems; i++, accum+=step ) 55 s->cent->data[0][i] = s->cent->data[0][0] + accum; 56 57 return s; 62 58 } 63 59 64 60 void del_aubio_hist(aubio_hist_t *s) { 65 uint_t i; 66 for (i=0; i< s->channels; i++) { 67 AUBIO_FREE(s->hist[i]); 68 } 69 AUBIO_FREE(s->hist); 70 AUBIO_FREE(s->cent); 71 del_aubio_scale(s->scaler); 72 AUBIO_FREE(s); 61 del_fvec(s->hist); 62 del_fvec(s->cent); 63 del_aubio_scale(s->scaler); 64 AUBIO_FREE(s); 73 65 } 74 66 … … 76 68 * do it 77 69 */ 78 void aubio_hist_do (aubio_hist_t *s, fvec_t *input) 79 { 80 uint_t i,j; 81 sint_t tmp = 0; 82 aubio_scale_do(s->scaler, input); 83 /* reset data */ 84 for (i=0; i < s->channels; i++) 85 for (j=0; j < s->nelems; j++) 86 s->hist[i][j] = 0; 87 /* run accum */ 88 for (i=0; i < input->channels; i++) 89 for (j=0; j < input->length; j++) 90 { 91 tmp = (sint_t)FLOOR(input->data[i][j]); 92 if ((tmp >= 0) && (tmp < (sint_t)s->nelems)) 93 s->hist[i][tmp] += 1; 94 } 70 void aubio_hist_do (aubio_hist_t *s, fvec_t *input) { 71 uint_t i,j; 72 sint_t tmp = 0; 73 aubio_scale_do(s->scaler, input); 74 /* reset data */ 75 for (i=0; i < s->channels; i++) 76 for (j=0; j < s->nelems; j++) 77 s->hist->data[i][j] = 0; 78 /* run accum */ 79 for (i=0; i < input->channels; i++) 80 for (j=0; j < input->length; j++) 81 { 82 tmp = (sint_t)FLOOR(input->data[i][j]); 83 if ((tmp >= 0) && (tmp < (sint_t)s->nelems)) 84 s->hist->data[i][tmp] += 1; 85 } 95 86 } 96 87 97 void aubio_hist_do_notnull (aubio_hist_t *s, fvec_t *input) 98 { 99 uint_t i,j; 100 sint_t tmp = 0; 101 aubio_scale_do(s->scaler, input); 102 /* reset data */ 103 for (i=0; i < s->channels; i++) 104 for (j=0; j < s->nelems; j++) 105 s->hist[i][j] = 0; 106 /* run accum */ 107 for (i=0; i < input->channels; i++) 108 for (j=0; j < input->length; j++) 109 { 110 if (input->data[i][j] != 0) { 111 tmp = (sint_t)FLOOR(input->data[i][j]); 112 if ((tmp >= 0) && (tmp < (sint_t)s->nelems)) 113 s->hist[i][tmp] += 1; 114 } 115 } 88 void aubio_hist_do_notnull (aubio_hist_t *s, fvec_t *input) { 89 uint_t i,j; 90 sint_t tmp = 0; 91 aubio_scale_do(s->scaler, input); 92 /* reset data */ 93 for (i=0; i < s->channels; i++) 94 for (j=0; j < s->nelems; j++) 95 s->hist->data[i][j] = 0; 96 /* run accum */ 97 for (i=0; i < input->channels; i++) 98 for (j=0; j < input->length; j++) { 99 if (input->data[i][j] != 0) { 100 tmp = (sint_t)FLOOR(input->data[i][j]); 101 if ((tmp >= 0) && (tmp < (sint_t)s->nelems)) 102 s->hist->data[i][tmp] += 1; 103 } 104 } 116 105 } 117 106 118 107 119 void aubio_hist_dyn_notnull (aubio_hist_t *s, fvec_t *input) 120 { 121 uint_t i,j; 122 sint_t tmp = 0; 123 smpl_t ilow = vec_min(input); 124 smpl_t ihig = vec_max(input); 125 smpl_t step = (ihig-ilow)/(smpl_t)(s->nelems); 126 127 /* readapt */ 128 aubio_scale_set(s->scaler, ilow, ihig, 0, s->nelems); 108 void aubio_hist_dyn_notnull (aubio_hist_t *s, fvec_t *input) { 109 uint_t i,j; 110 sint_t tmp = 0; 111 smpl_t ilow = vec_min(input); 112 smpl_t ihig = vec_max(input); 113 smpl_t step = (ihig-ilow)/(smpl_t)(s->nelems); 129 114 130 /* recalculate centers */ 131 s->cent[0] = ilow + 0.5f * step; 132 for (i=1; i < s->nelems; i++) 133 s->cent[i] = s->cent[0] + i * step; 115 /* readapt */ 116 aubio_scale_set(s->scaler, ilow, ihig, 0, s->nelems); 134 117 135 /* scale */ 136 aubio_scale_do(s->scaler, input); 118 /* recalculate centers */ 119 s->cent->data[0][0] = ilow + 0.5f * step; 120 for (i=1; i < s->nelems; i++) 121 s->cent->data[0][i] = s->cent->data[0][0] + i * step; 137 122 138 /* reset data */ 139 for (i=0; i < s->channels; i++) 140 for (j=0; j < s->nelems; j++) 141 s->hist[i][j] = 0; 142 /* run accum */ 143 for (i=0; i < input->channels; i++) 144 for (j=0; j < input->length; j++) 145 { 146 if (input->data[i][j] != 0) { 147 tmp = (sint_t)FLOOR(input->data[i][j]); 148 if ((tmp >= 0) && (tmp < (sint_t)s->nelems)) 149 s->hist[i][tmp] += 1; 150 } 151 } 123 /* scale */ 124 aubio_scale_do(s->scaler, input); 125 126 /* reset data */ 127 for (i=0; i < s->channels; i++) 128 for (j=0; j < s->nelems; j++) 129 s->hist->data[i][j] = 0; 130 /* run accum */ 131 for (i=0; i < input->channels; i++) 132 for (j=0; j < input->length; j++) { 133 if (input->data[i][j] != 0) { 134 tmp = (sint_t)FLOOR(input->data[i][j]); 135 if ((tmp >= 0) && (tmp < (sint_t)s->nelems)) 136 s->hist->data[i][tmp] += 1; 137 } 138 } 152 139 } 153 140 154 void aubio_hist_weigth (aubio_hist_t *s) 155 { 156 uint_t i,j; 157 for (i=0; i < s->channels; i++) 158 for (j=0; j < s->nelems; j++) { 159 s->hist[i][j] *= s->cent[j]; 160 } 141 void aubio_hist_weight (aubio_hist_t *s) { 142 uint_t i,j; 143 for (i=0; i < s->channels; i++) 144 for (j=0; j < s->nelems; j++) { 145 s->hist->data[i][j] *= s->cent->data[0][j]; 146 } 161 147 } 162 148 163 smpl_t aubio_hist_mean (aubio_hist_t *s) 164 { 165 uint_t i,j; 166 smpl_t tmp = 0.0f; 167 for (i=0; i < s->channels; i++) 168 for (j=0; j < s->nelems; j++) 169 tmp += s->hist[i][j]; 170 return tmp/(smpl_t)(s->nelems); 149 smpl_t aubio_hist_mean (aubio_hist_t *s) { 150 uint_t i,j; 151 smpl_t tmp = 0.0f; 152 for (i=0; i < s->channels; i++) 153 for (j=0; j < s->nelems; j++) 154 tmp += s->hist->data[i][j]; 155 return tmp/(smpl_t)(s->nelems); 171 156 } 172 157 -
src/hist.h
re00f769 rd57d1de 1 1 /* 2 2 Copyright (C) 2003 Paul Brossier 3 3 4 5 6 7 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 8 9 10 11 12 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 */ 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 18 */ 18 19 19 20 /** @file … … 34 35 typedef struct _aubio_hist_t aubio_hist_t; 35 36 36 /** histogram creation 37 /** histogram creation 37 38 * \param flow minimum input 38 39 * \param fhig maximum input 39 40 * \param nelems number of histogram columns 40 * \param channels number of channels 41 * \param channels number of channels 41 42 */ 42 43 aubio_hist_t * new_aubio_hist(smpl_t flow, smpl_t fhig, uint_t nelems, uint_t channels); … … 48 49 void aubio_hist_do_notnull(aubio_hist_t *s, fvec_t * input); 49 50 /** compute the mean of the histogram */ 50 smpl_t aubio_hist_mean(aubio_hist_t *s); 51 smpl_t aubio_hist_mean(aubio_hist_t *s); 51 52 /** weight the histogram */ 52 void aubio_hist_weig th(aubio_hist_t *s);53 void aubio_hist_weight(aubio_hist_t *s); 53 54 /** compute dynamic histogram for non-null elements */ 54 55 void aubio_hist_dyn_notnull (aubio_hist_t *s, fvec_t *input); -
src/onsetdetection.c
re00f769 rd57d1de 129 129 aubio_hist_dyn_notnull(o->histog,o->dev1); 130 130 /* weight it */ 131 aubio_hist_weig th(o->histog);131 aubio_hist_weight(o->histog); 132 132 /* its mean is the result */ 133 133 onset->data[i][0] = aubio_hist_mean(o->histog); … … 158 158 aubio_hist_dyn_notnull(o->histog,o->dev1); 159 159 /* weight it */ 160 aubio_hist_weig th(o->histog);160 aubio_hist_weight(o->histog); 161 161 /* its mean is the result */ 162 162 onset->data[i][0] = aubio_hist_mean(o->histog); -
src/phasevoc.c
re00f769 rd57d1de 19 19 20 20 #include "aubio_priv.h" 21 #include "sample.h" 21 #include "fvec.h" 22 #include "cvec.h" 22 23 #include "fft.h" 23 24 #include "mathutils.h" … … 29 30 uint_t hop_s; /** overlap step */ 30 31 uint_t channels; /** number of channels */ 31 aubio_ mfft_t * fft; /** spectral data*/32 fvec_t * synth; /** cur output grain [win_s] */33 fvec_t * synthold; /** last input frame [win_s-hop_s] */34 fvec_t * data; /** current input grain [win_s] */35 fvec_t * dataold; /** last input frame [win_s-hop_s] */36 smpl_t * w; 32 aubio_fft_t * fft; /** fft object */ 33 fvec_t * synth; /** cur output grain [win_s] */ 34 fvec_t * synthold; /** last input frame [win_s-hop_s] */ 35 fvec_t * data; /** current input grain [win_s] */ 36 fvec_t * dataold; /** last input frame [win_s-hop_s] */ 37 smpl_t * w; /** grain window [win_s] */ 37 38 }; 38 39 … … 58 59 vec_shift(pv->data); 59 60 /* calculate fft */ 60 aubio_ mfft_do (pv->fft,pv->data,fftgrain);61 aubio_fft_do (pv->fft,pv->data,fftgrain); 61 62 } 62 63 … … 64 65 uint_t i; 65 66 /* calculate rfft */ 66 aubio_ mfft_rdo(pv->fft,fftgrain,pv->synth);67 aubio_fft_rdo(pv->fft,fftgrain,pv->synth); 67 68 /* unshift */ 68 69 vec_shift(pv->synth); … … 88 89 } 89 90 90 pv->fft = new_aubio_ mfft(win_s,channels);91 pv->fft = new_aubio_fft(win_s,channels); 91 92 92 93 /* remember old */ … … 112 113 del_fvec(pv->dataold); 113 114 del_fvec(pv->synthold); 114 del_aubio_ mfft(pv->fft);115 del_aubio_fft(pv->fft); 115 116 AUBIO_FREE(pv->w); 116 117 AUBIO_FREE(pv); -
src/pitchfcomb.c
re00f769 rd57d1de 39 39 cvec_t * fftOut; 40 40 fvec_t * fftLastPhase; 41 aubio_ mfft_t * fft;41 aubio_fft_t * fft; 42 42 //aubio_pvoc_t * pvoc; 43 43 }; … … 52 52 p->fftOut = new_cvec(bufsize,1); 53 53 p->fftLastPhase = new_fvec(bufsize,1); 54 p->fft = new_aubio_ mfft(bufsize, 1);54 p->fft = new_aubio_fft(bufsize, 1); 55 55 p->win = new_fvec(bufsize,1); 56 56 aubio_window(p->win->data[0], bufsize, aubio_win_hanning); … … 74 74 p->winput->data[0][k] = p->win->data[0][k] * input->data[0][k]; 75 75 } 76 aubio_ mfft_do(p->fft,p->winput,p->fftOut);76 aubio_fft_do(p->fft,p->winput,p->fftOut); 77 77 78 78 for (k=0; k<=p->fftSize/2; k++) { … … 130 130 del_fvec(p->win); 131 131 del_fvec(p->winput); 132 del_aubio_ mfft(p->fft);132 del_aubio_fft(p->fft); 133 133 AUBIO_FREE(p); 134 134 } -
src/pitchyinfft.c
re00f769 rd57d1de 31 31 fvec_t * weight; /**< spectral weighting window (psychoacoustic model) */ 32 32 cvec_t * fftout; /**< Fourier transform output */ 33 aubio_ mfft_t * fft; /**< fft object to compute square difference function */33 aubio_fft_t * fft; /**< fft object to compute square difference function */ 34 34 fvec_t * yinfft; /**< Yin function */ 35 35 }; … … 49 49 aubio_pitchyinfft_t * p = AUBIO_NEW(aubio_pitchyinfft_t); 50 50 p->winput = new_fvec(bufsize,1); 51 p->fft = new_aubio_ mfft(bufsize, 1);51 p->fft = new_aubio_fft(bufsize, 1); 52 52 p->fftout = new_cvec(bufsize,1); 53 53 p->sqrmag = new_fvec(bufsize,1); … … 97 97 p->winput->data[0][l] = p->win->data[0][l] * input->data[0][l]; 98 98 } 99 aubio_ mfft_do(p->fft,p->winput,p->fftout);99 aubio_fft_do(p->fft,p->winput,p->fftout); 100 100 for (l=0; l < p->fftout->length; l++){ 101 101 p->sqrmag->data[0][l] = SQR(p->fftout->norm[0][l]); … … 112 112 } 113 113 sum *= 2.; 114 aubio_ mfft_do(p->fft,p->sqrmag,res);114 aubio_fft_do(p->fft,p->sqrmag,res); 115 115 yin->data[0][0] = 1.; 116 116 for (tau=1; tau < yin->length; tau++) { … … 143 143 void del_aubio_pitchyinfft(aubio_pitchyinfft_t *p){ 144 144 del_fvec(p->win); 145 del_aubio_ mfft(p->fft);145 del_aubio_fft(p->fft); 146 146 del_fvec(p->yinfft); 147 147 del_fvec(p->sqrmag); -
src/scale.c
re00f769 rd57d1de 1 1 /* 2 2 Copyright (C) 2003 Paul Brossier 3 3 4 5 6 7 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 8 9 10 11 12 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 17 18 */ 18 19 … … 22 23 23 24 struct _aubio_scale_t { 24 25 26 27 25 smpl_t ilow; 26 smpl_t ihig; 27 smpl_t olow; 28 smpl_t ohig; 28 29 29 30 31 32 33 34 35 30 smpl_t scaler; 31 smpl_t irange; 32 33 /* not implemented yet : type in/out data 34 bool inint; 35 bool outint; 36 */ 36 37 }; 37 38 38 aubio_scale_t * new_aubio_scale (smpl_t ilow, smpl_t ihig, smpl_t olow, smpl_t ohig ){ 39 aubio_scale_t * s = AUBIO_NEW(aubio_scale_t); 40 aubio_scale_set (s, ilow, ihig, olow, ohig); 41 return s; 39 aubio_scale_t * new_aubio_scale (smpl_t ilow, smpl_t ihig, 40 smpl_t olow, smpl_t ohig) { 41 aubio_scale_t * s = AUBIO_NEW(aubio_scale_t); 42 aubio_scale_set (s, ilow, ihig, olow, ohig); 43 return s; 42 44 } 43 45 44 46 void del_aubio_scale(aubio_scale_t *s) { 45 47 AUBIO_FREE(s); 46 48 } 47 49 48 void aubio_scale_set (aubio_scale_t *s, smpl_t ilow, smpl_t ihig, smpl_t olow, smpl_t ohig) 49 { 50 smpl_t inputrange = ihig - ilow; 51 smpl_t outputrange= ohig - olow; 52 s->ilow = ilow; 53 s->ihig = ihig; 54 s->olow = olow; 55 s->ohig = ohig; 56 if (inputrange == 0 ) 57 s->scaler = 0.0f; 58 else { 59 s->scaler = outputrange/inputrange; 60 if (inputrange < 0 ) 61 inputrange = inputrange * -1.0f; 62 } 50 void aubio_scale_set (aubio_scale_t *s, smpl_t ilow, smpl_t ihig, 51 smpl_t olow, smpl_t ohig) { 52 smpl_t inputrange = ihig - ilow; 53 smpl_t outputrange= ohig - olow; 54 s->ilow = ilow; 55 s->ihig = ihig; 56 s->olow = olow; 57 s->ohig = ohig; 58 if (inputrange == 0) { 59 s->scaler = 0.0f; 60 } else { 61 s->scaler = outputrange/inputrange; 62 if (inputrange < 0) { 63 inputrange = inputrange * -1.0f; 64 } 65 } 63 66 } 64 67 65 68 void aubio_scale_do (aubio_scale_t *s, fvec_t *input) 66 69 { 67 68 69 70 71 72 73 74 70 uint_t i, j; 71 for (i=0; i < input->channels; i++){ 72 for (j=0; j < input->length; j++){ 73 input->data[i][j] -= s->ilow; 74 input->data[i][j] *= s->scaler; 75 input->data[i][j] += s->olow; 76 } 77 } 75 78 } 76 79 -
src/scale.h
re00f769 rd57d1de 1 1 /* 2 2 Copyright (C) 2003 Paul Brossier 3 3 4 5 6 7 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 8 9 10 11 12 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 13 14 15 16 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 17 */ 18 18 … … 45 45 46 46 */ 47 aubio_scale_t * new_aubio_scale(smpl_t flow, smpl_t fhig, smpl_t ilow, smpl_t ihig ); 47 aubio_scale_t * new_aubio_scale(smpl_t flow, smpl_t fhig, 48 smpl_t ilow, smpl_t ihig); 48 49 /** delete a scale object 49 50 … … 68 69 69 70 */ 70 void aubio_scale_set (aubio_scale_t *s, smpl_t ilow, smpl_t ihig, smpl_t olow, smpl_t ohig); 71 void aubio_scale_set (aubio_scale_t *s, smpl_t ilow, smpl_t ihig, 72 smpl_t olow, smpl_t ohig); 71 73 72 74 #ifdef __cplusplus -
swig/aubio.i
re00f769 rd57d1de 72 72 73 73 /* fft */ 74 extern void aubio_fft_getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size); 75 extern void aubio_fft_getphas(smpl_t * phase, fft_data_t * spectrum, uint_t size); 76 77 extern aubio_mfft_t * new_aubio_mfft(uint_t winsize, uint_t channels); 78 extern void aubio_mfft_do (aubio_mfft_t * fft,fvec_t * in,cvec_t * fftgrain); 79 extern void aubio_mfft_rdo(aubio_mfft_t * fft,cvec_t * fftgrain, fvec_t * out); 80 extern void del_aubio_mfft(aubio_mfft_t * fft); 81 74 extern aubio_fft_t * new_aubio_fft(uint_t size, uint_t channels); 75 extern void del_aubio_fft(aubio_fft_t * s); 76 extern void aubio_fft_do (aubio_fft_t *s, fvec_t * input, cvec_t * spectrum); 77 extern void aubio_fft_rdo (aubio_fft_t *s, cvec_t * spectrum, fvec_t * output); 78 extern void aubio_fft_do_complex (aubio_fft_t *s, fvec_t * input, fvec_t * compspec); 79 extern void aubio_fft_rdo_complex (aubio_fft_t *s, fvec_t * compspec, fvec_t * output); 80 extern void aubio_fft_get_spectrum(fvec_t * compspec, cvec_t * spectrum); 81 extern void aubio_fft_get_realimag(cvec_t * spectrum, fvec_t * compspec); 82 extern void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum); 83 extern void aubio_fft_get_imag(cvec_t * spectrum, fvec_t * compspec); 84 extern void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum); 85 extern void aubio_fft_get_real(cvec_t * spectrum, fvec_t * compspec); 82 86 83 87 /* filter */ … … 101 105 extern void aubio_hist_do(aubio_hist_t *s, fvec_t * input); 102 106 extern void aubio_hist_do_notnull(aubio_hist_t *s, fvec_t * input); 103 extern void aubio_hist_dyn_notnull (aubio_hist_t *s, fvec_t *input); 107 extern void aubio_hist_dyn_notnull(aubio_hist_t *s, fvec_t *input); 108 extern void aubio_hist_weight(aubio_hist_t *s); 109 extern smpl_t aubio_hist_mean(aubio_hist_t *s); 104 110 105 111 /* mathutils */ -
tests/python/fft.py
re00f769 rd57d1de 1 import unittest2 1 import math 2 3 from template import aubio_unit_template 3 4 4 5 from aubio.aubiowrapper import * 5 6 6 buf_size = 80927 buf_size = 1024 7 8 channels = 4 8 9 9 precision = 6 10 11 class aubio_mfft_test_case(unittest.TestCase): 10 class fft_unit(aubio_unit_template): 12 11 13 12 def setUp(self): 14 self.o = new_aubio_ mfft(buf_size, channels)13 self.o = new_aubio_fft(buf_size, channels) 15 14 16 15 def tearDown(self): 17 del_aubio_ mfft(self.o)16 del_aubio_fft(self.o) 18 17 19 18 def test_create(self): … … 21 20 pass 22 21 23 def test_ aubio_mfft_do_zeroes(self):24 """ test aubio_ mfft_do on zeroes """22 def test_do_zeroes(self): 23 """ test aubio_fft_do on zeroes """ 25 24 input = new_fvec(buf_size, channels) 26 25 fftgrain = new_cvec(buf_size, channels) 27 26 for index in range(buf_size): 28 27 for channel in range(channels): 29 self.assert Equal(0., fvec_read_sample(input, channel, index))30 aubio_ mfft_do(self.o, input, fftgrain)28 self.assertCloseEnough(0., fvec_read_sample(input, channel, index)) 29 aubio_fft_do(self.o, input, fftgrain) 31 30 for index in range(buf_size/2+1): 32 31 for channel in range(channels): 33 self.assert Equal(0., cvec_read_norm(fftgrain, channel, index))32 self.assertCloseEnough(0., cvec_read_norm(fftgrain, channel, index)) 34 33 for index in range(buf_size/2+1): 35 34 for channel in range(channels): 36 self.assert Equal(0., cvec_read_phas(fftgrain, channel, index))35 self.assertCloseEnough(0., cvec_read_phas(fftgrain, channel, index)) 37 36 del fftgrain 38 37 del input 39 38 40 def test_ aubio_mfft_rdo_zeroes(self):41 """ test aubio_ mfft_rdo on zeroes """39 def test_rdo_zeroes(self): 40 """ test aubio_fft_rdo on zeroes """ 42 41 fftgrain = new_cvec(buf_size, channels) 43 42 output = new_fvec(buf_size, channels) 44 aubio_ mfft_rdo(self.o, fftgrain, output)43 aubio_fft_rdo(self.o, fftgrain, output) 45 44 # check output 46 45 for index in range(buf_size): … … 50 49 del output 51 50 52 def test_ aubio_mfft_do_impulse(self):53 """ test aubio_ mfft_do with an impulse on one channel """51 def test_do_impulse(self): 52 """ test aubio_fft_do with an impulse on one channel """ 54 53 input = new_fvec(buf_size, channels) 55 54 fftgrain = new_cvec(buf_size, channels) … … 57 56 some_constant = 0.3412432456 58 57 fvec_write_sample(input, some_constant, 0, 0) 59 aubio_ mfft_do(self.o, input, fftgrain)58 aubio_fft_do(self.o, input, fftgrain) 60 59 # check norm 61 60 for index in range(buf_size/2+1): 62 self.assert AlmostEqual(some_constant, cvec_read_norm(fftgrain, 0, index), precision)61 self.assertCloseEnough(some_constant, cvec_read_norm(fftgrain, 0, index)) 63 62 for index in range(buf_size/2+1): 64 63 for channel in range(1, channels): … … 71 70 del input 72 71 73 def test_ aubio_mfft_do_constant(self):74 """ test aubio_ mfft_do with a constant on one channel """72 def test_do_constant(self): 73 """ test aubio_fft_do with a constant on one channel """ 75 74 input = new_fvec(buf_size, channels) 76 75 fftgrain = new_cvec(buf_size, channels) … … 79 78 for index in range(1,buf_size): 80 79 fvec_write_sample(input, some_constant, 0, index) 81 aubio_ mfft_do(self.o, input, fftgrain)80 aubio_fft_do(self.o, input, fftgrain) 82 81 # check norm and phase == 0 in all other channels 83 82 for index in range(buf_size/2+1): 84 83 for channel in range(1, channels): 85 84 self.assertEqual(0., cvec_read_norm(fftgrain, channel, index)) 85 self.assertEqual(0., cvec_read_phas(fftgrain, channel, index)) 86 86 87 # check norm and phase == 0 in first first and last bin of first channel 87 self.assertAlmostEqual((buf_size-1)*some_constant, cvec_read_norm(fftgrain, 0, 0), precision) 88 self.assertEqual(0., cvec_read_phas(fftgrain, 0, 0)) 89 self.assertEqual(0., cvec_read_norm(fftgrain, 0, buf_size/2+1)) 90 self.assertEqual(0., cvec_read_phas(fftgrain, 0, buf_size/2+1)) 91 # check unwrap2pi(phas) ~= pi everywhere but in first bin 88 # check unwrap2pi(phas) ~= pi everywhere but in first and last bin 89 self.assertCloseEnough(0., cvec_read_phas(fftgrain, 0, 0)) 90 for index in range(1,buf_size/2): 91 self.assertCloseEnough(math.pi, aubio_unwrap2pi(cvec_read_phas(fftgrain, 0, index))) 92 self.assertCloseEnough(0., cvec_read_phas(fftgrain, 0, buf_size/2)) 93 self.assertCloseEnough(0., cvec_read_phas(fftgrain, 0, buf_size/2+1)) 94 95 self.assertCloseEnough((buf_size-1)*some_constant, cvec_read_norm(fftgrain, 0, 0)) 92 96 for index in range(1,buf_size/2+1): 93 self.assertAlmostEqual ( math.pi, aubio_unwrap2pi(cvec_read_phas(fftgrain, 0, index)), precision) 94 self.assertAlmostEqual(some_constant, cvec_read_norm(fftgrain, 0, index), precision) 97 self.assertCloseEnough(some_constant, abs(cvec_read_norm(fftgrain, 0, index))) 98 self.assertCloseEnough(0., cvec_read_norm(fftgrain, 0, buf_size/2+1)) 99 95 100 del fftgrain 96 101 del input 97 102 98 def test_ aubio_mfft_do_impulse_multichannel(self):99 " test aubio_ mfft_do on impulse two channels "103 def test_do_impulse_multichannel(self): 104 " test aubio_fft_do on impulse two channels " 100 105 input = new_fvec(buf_size, channels) 101 106 fftgrain = new_cvec(buf_size, channels) … … 103 108 fvec_write_sample(input, 1., 0, 0) 104 109 fvec_write_sample(input, 1., channels-1, 0) 105 aubio_ mfft_do(self.o, input, fftgrain)110 aubio_fft_do(self.o, input, fftgrain) 106 111 # check the norm 107 112 for index in range(buf_size/2+1): … … 119 124 del input 120 125 121 def test_ aubio_mfft_rdo_impulse(self):122 """ test aubio_ mfft_rdo on impulse """126 def test_rdo_impulse(self): 127 """ test aubio_fft_rdo on impulse """ 123 128 fftgrain = new_cvec(buf_size, channels) 124 129 for channel in range(channels): 125 130 cvec_write_norm(fftgrain, 1., channel, 0) 126 131 output = new_fvec(buf_size, channels) 127 aubio_ mfft_rdo(self.o, fftgrain, output)132 aubio_fft_rdo(self.o, fftgrain, output) 128 133 for index in range(buf_size/2+1): 129 134 for channel in range(channels): 130 self.assert AlmostEqual(fvec_read_sample(output, channel, index), 1./buf_size, precision)135 self.assertCloseEnough(fvec_read_sample(output, channel, index), 1./buf_size) 131 136 del fftgrain 132 137 del output 133 138 134 def test_ aubio_mfft_do_back_and_forth(self):135 """ test aubio_ mfft_rdo on a constant """139 def test_do_back_and_forth(self): 140 """ test aubio_fft_rdo on a constant """ 136 141 input = new_fvec(buf_size, channels) 137 142 output = new_fvec(buf_size, channels) … … 140 145 for channel in range(channels): 141 146 fvec_write_sample(input, 0.67, channel, index) 142 aubio_ mfft_do(self.o, input, fftgrain)143 aubio_ mfft_rdo(self.o, fftgrain, output)147 aubio_fft_do(self.o, input, fftgrain) 148 aubio_fft_rdo(self.o, fftgrain, output) 144 149 for index in range(buf_size/2+1): 145 150 for channel in range(channels): 146 self.assert AlmostEqual(fvec_read_sample(output, channel, index), 0.67, precision)151 self.assertCloseEnough(0.67, fvec_read_sample(output, channel, index)) 147 152 del fftgrain 148 153 del output
Note: See TracChangeset
for help on using the changeset viewer.