Edinburgh Speech Tools 2.4-release
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
49void inv_filter_ola(EST_Wave &sig, EST_Track &lpc, EST_Wave &res);
50void frame_filter(EST_Wave &sig, EST_Track &lpc, EST_Wave &res);
51void inv_lpc_filter_ola(EST_Wave &in_sig, EST_Track &lpc, EST_Wave &out_sig);
52
53void FIR_double_filter(EST_Wave &in_sig, EST_Wave &out_sig,
54 const EST_FVector &numerator);
55
56/** @name <command>sigfilter</command> <emphasis>Filter waveforms</emphasis>
57 * @id sigfilter-manual
58 * @toc
59 */
60
61//@{
62
63/**@name Synopsis
64 */
65//@{
66
67//@synopsis
68
69/**
70<command>sigfilter</command> filters an input waveform and produces a
71output waveform.
72
73*/
74
75//@}
76
77/**@name Options
78 */
79//@{
80
81//@options
82
83//@}
84
85int main (int argc, char *argv[])
86{
87 EST_Wave sig, fsig;
88 EST_String in_file("-"), out_file("-"), op_file(""), test;
89 EST_Option al;
91 EST_Track filter;
92
93 parse_command_line
94 (argc, argv,
95 EST_String("[input file0] -o [output file]\n") +
96 "Summary: filter waveform files\n"
97 "use \"-\" to make input and output files stdin/out\n"
98 "-h Options help\n"+
99 options_wave_input()+ "\n"+
100 options_wave_output()+ "\n"
101 "-scale <float> Scaling factor. Increase or descrease the amplitude\n"
102 " of the whole waveform by the factor given\n\n"
103
104 "-scaleN <float> Scaling factor with normalization. \n"
105 " The waveform is scaled to its maximum level, after which \n"
106 " it is scaled by the factor given\n\n"
107 "-double Perform double filtering by applying a forward filter,\n"
108 " then a backward filter, leaving the filtered signla in phase\n"
109 " with the original\n\n"
110 "-lpfilter <int> Low pass filter, with cutoff frequency in Hz \n"
111 " Filtering is performed by a FIR filter which is built at run \n"
112 " time. The order of the filter can be given by -forder. The \n"
113 " default value is 199\n\n"
114
115 "-hpfilter <int> High pass filter, with cutoff frequency in Hz \n"
116 " Filtering is performed by a FIR filter which is \n"
117 " built at run time. The order of the filter can \n"
118 " be given by -forder. The default value is 199.\n\n"
119
120 "-forder <int> Order of FIR filter used for lpfilter and \n"
121 " hpfilter. This must be ODD. Sensible values range \n"
122 " from 19 (quick but with a shallow rolloff) to 199 \n"
123 " (slow but with a steep rolloff). The default is 199.\n\n"
124 "-lpcfilter <ifile> Track file containing lpc filter coefficients\n\n"
125 "-firfilter <ifile> File containing a single set of FIR filter\n"
126 " coefficients\n\n"
127 "-inv_filter use filter coefficients for inverse filtering\n\n",
128 files, al);
129
130 out_file = al.present("-o") ? al.val("-o") : (EST_String)"-";
131
132 if (read_wave(sig, files.first(), al) != format_ok)
133 exit(-1);
134
135 if (al.present("-s")) // rescale
136 {
137 float scale = al.fval("-s", 0);
138 sig.rescale(scale);
139 }
140 else if (al.present("-scaleN")) // rescale
141 {
142 float scale = al.fval("-scaleN", 0);
143 if ((scale < 0) || (scale > 1.0))
144 {
145 cerr << "ch_wave: -scaleN must be in range 0 to 1" << endl;
146 exit(-1);
147 }
148 sig.rescale(scale,1);
149 }
150
151 // default is to filter before any resampling etc.
152 // (this may cause problems for multiplexed data !)
153
154 if (al.present("-lpfilter"))
155 {
156 FIRlowpass_filter(sig, al.ival("-lpfilter"),al.ival("-forder"));
157 fsig = sig;
158 }
159 if (al.present("-hpfilter"))
160 {
161 FIRhighpass_filter(sig,al.ival("-hpfilter"),al.ival("-forder"));
162 fsig = sig;
163 }
164
165 if (al.present("-lpcfilter"))
166 {
167 filter.load(al.val("-lpcfilter"));
168 if (al.present("-inv_filter"))
169 inv_lpc_filter_ola(sig, filter, fsig);
170 else
171// frame_filter(sig, filter, fsig);
172 cout << "not done yet\n";
173 }
174 if (al.present("-firfilter"))
175 {
176 EST_FVector firfilter;
177 firfilter.load(al.val("-firfilter"));
178 if (al.present("-double"))
179 FIR_double_filter(sig, fsig, firfilter);
180 else
181 FIRfilter(sig, fsig, firfilter);
182 }
183
184 if (write_wave(fsig, out_file, al) != write_ok)
185 {
186 cerr << "sigfilter: failed to write output to \"" << out_file
187 << "\"" << endl;
188 exit(-1);
189 }
190 return 0;
191}
EST_read_status load(const EST_String &filename)
load vector from file filename.
Definition: EST_FMatrix.cc:681
float fval(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:98
int ival(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:76
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
Definition: EST_TKVL.cc:145
const int present(const K &rkey) const
Returns true if key is present.
Definition: EST_TKVL.cc:222
const T & first() const
return const reference to first item in list
Definition: EST_TList.h:146
EST_read_status load(const EST_String name, float ishift=0.0, float startt=0.0)
Definition: EST_Track.cc:1309
void rescale(float gain, int normalize=0)
Definition: EST_Wave.cc:517