8 #include "test_macros.h"
11 main(int argc, char *argv[])
13 static const arg_t fe_args[] = {
14 waveform_to_cepstral_command_line_macro(),
15 { NULL, 0, NULL, NULL }
22 int32 frame_shift, frame_size;
23 mfcc_t **cepbuf1, **cepbuf2, **cptr;
27 TEST_ASSERT(config = cmd_ln_parse_r(NULL, fe_args, argc, argv, FALSE));
28 TEST_ASSERT(fe = fe_init_auto_r(config));
30 TEST_EQUAL(fe_get_output_size(fe), DEFAULT_NUM_CEPSTRA);
32 fe_get_input_size(fe, &frame_shift, &frame_size);
33 TEST_EQUAL(frame_shift, DEFAULT_FRAME_SHIFT);
34 TEST_EQUAL(frame_size, (int)(DEFAULT_WINDOW_LENGTH*DEFAULT_SAMPLING_RATE));
36 TEST_ASSERT(raw = fopen(TESTDATADIR "/chan3.raw", "rb"));
38 TEST_EQUAL(0, fe_start_utt(fe));
39 TEST_EQUAL(1024, fread(buf, sizeof(int16), 1024, raw));
42 TEST_ASSERT(fe_process_frames(fe, NULL, &nsamp, NULL, &nfr) >= 0);
43 TEST_EQUAL(1024, nsamp);
46 cepbuf1 = ckd_calloc_2d(5, DEFAULT_NUM_CEPSTRA, sizeof(**cepbuf1));
50 printf("frame_size %d frame_shift %d\n", frame_size, frame_shift);
51 /* Process the first frame. */
52 TEST_ASSERT(fe_process_frames(fe, &inptr, &nsamp, &cepbuf1[0], &nfr) >= 0);
53 printf("inptr %d nsamp %d nfr %d\n", inptr - buf, nsamp, nfr);
56 /* Note that this next one won't actually consume any frames
57 * of input, because it already got sufficient overflow
58 * samples last time around. This is implementation-dependent
59 * so we shouldn't actually test for it. */
60 TEST_ASSERT(fe_process_frames(fe, &inptr, &nsamp, &cepbuf1[1], &nfr) >= 0);
61 printf("inptr %d nsamp %d nfr %d\n", inptr - buf, nsamp, nfr);
64 TEST_ASSERT(fe_process_frames(fe, &inptr, &nsamp, &cepbuf1[2], &nfr) >= 0);
65 printf("inptr %d nsamp %d nfr %d\n", inptr - buf, nsamp, nfr);
68 TEST_ASSERT(fe_process_frames(fe, &inptr, &nsamp, &cepbuf1[3], &nfr) >= 0);
69 printf("inptr %d nsamp %d nfr %d\n", inptr - buf, nsamp, nfr);
72 TEST_ASSERT(fe_end_utt(fe, cepbuf1[4], &nfr) >= 0);
73 printf("nfr %d\n", nfr);
76 /* What we *should* test is that the output we get by
77 * processing one frame at a time is exactly the same as what
78 * we get from doing them all at once. So let's do that */
79 cepbuf2 = ckd_calloc_2d(5, DEFAULT_NUM_CEPSTRA, sizeof(**cepbuf2));
83 TEST_EQUAL(0, fe_start_utt(fe));
84 TEST_ASSERT(fe_process_frames(fe, &inptr, &nsamp, cepbuf2, &nfr) >= 0);
85 printf("nfr %d\n", nfr);
88 TEST_ASSERT(fe_end_utt(fe, cepbuf2[4], &nfr) >= 0);
89 printf("nfr %d\n", nfr);
92 for (i = 0; i < 5; ++i) {
95 for (j = 0; j < DEFAULT_NUM_CEPSTRA; ++j) {
97 MFCC2FLOAT(cepbuf1[i][j]),
98 MFCC2FLOAT(cepbuf2[i][j]));
99 TEST_EQUAL_FLOAT(cepbuf1[i][j], cepbuf2[i][j]);
104 /* Now, also test to make sure that even if we feed data in
105 * little tiny bits we can still make things work. */
106 memset(cepbuf2[0], 0, 5 * DEFAULT_NUM_CEPSTRA * sizeof(**cepbuf2));
112 TEST_EQUAL(0, fe_start_utt(fe));
113 TEST_ASSERT(fe_process_frames(fe, &inptr, &nsamp, cptr, &i) >= 0);
114 printf("inptr %d nsamp %d nfr %d\n", inptr - buf, nsamp, i);
119 TEST_ASSERT(fe_process_frames(fe, &inptr, &nsamp, cptr, &i) >= 0);
120 printf("inptr %d nsamp %d nfr %d\n", inptr - buf, nsamp, i);
125 TEST_ASSERT(fe_process_frames(fe, &inptr, &nsamp, cptr, &i) >= 0);
126 printf("inptr %d nsamp %d nfr %d\n", inptr - buf, nsamp, i);
131 TEST_ASSERT(fe_process_frames(fe, &inptr, &nsamp, cptr, &i) >= 0);
132 printf("inptr %d nsamp %d nfr %d\n", inptr - buf, nsamp, i);
135 TEST_ASSERT(fe_end_utt(fe, *cptr, &nfr) >= 0);
136 printf("nfr %d\n", nfr);
139 for (i = 0; i < 5; ++i) {
142 for (j = 0; j < DEFAULT_NUM_CEPSTRA; ++j) {
144 MFCC2FLOAT(cepbuf1[i][j]),
145 MFCC2FLOAT(cepbuf2[i][j]));
146 TEST_EQUAL_FLOAT(cepbuf1[i][j], cepbuf2[i][j]);
151 /* And now, finally, test fe_process_utt() */
154 TEST_EQUAL(0, fe_start_utt(fe));
155 TEST_ASSERT(fe_process_utt(fe, inptr, 256, &cptr, &nfr) >= 0);
156 printf("i %d nfr %d\n", i, nfr);
158 memcpy(cepbuf2[i], cptr[0], nfr * DEFAULT_NUM_CEPSTRA * sizeof(**cptr));
162 TEST_ASSERT(fe_process_utt(fe, inptr, 256, &cptr, &nfr) >= 0);
163 printf("i %d nfr %d\n", i, nfr);
165 memcpy(cepbuf2[i], cptr[0], nfr * DEFAULT_NUM_CEPSTRA * sizeof(**cptr));
169 TEST_ASSERT(fe_process_utt(fe, inptr, 256, &cptr, &nfr) >= 0);
170 printf("i %d nfr %d\n", i, nfr);
172 memcpy(cepbuf2[i], cptr[0], nfr * DEFAULT_NUM_CEPSTRA * sizeof(**cptr));
176 TEST_ASSERT(fe_process_utt(fe, inptr, 256, &cptr, &nfr) >= 0);
177 printf("i %d nfr %d\n", i, nfr);
179 memcpy(cepbuf2[i], cptr[0], nfr * DEFAULT_NUM_CEPSTRA * sizeof(**cptr));
183 TEST_ASSERT(fe_end_utt(fe, cepbuf2[i], &nfr) >= 0);
184 printf("i %d nfr %d\n", i, nfr);
187 for (i = 0; i < 5; ++i) {
190 for (j = 0; j < DEFAULT_NUM_CEPSTRA; ++j) {
192 MFCC2FLOAT(cepbuf1[i][j]),
193 MFCC2FLOAT(cepbuf2[i][j]));
194 TEST_EQUAL_FLOAT(cepbuf1[i][j], cepbuf2[i][j]);
199 ckd_free_2d(cepbuf1);
200 ckd_free_2d(cepbuf2);