/usr/include/speech_tools/sigpr/EST_filter.h is in libestools2.1-dev 1:2.1~release-8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | /*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
#ifndef __EST_FILTER_H__
#define __EST_FILTER_H__
#include "EST_Wave.h"
#include "EST_FMatrix.h"
#include "EST_Track.h"
#define DEFAULT_PRE_EMPH_FACTOR 0.95
#define DEFAULT_FILTER_ORDER 199
/** @defgroup FilterFunctions Filter Functions
*/
/**@defgroup FIRfilters FIR filters
@ingroup FilterFunctions
Finite impulse response (FIR) filters which are useful for band-pass,
low-pass and high-pass filtering.
FIR filters perform the following operation:
\f[y_t=\sum_{i=0}^{O-1} c_i \; x_{t-i}\f]
where \f$O\f$ is the filter order, \f$c_i\f$ are the filter coefficients,
\f$x_t\f$ is the input at time \f$t\f$ and \f$y_t\f$ is the output at time
\f$t\f$. Functions are provided for designing the filter (i.e. finding
the coefficients).
*/
///@{
/** General purpose FIR filter. This function will filter the
waveform `sig` with a previously designed filter, given as
`numerator`. The filter coefficients can be designed using one of the
designed functions, e.g. \ref design_FIR_filter.
@see design_FIR_filter, design_lowpass_FIR_filter, design_highpass_FIR_filter,
@see FIRfilter, FIRlowpass_filter, FIRhighpass_filter
*/
void FIRfilter(EST_Wave &in_sig, const EST_FVector &numerator,
int delay_correction=0);
/** General purpose FIR filter. This function will filter the
waveform `sig` with a previously designed filter, given as `numerator`.
The filter coefficients can be designed using one of the
designed functions, e.g. \ref design_FIR_filter.
@see design_FIR_filter, design_lowpass_FIR_filter, design_highpass_FIR_filter,
@see FIRfilter, FIRlowpass_filter, FIRhighpass_filter
*/
void FIRfilter(const EST_Wave &in_sig, EST_Wave &out_sig,
const EST_FVector &numerator, int delay_correction=0);
/** General purpose FIR double (zero-phase) filter. This function
will double filter the waveform `sig` with a previously designed
filter, given as `numerator`. The filter coefficients can be
designed using one of the designed functions,
e.g. \ref design_FIR_filter. Double filtering is performed by
filtering the signal normally, reversing the waveform, filtering
again and reversing the waveform again. Normal filtering will impose a
lag on the signal depending on the order of the filter. By filtering
the signal forwards and backwards, the lags cancel each other out and
the output signal is in phase with the input signal.
@see design_FIR_filter, design_lowpass_FIR_filter, design_highpass_FIR_filter,
@see FIRfilter, FIRlowpass_filter, FIRhighpass_filter
*/
void FIR_double_filter(EST_Wave &in_sig, EST_Wave &out_sig,
const EST_FVector &numerator);
/** Quick function for one-off low pass filtering. If repeated lowpass
filtering is needed, first design the required filter using
\ref design_lowpass_filter, and then use \ref FIRfilter to do the actual
filtering.
@see design_FIR_filter, design_lowpass_FIR_filter, design_highpass_FIR_filter, FIRfilter, FIRhighpass_filter, FIRlowpass_filter
@param sigin input waveform, which will be overwritten
@param freq
@param order number of filter coefficients, eg. 99
*/
void FIRlowpass_filter(EST_Wave &sigin, int freq, int order=DEFAULT_FILTER_ORDER);
/** Quick function for one-off low pass filtering. If repeated lowpass
filtering is needed, first design the required filter using
\ref design_lowpass_filter, and then use \ref FIRfilter to do the actual
filtering.
@param in_sig input waveform
@param out_sig output waveform
@param freq cutoff frequency in Hertz
@param order number of filter coefficients , e.g. 99
@see design_FIR_filter, design_lowpass_FIR_filter, design_highpass_FIR_filter, FIRfilter, FIRhighpass_filter
*/
void FIRlowpass_filter(const EST_Wave &in_sig, EST_Wave &out_sig,
int freq, int order=DEFAULT_FILTER_ORDER);
/** Quick function for one-off high pass filtering. If repeated lowpass
filtering is needed, first design the required filter using
design_lowpass_filter, and then use FIRfilter to do the actual
filtering.
@param in_sig input waveform, which will be overwritten
@param freq cutoff frequency in Hertz
@param order number of filter coefficients, eg. 99
@see design_FIR_filter, design_lowpass_FIR_filter, design_highpass_FIR_filter
@see FIRfilter, FIRlowpass_filter, FIRhighpass_filter
*/
void FIRhighpass_filter(EST_Wave &in_sig, int freq, int order);
/** Quick function for one-off high pass filtering. If repeated highpass
filtering is needed, first design the required filter using
design_highpass_filter, and then use FIRfilter to do the actual
filtering.
@param in_sig input waveform
@param out_sig output waveform
@param freq cutoff frequency in Hertz
@param order number of filter coefficients, eg. 99
@see design_FIR_filter, design_lowpass_FIR_filter, design_highpass_FIR_filter
@see FIRfilter, FIRlowpass_filter, FIRhighpass_filter
*/
void FIRhighpass_filter(const EST_Wave &sigin, EST_Wave &out_sig,
int freq, int order=DEFAULT_FILTER_ORDER);
/** Quick function for one-off double low pass filtering.
Normal low pass filtering (\ref FIRlowpass_filter) introduces a time delay.
This function filters the signal twice, first forward and then backwards,
which ensures a zero phase lag. Hence the order parameter need only be
half what it is for (\ref FIRlowpass_filter to achieve the same effect.
@param in_sig input waveform, which will be overwritten
@param freq cutoff frequency in Hertz
@param order number of filter coefficients, eg. 99
@see FIRhighpass_filter
*/
void FIRhighpass_double_filter(EST_Wave &sigin, int freq,
int order=DEFAULT_FILTER_ORDER);
/** Quick function for one-off double low pass filtering.
Normal low pass filtering (\ref FIRlowpass_filter) introduces a time delay.
This function filters the signal twice, first forward and then backwards,
which ensures a zero phase lag. Hence the order parameter need only be
half what it is for (\ref FIRlowpass_filter) to achieve the same effect.
@param in_sig input waveform
@param out_sig output waveform
@param freq cutoff frequency in Hertz
@param order number of filter coefficients, eg. 99
@see FIRhighpass_filter
*/
void FIRhighpass_double_filter(const EST_Wave &int_sig, EST_Wave &out_sig,
int freq, int order=DEFAULT_FILTER_ORDER);
/** Quick function for one-off zero phase high pass filtering.
Normal high pass filtering (\ref FIRhighpass_filter) introduces a time delay.
This function filters the signal twice, first forward and then backwards,
which ensures a zero phase lag. Hence the order parameter need only be
half what it is for (\ref FIRhighpass_filter) to achieve the same effect.
@param in_sig input waveform, which will be overwritten
@param freq cutoff frequency in Hertz
@param order number of filter coefficients, eg. 99
@see FIRlowpass_filter
*/
void FIRlowpass_double_filter(EST_Wave &sigin, int freq,
int order=DEFAULT_FILTER_ORDER);
/** Quick function for one-off zero phase high pass filtering.
Normal high pass filtering (\ref FIRhighpass_filter) introduces a time delay.
This function filters the signal twice, first forward and then backwards,
which ensures a zero phase lag. Hence the order parameter need only be
half what it is for (\ref FIRhighpass_filter) to achieve the same effect.
@param in_sig input waveform
@param out_sig output waveform
@param freq cutoff frequency in Hertz
@param order number of filter coefficients, eg. 99
@see FIRlowpass_filter
*/
void FIRlowpass_double_filter(const EST_Wave &in_sig, EST_Wave &out_sig,
int freq, int order=DEFAULT_FILTER_ORDER);
///@}
/**@defgroup LinearPredictionfilters Linear Prediction filters
@ingroup FilterFunctions
The linear prediction filters are used for the analysis and synthesis of
waveforms according the to linear prediction all-pole model.
The linear prediction states that the value of a signal at a given
point is equal to a weighted sum of the previous P values, plus a
correction value for that point:
\f[s_{n} = \sum_{i=1}^{P} a_{i}.s_{n-i} + e_{n}\f]
Given a set of coefficients and the original signal, we can use this
equation to work out e, the *residual*. Conversely given the
coefficients and the residual signal, an estimation of the original
signal can be calculated.
If a single set of coefficients were used for the entire waveform, the
filtering process would be simple. It is usual however to have a
different set of coefficients for every frame, and there are many
possible ways to switch from one coefficient set to another so as not
to cause discontinuities at the frame boundaries.
*/
///@{
/** Synthesize a signal from a single set of linear prediction
coefficients and the residual values.
@param sig the waveform to be synthesized
@param a a single set of LP coefficients
@param res the input residual waveform
*/
void lpc_filter(EST_Wave &sig, EST_FVector &a, EST_Wave &res);
/** Filter the waveform using a single set of coefficients so as to
produce a residual signal.
@param sig the speech waveform to be filtered
@param a a single set of LP coefficients
@param res the output residual waveform
*/
void inv_lpc_filter(EST_Wave &sig, EST_FVector &a, EST_Wave &res);
/** Synthesize a signal from a track of linear prediction coefficients.
This function takes a set of LP frames and a residual and produces a
synthesized signal.
For each frame, the function picks an end point, which is half-way
between the current frame's time position and the next frame's. A
start point is defined as being the previous frame's end. Using these
two values, a portion of residual is extracted and passed to
\ref lpc_filter along with the LP coefficients for that frame. This
function writes directly into the signal for the values between start
and end;
@param sig the waveform to be synthesized
@param lpc a track of time positioned LP coefficients
@param res the input residual waveform
*/
void lpc_filter_1(EST_Track &lpc, EST_Wave & res, EST_Wave &sig);
/** Synthesize a signal from a track of linear prediction coefficients.
This function takes a set of LP frames and a residual and produces a
synthesized signal.
This is functionally equivalent to \ref lpc_filter_1 except it
reduces the residual by 0.5 before filtering. Importantly it is
about three times faster than \ref lpc_filter_1 but in doing so uses
direct C buffers rather than the neat C++ access function. This
function should be regarded as temporary and will be deleted after
we restructure the low level classes to give better access.
@param sig the waveform to be synthesized
@param lpc a track of time positioned LP coefficients
@param res the input residual waveform
*/
void lpc_filter_fast(EST_Track &lpc, EST_Wave & res, EST_Wave &sig);
/** Produce a residual from a track of linear prediction coefficients
and a signal using an overlap add technique.
For each frame, the function estimates the local pitch period and
picks a start point one period before the current time position and an
end point one period after it.
A portion of residual corresponding to these times is then produced
using \ref inv_lpc_filter. The resultant section of residual is then
overlap-added into the main residual wave object.
@param sig the speech waveform to be filtered
@param lpc a track of time positioned LP coefficients
@param res the output residual waveform
*/
void inv_lpc_filter_ola(EST_Wave &sig, EST_Track &lpc, EST_Wave &res);
///@}
/**@defgroup PrePostEmphasisfilters Pre/Post Emphasis filters.
@ingroup FilterFunctions
@brief These functions adjust the spectral tilt of the input waveform.
*/
///@{
/** Pre-emphasis filtering. This performs simple high pass
filtering with a one tap filter of value `a`. Normal values of a
range between 0.95 and 0.99. */
void pre_emphasis(EST_Wave &sig, float a=DEFAULT_PRE_EMPH_FACTOR);
/** Pre-emphasis filtering. This performs simple high pass
filtering with a one tap filter of value `a`. Normal values of a
range between 0.95 and 0.99. */
void pre_emphasis(EST_Wave &sig, EST_Wave &out,
float a=DEFAULT_PRE_EMPH_FACTOR);
/** Post-emphasis filtering. This performs simple low pass
filtering with a one tap filter of value a. Normal values of a range
between 0.95 and 0.99. The same values of `a` should be used when
pre- and post-emphasizing the same signal. */
void post_emphasis(EST_Wave &sig, float a=DEFAULT_PRE_EMPH_FACTOR);
/** Post-emphasis filtering. This performs simple low pass
filtering with a one tap filter of value a. Normal values of a range
between 0.95 and 0.99. The same values of `a` should be used when
pre- and post-emphasizing the same signal. */
void post_emphasis(EST_Wave &sig, EST_Wave &out,
float a=DEFAULT_PRE_EMPH_FACTOR);
///@}
/**@defgroup Miscellaneousfilters Miscellaneous filters.
@ingroup FilterFunctions
@brief Some of these filters are non-linear and therefore don't fit the normal paradigm.
*/
///@{
/** Filters the waveform by means of median smoothing.
This is a sort of low pass filter which aims to remove extreme values.
Median smoothing works examining each sample in the wave, taking all
the values in a window of size `n` around that sample, sorting
them and replacing that sample with the middle ranking sample in the
sorted samples.
@param c waveform to be filtered
@param n size of smoothing window
*/
void simple_mean_smooth(EST_Wave &c, int n);
///@}
#endif /* __EST_FILTER_H__ */
|