43 #include "EST_cmd_line.h"
44 #include "EST_cmd_line_options.h"
45 #include "EST_sigpr.h"
46 #include "EST_wave_aux.h"
55 int main (
int argc,
char *argv[])
58 EST_String in_file(
"-"), out_file(
"-"), op_file(
""), test;
66 EST_String(
"[input file0] [input file1] ... -o [output file]\n")+
67 "Summary: change/copy/combine waveform files\n"+
68 "use \"-\" to make input and output files stdin/out\n"+
69 "-h Options help\n\n"+
71 options_wave_output()+
72 "-scale <float> Scaling factor. Increase or descrease the amplitude\n"
73 " of the whole waveform by the factor given\n\n"
75 "-scaleN <float> Scaling factor with normalization. \n"
76 " The waveform is scaled to its maximum level, after which \n"
77 " it is scaled by the factor given\n\n"
79 "-lpfilter <int> Low pass filter, with cutoff frequency in Hz \n"
80 " Filtering is performed by a FIR filter which is built at run \n"
81 " time. The order of the filter can be given by -forder. The \n"
82 " default value is 199\n\n"
84 "-hpfilter <int> High pass filter, with cutoff frequency in Hz \n"
85 " Filtering is performed by a FIR filter which is \n"
86 " built at run time. The order of the filter can \n"
87 " be given by -forder. The default value is 199.\n\n"
89 "-forder <int> Order of FIR filter used for lpfilter and \n"
90 " hpfilter. This must be ODD. Sensible values range \n"+
91 " from 19 (quick but with a shallow rolloff) to 199 \n"
92 " (slow but with a steep rolloff). The default is 199.\n\n"
94 "-fafter Do filtering after other operations such as \n"
95 " resampling (default : filter before other operations)\n\n"
97 "-info Print information about file and header. \n"
98 " This option gives useful information such as file \n"
99 " length, sampling rate, number of channels etc\n"
100 " No output is produced\n\n"
102 "-add A new single channel waveform is created by adding \n"
103 " the corresponding sample points of each input waveform\n\n"
105 "-pc <string> Combine input waveforms to form a single \n"
106 " multichannel waveform. The argument to this option controls \n"
107 " how long the new waveform should be. If the option \n"
108 " is LONGEST, the output wave if the length of the \n"
109 " longest input wave and shorter waves are padded with \n"
110 " zeros at the end. If the option is FIRST, the length \n"
111 " of the new waveform is the length of the first file \n"
112 " on the command line, and subsequent waves are padded \n"
113 " or cut to this length\n\n"
115 "-key <ifile> Label file designating subsections, for use with \n"
116 " -divide. The KEYLAB file is a label file which specifies \n"
117 " where chunks (such as individual sentences) in \n"
118 " a waveform begin and end. See section of wave extraction.\n\n"
120 "-divide Divide a single input waveform into multiple output \n"
121 " waveforms. Each output waveform is extracted from the \n"
122 " input waveform by using the KEYLAB file, which \n"
123 " specifies the start and stop times for each chunk. \n"
124 " The output files are named according to the filename \n"
125 " in the KEYLAB file, with extension given by -ext. See \n"
126 " section on wave extraction\n\n"
128 "-ext <string> File extension for divided waveforms\n\n"
130 "-extract <string> Used in conjunction with -key to extract a \n"
131 " single section of waveform from the input \n"
132 " waveform. The argument is the name of a file given \n"
133 " in the file column of the KEYLAB file.\n",
140 if (read_wave(sig, files.
first(), al) != format_ok)
146 if (files.length() > 1)
148 for (p= files.head()->next(); p != 0; p=p->next())
150 if (read_wave(sigload, files(p), al) != format_ok)
156 if ((downcase(al.
val(
"-pc")) ==
"longest") &&
164 add_waves(sig, sigload);
191 extract_channels(nsig, sig, il);
200 float scale = al.
fval(
"-scale", 0);
203 else if (al.
present(
"-scaleN"))
205 float scale = al.
fval(
"-scaleN", 0);
206 if ((scale < 0) || (scale > 1.0))
208 cerr <<
"ch_wave: -scaleN must be in range 0 to 1" << endl;
221 cerr <<
"Must have key file specified when dividing waveform\n";
224 if (key.
load(al.
val(
"-key")) != format_ok)
227 if (wave_divide(wl, sig, key, al.
val(
"-ext", 0)) == -1)
229 for (p = wl.head(); p; p = p->next())
230 wl(p).save(wl(p).name(), al.
val(
"-otype", 0));
233 else if (al.
present(
"-extract"))
238 cerr <<
"Must have key file specified when dividing waveform\n";
241 if (key.
load(al.
val(
"-key")) != format_ok)
244 if (wave_extract(e, sig, key, al.
val(
"-extract")) == -1)
257 write_wave(sig, out_file, al);
A class for storing digital waveforms. The waveform is stored as an array of 16 bit shorts...
int ival(const EST_String &rkey, int m=1) const
int StrListtoIList(EST_StrList &s, EST_IList &il)
Convert a list of strings to a list of integers.
void FIRlowpass_filter(EST_Wave &sigin, int freq, int order=DEFAULT_FILTER_ORDER)
float fval(const EST_String &rkey, int m=1) const
void rescale(float gain, int normalize=0)
int num_samples() const
return the number of samples in the waveform
void StringtoStrList(EST_String s, EST_StrList &l, EST_String sep)
Convert a EST_String to a EST_StrList by separating tokens in s delimited by the separator sep...
const T & first() const
return const reference to first item in list
const int present(const K &rkey) const
Returns true if key is present.
void FIRhighpass_filter(EST_Wave &in_sig, int freq, int order)
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
void resize(int num_samples, int num_channels=EST_ALL, int set=1)
resize the waveform
EST_read_status load(const EST_String &filename, const EST_String &type="esps")
void resample(int rate)
Resample waveform to rate