Mercurial > hg > libxtract
comparison examples/puredata/xtract~.c @ 42:84e69b155098
Numerous fixes, see ChangeLog
author | Jamie Bullock <jamie@postlude.co.uk> |
---|---|
date | Tue, 12 Dec 2006 21:47:42 +0000 |
parents | afb9e6fee244 |
children | 4a36f70a76e9 |
comparison
equal
deleted
inserted
replaced
41:afb9e6fee244 | 42:84e69b155098 |
---|---|
17 */ | 17 */ |
18 | 18 |
19 /* calculates the spectral xtract of one frame, given peak frequency and amplitude to first and second inputs respectively */ | 19 /* calculates the spectral xtract of one frame, given peak frequency and amplitude to first and second inputs respectively */ |
20 | 20 |
21 #include "m_pd.h" | 21 #include "m_pd.h" |
22 #include <math.h> | |
22 | 23 |
23 #define XTRACT | 24 #define XTRACT |
24 #include "xtract/libxtract.h" | 25 #include "xtract/libxtract.h" |
25 | 26 |
26 #define BLOCKSIZE 1024 | 27 #define BLOCKSIZE 1024 |
51 | 52 |
52 return_code = xtract[x->feature]((float *)in, N, x->argv, &result); | 53 return_code = xtract[x->feature]((float *)in, N, x->argv, &result); |
53 | 54 |
54 if(return_code == FEATURE_NOT_IMPLEMENTED) | 55 if(return_code == FEATURE_NOT_IMPLEMENTED) |
55 pd_error(x, "Feature not implemented"); | 56 pd_error(x, "Feature not implemented"); |
57 | |
58 /* set nan, inf or -inf to 0 */ | |
59 result = (isinf(result) || isnan(result) ? 0 : result); | |
56 | 60 |
57 outlet_float(x->x_obj.ob_outlet, result); | 61 outlet_float(x->x_obj.ob_outlet, result); |
58 return (w+4); | 62 return (w+4); |
59 } | 63 } |
60 | 64 |
164 case AVERAGE_DEVIATION: | 168 case AVERAGE_DEVIATION: |
165 case ROLLOFF: | 169 case ROLLOFF: |
166 case INHARMONICITY: | 170 case INHARMONICITY: |
167 case LOWEST_MATCH: | 171 case LOWEST_MATCH: |
168 case F0: | 172 case F0: |
173 case TONALITY: | |
169 floatargs = 1; | 174 floatargs = 1; |
170 break; | 175 break; |
171 case SKEWNESS: | 176 case SKEWNESS: |
172 case KURTOSIS: | 177 case KURTOSIS: |
173 case PEAKS: | 178 case PEAKS: |
183 case SMOOTHNESS: | 188 case SMOOTHNESS: |
184 case SPREAD: | 189 case SPREAD: |
185 case ZCR: | 190 case ZCR: |
186 case LOUDNESS: | 191 case LOUDNESS: |
187 case FLATNESS: | 192 case FLATNESS: |
188 case TONALITY: | |
189 case CREST: | 193 case CREST: |
190 case NOISINESS: | 194 case NOISINESS: |
191 case RMS_AMPLITUDE: | 195 case RMS_AMPLITUDE: |
192 case POWER: | 196 case POWER: |
193 case ODD_EVEN_RATIO: | 197 case ODD_EVEN_RATIO: |
216 if(x->feature == MFCC){ | 220 if(x->feature == MFCC){ |
217 x->memory.argv = (size_t)(sizeof(xtract_mel_filter)); | 221 x->memory.argv = (size_t)(sizeof(xtract_mel_filter)); |
218 x->argv = (xtract_mel_filter *)getbytes(x->memory.argv); | 222 x->argv = (xtract_mel_filter *)getbytes(x->memory.argv); |
219 } | 223 } |
220 else if(x->feature == BARK_COEFFICIENTS){ | 224 else if(x->feature == BARK_COEFFICIENTS){ |
221 x->memory.argv = (size_t)(sizeof(BARK_BANDS * sizeof(t_int))); | 225 x->memory.argv = (size_t)(BARK_BANDS * sizeof(t_int)); |
222 x->argv = (t_int *)getbytes(x->memory.argv); | 226 x->argv = (t_int *)getbytes(x->memory.argv); |
223 } | 227 } |
224 else if (floatargs){ | 228 else if (floatargs){ |
225 x->memory.argv = (size_t)(floatargs * sizeof(t_float)); | 229 x->memory.argv = (size_t)(floatargs * sizeof(t_float)); |
226 x->argv = (t_float *)getbytes(x->memory.argv); | 230 x->argv = (t_float *)getbytes(x->memory.argv); |