Debian Codegraph @

testsuite/combine_waves_main.c

raw
1 /*************************************************************************/
2 /* */
3 /* Language Technologies Institute */
4 /* Carnegie Mellon University */
5 /* Copyright (c) 2003 */
6 /* All Rights Reserved. */
7 /* */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
20 /* permission. */
21 /* */
22 /* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30 /* THIS SOFTWARE. */
31 /* */
32 /*************************************************************************/
33 /* Author: Alan W Black ([email protected]) */
34 /* Date: November 2003 */
35 /*************************************************************************/
36 /* */
37 /* Combine multichannel waveforms into a single waveform file */
38 /*************************************************************************/
39 #include <stdio.h>
40 #include "cst_wave.h"
41 #include "cst_tokenstream.h"
42 #include "cst_args.h"
43
44 float decode_time(const char *ctime)
45 {
46 /* return number of seconds from time */
47
48 return 0.0;
49 }
50
51 cst_val *get_wavelist(const char *wavelistfile)
52 {
53 cst_val *l = 0;
54 cst_tokenstream *ts;
55 const char *token;
56 int i=0;
57
58 ts = ts_open(wavelistfile,
59 cst_ts_default_whitespacesymbols,
60 cst_ts_default_singlecharsymbols,
61 cst_ts_default_prepunctuationsymbols,
62 cst_ts_default_postpunctuationsymbols);
63 if (!ts)
64 {
65 fprintf(stderr,"combine_waves: can't open \"%s\"\n",wavelistfile);
66 return 0;
67 }
68
69 while ((token=ts_get(ts)) != 0)
70 {
71 l = cons_val(string_val(token),l);
72 i++;
73 }
74
75 if (i%2 != 0)
76 {
77 fprintf(stderr,"combine_waves: doesn't have matched pairs \"%s\"\n",wavelistfile);
78 delete_val(l);
79 l = 0;
80 }
81
82 ts_close(ts);
83
84 return val_reverse(l);
85 }
86
87
88 int main(int argc, char **argv)
89 {
90 cst_wave *nw, *all;
91 cst_val *files;
92 const cst_val *w;
93 cst_val *wavelist;
94 cst_features *args;
95 int i,j;
96 float ntime;
97 int stime;
98 const char *nwfile;
99
100 args = new_features();
101 files =
102 cst_args(argv,argc,
103 "usage: combine_waves OPTIONS\n"
104 "Combine waves into single waveform\n"
105 "-o <string> Output waveform\n"
106 "-f <int> Input sample rate (for raw input)\n"
107 "-itype <string> Input type, raw or headered\n"
108 "-wavelist <string> File containing times and wave filenames\n",
109 args);
110
111 wavelist = get_wavelist(get_param_string(args,"-wavelist","-"));
112
113 if (wavelist == 0)
114 return -1;
115
116 all = new_wave();
117 for (w = wavelist; w; w = val_cdr(w))
118 {
119 ntime = decode_time(val_string(val_car(w)));
120 nwfile = val_string(val_car(val_cdr(w)));
121
122 nw = new_wave();
123 if (cst_wave_load_riff(nw,nwfile) != CST_OK_FORMAT)
124 {
125 fprintf(stderr,
126 "combine_waves: can't read file or wrong format \"%s\"\n",
127 nwfile);
128 continue;
129 }
130
131 stime = ntime * nw->sample_rate;
132
133 cst_wave_resize(all,stime+nw->num_samples,1);
134
135 for (i=0,j=stime; i<nw->num_samples; i++,j++)
136 {
137 /* this will cause overflows */
138 all->samples[j] += nw->samples[i];
139 }
140 delete_wave(nw);
141 }
142
143 cst_wave_save_riff(all,get_param_string(args,"-o","-"));
144
145 return 0;
146 }