comparison examples/MSP/xtract~.c @ 78:afb298ce1b4d

Fixes for MSP example, and changed the fundamental estimators so that if they don't get a samplerate 44100 is assumed (I'm not sure if this is a good idea!).
author Jamie Bullock <jamie@postlude.co.uk>
date Sun, 19 Aug 2007 16:54:25 +0000
parents 899c31350e8d
children 06c3ca76e007
comparison
equal deleted inserted replaced
77:899c31350e8d 78:afb298ce1b4d
44 tracked_memory memory; 44 tracked_memory memory;
45 void *argv; 45 void *argv;
46 } t_xtract_tilde; 46 } t_xtract_tilde;
47 47
48 static t_int *xtract_perform(t_int *w) { 48 static t_int *xtract_perform(t_int *w) {
49 t_sample *in = (t_sample *)(w[1]); 49 t_float *in = (t_float *)(w[1]);
50 t_xtract_tilde *x = (t_xtract_tilde *)(w[2]); 50 t_xtract_tilde *x = (t_xtract_tilde *)(w[2]);
51 t_int N = (t_int)(w[3]); 51 t_int N = (t_int)(w[3]);
52 t_int return_code = 0; 52 t_int return_code = 0;
53 float result = 0; 53 float result = 0.f;
54 54
55 return_code = xtract[x->feature]((float *)in, N, x->argv, &result); 55 return_code = xtract[x->feature]((float *)in, N, x->argv, &result);
56 56
57 if(return_code == XTRACT_FEATURE_NOT_IMPLEMENTED) 57 if(return_code == XTRACT_FEATURE_NOT_IMPLEMENTED)
58 perror("Feature not implemented"); 58 perror("Feature not implemented");
63 outlet_float(x->outlet, result); 63 outlet_float(x->outlet, result);
64 return (w+4); 64 return (w+4);
65 } 65 }
66 66
67 static t_int *xtract_perform_vector(t_int *w) { 67 static t_int *xtract_perform_vector(t_int *w) {
68 t_sample *in = (t_sample *)(w[1]); 68 t_sample *in = (t_float *)(w[1]);
69 t_sample *out = (t_sample *)(w[2]); 69 t_sample *out = (t_float *)(w[2]);
70 float *temp_in, *temp_out; 70 float *temp_in, *temp_out;
71 t_xtract_tilde *x = (t_xtract_tilde *)(w[3]); 71 t_xtract_tilde *x = (t_xtract_tilde *)(w[3]);
72 t_int N = (t_int)(w[4]), n; 72 t_int N = (t_int)(w[4]), n;
73 t_int return_code = 0; 73 t_int return_code = 0;
74 74
112 static void *xtract_tilde_new(t_symbol *me, t_int argc, t_atom *argv) { 112 static void *xtract_tilde_new(t_symbol *me, t_int argc, t_atom *argv) {
113 113
114 t_symbol *tmp; 114 t_symbol *tmp;
115 t_xtract_tilde *x = (t_xtract_tilde *)newobject(xtract_tilde_class); 115 t_xtract_tilde *x = (t_xtract_tilde *)newobject(xtract_tilde_class);
116 xtract_mel_filter *mf; 116 xtract_mel_filter *mf;
117 t_int n, N, f, F, n_args, type; 117 t_int n, N, f, F, n_args, type, blocksize;
118 t_float *argv_max; 118 t_float *argv_max;
119 xtract_function_descriptor_t *fd; 119 xtract_function_descriptor_t *fd;
120 char *p_name, *p_desc, *author; 120 char *p_name, *p_desc, *author;
121 int year; 121 int year;
122 122
123
124 blocksize = BLOCKSIZE; /* Default */
125 tmp = NULL;
123 p_name = p_desc = author = NULL; 126 p_name = p_desc = author = NULL;
124 127
125 n_args = type = x->feature = 0; 128 n_args = type = x->feature = 0;
126 129
127 f = F = XTRACT_FEATURES; 130 f = F = XTRACT_FEATURES;
128 131
129 N = BLOCKSIZE; 132 /* N = BLOCKSIZE;*/
130 133
131 x->argv = NULL; 134 x->argv = NULL;
132 135
133 tmp = argv->a_w.w_sym; /*atom_getsymbol(argv); */ 136 if(argc)
137 tmp = argv[0].a_w.w_sym; /*atom_getsymbol(argv); */
138 if(argc > 1)
139 blocksize = (t_int)argv[1].a_w.w_long;
140
141 N = blocksize;
134 142
135 /* get function descriptors */ 143 /* get function descriptors */
136 fd = (xtract_function_descriptor_t *)xtract_make_descriptors(); 144 fd = (xtract_function_descriptor_t *)xtract_make_descriptors();
137 145
138 /* iterate over descriptors */ 146 /* iterate over descriptors */
184 post("xtract~: %s(%d)", author, year); 192 post("xtract~: %s(%d)", author, year);
185 } 193 }
186 else 194 else
187 post("xtract~: No arguments given"); 195 post("xtract~: No arguments given");
188 196
189
190 /* do init if needed */ 197 /* do init if needed */
191 if(x->feature == XTRACT_MFCC){ 198 if(x->feature == XTRACT_MFCC){
192 199
193 mf = x->argv; 200 mf = x->argv;
194 201
222 x->feature_type = XTRACT_DELTA; 229 x->feature_type = XTRACT_DELTA;
223 230
224 else x->feature_type = XTRACT_SCALAR; 231 else x->feature_type = XTRACT_SCALAR;
225 232
226 /* argv through right inlet */ 233 /* argv through right inlet */
227 inlet_new((t_pxobject *)x, "argv"); 234 inlet_new((t_pxobject *)x, "list");
228 235
229 /* DSP inlet */ 236 /* DSP inlet */
230 dsp_setup((t_pxobject *)x, 1); 237 dsp_setup((t_pxobject *)x, 1);
231 238
232 239
292 sizeof(t_xtract_tilde), 299 sizeof(t_xtract_tilde),
293 0L, 300 0L,
294 A_GIMME, 0); 301 A_GIMME, 0);
295 302
296 addmess((method)xtract_tilde_dsp, "dsp", A_CANT, 0); 303 addmess((method)xtract_tilde_dsp, "dsp", A_CANT, 0);
297 addmess((method)xtract_tilde_get_args, "argv", A_GIMME, 0); 304 addmess((method)xtract_tilde_get_args, "list", A_GIMME, 0);
298 addmess((method)xtract_tilde_show_help, "help", A_DEFSYM, 0); 305 addmess((method)xtract_tilde_show_help, "help", A_DEFSYM, 0);
299 dsp_initclass(); 306 dsp_initclass();
300 //class_setname("xtract~", "xtract~"); 307 //class_setname("xtract~", "xtract~");
301 308
302 return 0; 309 return 0;