Mercurial > hg > libxtract
comparison examples/puredata/xtract~.c @ 146:baaa9d8b4d10
switched from single to double precision througout. closes #9
author | Jamie Bullock <jamie@jamiebullock.com> |
---|---|
date | Wed, 09 Jan 2013 12:45:29 +0000 |
parents | e4f704649c50 |
children | 246c203cc733 |
comparison
equal
deleted
inserted
replaced
145:2663eac093a5 | 146:baaa9d8b4d10 |
---|---|
49 } tracked_memory; | 49 } tracked_memory; |
50 | 50 |
51 typedef struct _xtract { | 51 typedef struct _xtract { |
52 t_object x_obj; | 52 t_object x_obj; |
53 t_float f; | 53 t_float f; |
54 t_float *window; | 54 double *window; |
55 double *data; | |
56 double *result; | |
55 t_int feature, | 57 t_int feature, |
56 is_scalar, | 58 is_scalar, |
57 is_subframe, | 59 is_subframe, |
58 argv_type, | 60 argv_type, |
59 init_blocksize, | 61 init_blocksize, |
66 static t_int *xtract_perform(t_int *w) { | 68 static t_int *xtract_perform(t_int *w) { |
67 t_sample *in = (t_sample *)(w[1]); | 69 t_sample *in = (t_sample *)(w[1]); |
68 t_xtract_tilde *x = (t_xtract_tilde *)(w[2]); | 70 t_xtract_tilde *x = (t_xtract_tilde *)(w[2]); |
69 t_int N = (t_int)(w[3]); | 71 t_int N = (t_int)(w[3]); |
70 t_int rv = 0; | 72 t_int rv = 0; |
71 float result = 0; | 73 double result = 0.0; |
72 | 74 |
73 rv = xtract[x->feature]((float *)in, N, x->argv, &result); | 75 for(n = 0; n < N; ++n) { |
76 x->data[n] = (double)in[n]; | |
77 } | |
78 | |
79 rv = xtract[x->feature](x->data, N, x->argv, &result); | |
74 | 80 |
75 if(rv == XTRACT_FEATURE_NOT_IMPLEMENTED) | 81 if(rv == XTRACT_FEATURE_NOT_IMPLEMENTED) |
76 pd_error(x, "Feature not implemented"); | 82 pd_error(x, "Feature not implemented"); |
77 | 83 |
78 /* set nan, inf or -inf to 0 */ | 84 /* set nan, inf or -inf to 0 */ |
79 result = (isinf(result) || isnan(result) ? 0 : result); | 85 result = (isinf(result) || isnan(result) ? 0.0 : result); |
80 | 86 |
81 outlet_float(x->x_obj.ob_outlet, result); | 87 outlet_float(x->x_obj.ob_outlet, (float)result); |
82 return (w+4); | 88 return (w+4); |
83 } | 89 } |
84 | 90 |
85 static t_int *xtract_perform_vector(t_int *w) { | 91 static t_int *xtract_perform_vector(t_int *w) { |
86 | 92 |
87 t_sample *in = (t_sample *)(w[1]); | 93 t_sample *in = (t_sample *)(w[1]); |
88 t_sample *out = (t_sample *)(w[2]); | 94 t_sample *out = (t_sample *)(w[2]); |
89 t_float *tmp_in, *tmp_out; | |
90 t_xtract_tilde *x = (t_xtract_tilde *)(w[3]); | 95 t_xtract_tilde *x = (t_xtract_tilde *)(w[3]); |
91 t_int N = (t_int)(w[4]), n; | 96 t_int N = (t_int)(w[4]), n; |
92 t_int rv = 0; | 97 t_int rv = 0; |
93 | 98 |
94 if(N != x->init_blocksize && x->done_init){ | 99 if(N != x->init_blocksize && x->done_init){ |
96 return (w+5); | 101 return (w+5); |
97 } | 102 } |
98 | 103 |
99 n = N; | 104 n = N; |
100 | 105 |
101 tmp_in = copybytes(in, N * sizeof(t_float)); | 106 for(n = 0; n < N; ++n) { |
102 tmp_out = getbytes(N * sizeof(t_float)); | 107 x->data[n] = (double)in[n]; |
108 } | |
103 | 109 |
104 if(x->feature == XTRACT_PEAK_SPECTRUM || x->feature == XTRACT_LPC) | 110 if(x->feature == XTRACT_PEAK_SPECTRUM || x->feature == XTRACT_LPC) |
105 N >>= 1; | 111 N >>= 1; |
106 | 112 |
107 if(x->is_subframe){ | 113 if(x->is_subframe){ |
108 | 114 |
109 rv = xtract_features_from_subframes(tmp_in, N, x->feature, | 115 rv = xtract_features_from_subframes(x->data, N, x->feature, |
110 x->argv, tmp_out); | 116 x->argv, x->result); |
111 } | 117 } |
112 else{ | 118 else{ |
113 | 119 |
114 rv = xtract[x->feature](tmp_in, N, x->argv, tmp_out); | 120 rv = xtract[x->feature](x->data, N, x->argv, x->result); |
115 | |
116 } | 121 } |
117 | 122 |
118 if(rv == XTRACT_FEATURE_NOT_IMPLEMENTED) | 123 if(rv == XTRACT_FEATURE_NOT_IMPLEMENTED) |
119 pd_error(x, "Feature not implemented"); | 124 pd_error(x, "Feature not implemented"); |
120 | 125 |
121 while(n--) | 126 while(n--) |
122 out[n] = tmp_out[n]; | 127 out[n] = (float)x->result[n]; |
123 | |
124 freebytes(tmp_in, N * sizeof(t_float)); | |
125 freebytes(tmp_out, N * sizeof(t_float)); | |
126 | 128 |
127 return (w+5); | 129 return (w+5); |
128 } | 130 } |
129 | 131 |
130 static void xtract_dsp(t_xtract_tilde *x, t_signal **sp) { | 132 static void xtract_dsp(t_xtract_tilde *x, t_signal **sp) { |
167 x->done_init = 0; | 169 x->done_init = 0; |
168 x->is_scalar = 0; | 170 x->is_scalar = 0; |
169 x->is_subframe = 0; | 171 x->is_subframe = 0; |
170 x->feature = -1; | 172 x->feature = -1; |
171 | 173 |
174 /* Allocate data area */ | |
175 x->data = (double *)getbytes(N * sizeof(double)); | |
176 x->result = (double *)getbytes(N * sizeof(double)); | |
177 | |
172 /* Parse arguments */ | 178 /* Parse arguments */ |
173 if(argc){ | 179 if(argc){ |
174 arg1 = atom_getsymbol(argv); | 180 arg1 = atom_getsymbol(argv); |
175 if(arg1 == gensym("subframe")) | 181 if(arg1 == gensym("subframe")) |
176 x->is_subframe = 1; | 182 x->is_subframe = 1; |