comparison examples/puredata/xtract~.c @ 161:246c203cc733

Add wavelet-based pitch tracker
author Jamie Bullock <jamie@jamiebullock.com>
date Fri, 31 May 2013 22:44:03 +0100
parents baaa9d8b4d10
children
comparison
equal deleted inserted replaced
160:f7d0b6607193 161:246c203cc733
70 t_xtract_tilde *x = (t_xtract_tilde *)(w[2]); 70 t_xtract_tilde *x = (t_xtract_tilde *)(w[2]);
71 t_int N = (t_int)(w[3]); 71 t_int N = (t_int)(w[3]);
72 t_int rv = 0; 72 t_int rv = 0;
73 double result = 0.0; 73 double result = 0.0;
74 74
75 for(n = 0; n < N; ++n) { 75 for(t_int n = 0; n < N; ++n) {
76 x->data[n] = (double)in[n]; 76 x->data[n] = (double)in[n];
77 } 77 }
78 78
79 rv = xtract[x->feature](x->data, N, x->argv, &result); 79 rv = xtract[x->feature](x->data, N, x->argv, &result);
80 80
146 t_xtract_tilde *x = (t_xtract_tilde *)pd_new(xtract_class); 146 t_xtract_tilde *x = (t_xtract_tilde *)pd_new(xtract_class);
147 xtract_mel_filter *mf; 147 xtract_mel_filter *mf;
148 t_int n, N, M, f, F, 148 t_int n, N, M, f, F,
149 n_args, 149 n_args,
150 type; 150 type;
151 t_float *argv_max; 151 double *argv_max;
152 t_symbol *arg1; 152 t_symbol *arg1;
153 xtract_function_descriptor_t *fd; 153 xtract_function_descriptor_t *fd;
154 char *p_name, 154 char *p_name,
155 *p_desc, 155 *p_desc,
156 *author; 156 *author;
257 257
258 /* Adjust frame size if we are using subframe features */ 258 /* Adjust frame size if we are using subframe features */
259 if(x->is_subframe) 259 if(x->is_subframe)
260 N = M; 260 N = M;
261 261
262 post("xtract~: window size: %d", N); 262 post("xtract~: assumed window size: %d", N);
263 263
264 /* do init if needed */ 264 /* do init if needed */
265 if(x->feature == XTRACT_MFCC){ 265 if(x->feature == XTRACT_MFCC){
266 266
267 mf = x->argv; 267 mf = x->argv;
269 mf->n_filters = 20; 269 mf->n_filters = 20;
270 270
271 post("xtract~: mfcc: filters = %d", 271 post("xtract~: mfcc: filters = %d",
272 ((xtract_mel_filter *)x->argv)->n_filters); 272 ((xtract_mel_filter *)x->argv)->n_filters);
273 mf->filters = 273 mf->filters =
274 (t_float **)getbytes(mf->n_filters * sizeof(t_float *)); 274 (double **)getbytes(mf->n_filters * sizeof(double *));
275 for(n = 0; n < mf->n_filters; n++) 275 for(n = 0; n < mf->n_filters; n++)
276 mf->filters[n] = (float *)getbytes(N * sizeof(float)); 276 mf->filters[n] = (double *)getbytes(N * sizeof(double));
277 277
278 xtract_init_mfcc(N, NYQUIST, XTRACT_EQUAL_GAIN, 80.0f, 278 xtract_init_mfcc(N, NYQUIST, XTRACT_EQUAL_GAIN, 80.0f,
279 18000.0f, mf->n_filters, mf->filters); 279 18000.0f, mf->n_filters, mf->filters);
280 x->done_init = 1; 280 x->done_init = 1;
281 } 281 }
285 } 285 }
286 else if(x->feature == XTRACT_WINDOWED){ 286 else if(x->feature == XTRACT_WINDOWED){
287 x->window = xtract_init_window(N, XTRACT_HANN); 287 x->window = xtract_init_window(N, XTRACT_HANN);
288 x->argv = x->window; 288 x->argv = x->window;
289 x->done_init = 1; 289 x->done_init = 1;
290 }
291 else if(x->feature == XTRACT_WAVELET_F0){
292 xtract_init_wavelet_f0_state();
290 } 293 }
291 294
292 /* Initialise fft_plan if required */ 295 /* Initialise fft_plan if required */
293 if(x->feature == XTRACT_AUTOCORRELATION_FFT || 296 if(x->feature == XTRACT_AUTOCORRELATION_FFT ||
294 x->feature == XTRACT_SPECTRUM || 297 x->feature == XTRACT_SPECTRUM ||