comparison src/descriptors.c @ 55:4ea1a8838b14

Finished the essentials of descriptors.c
author Jamie Bullock <jamie@postlude.co.uk>
date Sun, 21 Jan 2007 14:40:23 +0000
parents 9762d7e3d129
children 450712b21565
comparison
equal deleted inserted replaced
54:9762d7e3d129 55:4ea1a8838b14
24 #define XTRACT 24 #define XTRACT
25 25
26 void *xtract_make_descriptors(){ 26 void *xtract_make_descriptors(){
27 27
28 t_function_descriptor *fd, *d; 28 t_function_descriptor *fd, *d;
29 t_type *type; 29 t_type *argv_type;
30 int f , F; 30 int f , F;
31 char *name, *p_name, *desc, *p_desc, *author; 31 char *name, *p_name, *desc, *p_desc, *author, *argv_donor;
32 float *argv_min, *argv_max, *argv_def, *result_min, *result_max;
32 int *argc, *year; 33 int *argc, *year;
33 t_vector *data_format; 34 t_vector *data_format;
34 /* *result_format; */ 35 t_unit *data_unit, *argv_unit, *result_unit;
36 t_bool *is_scalar;
37 t_vector *result_format;
35 38
36 f = F = XTRACT_FEATURES; 39 f = F = XTRACT_FEATURES;
37 40
38 fd = malloc(XTRACT_FEATURES * sizeof(t_function_descriptor)); 41 fd = malloc(XTRACT_FEATURES * sizeof(t_function_descriptor));
39 42
43 /* FIX - this file probably needs a rewrite for readability */
40 44
41 while(f--){ 45 while(f--){
42 46
43 d = &fd[f]; 47 d = &fd[f];
44 argc = &d->argc; 48 argc = &d->argc;
45 type = &d->argv.type; 49 argv_type = &d->argv.type;
46 50
47 switch(f){ 51 switch(f){
48 52
49 case MEAN:
50 case VARIANCE: 53 case VARIANCE:
51 case STANDARD_DEVIATION: 54 case STANDARD_DEVIATION:
52 case AVERAGE_DEVIATION: 55 case AVERAGE_DEVIATION:
53 case SPECTRAL_MEAN:
54 case SPECTRAL_VARIANCE: 56 case SPECTRAL_VARIANCE:
55 case SPECTRAL_STANDARD_DEVIATION: 57 case SPECTRAL_STANDARD_DEVIATION:
56 case SPECTRAL_AVERAGE_DEVIATION: 58 case SPECTRAL_AVERAGE_DEVIATION:
57 case ROLLOFF:
58 case SPECTRAL_INHARMONICITY: 59 case SPECTRAL_INHARMONICITY:
59 case ODD_EVEN_RATIO: 60 case ODD_EVEN_RATIO:
60 case LOWEST_VALUE: 61 case LOWEST_VALUE:
61 case F0: 62 case F0:
62 case FAILSAFE_F0: 63 case FAILSAFE_F0:
63 case TONALITY: 64 case TONALITY:
64 *argc = 1; 65 *argc = 1;
65 *type = FLOAT; 66 *argv_type = FLOAT;
66 break; 67 break;
67 case SKEWNESS: 68 case SKEWNESS:
68 case KURTOSIS: 69 case KURTOSIS:
69 case SPECTRAL_SKEWNESS: 70 case SPECTRAL_SKEWNESS:
70 case SPECTRAL_KURTOSIS: 71 case SPECTRAL_KURTOSIS:
71 case SPECTRUM: 72 case SPECTRUM:
72 case PEAK_SPECTRUM: 73 case PEAK_SPECTRUM:
73 case HARMONIC_SPECTRUM: 74 case HARMONIC_SPECTRUM:
74 case NOISINESS: 75 case NOISINESS:
75 case CREST: 76 case CREST:
77 case ROLLOFF:
76 *argc = 2; 78 *argc = 2;
77 *type = FLOAT; 79 *argv_type = FLOAT;
78 break; 80 break;
79 case MFCC: 81 case MFCC:
80 *argc = 1; 82 *argc = 1;
81 *type = MEL_FILTER; 83 *argv_type = MEL_FILTER;
82 break; 84 break;
83 case BARK_COEFFICIENTS: 85 case BARK_COEFFICIENTS:
84 *argc = BARK_BANDS; 86 *argc = BARK_BANDS;
85 *type = INT; 87 *argv_type = INT;
86 break; 88 break;
89 case MEAN:
90 case SPECTRAL_MEAN:
87 case SPECTRAL_CENTROID: 91 case SPECTRAL_CENTROID:
88 case IRREGULARITY_K: 92 case IRREGULARITY_K:
89 case IRREGULARITY_J: 93 case IRREGULARITY_J:
90 case TRISTIMULUS_1: 94 case TRISTIMULUS_1:
91 case TRISTIMULUS_2: 95 case TRISTIMULUS_2:
109 case AUTOCORRELATION_FFT: 113 case AUTOCORRELATION_FFT:
110 case DCT: 114 case DCT:
111 case AUTOCORRELATION: 115 case AUTOCORRELATION:
112 case AMDF: 116 case AMDF:
113 case ASDF: 117 case ASDF:
114 *argc = 0;
115 break;
116 default: 118 default:
117 *argc = 0; 119 *argc = 0;
120 break;
121 }
122
123 argv_min = &d->argv.min[0];
124 argv_max = &d->argv.max[0];
125 argv_def = &d->argv.def[0];
126 argv_unit = &d->argv.unit[0];
127
128 switch (f) {
129 /* argc = 1 */
130 case VARIANCE:
131 case SPECTRAL_VARIANCE:
132 case STANDARD_DEVIATION:
133 case AVERAGE_DEVIATION:
134 case SPECTRAL_STANDARD_DEVIATION:
135 case SPECTRAL_AVERAGE_DEVIATION:
136 case LOWEST_VALUE:
137 case TONALITY:
138 case MFCC:
139 *argv_min = ANY;
140 *argv_max = ANY;
141 *argv_def = ANY;
142 *argv_unit = ANY;
143 case SPECTRAL_INHARMONICITY:
144 case ODD_EVEN_RATIO:
145 *argv_min = 0.f;
146 *argv_max = SR_UPPER_LIMIT / 2;
147 *argv_def = FUNDAMENTAL_DEFAULT;
148 *argv_unit = HERTZ;
149 case F0:
150 case FAILSAFE_F0:
151 *argv_min = SR_LOWER_LIMIT;
152 *argv_max = SR_UPPER_LIMIT;
153 *argv_def = SR_DEFAULT;
154 *argv_unit = HERTZ;
155 /* argc = 2 */;
156 case ROLLOFF:
157 *argv_min = FFT_BANDS_MIN;
158 *argv_max = FFT_BANDS_MAX;
159 *argv_def = SPEC_BW_DEF ;
160 *argv_unit = HERTZ;
161 *(argv_min + 1) = 0.f;
162 *(argv_max + 1) = 100.f;
163 *(argv_def + 1) = 95.f;
164 *(argv_unit + 1) = PERCENT;
165 case SPECTRUM:
166 *argv_min = SR_LOWER_LIMIT / 2;
167 *argv_max = SR_UPPER_LIMIT / 2;
168 *argv_def = SR_DEFAULT / 2;
169 *argv_unit = HERTZ;
170 *(argv_min + 1) = 0;
171 *(argv_max + 1) = 3 ;
172 *(argv_def + 1) = 0;
173 *(argv_unit + 1) = NONE;
174 case PEAK_SPECTRUM:
175 *argv_min = SR_LOWER_LIMIT / 2;
176 *argv_max = SR_UPPER_LIMIT / 2;
177 *argv_def = SR_DEFAULT / 2;
178 *argv_unit = HERTZ;
179 *(argv_min + 1) = 0.f;
180 *(argv_max + 1) = 100.f ;
181 *(argv_def + 1) = 10.f ;
182 *(argv_unit + 1) = PERCENT;
183 case HARMONIC_SPECTRUM:
184 *argv_min = 0.f;
185 *argv_max = SR_UPPER_LIMIT / 2;
186 *argv_def = FUNDAMENTAL_DEFAULT;
187 *argv_unit = HERTZ;
188 *(argv_min + 1) = 0.f;
189 *(argv_max + 1) = 1.f ;
190 *(argv_def + 1) = .1f ;
191 *(argv_unit + 1) = NONE;
192 case NOISINESS:
193 case SKEWNESS:
194 case KURTOSIS:
195 case SPECTRAL_SKEWNESS:
196 case SPECTRAL_KURTOSIS:
197 case CREST:
198 *argv_min = NONE;
199 *argv_max = NONE;
200 *argv_def = NONE;
201 *argv_unit = NONE;
202 *(argv_min + 1) = NONE;
203 *(argv_max + 1) = NONE;
204 *(argv_def + 1) = NONE;
205 *(argv_unit + 1) = NONE;
206 case BARK_COEFFICIENTS:
207 /* BARK_COEFFICIENTS is special because argc = BARK_BANDS */
208 default:
209 *argv_min = NONE;
210 *argv_max = NONE;
211 *argv_def = NONE;
212 *argv_unit = NONE;
213 }
214
215 argv_donor = &d->argv.donor[0];
216
217 switch (f) {
218 /* argc = 1 */
219 case VARIANCE:
220 *argv_donor = MEAN;
221 break;
222 case SPECTRAL_VARIANCE:
223 *argv_donor = SPECTRAL_MEAN;
224 break;
225 case STANDARD_DEVIATION:
226 *argv_donor = VARIANCE;
227 break;
228 case AVERAGE_DEVIATION:
229 *argv_donor = MEAN;
230 break;
231 case SPECTRAL_STANDARD_DEVIATION:
232 *argv_donor = SPECTRAL_VARIANCE;
233 break;
234 case SPECTRAL_AVERAGE_DEVIATION:
235 *argv_donor = SPECTRAL_MEAN;
236 break;
237 case SPECTRAL_INHARMONICITY:
238 case ODD_EVEN_RATIO:
239 *argv_donor = FAILSAFE_F0;
240 break;
241 case TONALITY:
242 *argv_donor = FLATNESS;
243 break;
244 case LOWEST_VALUE:
245 case F0:
246 case FAILSAFE_F0:
247 *argv_donor = ANY;
248 break;
249 case MFCC:
250 *argv_donor = INIT_MFCC;
251 break;
252 /* argc = 2 */;
253 case SPECTRUM:
254 case ROLLOFF:
255 case PEAK_SPECTRUM:
256 *argv_donor = ANY;
257 *(argv_donor + 1) = ANY;
258 break;
259 case SKEWNESS:
260 case KURTOSIS:
261 *argv_donor = MEAN;
262 *(argv_donor + 1) = STANDARD_DEVIATION;
263 break;
264 case SPECTRAL_SKEWNESS:
265 case SPECTRAL_KURTOSIS:
266 *argv_donor = SPECTRAL_MEAN;
267 *(argv_donor + 1) = SPECTRAL_STANDARD_DEVIATION;
268 break;
269 case HARMONIC_SPECTRUM:
270 *argv_donor = FAILSAFE_F0;
271 *(argv_donor + 1) = ANY;
272 break;
273 case NOISINESS:
274 *argv_donor = SUM;
275 *(argv_donor + 1) = SUM;
276 break;
277 case CREST:
278 *argv_donor = HIGHEST_VALUE;
279 *(argv_donor + 1) = SPECTRAL_MEAN;
280 break;
281 /* argc = BARK_BANDS */
282 case BARK_COEFFICIENTS:
283 *argv_donor = INIT_BARK;
284 break;
285 default:
286 *argv_donor = ANY;
118 break; 287 break;
119 } 288 }
120 289
121 data_format = &d->data.format; 290 data_format = &d->data.format;
122 291
196 default: 365 default:
197 *data_format = NO_DATA; 366 *data_format = NO_DATA;
198 break; 367 break;
199 } 368 }
200 369
370 data_unit = &d->data.unit;
371
372 switch(f){
373
374 case MEAN:
375 case VARIANCE:
376 case STANDARD_DEVIATION:
377 case AVERAGE_DEVIATION:
378 case SKEWNESS:
379 case KURTOSIS:
380 case LOWEST_VALUE:
381 case HIGHEST_VALUE:
382 case SUM:
383 case ZCR:
384 case PEAK_SPECTRUM:
385 case TRISTIMULUS_1:
386 case TRISTIMULUS_2:
387 case TRISTIMULUS_3:
388 case DCT:
389 case AMDF:
390 case ASDF:
391 case IRREGULARITY_K:
392 case IRREGULARITY_J:
393 case ATTACK_TIME:
394 case DECAY_TIME:
395 case DELTA_FEATURE:
396 case FLUX:
397 case F0:
398 case FAILSAFE_F0:
399 case MFCC:
400 case AUTOCORRELATION:
401 case AUTOCORRELATION_FFT:
402 case ROLLOFF:
403 case NOISINESS:
404 case CREST:
405 case FLATNESS:
406 case POWER:
407 case BARK_COEFFICIENTS:
408 case RMS_AMPLITUDE:
409 case SMOOTHNESS:
410 case SPREAD:
411 case SHARPNESS:
412 case HPS:
413 case SPECTRUM:
414 case TONALITY:
415 case LOUDNESS:
416 *data_unit = ANY;
417 break;
418 case SPECTRAL_MEAN:
419 case SPECTRAL_VARIANCE:
420 case SPECTRAL_STANDARD_DEVIATION:
421 case SPECTRAL_AVERAGE_DEVIATION:
422 case SPECTRAL_SKEWNESS:
423 case SPECTRAL_KURTOSIS:
424 case SPECTRAL_CENTROID:
425 case SPECTRAL_SLOPE:
426 case HARMONIC_SPECTRUM:
427 case SPECTRAL_INHARMONICITY:
428 *data_unit = ANY_AMPLITUDE_HERTZ;
429 break;
430 case ODD_EVEN_RATIO:
431 *data_unit = HERTZ;
432 break;
433 }
434
201 name = d->algo.name; 435 name = d->algo.name;
202 p_name = d->algo.p_name; 436 p_name = d->algo.p_name;
203 desc = d->algo.desc; 437 desc = d->algo.desc;
204 p_desc = d->algo.p_desc; 438 p_desc = d->algo.p_desc;
205 author = d->algo.author; 439 author = d->algo.author;
212 strcpy(name, "mean"); 446 strcpy(name, "mean");
213 strcpy(p_name, "Mean"); 447 strcpy(p_name, "Mean");
214 strcpy(desc, "Extract the mean of an input vector"); 448 strcpy(desc, "Extract the mean of an input vector");
215 strcpy(p_desc, "Extract the mean of a range of values"); 449 strcpy(p_desc, "Extract the mean of a range of values");
216 strcpy(author, ""); 450 strcpy(author, "");
451 d->argv.type = NONE;
217 break; 452 break;
218 case VARIANCE: 453 case VARIANCE:
219 strcpy(name, "variance"); 454 strcpy(name, "variance");
220 strcpy(p_name, "Variance"); 455 strcpy(p_name, "Variance");
221 strcpy(desc, "Extract the variance of an input vector"); 456 strcpy(desc, "Extract the variance of an input vector");
627 strcpy(desc, ""); 862 strcpy(desc, "");
628 strcpy(p_desc, ""); 863 strcpy(p_desc, "");
629 strcpy(author, ""); 864 strcpy(author, "");
630 break; 865 break;
631 } 866 }
867
868
869 switch(f){
870
871 case VARIANCE:
872 case STANDARD_DEVIATION:
873 case AVERAGE_DEVIATION:
874 case SPECTRAL_VARIANCE:
875 case SPECTRAL_STANDARD_DEVIATION:
876 case SPECTRAL_AVERAGE_DEVIATION:
877 case SPECTRAL_INHARMONICITY:
878 case ODD_EVEN_RATIO:
879 case LOWEST_VALUE:
880 case F0:
881 case FAILSAFE_F0:
882 case TONALITY:
883 *argc = 1;
884 *argv_type = FLOAT;
885 break;
886 case SKEWNESS:
887 case KURTOSIS:
888 case SPECTRAL_SKEWNESS:
889 case SPECTRAL_KURTOSIS:
890 case SPECTRUM:
891 case PEAK_SPECTRUM:
892 case HARMONIC_SPECTRUM:
893 case NOISINESS:
894 case CREST:
895 case ROLLOFF:
896 *argc = 2;
897 *argv_type = FLOAT;
898 break;
899 case MFCC:
900 *argc = 1;
901 *argv_type = MEL_FILTER;
902 break;
903 case BARK_COEFFICIENTS:
904 *argc = BARK_BANDS;
905 *argv_type = INT;
906 break;
907 case MEAN:
908 case SPECTRAL_MEAN:
909 case SPECTRAL_CENTROID:
910 case IRREGULARITY_K:
911 case IRREGULARITY_J:
912 case TRISTIMULUS_1:
913 case TRISTIMULUS_2:
914 case TRISTIMULUS_3:
915 case SMOOTHNESS:
916 case FLATNESS:
917 case SPREAD:
918 case ZCR:
919 case LOUDNESS:
920 case HIGHEST_VALUE:
921 case SUM:
922 case RMS_AMPLITUDE:
923 case POWER:
924 case SHARPNESS:
925 case SPECTRAL_SLOPE:
926 case HPS:
927 case FLUX:
928 case ATTACK_TIME:
929 case DECAY_TIME:
930 case DELTA_FEATURE:
931 case AUTOCORRELATION_FFT:
932 case DCT:
933 case AUTOCORRELATION:
934 case AMDF:
935 case ASDF:
936 default:
937 *argc = 0;
938 break;
939 }
940
941 is_scalar = &d->is_scalar;
942
943 switch(f){
944 case MEAN:
945 case VARIANCE:
946 case STANDARD_DEVIATION:
947 case AVERAGE_DEVIATION:
948 case SKEWNESS:
949 case KURTOSIS:
950 case SPECTRAL_MEAN:
951 case SPECTRAL_VARIANCE:
952 case SPECTRAL_STANDARD_DEVIATION:
953 case SPECTRAL_AVERAGE_DEVIATION:
954 case SPECTRAL_SKEWNESS:
955 case SPECTRAL_KURTOSIS:
956 case SPECTRAL_CENTROID:
957 case IRREGULARITY_K:
958 case IRREGULARITY_J:
959 case TRISTIMULUS_1:
960 case TRISTIMULUS_2:
961 case TRISTIMULUS_3:
962 case SMOOTHNESS:
963 case SPREAD:
964 case ZCR:
965 case ROLLOFF:
966 case LOUDNESS:
967 case FLATNESS:
968 case TONALITY:
969 case CREST:
970 case NOISINESS:
971 case RMS_AMPLITUDE:
972 case SPECTRAL_INHARMONICITY:
973 case POWER:
974 case ODD_EVEN_RATIO:
975 case SHARPNESS:
976 case SPECTRAL_SLOPE:
977 case LOWEST_VALUE:
978 case HIGHEST_VALUE:
979 case SUM:
980 case HPS:
981 case F0:
982 case FAILSAFE_F0:
983 *is_scalar = TRUE;
984 break;
985 case AUTOCORRELATION:
986 case AMDF:
987 case ASDF:
988 case BARK_COEFFICIENTS:
989 case PEAK_SPECTRUM:
990 case SPECTRUM:
991 case AUTOCORRELATION_FFT:
992 case MFCC:
993 case DCT:
994 case HARMONIC_SPECTRUM:
995 *is_scalar = FALSE;
996 break;
997 default:
998 *is_scalar = TRUE;
999 break;
1000
1001 }
1002
1003 if(*is_scalar){
1004
1005 result_unit = &d->result.scalar.unit;
1006 result_min = &d->result.scalar.min;
1007 result_max = &d->result.scalar.max;
1008
1009 switch(f){
1010 case MEAN:
1011 case VARIANCE:
1012 case STANDARD_DEVIATION:
1013 case AVERAGE_DEVIATION:
1014 case SKEWNESS:
1015 case KURTOSIS:
1016 case RMS_AMPLITUDE:
1017 case LOWEST_VALUE:
1018 case HIGHEST_VALUE:
1019 case SUM:
1020 *result_unit = ANY;
1021 *result_min = ANY;
1022 *result_max = ANY;
1023 break;
1024 case SPECTRAL_SKEWNESS:
1025 case SPECTRAL_KURTOSIS:
1026 case IRREGULARITY_K:
1027 case IRREGULARITY_J:
1028 case TRISTIMULUS_1:
1029 case TRISTIMULUS_2:
1030 case TRISTIMULUS_3:
1031 case NOISINESS:
1032 case SMOOTHNESS:
1033 *result_unit = NONE;
1034 *result_min = ANY; /* FIX: need to check these */
1035 *result_max = ANY;
1036 break;
1037 case SPECTRAL_MEAN:
1038 case SPECTRAL_VARIANCE:
1039 case SPECTRAL_STANDARD_DEVIATION:
1040 case SPECTRAL_AVERAGE_DEVIATION:
1041 case SPECTRAL_CENTROID:
1042 case SPREAD:
1043 case F0:
1044 case FAILSAFE_F0:
1045 case HPS:
1046 case ROLLOFF:
1047 *result_unit = HERTZ;
1048 *result_min = 0.f;
1049 *result_max = SR_UPPER_LIMIT / 2;
1050 case ZCR:
1051 *result_unit = HERTZ;
1052 *result_min = 0.f;
1053 *result_max = ANY;
1054 case ODD_EVEN_RATIO:
1055 *result_unit = NONE;
1056 *result_min = 0.f;
1057 *result_max = 1.f;
1058 case LOUDNESS:
1059 case FLATNESS:
1060 case TONALITY:
1061 case CREST:
1062 case SPECTRAL_INHARMONICITY:
1063 case POWER:
1064 case SHARPNESS:
1065 case SPECTRAL_SLOPE:
1066 default:
1067 *result_unit = UNKNOWN;
1068 *result_min = UNKNOWN;
1069 *result_max = UNKNOWN;
1070 }
1071 }
1072 else {
1073
1074 result_min = NULL;
1075 result_max = NULL;
1076 result_unit = &d->result.vector.unit;
1077 result_format = &d->result.vector.format;
1078
1079 switch(f) {
1080 case AUTOCORRELATION:
1081 case AMDF:
1082 case ASDF:
1083 case DCT:
1084 *result_format = ARBITRARY_SERIES;
1085 *result_unit = ANY;
1086 case BARK_COEFFICIENTS:
1087 *result_format = BARK_COEFFS;
1088 *result_unit = UNKNOWN; /* FIX: check */
1089 case PEAK_SPECTRUM:
1090 case SPECTRUM:
1091 case HARMONIC_SPECTRUM:
1092 *result_format = SPECTRAL;
1093 *result_unit = ANY_AMPLITUDE_HERTZ;
1094 case AUTOCORRELATION_FFT:
1095 case MFCC:
1096 *result_format = MEL_COEFFS;
1097 *result_unit = UNKNOWN; /* FIX: check */
1098 default:
1099 break;
1100 }
1101 }
632 } 1102 }
633 1103
634 return fd; 1104 return fd;
635 } 1105 }
636 1106