1 #include <string.h>
2 #include <stdio.h>
3 #include <sbthread.h>
4 #include <strfuncs.h>
5 #include <fe.h>
worker_main(sbthread_t * th)6 #include <ckd_alloc.h>
7 #include <err.h>
8
9 #include "test_macros.h"
10
11 static const arg_t fe_args[] = {
12 waveform_to_cepstral_command_line_macro(),
13 { NULL, 0, NULL, NULL }
14 };
15
16 static int
17 process(sbthread_t *th)
18 {
19 FILE *raw, *logfh;
20 int16 *buf;
21 mfcc_t **cepbuf;
22 size_t nsamps;
23 fe_t *fe;
main(int argc,char * argv[])24 long fsize;
25 int32 nfr;
26 char outfile[16];
27
28 sprintf(outfile, "%03ld.log", (long)sbthread_arg(th));
29 if ((logfh = fopen(outfile, "w")) == NULL)
30 return -1;
31 err_set_logfp(logfh);
32 if ((fe = fe_init_auto_r(sbthread_config(th))) == NULL)
33 return -1;
34 if ((raw = fopen(TESTDATADIR "/chan3.raw", "rb")) == NULL)
35 return -1;
36 fseek(raw, 0, SEEK_END);
37 fsize = ftell(raw);
38 fseek(raw, 0, SEEK_SET);
39 buf = ckd_malloc(fsize);
40 fread(buf, 1, fsize, raw);
41 nsamps = fsize / 2;
42
43 fe_process_utt(fe, buf, nsamps, &cepbuf, &nfr);
44 E_INFO("nfr = %d\n", nfr);
45 fe_free_2d(cepbuf);
46 ckd_free(buf);
47 fclose(raw);
48 fe_free(fe);
49 fclose(logfh);
50
51 return 0;
52 }
53
54 int
55 main(int argc, char *argv[])
56 {
57 sbthread_t *threads[10];
58 cmd_ln_t *config;
59 int i;
60
61 E_INFO("Processing chan3.raw in 10 threads\n");
62 if ((config = cmd_ln_parse_r(NULL, fe_args, 0, NULL, FALSE)) == NULL)
63 return -1;
64 for (i = 0; i < 10; ++i) {
65 config = cmd_ln_retain(config);
66 threads[i] = sbthread_start(config, process, (void *)(long)i);
67 }
68 for (i = 0; i < 10; ++i) {
69 int rv;
70 rv = sbthread_wait(threads[i]);
71 E_INFO("Thread %d exited with status %d\n", i, rv);
72 sbthread_free(threads[i]);
73 }
74 /* Now check to make sure they all created logfiles with the
75 * correct contents. */
76 for (i = 0; i < 10; ++i) {
77 char logfile[16], line[256];
78 FILE *logfh;
79
80 sprintf(logfile, "%03d.log", i);
81 TEST_ASSERT(logfh = fopen(logfile, "r"));
82 while (fgets(line, sizeof(line), logfh)) {
83 string_trim(line, STRING_BOTH);
84 printf("%s: |%s|\n", logfile, line);
85 TEST_EQUAL(0, strcmp(line, "INFO: test_tls_log.c(44): nfr = 1436"));
86 }
87 fclose(logfh);
88 }
89 cmd_ln_free_r(config);
90 return 0;
91 }
92