1 #include <stdio.h>
2 #include <sbthread.h>
3 #include <fe.h>
4 #include <ckd_alloc.h>
5 #include <err.h>
6
7 static const arg_t fe_args[] = {
8 waveform_to_cepstral_command_line_macro(),
9 { NULL, 0, NULL, NULL }
10 };
11
12 static int
process(sbthread_t * th)13 process(sbthread_t *th)
14 {
15 FILE *raw;
16 int16 *buf;
17 mfcc_t **cepbuf;
18 size_t nsamps;
19 fe_t *fe;
20 long fsize;
21 int32 nfr;
22
23 if ((fe = fe_init_auto_r(sbthread_config(th))) == NULL)
24 return -1;
25
26 if ((raw = fopen(TESTDATADIR "/chan3.raw", "rb")) == NULL)
27 return -1;
28 fseek(raw, 0, SEEK_END);
29 fsize = ftell(raw);
30 fseek(raw, 0, SEEK_SET);
31 buf = ckd_malloc(fsize);
32 fread(buf, 1, fsize, raw);
33 nsamps = fsize / 2;
34
35 fe_process_utt(fe, buf, nsamps, &cepbuf, &nfr);
36 E_INFO("nfr = %d\n", nfr);
37 fe_free_2d(cepbuf);
38 ckd_free(buf);
39 fclose(raw);
40 fe_free(fe);
41
42 return 0;
43 }
44
45 int
main(int argc,char * argv[])46 main(int argc, char *argv[])
47 {
48 sbthread_t *threads[10];
49 cmd_ln_t *config;
50 int i;
51
52 E_INFO("Processing chan3.raw in 10 threads\n");
53 if ((config = cmd_ln_parse_r(NULL, fe_args, 0, NULL, FALSE)) == NULL)
54 return -1;
55 for (i = 0; i < 10; ++i) {
56 config = cmd_ln_retain(config);
57 threads[i] = sbthread_start(config, process, NULL);
58 }
59 for (i = 0; i < 10; ++i) {
60 int rv;
61 rv = sbthread_wait(threads[i]);
62 E_INFO("Thread %d exited with status %d\n", i, rv);
63 sbthread_free(threads[i]);
64 }
65 cmd_ln_free_r(config);
66 return 0;
67 }
68