Initial import to Tizen
[profile/ivi/sphinxbase.git] / test / unit / test_fe / test_pitch.c
1 #include <stdio.h>
2
3 #include "yin.h"
4 #include "ckd_alloc.h"
5
6 #include "test_macros.h"
7
8 int
9 main(int argc, char *argv[])
10 {
11         /* This is 11025Hz data (yikes) */
12         static const int frame_shift = 110, frame_size = 265;
13         FILE *raw;
14         yin_t *pe;
15         int16 *buf;
16         size_t nsamp, start;
17         uint16 period, bestdiff;
18         int nfr;
19
20         /* To make life easier, read the whole thing. */
21         TEST_ASSERT(raw = fopen(TESTDATADIR "/chan3.raw", "rb"));
22         fseek(raw, 0, SEEK_END);
23         nsamp = ftell(raw) / 2;
24         buf = ckd_calloc(nsamp, 2);
25         fseek(raw, 0, SEEK_SET);
26         TEST_EQUAL(nsamp, fread(buf, 2, nsamp, raw));
27         fclose(raw);
28
29         TEST_ASSERT(pe = yin_init(frame_size, 0.1, 0.2, 2));
30         yin_start(pe);
31         nfr = 0;
32         for (start = 0; start + frame_size < nsamp; start += frame_shift) {
33                 yin_write(pe, buf + start);
34                 if (yin_read(pe, &period, &bestdiff)) {
35                         if (bestdiff < 0.2 * 32768)
36                                 printf("%d ", period ? 11025/period : 0);
37                         else
38                                 printf("0 ");
39                         ++nfr;
40                 }
41         }
42         yin_end(pe);
43         while (yin_read(pe, &period, &bestdiff)) {
44                 if (bestdiff < 0.2 * 32768)
45                         printf("%d ", period ? 11025/period : 0);
46                 else
47                         printf("0 ");
48                 ++nfr;
49         }
50         printf("\n");
51         yin_free(pe);
52         ckd_free(buf);
53
54         return 0;
55 }