Changeset d95ff38
- Timestamp:
- Dec 4, 2009, 1:38:30 AM (15 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:
- 741bdda
- Parents:
- 0b9a02a
- Location:
- src/spectral
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
src/spectral/fft.c
r0b9a02a rd95ff38 75 75 struct _aubio_fft_t { 76 76 uint_t winsize; 77 uint_t channels;78 77 uint_t fft_size; 79 78 real_t *in, *out; … … 83 82 }; 84 83 85 aubio_fft_t * new_aubio_fft(uint_t winsize , uint_t channels) {84 aubio_fft_t * new_aubio_fft(uint_t winsize) { 86 85 aubio_fft_t * s = AUBIO_NEW(aubio_fft_t); 87 86 uint_t i; 88 87 s->winsize = winsize; 89 s->channels = channels;90 88 /* allocate memory */ 91 89 s->in = AUBIO_ARRAY(real_t,winsize); 92 90 s->out = AUBIO_ARRAY(real_t,winsize); 93 s->compspec = new_fvec(winsize ,channels);91 s->compspec = new_fvec(winsize); 94 92 /* create plans */ 95 93 #ifdef HAVE_COMPLEX_H … … 136 134 137 135 void aubio_fft_do_complex(aubio_fft_t * s, fvec_t * input, fvec_t * compspec) { 138 uint_t i, j; 139 for (i = 0; i < s->channels; i++) { 140 for (j=0; j < s->winsize; j++) { 141 s->in[j] = input->data[i][j]; 142 } 143 fftw_execute(s->pfw); 144 #ifdef HAVE_COMPLEX_H 145 compspec->data[i][0] = REAL(s->specdata[0]); 146 for (j = 1; j < s->fft_size -1 ; j++) { 147 compspec->data[i][j] = REAL(s->specdata[j]); 148 compspec->data[i][compspec->length - j] = IMAG(s->specdata[j]); 149 } 150 compspec->data[i][s->fft_size-1] = REAL(s->specdata[s->fft_size-1]); 151 #else 152 for (j = 0; j < s->fft_size; j++) { 153 compspec->data[i][j] = s->specdata[j]; 154 } 155 #endif 156 } 136 uint_t j; 137 for (j=0; j < s->winsize; j++) { 138 s->in[j] = input->data[j]; 139 } 140 fftw_execute(s->pfw); 141 #ifdef HAVE_COMPLEX_H 142 compspec->data[0] = REAL(s->specdata[0]); 143 for (j = 1; j < s->fft_size -1 ; j++) { 144 compspec->data[j] = REAL(s->specdata[j]); 145 compspec->data[compspec->length - j] = IMAG(s->specdata[j]); 146 } 147 compspec->data[s->fft_size-1] = REAL(s->specdata[s->fft_size-1]); 148 #else 149 for (j = 0; j < s->fft_size; j++) { 150 compspec->data[j] = s->specdata[j]; 151 } 152 #endif 157 153 } 158 154 159 155 void aubio_fft_rdo_complex(aubio_fft_t * s, fvec_t * compspec, fvec_t * output) { 160 uint_t i,j;156 uint_t j; 161 157 const smpl_t renorm = 1./(smpl_t)s->winsize; 162 for (i = 0; i < compspec->channels; i++) { 163 #ifdef HAVE_COMPLEX_H 164 s->specdata[0] = compspec->data[i][0]; 165 for (j=1; j < s->fft_size - 1; j++) { 166 s->specdata[j] = compspec->data[i][j] + 167 I * compspec->data[i][compspec->length - j]; 168 } 169 s->specdata[s->fft_size - 1] = compspec->data[i][s->fft_size - 1]; 170 #else 171 for (j=0; j < s->fft_size; j++) { 172 s->specdata[j] = compspec->data[i][j]; 173 } 174 #endif 175 fftw_execute(s->pbw); 176 for (j = 0; j < output->length; j++) { 177 output->data[i][j] = s->out[j]*renorm; 178 } 158 #ifdef HAVE_COMPLEX_H 159 s->specdata[0] = compspec->data[0]; 160 for (j=1; j < s->fft_size - 1; j++) { 161 s->specdata[j] = compspec->data[j] + 162 I * compspec->data[compspec->length - j]; 163 } 164 s->specdata[s->fft_size - 1] = compspec->data[s->fft_size - 1]; 165 #else 166 for (j=0; j < s->fft_size; j++) { 167 s->specdata[j] = compspec->data[j]; 168 } 169 #endif 170 fftw_execute(s->pbw); 171 for (j = 0; j < output->length; j++) { 172 output->data[j] = s->out[j]*renorm; 179 173 } 180 174 } … … 191 185 192 186 void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum) { 193 uint_t i, j; 194 for (i = 0; i < spectrum->channels; i++) { 195 if (compspec->data[i][0] < 0) { 196 spectrum->phas[i][0] = PI; 197 } else { 198 spectrum->phas[i][0] = 0.; 199 } 200 for (j=1; j < spectrum->length - 1; j++) { 201 spectrum->phas[i][j] = ATAN2(compspec->data[i][compspec->length-j], 202 compspec->data[i][j]); 203 } 204 if (compspec->data[i][compspec->length/2] < 0) { 205 spectrum->phas[i][spectrum->length - 1] = PI; 206 } else { 207 spectrum->phas[i][spectrum->length - 1] = 0.; 208 } 187 uint_t j; 188 if (compspec->data[0] < 0) { 189 spectrum->phas[0] = PI; 190 } else { 191 spectrum->phas[0] = 0.; 192 } 193 for (j=1; j < spectrum->length - 1; j++) { 194 spectrum->phas[j] = ATAN2(compspec->data[compspec->length-j], 195 compspec->data[j]); 196 } 197 if (compspec->data[compspec->length/2] < 0) { 198 spectrum->phas[spectrum->length - 1] = PI; 199 } else { 200 spectrum->phas[spectrum->length - 1] = 0.; 209 201 } 210 202 } 211 203 212 204 void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum) { 213 uint_t i, j = 0; 214 for (i = 0; i < spectrum->channels; i++) { 215 spectrum->norm[i][0] = ABS(compspec->data[i][0]); 216 for (j=1; j < spectrum->length - 1; j++) { 217 spectrum->norm[i][j] = SQRT(SQR(compspec->data[i][j]) 218 + SQR(compspec->data[i][compspec->length - j]) ); 219 } 220 spectrum->norm[i][spectrum->length-1] = 221 ABS(compspec->data[i][compspec->length/2]); 222 } 205 uint_t j = 0; 206 spectrum->norm[0] = ABS(compspec->data[0]); 207 for (j=1; j < spectrum->length - 1; j++) { 208 spectrum->norm[j] = SQRT(SQR(compspec->data[j]) 209 + SQR(compspec->data[compspec->length - j]) ); 210 } 211 spectrum->norm[spectrum->length-1] = 212 ABS(compspec->data[compspec->length/2]); 223 213 } 224 214 225 215 void aubio_fft_get_imag(cvec_t * spectrum, fvec_t * compspec) { 226 uint_t i, j; 227 for (i = 0; i < compspec->channels; i++) { 228 for (j = 1; j < ( compspec->length + 1 ) / 2 /*- 1 + 1*/; j++) { 229 compspec->data[i][compspec->length - j] = 230 spectrum->norm[i][j]*SIN(spectrum->phas[i][j]); 231 } 216 uint_t j; 217 for (j = 1; j < ( compspec->length + 1 ) / 2 /*- 1 + 1*/; j++) { 218 compspec->data[compspec->length - j] = 219 spectrum->norm[j]*SIN(spectrum->phas[j]); 232 220 } 233 221 } 234 222 235 223 void aubio_fft_get_real(cvec_t * spectrum, fvec_t * compspec) { 236 uint_t i, j; 237 for (i = 0; i < compspec->channels; i++) { 238 for (j = 0; j < compspec->length / 2 + 1; j++) { 239 compspec->data[i][j] = 240 spectrum->norm[i][j]*COS(spectrum->phas[i][j]); 241 } 242 } 243 } 224 uint_t j; 225 for (j = 0; j < compspec->length / 2 + 1; j++) { 226 compspec->data[j] = 227 spectrum->norm[j]*COS(spectrum->phas[j]); 228 } 229 } -
src/spectral/fft.h
r0b9a02a rd95ff38 45 45 46 46 \param size length of the FFT 47 \param channels number of channels48 47 49 48 */ 50 aubio_fft_t * new_aubio_fft (uint_t size, uint_t channels);49 aubio_fft_t * new_aubio_fft (uint_t size); 51 50 /** delete FFT object 52 51 -
src/spectral/filterbank.c
r0b9a02a rd95ff38 22 22 #include "aubio_priv.h" 23 23 #include "fvec.h" 24 #include "fmat.h" 24 25 #include "cvec.h" 25 26 #include "spectral/filterbank.h" … … 31 32 uint_t win_s; 32 33 uint_t n_filters; 33 f vec_t *filters;34 fmat_t *filters; 34 35 }; 35 36 … … 42 43 fb->n_filters = n_filters; 43 44 44 /* allocate filter tables, a n fvec of length win_s and of filter_cnt channel*/45 fb->filters = new_f vec(win_s / 2 + 1, n_filters);45 /* allocate filter tables, a matrix of length win_s and of height n_filters */ 46 fb->filters = new_fmat (win_s / 2 + 1, n_filters); 46 47 47 48 return fb; … … 51 52 del_aubio_filterbank (aubio_filterbank_t * fb) 52 53 { 53 del_f vec(fb->filters);54 del_fmat (fb->filters); 54 55 AUBIO_FREE (fb); 55 56 } … … 58 59 aubio_filterbank_do (aubio_filterbank_t * f, cvec_t * in, fvec_t * out) 59 60 { 60 uint_t i,j, fn;61 uint_t j, fn; 61 62 62 63 /* apply filter to all input channel, provided out has enough channels */ 63 uint_t max_channels = MIN (in->channels, out->channels);64 64 uint_t max_filters = MIN (f->n_filters, out->length); 65 65 uint_t max_length = MIN (in->length, f->filters->length); … … 68 68 fvec_zeros (out); 69 69 70 /* apply filters on all channels*/71 for ( i = 0; i < max_channels; i++) {70 /* for each filter */ 71 for (fn = 0; fn < max_filters; fn++) { 72 72 73 /* for each filter */ 74 for (fn = 0; fn < max_filters; fn++) { 75 76 /* for each sample */ 77 for (j = 0; j < max_length; j++) { 78 out->data[i][fn] += in->norm[i][j] * f->filters->data[fn][j]; 79 } 73 /* for each sample */ 74 for (j = 0; j < max_length; j++) { 75 out->data[fn] += in->norm[j] * f->filters->data[fn][j]; 80 76 } 81 77 } … … 84 80 } 85 81 86 f vec_t *82 fmat_t * 87 83 aubio_filterbank_get_coeffs (aubio_filterbank_t * f) 88 84 { … … 91 87 92 88 uint_t 93 aubio_filterbank_set_coeffs (aubio_filterbank_t * f, f vec_t * filters)89 aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fmat_t * filter_coeffs) 94 90 { 95 f vec_copy(filters, f->filters);91 fmat_copy(filter_coeffs, f->filters); 96 92 return 0; 97 93 } -
src/spectral/filterbank.h
r0b9a02a rd95ff38 63 63 void aubio_filterbank_do (aubio_filterbank_t * fb, cvec_t * in, fvec_t * out); 64 64 65 /** return a pointer to the fvecobject containing all filter coefficients65 /** return a pointer to the matrix object containing all filter coefficients 66 66 67 67 \param f filterbank object to get coefficients from 68 68 69 69 */ 70 f vec_t *aubio_filterbank_get_coeffs (aubio_filterbank_t * f);70 fmat_t *aubio_filterbank_get_coeffs (aubio_filterbank_t * f); 71 71 72 72 /** copy filter coefficients to the filterbank … … 76 76 77 77 */ 78 uint_t aubio_filterbank_set_coeffs (aubio_filterbank_t * f, f vec_t * filters);78 uint_t aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fmat_t * filters); 79 79 80 80 #ifdef __cplusplus -
src/spectral/filterbank_mel.c
r0b9a02a rd95ff38 21 21 22 22 #include "aubio_priv.h" 23 #include "fmat.h" 23 24 #include "fvec.h" 24 25 #include "cvec.h" … … 31 32 { 32 33 33 f vec_t *filters = aubio_filterbank_get_coeffs (fb);34 uint_t n_filters = filters-> channels, win_s = filters->length;34 fmat_t *filters = aubio_filterbank_get_coeffs (fb); 35 uint_t n_filters = filters->height, win_s = filters->length; 35 36 36 37 uint_t fn; /* filter counter */ … … 49 50 } 50 51 51 if (freqs->data[ 0][freqs->length - 1] > samplerate / 2) {52 if (freqs->data[freqs->length - 1] > samplerate / 2) { 52 53 AUBIO_WRN ("Nyquist frequency is %fHz, but highest frequency band ends at \ 53 %fHz\n", samplerate / 2, freqs->data[ 0][freqs->length - 1]);54 %fHz\n", samplerate / 2, freqs->data[freqs->length - 1]); 54 55 } 55 56 56 57 /* convenience reference to lower/center/upper frequency for each triangle */ 57 fvec_t *lower_freqs = new_fvec (n_filters , 1);58 fvec_t *upper_freqs = new_fvec (n_filters , 1);59 fvec_t *center_freqs = new_fvec (n_filters , 1);58 fvec_t *lower_freqs = new_fvec (n_filters); 59 fvec_t *upper_freqs = new_fvec (n_filters); 60 fvec_t *center_freqs = new_fvec (n_filters); 60 61 61 62 /* height of each triangle */ 62 fvec_t *triangle_heights = new_fvec (n_filters , 1);63 fvec_t *triangle_heights = new_fvec (n_filters); 63 64 64 65 /* lookup table of each bin frequency in hz */ 65 fvec_t *fft_freqs = new_fvec (win_s , 1);66 fvec_t *fft_freqs = new_fvec (win_s); 66 67 67 68 /* fill up the lower/center/upper */ 68 69 for (fn = 0; fn < n_filters; fn++) { 69 lower_freqs->data[ 0][fn] = freqs->data[0][fn];70 center_freqs->data[ 0][fn] = freqs->data[0][fn + 1];71 upper_freqs->data[ 0][fn] = freqs->data[0][fn + 2];70 lower_freqs->data[fn] = freqs->data[fn]; 71 center_freqs->data[fn] = freqs->data[fn + 1]; 72 upper_freqs->data[fn] = freqs->data[fn + 2]; 72 73 } 73 74 74 75 /* compute triangle heights so that each triangle has unit area */ 75 76 for (fn = 0; fn < n_filters; fn++) { 76 triangle_heights->data[ 0][fn] =77 2. / (upper_freqs->data[ 0][fn] - lower_freqs->data[0][fn]);77 triangle_heights->data[fn] = 78 2. / (upper_freqs->data[fn] - lower_freqs->data[fn]); 78 79 } 79 80 80 81 /* fill fft_freqs lookup table, which assigns the frequency in hz to each bin */ 81 82 for (bin = 0; bin < win_s; bin++) { 82 fft_freqs->data[ 0][bin] =83 fft_freqs->data[bin] = 83 84 aubio_bintofreq (bin, samplerate, (win_s - 1) * 2); 84 85 } 85 86 86 87 /* zeroing of all filters */ 87 f vec_zeros (filters);88 89 if (fft_freqs->data[ 0][1] >= lower_freqs->data[0][0]) {88 fmat_zeros (filters); 89 90 if (fft_freqs->data[1] >= lower_freqs->data[0]) { 90 91 /* - 1 to make sure we don't miss the smallest power of two */ 91 92 uint_t min_win_s = 92 (uint_t) FLOOR (samplerate / lower_freqs->data[0] [0]) - 1;93 (uint_t) FLOOR (samplerate / lower_freqs->data[0]) - 1; 93 94 AUBIO_WRN ("Lowest frequency bin (%.2fHz) is higher than lowest frequency \ 94 95 band (%.2f-%.2fHz). Consider increasing the window size from %d to %d.\n", 95 fft_freqs->data[ 0][1], lower_freqs->data[0][0],96 upper_freqs->data[0] [0], (win_s - 1) * 2,96 fft_freqs->data[1], lower_freqs->data[0], 97 upper_freqs->data[0], (win_s - 1) * 2, 97 98 aubio_next_power_of_two (min_win_s)); 98 99 } … … 103 104 /* skip first elements */ 104 105 for (bin = 0; bin < win_s - 1; bin++) { 105 if (fft_freqs->data[ 0][bin] <= lower_freqs->data[0][fn] &&106 fft_freqs->data[ 0][bin + 1] > lower_freqs->data[0][fn]) {106 if (fft_freqs->data[bin] <= lower_freqs->data[fn] && 107 fft_freqs->data[bin + 1] > lower_freqs->data[fn]) { 107 108 bin++; 108 109 break; … … 112 113 /* compute positive slope step size */ 113 114 smpl_t riseInc = 114 triangle_heights->data[ 0][fn] /115 (center_freqs->data[ 0][fn] - lower_freqs->data[0][fn]);115 triangle_heights->data[fn] / 116 (center_freqs->data[fn] - lower_freqs->data[fn]); 116 117 117 118 /* compute coefficients in positive slope */ 118 119 for (; bin < win_s - 1; bin++) { 119 120 filters->data[fn][bin] = 120 (fft_freqs->data[ 0][bin] - lower_freqs->data[0][fn]) * riseInc;121 122 if (fft_freqs->data[ 0][bin + 1] >= center_freqs->data[0][fn]) {121 (fft_freqs->data[bin] - lower_freqs->data[fn]) * riseInc; 122 123 if (fft_freqs->data[bin + 1] >= center_freqs->data[fn]) { 123 124 bin++; 124 125 break; … … 128 129 /* compute negative slope step size */ 129 130 smpl_t downInc = 130 triangle_heights->data[ 0][fn] /131 (upper_freqs->data[ 0][fn] - center_freqs->data[0][fn]);131 triangle_heights->data[fn] / 132 (upper_freqs->data[fn] - center_freqs->data[fn]); 132 133 133 134 /* compute coefficents in negative slope */ 134 135 for (; bin < win_s - 1; bin++) { 135 136 filters->data[fn][bin] += 136 (upper_freqs->data[ 0][fn] - fft_freqs->data[0][bin]) * downInc;137 (upper_freqs->data[fn] - fft_freqs->data[bin]) * downInc; 137 138 138 139 if (filters->data[fn][bin] < 0.) { … … 140 141 } 141 142 142 if (fft_freqs->data[ 0][bin + 1] >= upper_freqs->data[0][fn])143 if (fft_freqs->data[bin + 1] >= upper_freqs->data[fn]) 143 144 break; 144 145 } … … 176 177 177 178 /* buffers to compute filter frequencies */ 178 fvec_t *freqs = new_fvec (n_filters + 2 , 1);179 fvec_t *freqs = new_fvec (n_filters + 2); 179 180 180 181 /* first step: fill all the linear filter frequencies */ 181 182 for (fn = 0; fn < linearFilters; fn++) { 182 freqs->data[ 0][fn] = lowestFrequency + fn * linearSpacing;183 } 184 smpl_t lastlinearCF = freqs->data[ 0][fn - 1];183 freqs->data[fn] = lowestFrequency + fn * linearSpacing; 184 } 185 smpl_t lastlinearCF = freqs->data[fn - 1]; 185 186 186 187 /* second step: fill all the log filter frequencies */ 187 188 for (fn = 0; fn < logFilters + 2; fn++) { 188 freqs->data[ 0][fn + linearFilters] =189 freqs->data[fn + linearFilters] = 189 190 lastlinearCF * (POW (logSpacing, fn + 1)); 190 191 } -
src/spectral/mfcc.c
r0b9a02a rd95ff38 22 22 #include "aubio_priv.h" 23 23 #include "fvec.h" 24 #include "fmat.h" 24 25 #include "cvec.h" 25 26 #include "mathutils.h" … … 40 41 aubio_filterbank_t *fb; /** filter bank */ 41 42 fvec_t *in_dct; /** input buffer for dct * [fb->n_filters] */ 42 f vec_t *dct_coeffs; /** DCT transform n_filters * n_coeffs */43 fmat_t *dct_coeffs; /** DCT transform n_filters * n_coeffs */ 43 44 }; 44 45 … … 64 65 65 66 /* allocating buffers */ 66 mfcc->in_dct = new_fvec (n_filters , 1);67 mfcc->in_dct = new_fvec (n_filters); 67 68 68 mfcc->dct_coeffs = new_f vec(n_coefs, n_filters);69 mfcc->dct_coeffs = new_fmat (n_coefs, n_filters); 69 70 70 71 /* compute DCT transform dct_coeffs[i][j] as … … 100 101 aubio_mfcc_do (aubio_mfcc_t * mf, cvec_t * in, fvec_t * out) 101 102 { 102 uint_t i,j, k;103 uint_t j, k; 103 104 104 105 /* compute filterbank */ … … 115 116 116 117 /* compute discrete cosine transform */ 117 for (i = 0; i < out->channels; i++) { 118 for (j = 0; j < mf->n_filters; j++) { 119 for (k = 0; k < mf->n_coefs; k++) { 120 out->data[i][k] += mf->in_dct->data[i][j] 121 * mf->dct_coeffs->data[j][k]; 122 } 118 for (j = 0; j < mf->n_filters; j++) { 119 for (k = 0; k < mf->n_coefs; k++) { 120 out->data[k] += mf->in_dct->data[j] 121 * mf->dct_coeffs->data[j][k]; 123 122 } 124 123 } -
src/spectral/phasevoc.c
r0b9a02a rd95ff38 30 30 uint_t win_s; /** grain length */ 31 31 uint_t hop_s; /** overlap step */ 32 uint_t channels; /** number of channels */33 32 aubio_fft_t * fft; /** fft object */ 34 33 fvec_t * synth; /** cur output grain [win_s] */ … … 49 48 50 49 void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t * datanew, cvec_t *fftgrain) { 51 uint_t i; 52 for (i=0; i<pv->channels; i++) { 53 /* slide */ 54 aubio_pvoc_swapbuffers(pv->data->data[i],pv->dataold->data[i], 55 datanew->data[i],pv->win_s,pv->hop_s); 56 } 50 /* slide */ 51 aubio_pvoc_swapbuffers(pv->data->data,pv->dataold->data, 52 datanew->data,pv->win_s,pv->hop_s); 57 53 /* windowing */ 58 54 fvec_weight(pv->data, pv->w); … … 64 60 65 61 void aubio_pvoc_rdo(aubio_pvoc_t *pv,cvec_t * fftgrain, fvec_t * synthnew) { 66 uint_t i;67 62 /* calculate rfft */ 68 63 aubio_fft_rdo(pv->fft,fftgrain,pv->synth); 69 64 /* unshift */ 70 65 fvec_shift(pv->synth); 71 for (i=0; i<pv->channels; i++) { 72 aubio_pvoc_addsynth(pv->synth->data[i],pv->synthold->data[i], 73 synthnew->data[i],pv->win_s,pv->hop_s); 74 } 66 aubio_pvoc_addsynth(pv->synth->data,pv->synthold->data, 67 synthnew->data,pv->win_s,pv->hop_s); 75 68 } 76 69 77 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s , uint_t channels) {70 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s) { 78 71 aubio_pvoc_t * pv = AUBIO_NEW(aubio_pvoc_t); 79 72 … … 88 81 } 89 82 90 pv->fft = new_aubio_fft (win_s,channels);83 pv->fft = new_aubio_fft (win_s); 91 84 92 85 /* remember old */ 93 pv->data = new_fvec (win_s , channels);94 pv->synth = new_fvec (win_s , channels);86 pv->data = new_fvec (win_s); 87 pv->synth = new_fvec (win_s); 95 88 96 89 /* new input output */ 97 pv->dataold = new_fvec (win_s-hop_s , channels);98 pv->synthold = new_fvec (win_s-hop_s , channels);90 pv->dataold = new_fvec (win_s-hop_s); 91 pv->synthold = new_fvec (win_s-hop_s); 99 92 pv->w = new_aubio_window ("hanningz", win_s); 100 93 101 pv->channels = channels;102 94 pv->hop_s = hop_s; 103 95 pv->win_s = win_s; -
src/spectral/phasevoc.h
r0b9a02a rd95ff38 26 26 using a HanningZ window and a swapped version of the signal to simplify the 27 27 phase relationships across frames. The window sizes and overlap are specified 28 at creation time. Multiple channels are fully supported.28 at creation time. 29 29 30 30 */ … … 44 44 \param win_s size of analysis buffer (and length the FFT transform) 45 45 \param hop_s step size between two consecutive analysis 46 \param channels number of channels47 46 48 47 */ 49 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s , uint_t channels);48 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s); 50 49 /** delete phase vocoder object 51 50 … … 57 56 /** compute spectral frame 58 57 59 This function accepts an input vector of size [ channels]x[hop_s]. The58 This function accepts an input vector of size [hop_s]. The 60 59 analysis buffer is rotated and filled with the new data. After windowing of 61 60 this signal window, the Fourier transform is computed and returned in … … 71 70 72 71 This function takes an input spectral frame fftgrain of size 73 [ channels]x[buf_s] and computes its inverse Fourier transform. Overlap-add72 [buf_s] and computes its inverse Fourier transform. Overlap-add 74 73 synthesis is then computed using the previously synthetised frames, and the 75 74 output stored in out. … … 94 93 */ 95 94 uint_t aubio_pvoc_get_hop(aubio_pvoc_t* pv); 96 /** get channel number97 98 \param pv phase vocoder to get the number of channels from99 100 */101 uint_t aubio_pvoc_get_channels(aubio_pvoc_t* pv);102 95 103 96 #ifdef __cplusplus -
src/spectral/specdesc.c
r0b9a02a rd95ff38 89 89 void aubio_specdesc_energy (aubio_specdesc_t *o UNUSED, 90 90 cvec_t * fftgrain, fvec_t * onset) { 91 uint_t i,j; 92 for (i=0;i<fftgrain->channels;i++) { 93 onset->data[i][0] = 0.; 94 for (j=0;j<fftgrain->length;j++) { 95 onset->data[i][0] += SQR(fftgrain->norm[i][j]); 96 } 91 uint_t j; 92 onset->data[0] = 0.; 93 for (j=0;j<fftgrain->length;j++) { 94 onset->data[0] += SQR(fftgrain->norm[j]); 97 95 } 98 96 } … … 101 99 void aubio_specdesc_hfc(aubio_specdesc_t *o UNUSED, 102 100 cvec_t * fftgrain, fvec_t * onset){ 103 uint_t i,j; 104 for (i=0;i<fftgrain->channels;i++) { 105 onset->data[i][0] = 0.; 106 for (j=0;j<fftgrain->length;j++) { 107 onset->data[i][0] += (j+1)*fftgrain->norm[i][j]; 108 } 101 uint_t j; 102 onset->data[0] = 0.; 103 for (j=0;j<fftgrain->length;j++) { 104 onset->data[0] += (j+1)*fftgrain->norm[j]; 109 105 } 110 106 } … … 113 109 /* Complex Domain Method onset detection function */ 114 110 void aubio_specdesc_complex (aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset) { 115 uint_t i,j;111 uint_t j; 116 112 uint_t nbins = fftgrain->length; 117 for (i=0;i<fftgrain->channels; i++) { 118 onset->data[i][0] = 0.; 119 for (j=0;j<nbins; j++) { 120 // compute the predicted phase 121 o->dev1->data[i][j] = 2. * o->theta1->data[i][j] - o->theta2->data[i][j]; 122 // compute the euclidean distance in the complex domain 123 // sqrt ( r_1^2 + r_2^2 - 2 * r_1 * r_2 * \cos ( \phi_1 - \phi_2 ) ) 124 onset->data[i][0] += 125 SQRT (ABS (SQR (o->oldmag->data[i][j]) + SQR (fftgrain->norm[i][j]) 126 - 2. * o->oldmag->data[i][j] * fftgrain->norm[i][j] 127 * COS (o->dev1->data[i][j] - fftgrain->phas[i][j]))); 128 /* swap old phase data (need to remember 2 frames behind)*/ 129 o->theta2->data[i][j] = o->theta1->data[i][j]; 130 o->theta1->data[i][j] = fftgrain->phas[i][j]; 131 /* swap old magnitude data (1 frame is enough) */ 132 o->oldmag->data[i][j] = fftgrain->norm[i][j]; 133 } 113 onset->data[0] = 0.; 114 for (j=0;j<nbins; j++) { 115 // compute the predicted phase 116 o->dev1->data[j] = 2. * o->theta1->data[j] - o->theta2->data[j]; 117 // compute the euclidean distance in the complex domain 118 // sqrt ( r_1^2 + r_2^2 - 2 * r_1 * r_2 * \cos ( \phi_1 - \phi_2 ) ) 119 onset->data[0] += 120 SQRT (ABS (SQR (o->oldmag->data[j]) + SQR (fftgrain->norm[j]) 121 - 2. * o->oldmag->data[j] * fftgrain->norm[j] 122 * COS (o->dev1->data[j] - fftgrain->phas[j]))); 123 /* swap old phase data (need to remember 2 frames behind)*/ 124 o->theta2->data[j] = o->theta1->data[j]; 125 o->theta1->data[j] = fftgrain->phas[j]; 126 /* swap old magnitude data (1 frame is enough) */ 127 o->oldmag->data[j] = fftgrain->norm[j]; 134 128 } 135 129 } … … 139 133 void aubio_specdesc_phase(aubio_specdesc_t *o, 140 134 cvec_t * fftgrain, fvec_t * onset){ 141 uint_t i,j;135 uint_t j; 142 136 uint_t nbins = fftgrain->length; 143 for (i=0;i<fftgrain->channels; i++) { 144 onset->data[i][0] = 0.0; 145 o->dev1->data[i][0]=0.; 146 for ( j=0;j<nbins; j++ ) { 147 o->dev1->data[i][j] = 148 aubio_unwrap2pi( 149 fftgrain->phas[i][j] 150 -2.0*o->theta1->data[i][j] 151 +o->theta2->data[i][j]); 152 if ( o->threshold < fftgrain->norm[i][j] ) 153 o->dev1->data[i][j] = ABS(o->dev1->data[i][j]); 154 else 155 o->dev1->data[i][j] = 0.0; 156 /* keep a track of the past frames */ 157 o->theta2->data[i][j] = o->theta1->data[i][j]; 158 o->theta1->data[i][j] = fftgrain->phas[i][j]; 159 } 160 /* apply o->histogram */ 161 aubio_hist_dyn_notnull(o->histog,o->dev1); 162 /* weight it */ 163 aubio_hist_weight(o->histog); 164 /* its mean is the result */ 165 onset->data[i][0] = aubio_hist_mean(o->histog); 166 //onset->data[i][0] = fvec_mean(o->dev1); 167 } 137 onset->data[0] = 0.0; 138 o->dev1->data[0]=0.; 139 for ( j=0;j<nbins; j++ ) { 140 o->dev1->data[j] = 141 aubio_unwrap2pi( 142 fftgrain->phas[j] 143 -2.0*o->theta1->data[j] 144 +o->theta2->data[j]); 145 if ( o->threshold < fftgrain->norm[j] ) 146 o->dev1->data[j] = ABS(o->dev1->data[j]); 147 else 148 o->dev1->data[j] = 0.0; 149 /* keep a track of the past frames */ 150 o->theta2->data[j] = o->theta1->data[j]; 151 o->theta1->data[j] = fftgrain->phas[j]; 152 } 153 /* apply o->histogram */ 154 aubio_hist_dyn_notnull(o->histog,o->dev1); 155 /* weight it */ 156 aubio_hist_weight(o->histog); 157 /* its mean is the result */ 158 onset->data[0] = aubio_hist_mean(o->histog); 159 //onset->data[0] = fvec_mean(o->dev1); 168 160 } 169 161 … … 171 163 void aubio_specdesc_specdiff(aubio_specdesc_t *o, 172 164 cvec_t * fftgrain, fvec_t * onset){ 173 uint_t i,j;165 uint_t j; 174 166 uint_t nbins = fftgrain->length; 175 for (i=0;i<fftgrain->channels; i++) { 176 onset->data[i][0] = 0.0; 167 onset->data[0] = 0.0; 177 168 for (j=0;j<nbins; j++) { 178 o->dev1->data[ i][j] = SQRT(179 ABS(SQR( fftgrain->norm[ i][j])180 - SQR(o->oldmag->data[ i][j])));181 if (o->threshold < fftgrain->norm[ i][j] )182 o->dev1->data[ i][j] = ABS(o->dev1->data[i][j]);169 o->dev1->data[j] = SQRT( 170 ABS(SQR( fftgrain->norm[j]) 171 - SQR(o->oldmag->data[j]))); 172 if (o->threshold < fftgrain->norm[j] ) 173 o->dev1->data[j] = ABS(o->dev1->data[j]); 183 174 else 184 o->dev1->data[ i][j] = 0.0;185 o->oldmag->data[ i][j] = fftgrain->norm[i][j];175 o->dev1->data[j] = 0.0; 176 o->oldmag->data[j] = fftgrain->norm[j]; 186 177 } 187 178 … … 192 183 aubio_hist_weight(o->histog); 193 184 /* its mean is the result */ 194 onset->data[i][0] = aubio_hist_mean(o->histog); 195 196 } 185 onset->data[0] = aubio_hist_mean(o->histog); 197 186 } 198 187 … … 201 190 * negative (1.+) and infinite values (+1.e-10) */ 202 191 void aubio_specdesc_kl(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){ 203 uint_t i,j; 204 for (i=0;i<fftgrain->channels;i++) { 205 onset->data[i][0] = 0.; 192 uint_t j; 193 onset->data[0] = 0.; 206 194 for (j=0;j<fftgrain->length;j++) { 207 onset->data[ i][0] += fftgrain->norm[i][j]208 *LOG(1.+fftgrain->norm[ i][j]/(o->oldmag->data[i][j]+1.e-10));209 o->oldmag->data[ i][j] = fftgrain->norm[i][j];195 onset->data[0] += fftgrain->norm[j] 196 *LOG(1.+fftgrain->norm[j]/(o->oldmag->data[j]+1.e-10)); 197 o->oldmag->data[j] = fftgrain->norm[j]; 210 198 } 211 if (isnan(onset->data[i][0])) onset->data[i][0] = 0.; 212 } 199 if (isnan(onset->data[0])) onset->data[0] = 0.; 213 200 } 214 201 … … 217 204 * negative (1.+) and infinite values (+1.e-10) */ 218 205 void aubio_specdesc_mkl(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){ 219 uint_t i,j; 220 for (i=0;i<fftgrain->channels;i++) { 221 onset->data[i][0] = 0.; 206 uint_t j; 207 onset->data[0] = 0.; 222 208 for (j=0;j<fftgrain->length;j++) { 223 onset->data[ i][0] += LOG(1.+fftgrain->norm[i][j]/(o->oldmag->data[i][j]+1.e-10));224 o->oldmag->data[ i][j] = fftgrain->norm[i][j];209 onset->data[0] += LOG(1.+fftgrain->norm[j]/(o->oldmag->data[j]+1.e-10)); 210 o->oldmag->data[j] = fftgrain->norm[j]; 225 211 } 226 if (isnan(onset->data[i][0])) onset->data[i][0] = 0.; 227 } 212 if (isnan(onset->data[0])) onset->data[0] = 0.; 228 213 } 229 214 230 215 /* Spectral flux */ 231 216 void aubio_specdesc_specflux(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){ 232 uint_t i, j; 233 for (i=0;i<fftgrain->channels;i++) { 234 onset->data[i][0] = 0.; 235 for (j=0;j<fftgrain->length;j++) { 236 if (fftgrain->norm[i][j] > o->oldmag->data[i][j]) 237 onset->data[i][0] += fftgrain->norm[i][j] - o->oldmag->data[i][j]; 238 o->oldmag->data[i][j] = fftgrain->norm[i][j]; 239 } 217 uint_t j; 218 onset->data[0] = 0.; 219 for (j=0;j<fftgrain->length;j++) { 220 if (fftgrain->norm[j] > o->oldmag->data[j]) 221 onset->data[0] += fftgrain->norm[j] - o->oldmag->data[j]; 222 o->oldmag->data[j] = fftgrain->norm[j]; 240 223 } 241 224 } … … 252 235 */ 253 236 aubio_specdesc_t * 254 new_aubio_specdesc (char_t * onset_mode, 255 uint_t size, uint_t channels){ 237 new_aubio_specdesc (char_t * onset_mode, uint_t size){ 256 238 aubio_specdesc_t * o = AUBIO_NEW(aubio_specdesc_t); 257 239 uint_t rsize = size/2+1; … … 303 285 /* the other approaches will need some more memory spaces */ 304 286 case aubio_onset_complex: 305 o->oldmag = new_fvec(rsize ,channels);306 o->dev1 = new_fvec(rsize ,channels);307 o->theta1 = new_fvec(rsize ,channels);308 o->theta2 = new_fvec(rsize ,channels);287 o->oldmag = new_fvec(rsize); 288 o->dev1 = new_fvec(rsize); 289 o->theta1 = new_fvec(rsize); 290 o->theta2 = new_fvec(rsize); 309 291 break; 310 292 case aubio_onset_phase: 311 o->dev1 = new_fvec(rsize ,channels);312 o->theta1 = new_fvec(rsize ,channels);313 o->theta2 = new_fvec(rsize ,channels);314 o->histog = new_aubio_hist(0.0, PI, 10 , channels);293 o->dev1 = new_fvec(rsize); 294 o->theta1 = new_fvec(rsize); 295 o->theta2 = new_fvec(rsize); 296 o->histog = new_aubio_hist(0.0, PI, 10); 315 297 o->threshold = 0.1; 316 298 break; 317 299 case aubio_onset_specdiff: 318 o->oldmag = new_fvec(rsize ,channels);319 o->dev1 = new_fvec(rsize ,channels);320 o->histog = new_aubio_hist(0.0, PI, 10 , channels);300 o->oldmag = new_fvec(rsize); 301 o->dev1 = new_fvec(rsize); 302 o->histog = new_aubio_hist(0.0, PI, 10); 321 303 o->threshold = 0.1; 322 304 break; … … 324 306 case aubio_onset_mkl: 325 307 case aubio_onset_specflux: 326 o->oldmag = new_fvec(rsize ,channels);308 o->oldmag = new_fvec(rsize); 327 309 break; 328 310 default: -
src/spectral/specdesc.h
r0b9a02a rd95ff38 25 25 All of the following spectral description functions take as arguments the FFT 26 26 of a windowed signal (as created with aubio_pvoc). They output one smpl_t per 27 buffer and per channel (stored in a vector of size [channels]x[1]).27 buffer (stored in a vector of size [1]). 28 28 29 29 A list of the spectral description methods currently available follows. … … 168 168 \param method spectral description method 169 169 \param buf_size length of the input spectrum frame 170 \param channels number of input channels171 170 172 171 */ 173 aubio_specdesc_t *new_aubio_specdesc (char_t * method, uint_t buf_size, 174 uint_t channels); 172 aubio_specdesc_t *new_aubio_specdesc (char_t * method, uint_t buf_size); 175 173 176 174 /** deletion of a spectral descriptor -
src/spectral/statistics.c
r0b9a02a rd95ff38 24 24 25 25 smpl_t 26 cvec_sum _channel (cvec_t * s, uint_t i)26 cvec_sum (cvec_t * s) 27 27 { 28 28 uint_t j; 29 29 smpl_t tmp = 0.0; 30 for (j = 0; j < s->length; j++) 31 tmp += s->norm[i][j]; 30 for (j = 0; j < s->length; j++) { 31 tmp += s->norm[j]; 32 } 32 33 return tmp; 33 34 } 34 35 35 36 smpl_t 36 cvec_mean _channel (cvec_t * s, uint_t i)37 cvec_mean (cvec_t * s) 37 38 { 38 return cvec_sum _channel(s, i) / (smpl_t) (s->length);39 return cvec_sum (s) / (smpl_t) (s->length); 39 40 } 40 41 41 42 smpl_t 42 cvec_centroid _channel (cvec_t * spec, uint_t i)43 cvec_centroid (cvec_t * spec) 43 44 { 44 45 smpl_t sum = 0., sc = 0.; 45 46 uint_t j; 46 sum = cvec_sum _channel (spec, i);47 sum = cvec_sum (spec); 47 48 if (sum == 0.) { 48 49 return 0.; 49 50 } else { 50 51 for (j = 0; j < spec->length; j++) { 51 sc += (smpl_t) j *spec->norm[ i][j];52 sc += (smpl_t) j *spec->norm[j]; 52 53 } 53 54 return sc / sum; … … 56 57 57 58 smpl_t 58 cvec_moment _channel (cvec_t * spec, uint_t i, uint_t order)59 cvec_moment (cvec_t * spec, uint_t order) 59 60 { 60 61 smpl_t sum = 0., centroid = 0., sc = 0.; 61 62 uint_t j; 62 sum = cvec_sum _channel (spec, i);63 sum = cvec_sum (spec); 63 64 if (sum == 0.) { 64 65 return 0.; 65 66 } else { 66 centroid = cvec_centroid _channel (spec, i);67 centroid = cvec_centroid (spec); 67 68 for (j = 0; j < spec->length; j++) { 68 sc += (smpl_t) POW(j - centroid, order) * spec->norm[ i][j];69 sc += (smpl_t) POW(j - centroid, order) * spec->norm[j]; 69 70 } 70 71 return sc / sum; … … 76 77 fvec_t * desc) 77 78 { 78 uint_t i; 79 for (i = 0; i < spec->channels; i++) { 80 desc->data[i][0] = cvec_centroid_channel (spec, i); 81 } 79 desc->data[0] = cvec_centroid (spec); 82 80 } 83 81 … … 86 84 fvec_t * desc) 87 85 { 88 uint_t i; 89 for (i = 0; i < spec->channels; i++) { 90 desc->data[i][0] = cvec_moment_channel (spec, i, 2); 91 } 86 desc->data[0] = cvec_moment (spec, 2); 92 87 } 93 88 … … 96 91 fvec_t * desc) 97 92 { 98 uint_t i; smpl_t spread; 99 for (i = 0; i < spec->channels; i++) { 100 spread = cvec_moment_channel (spec, i, 2); 101 if (spread == 0) { 102 desc->data[i][0] = 0.; 103 } else { 104 desc->data[i][0] = cvec_moment_channel (spec, i, 3); 105 desc->data[i][0] /= POW ( SQRT (spread), 3); 106 } 93 smpl_t spread; 94 spread = cvec_moment (spec, 2); 95 if (spread == 0) { 96 desc->data[0] = 0.; 97 } else { 98 desc->data[0] = cvec_moment (spec, 3); 99 desc->data[0] /= POW ( SQRT (spread), 3); 107 100 } 108 101 } … … 112 105 fvec_t * desc) 113 106 { 114 uint_t i; smpl_t spread; 115 for (i = 0; i < spec->channels; i++) { 116 spread = cvec_moment_channel (spec, i, 2); 117 if (spread == 0) { 118 desc->data[i][0] = 0.; 119 } else { 120 desc->data[i][0] = cvec_moment_channel (spec, i, 4); 121 desc->data[i][0] /= SQR (spread); 122 } 107 smpl_t spread; 108 spread = cvec_moment (spec, 2); 109 if (spread == 0) { 110 desc->data[0] = 0.; 111 } else { 112 desc->data[0] = cvec_moment (spec, 4); 113 desc->data[0] /= SQR (spread); 123 114 } 124 115 } … … 128 119 fvec_t * desc) 129 120 { 130 uint_t i,j;121 uint_t j; 131 122 smpl_t norm = 0, sum = 0.; 132 123 // compute N * sum(j**2) - sum(j)**2 … … 137 128 // sum_0^N(j) = length * (length + 1) / 2 138 129 norm -= SQR( (spec->length) * (spec->length - 1.) / 2. ); 139 for (i = 0; i < spec->channels; i++) { 140 sum = cvec_sum_channel (spec, i); 141 desc->data[i][0] = 0.; 142 if (sum == 0.) { 143 break; 144 } else { 145 for (j = 0; j < spec->length; j++) { 146 desc->data[i][0] += j * spec->norm[i][j]; 147 } 148 desc->data[i][0] *= spec->length; 149 desc->data[i][0] -= sum * spec->length * (spec->length - 1) / 2.; 150 desc->data[i][0] /= norm; 151 desc->data[i][0] /= sum; 130 sum = cvec_sum (spec); 131 desc->data[0] = 0.; 132 if (sum == 0.) { 133 return; 134 } else { 135 for (j = 0; j < spec->length; j++) { 136 desc->data[0] += j * spec->norm[j]; 152 137 } 138 desc->data[0] *= spec->length; 139 desc->data[0] -= sum * spec->length * (spec->length - 1) / 2.; 140 desc->data[0] /= norm; 141 desc->data[0] /= sum; 153 142 } 154 143 } … … 158 147 fvec_t * desc) 159 148 { 160 uint_t i, j; smpl_t sum; 161 for (i = 0; i < spec->channels; i++) { 162 sum = cvec_sum_channel (spec, i); 163 desc->data[i][0] = 0; 164 if (sum == 0.) { 165 break; 166 } else { 167 sum -= spec->norm[i][0]; 168 for (j = 1; j < spec->length; j++) { 169 desc->data[i][0] += (spec->norm[i][j] - spec->norm[i][0]) / j; 170 } 171 desc->data[i][0] /= sum; 149 uint_t j; smpl_t sum; 150 sum = cvec_sum (spec); 151 desc->data[0] = 0; 152 if (sum == 0.) { 153 return; 154 } else { 155 sum -= spec->norm[0]; 156 for (j = 1; j < spec->length; j++) { 157 desc->data[0] += (spec->norm[j] - spec->norm[0]) / j; 172 158 } 159 desc->data[0] /= sum; 173 160 } 174 161 } … … 178 165 fvec_t *desc) 179 166 { 180 uint_t i, j; smpl_t cumsum, rollsum; 181 for (i = 0; i < spec->channels; i++) { 182 cumsum = 0.; rollsum = 0.; 183 for (j = 0; j < spec->length; j++) { 184 cumsum += SQR (spec->norm[i][j]); 167 uint_t j; smpl_t cumsum, rollsum; 168 cumsum = 0.; rollsum = 0.; 169 for (j = 0; j < spec->length; j++) { 170 cumsum += SQR (spec->norm[j]); 171 } 172 if (cumsum == 0) { 173 desc->data[0] = 0.; 174 } else { 175 cumsum *= 0.95; 176 j = 0; 177 while (rollsum < cumsum) { 178 rollsum += SQR (spec->norm[j]); 179 j++; 185 180 } 186 if (cumsum == 0) { 187 desc->data[i][0] = 0.; 188 } else { 189 cumsum *= 0.95; 190 j = 0; 191 while (rollsum < cumsum) { 192 rollsum += SQR (spec->norm[i][j]); 193 j++; 194 } 195 desc->data[i][0] = j; 196 } 181 desc->data[0] = j; 197 182 } 198 183 } -
src/spectral/tss.c
r0b9a02a rd95ff38 44 44 cvec_t * trans, cvec_t * stead) 45 45 { 46 uint_t i,j;46 uint_t j; 47 47 uint_t test; 48 48 uint_t nbins = input->length; 49 uint_t channels = input->channels;50 49 smpl_t alpha = o->alpha; 51 50 smpl_t beta = o->beta; 52 51 smpl_t parm = o->parm; 53 smpl_t * * dev = (smpl_t **)o->dev->data;54 smpl_t * * oft1 = (smpl_t **)o->oft1->data;55 smpl_t * * oft2 = (smpl_t **)o->oft2->data;56 smpl_t * * theta1 = (smpl_t **)o->theta1->data;57 smpl_t * * theta2 = (smpl_t **)o->theta2->data;52 smpl_t * dev = (smpl_t *)o->dev->data; 53 smpl_t * oft1 = (smpl_t *)o->oft1->data; 54 smpl_t * oft2 = (smpl_t *)o->oft2->data; 55 smpl_t * theta1 = (smpl_t *)o->theta1->data; 56 smpl_t * theta2 = (smpl_t *)o->theta2->data; 58 57 /* second phase derivative */ 59 for (i=0;i<channels; i++){ 60 for (j=0;j<nbins; j++){ 61 dev[i][j] = aubio_unwrap2pi(input->phas[i][j] 62 -2.0*theta1[i][j]+theta2[i][j]); 63 theta2[i][j] = theta1[i][j]; 64 theta1[i][j] = input->phas[i][j]; 65 } 58 for (j=0;j<nbins; j++){ 59 dev[j] = aubio_unwrap2pi(input->phas[j] 60 -2.0*theta1[j]+theta2[j]); 61 theta2[j] = theta1[j]; 62 theta1[j] = input->phas[j]; 63 } 66 64 67 68 69 test = (ABS(dev[i][j]) > parm*oft1[i][j]);70 trans->norm[i][j] = input->norm[i][j] * test;71 trans->phas[i][j] = input->phas[i][j] * test;72 65 for (j=0;j<nbins; j++){ 66 /* transient analysis */ 67 test = (ABS(dev[j]) > parm*oft1[j]); 68 trans->norm[j] = input->norm[j] * test; 69 trans->phas[j] = input->phas[j] * test; 70 } 73 71 74 75 76 test = (ABS(dev[i][j]) < parm*oft2[i][j]);77 stead->norm[i][j] = input->norm[i][j] * test;78 stead->phas[i][j] = input->phas[i][j] * test;72 for (j=0;j<nbins; j++){ 73 /* steady state analysis */ 74 test = (ABS(dev[j]) < parm*oft2[j]); 75 stead->norm[j] = input->norm[j] * test; 76 stead->phas[j] = input->phas[j] * test; 79 77 80 /*increase sstate probability for sines */ 81 test = (trans->norm[i][j]==0.); 82 oft1[i][j] = test; 83 test = (stead->norm[i][j]==0.); 84 oft2[i][j] = test; 85 test = (trans->norm[i][j]>0.); 86 oft1[i][j] += alpha*test; 87 test = (stead->norm[i][j]>0.); 88 oft2[i][j] += alpha*test; 89 test = (oft1[i][j]>1. && trans->norm[i][j]>0.); 90 oft1[i][j] += beta*test; 91 test = (oft2[i][j]>1. && stead->norm[i][j]>0.); 92 oft2[i][j] += beta*test; 93 } 78 /*increase sstate probability for sines */ 79 test = (trans->norm[j]==0.); 80 oft1[j] = test; 81 test = (stead->norm[j]==0.); 82 oft2[j] = test; 83 test = (trans->norm[j]>0.); 84 oft1[j] += alpha*test; 85 test = (stead->norm[j]>0.); 86 oft2[j] += alpha*test; 87 test = (oft1[j]>1. && trans->norm[j]>0.); 88 oft1[j] += beta*test; 89 test = (oft2[j]>1. && stead->norm[j]>0.); 90 oft2[j] += beta*test; 94 91 } 95 92 } … … 101 98 } 102 99 103 aubio_tss_t * new_aubio_tss(uint_t buf_size, uint_t hop_size , uint_t channels)100 aubio_tss_t * new_aubio_tss(uint_t buf_size, uint_t hop_size) 104 101 { 105 102 aubio_tss_t * o = AUBIO_NEW(aubio_tss_t); … … 110 107 o->beta = 4.; 111 108 o->parm = o->threshold*o->thrsfact; 112 o->theta1 = new_fvec(rsize ,channels);113 o->theta2 = new_fvec(rsize ,channels);114 o->oft1 = new_fvec(rsize ,channels);115 o->oft2 = new_fvec(rsize ,channels);116 o->dev = new_fvec(rsize ,channels);109 o->theta1 = new_fvec(rsize); 110 o->theta2 = new_fvec(rsize); 111 o->oft1 = new_fvec(rsize); 112 o->oft2 = new_fvec(rsize); 113 o->dev = new_fvec(rsize); 117 114 return o; 118 115 } -
src/spectral/tss.h
r0b9a02a rd95ff38 49 49 \param buf_size buffer size 50 50 \param hop_size step size 51 \param channels number of input channels52 51 53 52 */ 54 aubio_tss_t *new_aubio_tss (uint_t buf_size, uint_t hop_size , uint_t channels);53 aubio_tss_t *new_aubio_tss (uint_t buf_size, uint_t hop_size); 55 54 56 55 /** delete tss object
Note: See TracChangeset
for help on using the changeset viewer.