Changes in / [c721874:1da7e08]
- Files:
-
- 1 added
- 6 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/aubio_priv.h
rc721874 r1da7e08 1 1 /* 2 Copyright (C) 2003-2007Paul Brossier2 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 … … 71 71 72 72 /* Memory management */ 73 #define AUBIO_MALLOC(_n) 74 #define AUBIO_REALLOC(_p,_n) 75 #define AUBIO_NEW(_t) 76 #define AUBIO_ARRAY(_t,_n) 77 #define AUBIO_MEMCPY(_dst,_src,_n) 78 #define AUBIO_MEMSET(_dst,_src,_t) 79 #define AUBIO_FREE(_p) free(_p)73 #define AUBIO_MALLOC(_n) malloc(_n) 74 #define AUBIO_REALLOC(_p,_n) realloc(_p,_n) 75 #define AUBIO_NEW(_t) (_t*)malloc(sizeof(_t)) 76 #define AUBIO_ARRAY(_t,_n) (_t*)malloc((_n)*sizeof(_t)) 77 #define AUBIO_MEMCPY(_dst,_src,_n) memcpy(_dst,_src,_n) 78 #define AUBIO_MEMSET(_dst,_src,_t) memset(_dst,_src,_t) 79 #define AUBIO_FREE(_p) free(_p) 80 80 81 81 -
src/fft.c
rc721874 r1da7e08 24 24 25 25 #if FFTW3F_SUPPORT 26 #define fftw_malloc 27 #define fftw_free 28 #define fftw_execute 29 #define fftw_plan_dft_r2c_1d 30 #define fftw_plan_dft_c2r_1d 31 #define fftw_plan_r2r_1d 32 #define fftw_plan 33 #define fftw_destroy_plan 26 #define fftw_malloc fftwf_malloc 27 #define fftw_free fftwf_free 28 #define fftw_execute fftwf_execute 29 #define fftw_plan_dft_r2c_1d fftwf_plan_dft_r2c_1d 30 #define fftw_plan_dft_c2r_1d fftwf_plan_dft_c2r_1d 31 #define fftw_plan_r2r_1d fftwf_plan_r2r_1d 32 #define fftw_plan fftwf_plan 33 #define fftw_destroy_plan fftwf_destroy_plan 34 34 #endif 35 35 … … 41 41 42 42 struct _aubio_fft_t { 43 44 45 real_t*in, *out;46 fft_data_t*specdata;47 fftw_planpfw, pbw;43 uint_t fft_size; 44 uint_t channels; 45 real_t *in, *out; 46 fft_data_t *specdata; 47 fftw_plan pfw, pbw; 48 48 }; 49 49 … … 51 51 52 52 aubio_fft_t * new_aubio_fft(uint_t size) { 53 aubio_fft_t * s = AUBIO_NEW(aubio_fft_t); 54 /* allocate memory */ 55 s->in = AUBIO_ARRAY(real_t,size); 56 s->out = AUBIO_ARRAY(real_t,size); 57 /* create plans */ 53 aubio_fft_t * s = AUBIO_NEW(aubio_fft_t); 54 /* allocate memory */ 55 s->in = AUBIO_ARRAY(real_t,size); 56 s->out = AUBIO_ARRAY(real_t,size); 57 s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*size); 58 /* create plans */ 58 59 #ifdef HAVE_COMPLEX_H 59 s->fft_size = size/2+1; 60 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); 60 s->pfw = fftw_plan_dft_r2c_1d(size, s->in, s->specdata, FFTW_ESTIMATE); 61 s->pbw = fftw_plan_dft_c2r_1d(size, s->specdata, s->out, FFTW_ESTIMATE); 63 62 #else 64 s->fft_size = size; 65 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); 63 s->pfw = fftw_plan_r2r_1d(size, s->in, s->specdata, FFTW_R2HC, FFTW_ESTIMATE); 64 s->pbw = fftw_plan_r2r_1d(size, s->specdata, s->out, FFTW_HC2R, FFTW_ESTIMATE); 68 65 #endif 69 66 return s; 70 67 } 71 68 72 69 void del_aubio_fft(aubio_fft_t * s) { 73 74 75 76 77 78 79 70 /* destroy data */ 71 fftw_destroy_plan(s->pfw); 72 fftw_destroy_plan(s->pbw); 73 fftw_free(s->specdata); 74 AUBIO_FREE(s->out); 75 AUBIO_FREE(s->in ); 76 AUBIO_FREE(s); 80 77 } 81 78 82 79 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]; 80 const smpl_t * data, fft_data_t * spectrum, 81 const uint_t size) { 82 uint_t i; 83 for (i=0;i<size;i++) s->in[i] = data[i]; 84 fftw_execute(s->pfw); 85 for (i=0;i<size;i++) spectrum[i] = s->specdata[i]; 88 86 } 89 87 90 88 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; 89 const fft_data_t * spectrum, 90 smpl_t * data, 91 const uint_t size) { 92 uint_t i; 93 const smpl_t renorm = 1./(smpl_t)size; 94 for (i=0;i<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; 97 97 } 98 98 … … 100 100 101 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]); 102 uint_t i; 103 for (i=0;i<size/2+1;i++) norm[i] = ABSC(spectrum[i]); 104 //for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", norm[i]); 104 105 } 105 106 106 107 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]); 108 uint_t i; 109 for (i=0;i<size/2+1;i++) phas[i] = ARGC(spectrum[i]); 110 //for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", phas[i]); 109 111 } 110 112 … … 120 122 121 123 void aubio_fft_getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size) { 122 123 norm[0] = SQR(spectrum[0]);124 for (i=1;i<size/2;i++) norm[i] =(SQR(spectrum[i]) + SQR(spectrum[size-i]));125 norm[size/2] = SQR(spectrum[size/2]);124 uint_t i; 125 norm[0] = -spectrum[0]; 126 for (i=1;i<size/2+1;i++) norm[i] = SQRT(SQR(spectrum[i]) + SQR(spectrum[size-i])); 127 //for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", norm[i]); 126 128 } 127 129 128 130 void aubio_fft_getphas(smpl_t * phas, fft_data_t * spectrum, uint_t size) { 129 130 phas[0] = 0;131 132 phas[size/2] = 0;131 uint_t i; 132 phas[0] = PI; 133 for (i=1;i<size/2+1;i++) phas[i] = atan2f(spectrum[size-i] , spectrum[i]); 134 //for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", phas[i]); 133 135 } 134 136 … … 154 156 155 157 aubio_mfft_t * new_aubio_mfft(uint_t winsize, uint_t channels){ 156 uint_t i;157 158 159 160 161 162 for (i=0; i < channels; i++)163 fft->spec[i] = AUBIO_ARRAY(fft_data_t,winsize);164 return fft;158 uint_t i; 159 aubio_mfft_t * fft = AUBIO_NEW(aubio_mfft_t); 160 fft->winsize = winsize; 161 fft->channels = channels; 162 fft->fft = new_aubio_fft(winsize); 163 fft->spec = AUBIO_ARRAY(fft_data_t*,channels); 164 for (i=0; i < channels; i++) 165 fft->spec[i] = AUBIO_ARRAY(fft_data_t,winsize); 166 return fft; 165 167 } 166 168 167 169 /* execute stft */ 168 170 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);176 }171 uint_t i=0; 172 /* execute stft */ 173 for (i=0; i < fft->channels; i++) { 174 aubio_fft_do (fft->fft,in->data[i],fft->spec[i],fft->winsize); 175 /* put norm and phase into fftgrain */ 176 aubio_fft_getnorm(fftgrain->norm[i], fft->spec[i], fft->winsize); 177 aubio_fft_getphas(fftgrain->phas[i], fft->spec[i], fft->winsize); 178 } 177 179 } 178 180 179 181 /* execute inverse fourier transform */ 180 182 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);185 }183 uint_t i=0; 184 for (i=0; i < fft->channels; i++) { 185 aubio_fft_getspectrum(fft->spec[i],fftgrain->norm[i],fftgrain->phas[i],fft->winsize); 186 aubio_fft_rdo(fft->fft,fft->spec[i],out->data[i],fft->winsize); 187 } 186 188 } 187 189 188 190 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);191 uint_t i; 192 for (i=0; i < fft->channels; i++) 193 AUBIO_FREE(fft->spec[i]); 194 AUBIO_FREE(fft->spec); 195 del_aubio_fft(fft->fft); 196 AUBIO_FREE(fft); 195 197 } -
src/fft.h
rc721874 r1da7e08 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 -
src/phasevoc.c
rc721874 r1da7e08 26 26 /** phasevocoder internal object */ 27 27 struct _aubio_pvoc_t { 28 uint_t win_s; /** grain length */ 29 uint_t hop_s; /** overlap step */ 30 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; /** grain window [win_s] */ 28 /** grain length */ 29 uint_t win_s; 30 /** overlap step */ 31 uint_t hop_s; 32 /** number of channels */ 33 uint_t channels; 34 /** spectral data */ 35 aubio_mfft_t * fft; 36 /**cur output grain [win_s] */ 37 fvec_t * synth; 38 /**last input frame [win_s-hop_s] */ 39 fvec_t * synthold; 40 /**current input grain [win_s] */ 41 fvec_t * data; 42 /**last input frame [win_s-hop_s] */ 43 fvec_t * dataold; 44 /** grain window [win_s] */ 45 float * w; 37 46 }; 38 47 39 48 40 49 /** returns data and dataold slided by hop_s */ 41 static void aubio_pvoc_swapbuffers(smpl_t * data, smpl_t * dataold, const 42 smpl_t * datanew, uint_t win_s, uint_t hop_s); 50 static void aubio_pvoc_swapbuffers( 51 smpl_t * data, 52 smpl_t * dataold, 53 const smpl_t * datanew, 54 uint_t win_s, uint_t hop_s); 55 /** do additive synthesis from 'old' and 'cur' */ 56 static void aubio_pvoc_addsynth( 57 const smpl_t * synth, 58 smpl_t * synthold, 59 smpl_t * synthnew, 60 uint_t win_s, uint_t hop_s); 43 61 44 /** do additive synthesis from 'old' and 'cur' */45 static void aubio_pvoc_addsynth(const smpl_t * synth, smpl_t * synthold,46 smpl_t * synthnew, uint_t win_s, uint_t hop_s);47 62 48 63 void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t * datanew, cvec_t *fftgrain) { 49 50 51 52 53 54 55 56 }57 /* shift */58 vec_shift(pv->data);59 60 aubio_mfft_do (pv->fft,pv->data,fftgrain);64 uint_t i,j; 65 for (i=0; i<pv->channels; i++) { 66 /* slide */ 67 aubio_pvoc_swapbuffers(pv->data->data[i],pv->dataold->data[i], 68 datanew->data[i],pv->win_s,pv->hop_s); 69 /* windowing */ 70 for (j=0; j<pv->win_s; j++) pv->data->data[i][j] *= pv->w[j]; 71 } 72 /* shift */ 73 vec_shift(pv->data); 74 /* calculate fft */ 75 aubio_mfft_do (pv->fft,pv->data,fftgrain); 61 76 } 62 77 63 78 void aubio_pvoc_rdo(aubio_pvoc_t *pv,cvec_t * fftgrain, fvec_t * synthnew) { 64 uint_t i; 65 /* calculate rfft */ 66 aubio_mfft_rdo(pv->fft,fftgrain,pv->synth); 67 /* unshift */ 68 vec_shift(pv->synth); 69 for (i=0; i<pv->channels; i++) { 70 aubio_pvoc_addsynth(pv->synth->data[i],pv->synthold->data[i], 71 synthnew->data[i],pv->win_s,pv->hop_s); 72 } 79 uint_t i,j; 80 /* calculate rfft */ 81 aubio_mfft_rdo(pv->fft,fftgrain,pv->synth); 82 /* unshift */ 83 vec_shift(pv->synth); 84 for (i=0; i<pv->channels; i++) { 85 for (j=0; j<pv->win_s; j++) pv->synth->data[i][j] *= pv->w[j]; 86 aubio_pvoc_addsynth(pv->synth->data[i],pv->synthold->data[i], 87 synthnew->data[i],pv->win_s,pv->hop_s); 88 } 73 89 } 74 90 75 91 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s, uint_t channels) { 76 92 aubio_pvoc_t * pv = AUBIO_NEW(aubio_pvoc_t); 77 93 78 79 80 81 hop_s = win_s / 2;82 94 if (win_s < 2*hop_s) { 95 AUBIO_ERR("Hop size bigger than half the window size!\n"); 96 AUBIO_ERR("Resetting hop size to half the window size.\n"); 97 hop_s = win_s / 2; 98 } 83 99 84 if (hop_s < 1) { 85 AUBIO_ERR("Hop size is smaller than 1!\n"); 86 AUBIO_ERR("Resetting hop size to half the window size.\n"); 87 hop_s = win_s / 2; 88 } 100 if (hop_s < 1) { 101 AUBIO_ERR("Hop size is smaller than 1!\n"); 102 AUBIO_ERR("Resetting hop size to half the window size.\n"); 103 hop_s = win_s / 2; 104 } 105 106 pv->fft = new_aubio_mfft(win_s,channels); 89 107 90 pv->fft = new_aubio_mfft(win_s,channels); 108 /* remember old */ 109 pv->data = new_fvec (win_s, channels); 110 pv->synth = new_fvec (win_s, channels); 91 111 92 /* remember old */ 93 pv->data = new_fvec (win_s, channels); 94 pv->synth = new_fvec (win_s, channels); 112 /* new input output */ 113 pv->dataold = new_fvec (win_s-hop_s, channels); 114 pv->synthold = new_fvec (win_s-hop_s, channels); 115 pv->w = AUBIO_ARRAY(smpl_t,win_s); 116 aubio_window(pv->w,win_s,aubio_win_hanningz); 95 117 96 /* new input output */ 97 pv->dataold = new_fvec (win_s-hop_s, channels); 98 pv->synthold = new_fvec (win_s-hop_s, channels); 99 pv->w = AUBIO_ARRAY(smpl_t,win_s); 100 aubio_window(pv->w,win_s,aubio_win_hanningz); 118 pv->channels = channels; 119 pv->hop_s = hop_s; 120 pv->win_s = win_s; 101 121 102 pv->channels = channels; 103 pv->hop_s = hop_s; 104 pv->win_s = win_s; 105 106 return pv; 122 return pv; 107 123 } 108 124 109 125 void del_aubio_pvoc(aubio_pvoc_t *pv) { 110 111 112 113 114 115 116 126 del_fvec(pv->data); 127 del_fvec(pv->synth); 128 del_fvec(pv->dataold); 129 del_fvec(pv->synthold); 130 del_aubio_mfft(pv->fft); 131 AUBIO_FREE(pv->w); 132 AUBIO_FREE(pv); 117 133 } 118 134 119 135 static void aubio_pvoc_swapbuffers(smpl_t * data, smpl_t * dataold, 120 const smpl_t * datanew, uint_t win_s, uint_t hop_s)136 const smpl_t * datanew, uint_t win_s, uint_t hop_s) 121 137 { 122 123 124 125 126 127 128 138 uint_t i; 139 for (i=0;i<win_s-hop_s;i++) 140 data[i] = dataold[i]; 141 for (i=0;i<hop_s;i++) 142 data[win_s-hop_s+i] = datanew[i]; 143 for (i=0;i<win_s-hop_s;i++) 144 dataold[i] = data[i+hop_s]; 129 145 } 130 146 … … 132 148 smpl_t * synthnew, uint_t win_s, uint_t hop_s) 133 149 { 134 135 136 137 for (i=0;i<hop_s;i++) 138 139 140 for (i=0;i<win_s-2*hop_s;i++) 141 142 143 for (i=win_s-hop_s;i<win_s;i++) 144 145 146 for (i=0;i<win_s-hop_s;i++) 147 150 uint_t i; 151 smpl_t scale = 2*hop_s/(win_s+.0); 152 /* add new synth to old one and put result in synthnew */ 153 for (i=0;i<hop_s;i++) 154 synthnew[i] = synthold[i]+synth[i]*scale; 155 /* shift synthold */ 156 for (i=0;i<win_s-2*hop_s;i++) 157 synthold[i] = synthold[i+hop_s]; 158 /* erase last frame in synthold */ 159 for (i=win_s-hop_s;i<win_s;i++) 160 synthold[i-hop_s]=0.; 161 /* additive synth */ 162 for (i=0;i<win_s-hop_s;i++) 163 synthold[i] += synth[i+hop_s]*scale; 148 164 } 149 165 -
src/types.h
rc721874 r1da7e08 40 40 41 41 /** short sample format (32 or 64 bits) */ 42 //typedef float smpl_t;43 typedef double smpl_t;42 typedef float smpl_t; 43 //typedef double smpl_t; 44 44 /** long sample format (64 bits or more) */ 45 45 typedef double lsmp_t; -
tests/python/fvec.py
rc721874 r1da7e08 22 22 for index in range(buf_size): 23 23 for channel in range(channels): 24 self.assertEqual( 0., fvec_read_sample(self.vector,channel,index))24 self.assertEqual(fvec_read_sample(self.vector,channel,index),0.) 25 25 26 26 def test_fvec_write_sample(self): … … 31 31 for index in range(buf_size): 32 32 for channel in range(channels): 33 self.assertEqual( 1., fvec_read_sample(self.vector,channel,index))33 self.assertEqual(fvec_read_sample(self.vector,channel,index),1.) 34 34 35 35 if __name__ == '__main__': -
tests/src/Makefile.am
rc721874 r1da7e08 10 10 test-hist \ 11 11 test-scale \ 12 test-cvec \ 13 test-fvec \ 12 test-sample \ 14 13 test-window \ 15 14 test-filter \
Note: See TracChangeset
for help on using the changeset viewer.