Edinburgh Speech Tools  2.1-release
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sigfilter_main.cc
1 /*************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1995,1996 */
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 /* THE UNIVERSITY OF EDINBURGH 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 THE UNIVERSITY OF EDINBURGH 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 : Paul Taylor */
34 /* Date : April 1995 */
35 /*-----------------------------------------------------------------------*/
36 /* Filter signals */
37 /* */
38 /*=======================================================================*/
39 
40 #include <cstdlib>
41 #include <iostream>
42 #include <cmath>
43 #include "EST_Wave.h"
44 #include "EST_cmd_line.h"
45 #include "EST_cmd_line_options.h"
46 #include "EST_sigpr.h"
47 #include "EST_wave_aux.h"
48 
49 void inv_filter_ola(EST_Wave &sig, EST_Track &lpc, EST_Wave &res);
50 void frame_filter(EST_Wave &sig, EST_Track &lpc, EST_Wave &res);
51 void inv_lpc_filter_ola(EST_Wave &in_sig, EST_Track &lpc, EST_Wave &out_sig);
52 
53 void FIR_double_filter(EST_Wave &in_sig, EST_Wave &out_sig,
54  const EST_FVector &numerator);
55 
56 
57 int main (int argc, char *argv[])
58 {
59  EST_Wave sig, fsig;
60  EST_String in_file("-"), out_file("-"), op_file(""), test;
61  EST_Option al;
63  EST_Track filter;
64 
65  parse_command_line
66  (argc, argv,
67  EST_String("[input file0] -o [output file]\n") +
68  "Summary: filter waveform files\n"
69  "use \"-\" to make input and output files stdin/out\n"
70  "-h Options help\n"+
71  options_wave_input()+ "\n"+
72  options_wave_output()+ "\n"
73  "-scale <float> Scaling factor. Increase or descrease the amplitude\n"
74  " of the whole waveform by the factor given\n\n"
75 
76  "-scaleN <float> Scaling factor with normalization. \n"
77  " The waveform is scaled to its maximum level, after which \n"
78  " it is scaled by the factor given\n\n"
79  "-double Perform double filtering by applying a forward filter,\n"
80  " then a backward filter, leaving the filtered signla in phase\n"
81  " with the original\n\n"
82  "-lpfilter <int> Low pass filter, with cutoff frequency in Hz \n"
83  " Filtering is performed by a FIR filter which is built at run \n"
84  " time. The order of the filter can be given by -forder. The \n"
85  " default value is 199\n\n"
86 
87  "-hpfilter <int> High pass filter, with cutoff frequency in Hz \n"
88  " Filtering is performed by a FIR filter which is \n"
89  " built at run time. The order of the filter can \n"
90  " be given by -forder. The default value is 199.\n\n"
91 
92  "-forder <int> Order of FIR filter used for lpfilter and \n"
93  " hpfilter. This must be ODD. Sensible values range \n"
94  " from 19 (quick but with a shallow rolloff) to 199 \n"
95  " (slow but with a steep rolloff). The default is 199.\n\n"
96  "-lpcfilter <ifile> Track file containing lpc filter coefficients\n\n"
97  "-firfilter <ifile> File containing a single set of FIR filter\n"
98  " coefficients\n\n"
99  "-inv_filter use filter coefficients for inverse filtering\n\n",
100  files, al);
101 
102  out_file = al.present("-o") ? al.val("-o") : (EST_String)"-";
103 
104  if (read_wave(sig, files.first(), al) != format_ok)
105  exit(-1);
106 
107  if (al.present("-s")) // rescale
108  {
109  float scale = al.fval("-s", 0);
110  sig.rescale(scale);
111  }
112  else if (al.present("-scaleN")) // rescale
113  {
114  float scale = al.fval("-scaleN", 0);
115  if ((scale < 0) || (scale > 1.0))
116  {
117  cerr << "ch_wave: -scaleN must be in range 0 to 1" << endl;
118  exit(-1);
119  }
120  sig.rescale(scale,1);
121  }
122 
123  // default is to filter before any resampling etc.
124  // (this may cause problems for multiplexed data !)
125 
126  if (al.present("-lpfilter"))
127  {
128  FIRlowpass_filter(sig, al.ival("-lpfilter"),al.ival("-forder"));
129  fsig = sig;
130  }
131  if (al.present("-hpfilter"))
132  {
133  FIRhighpass_filter(sig,al.ival("-hpfilter"),al.ival("-forder"));
134  fsig = sig;
135  }
136 
137  if (al.present("-lpcfilter"))
138  {
139  filter.load(al.val("-lpcfilter"));
140  if (al.present("-inv_filter"))
141  inv_lpc_filter_ola(sig, filter, fsig);
142  else
143 // frame_filter(sig, filter, fsig);
144  cout << "not done yet\n";
145  }
146  if (al.present("-firfilter"))
147  {
148  EST_FVector firfilter;
149  firfilter.load(al.val("-firfilter"));
150  if (al.present("-double"))
151  FIR_double_filter(sig, fsig, firfilter);
152  else
153  FIRfilter(sig, fsig, firfilter);
154  }
155 
156  if (write_wave(fsig, out_file, al) != write_ok)
157  {
158  cerr << "sigfilter: failed to write output to \"" << out_file
159  << "\"" << endl;
160  exit(-1);
161  }
162  return 0;
163 }
A class for storing digital waveforms. The waveform is stored as an array of 16 bit shorts...
Definition: EST_Wave.h:64
void FIRfilter(EST_Wave &in_sig, const EST_FVector &numerator, int delay_correction=0)
Definition: filter.cc:334
EST_read_status load(const EST_String &filename)
load vector from file filename.
Definition: EST_FMatrix.cc:681
A vector class for floating point numbers. EST_FVector x should be used instead of float *x wherever ...
Definition: EST_FMatrix.h:118
int ival(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:76
void FIRlowpass_filter(EST_Wave &sigin, int freq, int order=DEFAULT_FILTER_ORDER)
Definition: filter.cc:524
float fval(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:98
void rescale(float gain, int normalize=0)
Definition: EST_Wave.cc:501
void FIR_double_filter(EST_Wave &in_sig, EST_Wave &out_sig, const EST_FVector &numerator)
Definition: filter.cc:406
EST_read_status load(const EST_String name, float ishift=0.0, float startt=0.0)
Definition: EST_Track.cc:1309
void inv_lpc_filter_ola(EST_Wave &in_sig, EST_Track &lpc, EST_Wave &out_sig)
Definition: filter.cc:100
const T & first() const
return const reference to first item in list
Definition: EST_TList.h:154
const int present(const K &rkey) const
Returns true if key is present.
Definition: EST_TKVL.cc:222
void FIRhighpass_filter(EST_Wave &in_sig, int freq, int order)
Definition: filter.cc:532
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
Definition: EST_TKVL.cc:145