Initial import to Tizen
[profile/ivi/sphinxbase.git] / test / unit / test_feat / test_feat_live.c
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4
5 #include <stdio.h>
6 #include <string.h>
7 #include <math.h>
8
9 #include "feat.h"
10 #include "ckd_alloc.h"
11 #include "test_macros.h"
12
13 const mfcc_t data[6][13] = {
14         { FLOAT2MFCC(15.114), FLOAT2MFCC(-1.424), FLOAT2MFCC(-0.953),
15           FLOAT2MFCC(0.186), FLOAT2MFCC(-0.656), FLOAT2MFCC(-0.226),
16           FLOAT2MFCC(-0.105), FLOAT2MFCC(-0.412), FLOAT2MFCC(-0.024),
17           FLOAT2MFCC(-0.091), FLOAT2MFCC(-0.124), FLOAT2MFCC(-0.158), FLOAT2MFCC(-0.197)},
18         { FLOAT2MFCC(14.729), FLOAT2MFCC(-1.313), FLOAT2MFCC(-0.892),
19           FLOAT2MFCC(0.140), FLOAT2MFCC(-0.676), FLOAT2MFCC(-0.089),
20           FLOAT2MFCC(-0.313), FLOAT2MFCC(-0.422), FLOAT2MFCC(-0.058),
21           FLOAT2MFCC(-0.101), FLOAT2MFCC(-0.100), FLOAT2MFCC(-0.128), FLOAT2MFCC(-0.123)},
22         { FLOAT2MFCC(14.502), FLOAT2MFCC(-1.351), FLOAT2MFCC(-1.028),
23           FLOAT2MFCC(-0.189), FLOAT2MFCC(-0.718), FLOAT2MFCC(-0.139),
24           FLOAT2MFCC(-0.121), FLOAT2MFCC(-0.365), FLOAT2MFCC(-0.139),
25           FLOAT2MFCC(-0.154), FLOAT2MFCC(0.041), FLOAT2MFCC(0.009), FLOAT2MFCC(-0.073)},
26         { FLOAT2MFCC(14.557), FLOAT2MFCC(-1.676), FLOAT2MFCC(-0.864),
27           FLOAT2MFCC(0.118), FLOAT2MFCC(-0.445), FLOAT2MFCC(-0.168),
28           FLOAT2MFCC(-0.069), FLOAT2MFCC(-0.503), FLOAT2MFCC(-0.013),
29           FLOAT2MFCC(0.007), FLOAT2MFCC(-0.056), FLOAT2MFCC(-0.075), FLOAT2MFCC(-0.237)},
30         { FLOAT2MFCC(14.665), FLOAT2MFCC(-1.498), FLOAT2MFCC(-0.582),
31           FLOAT2MFCC(0.209), FLOAT2MFCC(-0.487), FLOAT2MFCC(-0.247),
32           FLOAT2MFCC(-0.142), FLOAT2MFCC(-0.439), FLOAT2MFCC(0.059),
33           FLOAT2MFCC(-0.058), FLOAT2MFCC(-0.265), FLOAT2MFCC(-0.109), FLOAT2MFCC(-0.196)},
34         { FLOAT2MFCC(15.025), FLOAT2MFCC(-1.199), FLOAT2MFCC(-0.607),
35           FLOAT2MFCC(0.235), FLOAT2MFCC(-0.499), FLOAT2MFCC(-0.080),
36           FLOAT2MFCC(-0.062), FLOAT2MFCC(-0.554), FLOAT2MFCC(-0.209),
37           FLOAT2MFCC(-0.124), FLOAT2MFCC(-0.445), FLOAT2MFCC(-0.352), FLOAT2MFCC(-0.400)},
38 };
39
40 int
41 main(int argc, char *argv[])
42 {
43         feat_t *fcb;
44         mfcc_t **in_feats, ***out_feats, ***out_feats2, ***optr;
45         int32 i, j, ncep, nfr, nfr1, nfr2;
46
47         in_feats = (mfcc_t **)ckd_alloc_2d_ptr(6, 13, data, sizeof(mfcc_t));
48         out_feats = (mfcc_t ***)ckd_calloc_3d(8, 1, 39, sizeof(mfcc_t));
49         /* Test 1s_c_d_dd features */
50         fcb = feat_init("1s_c_d_dd", CMN_NONE, 0, AGC_NONE, 1, 13);
51         ncep = 6;
52         nfr1 = feat_s2mfc2feat_live(fcb, in_feats, &ncep, 1, 1, out_feats);
53         printf("Processed %d input %d output frames\n", ncep, nfr1);
54         for (i = 0; i < nfr1; ++i) {
55                 printf("%d: ", i);
56                 for (j = 0; j < 39; ++j) {
57                         printf("%.3f ", MFCC2FLOAT(out_feats[i][0][j]));
58                 }
59                 printf("\n");
60         }
61         feat_free(fcb);
62
63         /* Test in "live" mode. */
64         fcb = feat_init("1s_c_d_dd", CMN_NONE, 0, AGC_NONE, 1, 13);
65         optr = out_feats2 = (mfcc_t ***)ckd_calloc_3d(8, 1, 39, sizeof(mfcc_t));
66         nfr2 = 0;
67         ncep = 2;
68         nfr = feat_s2mfc2feat_live(fcb, in_feats, &ncep, TRUE, FALSE, optr);
69         printf("Processed %d input %d output frames\n", ncep, nfr);
70         nfr2 += nfr;
71         for (i = 0; i < nfr; ++i) {
72                 printf("%d: ", i);
73                 for (j = 0; j < 39; ++j) {
74                         printf("%.3f ", MFCC2FLOAT(optr[i][0][j]));
75                 }
76                 printf("\n");
77         }
78         optr += nfr;
79
80         ncep = 2;
81         nfr = feat_s2mfc2feat_live(fcb, in_feats + 2, &ncep, FALSE, FALSE, optr);
82         nfr2 += nfr;
83         printf("Processed %d input %d output frames\n", ncep, nfr);
84         for (i = 0; i < nfr; ++i) {
85                 printf("%d: ", i);
86                 for (j = 0; j < 39; ++j) {
87                         printf("%.3f ", MFCC2FLOAT(optr[i][0][j]));
88                 }
89                 printf("\n");
90         }
91         optr += nfr;
92
93         ncep = 2;
94         nfr = feat_s2mfc2feat_live(fcb, in_feats + 4, &ncep, FALSE, TRUE, optr);
95         nfr2 += nfr;
96         printf("Processed %d input %d output frames\n", ncep, nfr);
97         for (i = 0; i < nfr; ++i) {
98                 printf("%d: ", i);
99                 for (j = 0; j < 39; ++j) {
100                         printf("%.3f ", MFCC2FLOAT(optr[i][0][j]));
101                 }
102                 printf("\n");
103         }
104         optr += nfr;
105         feat_free(fcb);
106
107         TEST_EQUAL(nfr1, nfr2);
108         for (i = 0; i < nfr1; ++i) {
109                 for (j = 0; j < 39; ++j) {
110                         TEST_EQUAL(out_feats[i][0][j], out_feats2[i][0][j]);
111                 }
112         }
113         ckd_free_3d(out_feats2);
114         ckd_free_3d(out_feats);
115         ckd_free(in_feats);
116
117         return 0;
118 }