43 #include "EST_cmd_line.h" 44 #include "EST_cmd_line_options.h" 45 #include "EST_sigpr.h" 46 #include "EST_wave_aux.h" 49 #define sgn(x) (x>0?1:x?-1:0) 103 int main (
int argc,
char *argv[])
106 EST_String in_file(
"-"), out_file(
"-"), op_file(
""), test;
114 EST_String(
"[input file0] [input file1] ... -o [output file]\n")+
115 "Summary: change/copy/combine waveform files\n"+
116 "use \"-\" to make input and output files stdin/out\n"+
117 "-h Options help\n\n"+
118 options_wave_input()+
119 options_wave_output()+
120 "-scale <float> Scaling factor. Increase or descrease the amplitude\n" 121 " of the whole waveform by the factor given\n\n" 123 "-scaleN <float> Scaling factor with normalization. \n" 124 " The waveform is scaled to its maximum level, after which \n" 125 " it is scaled by the factor given\n\n" 127 "-lpfilter <int> Low pass filter, with cutoff frequency in Hz \n" 128 " Filtering is performed by a FIR filter which is built at run \n" 129 " time. The order of the filter can be given by -forder. The \n" 130 " default value is 199\n\n" 132 "-hpfilter <int> High pass filter, with cutoff frequency in Hz \n" 133 " Filtering is performed by a FIR filter which is \n" 134 " built at run time. The order of the filter can \n" 135 " be given by -forder. The default value is 199.\n\n" 137 "-forder <int> Order of FIR filter used for lpfilter and \n" 138 " hpfilter. This must be ODD. Sensible values range \n"+
139 " from 19 (quick but with a shallow rolloff) to 199 \n" 140 " (slow but with a steep rolloff). The default is 199.\n\n" 142 "-fafter Do filtering after other operations such as \n" 143 " resampling (default : filter before other operations)\n\n" 145 "-info Print information about file and header. \n" 146 " This option gives useful information such as file \n" 147 " length, sampling rate, number of channels etc\n" 148 " No output is produced\n\n" 150 "-add A new single channel waveform is created by adding \n" 151 " the corresponding sample points of each input waveform\n\n" 153 "-pc <string> Combine input waveforms to form a single \n" 154 " multichannel waveform. The argument to this option controls \n" 155 " how long the new waveform should be. If the option \n" 156 " is LONGEST, the output wave if the length of the \n" 157 " longest input wave and shorter waves are padded with \n" 158 " zeros at the end. If the option is FIRST, the length \n" 159 " of the new waveform is the length of the first file \n" 160 " on the command line, and subsequent waves are padded \n" 161 " or cut to this length\n\n" 163 "-key <ifile> Label file designating subsections, for use with \n" 164 " -divide. The KEYLAB file is a label file which specifies \n" 165 " where chunks (such as individual sentences) in \n" 166 " a waveform begin and end. See section of wave extraction.\n\n" 168 "-divide Divide a single input waveform into multiple output \n" 169 " waveforms. Each output waveform is extracted from the \n" 170 " input waveform by using the KEYLAB file, which \n" 171 " specifies the start and stop times for each chunk. \n" 172 " The output files are named according to the filename \n" 173 " in the KEYLAB file, with extension given by -ext. See \n" 174 " section on wave extraction\n\n" 176 "-ext <string> File extension for divided waveforms\n\n" 178 "-compress <float> Apply Dynamic Range Compression by factor specified \n" 180 "-extract <string> Used in conjunction with -key to extract a \n" 181 " single section of waveform from the input \n" 182 " waveform. The argument is the name of a file given \n" 183 " in the file column of the KEYLAB file.\n",
190 if (read_wave(sig, files.
first(), al) != format_ok)
196 if (files.length() > 1)
198 for (p= files.head()->next(); p != 0; p=p->next())
200 if (read_wave(sigload, files(p), al) != format_ok)
206 if ((downcase(al.
val(
"-pc")) ==
"longest") &&
214 add_waves(sig, sigload);
229 FIRlowpass_filter(sig,al.
ival(
"-lpfilter"),al.
ival(
"-forder"));
231 FIRhighpass_filter(sig,al.
ival(
"-hpfilter"),al.
ival(
"-forder"));
239 StringtoStrList(al.
val(
"-c"), s,
" ,");
240 StrListtoIList(s, il);
241 extract_channels(nsig, sig, il);
250 float mu = al.
fval(
"-compress" , 0);
258 float scale = al.
fval(
"-scale", 0);
263 float scale = al.
fval(
"-scaleN", 0);
264 if ((scale < 0) || (scale > 1.0))
266 cerr <<
"ch_wave: -scaleN must be in range 0 to 1" << endl;
279 cerr <<
"Must have key file specified when dividing waveform\n";
282 if (key.
load(al.
val(
"-key")) != format_ok)
285 if (wave_divide(wl, sig, key, al.
val(
"-ext", 0)) == -1)
287 for (p = wl.head(); p; p = p->next())
288 wl(p).save(wl(p).name(), al.
val(
"-otype", 0));
291 else if (al.
present(
"-extract"))
296 cerr <<
"Must have key file specified when dividing waveform\n";
299 if (key.
load(al.
val(
"-key")) != format_ok)
302 if (wave_extract(e, sig, key, al.
val(
"-extract")) == -1)
310 FIRlowpass_filter(sig,al.
ival(
"-lpfilter"),al.
ival(
"-forder"));
312 FIRhighpass_filter(sig,al.
ival(
"-hpfilter"),al.
ival(
"-forder"));
315 write_wave(sig, out_file, al);
void rescale(float gain, int normalize=0)
int num_samples() const
return the number of samples in the waveform
float fval(const EST_String &rkey, int m=1) const
const int present(const K &rkey) const
Returns true if key is present.
void resize(int num_samples, int num_channels=EST_ALL, int set=1)
resize the waveform
int ival(const EST_String &rkey, int m=1) const
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
EST_read_status load(const EST_String &filename, const EST_String &type="esps")
void resample(int rate)
Resample waveform to rate
const T & first() const
return const reference to first item in list
void compress(float mu, float limit)
Dynamic Range Compression - SaiKrishna May 2017.