SAF
Loading...
Searching...
No Matches
saf_utility_filters.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 Leo McCormack
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
15 */
16
28#ifndef SAF_FILTERS_H_INCLUDED
29#define SAF_FILTERS_H_INCLUDED
30
31#ifdef __cplusplus
32extern "C" {
33#endif /* __cplusplus */
34
35#include "saf_utilities.h"
36
37/* ========================================================================== */
38/* Enums */
39/* ========================================================================== */
40
64
73
82
101
102
103/* ========================================================================== */
104/* Misc. Functions */
105/* ========================================================================== */
106
124 int winlength,
125 float* win);
126
156void getOctaveBandCutoffFreqs(float* centreFreqs,
157 int nCentreFreqs,
158 float* cutoffFreqs);
159
172void flattenMinphase(float* x,
173 int len);
174
184void interpolateFiltersH(/* Input arguments */
185 int inFFTsize,
186 int outFFTsize,
187 int nFilters,
188 float_complex* filters_in,
189 /* Output arguments */
190 float_complex* filters_out);
191
193float convertBW2Q(float BW);
194
196float convertQ2BW(float Q);
197
198
199/* ========================================================================== */
200/* IIR Filter Functions */
201/* ========================================================================== */
202
217void biQuadCoeffs(/* input arguments */
218 BIQUAD_FILTER_TYPES filterType,
219 float fc,
220 float fs,
221 float Q,
222 float gain_dB,
223 /* output arguments */
224 float b[3],
225 float a[3]);
226
241void applyBiQuadFilter(/* Input arguments */
242 float b[3],
243 float a[3],
244 float w_z_12[2],
245 float* signal,
246 int nSamples);
247
263void evalBiQuadTransferFunction(/* Input arguments */
264 float b[3],
265 float a[3],
266 float* freqs,
267 int nFreqs,
268 float fs,
269 int mag2dB,
270 /* Output arguments */
271 float* magnitude,
272 float* phase_rad);
273
301void evalIIRTransferFunction(/* Input arguments */
302 double* b,
303 double* a,
304 int nCoeffs,
305 float* freqs,
306 int nFreqs,
307 float fs,
308 int mag2dB,
309 /* Output arguments */
310 float* magnitude,
311 float* phase_rad);
312
340void evalIIRTransferFunctionf(/* Input arguments */
341 float* b,
342 float* a,
343 int nCoeffs,
344 float* freqs,
345 int nFreqs,
346 float fs,
347 int mag2dB,
348 /* Output arguments */
349 float* magnitude,
350 float* phase_rad);
351
371void applyIIR(/* Input arguments */
372 float* in_signal,
373 int nSamples,
374 int nCoeffs,
375 float* b,
376 float* a,
377 /* Input/output arguments */
378 float* wz,
379 /* Output arguments */
380 float* out_signal);
381
411void butterCoeffs(/* Input arguments */
412 BUTTER_FILTER_TYPES filterType,
413 int order,
414 float cutoff1,
415 float cutoff2,
416 float sampleRate,
417 /* Output arguments */
418 double* b_coeffs,
419 double* a_coeffs);
420
448void faf_IIRFilterbank_create(void** phFaF,
449 int order,
450 float* fc,
451 int nCutoffFreqs,
452 float sampleRate,
453 int maxNumSamples);
454
463void faf_IIRFilterbank_apply(void* hFaF,
464 float* inSig,
465 float** outBands,
466 int nSamples);
467
473void faf_IIRFilterbank_flushBuffers(void* hFaF);
474
480void faf_IIRFilterbank_destroy(void** hFaF);
481
482
483/* ========================================================================== */
484/* FIR Filter Functions */
485/* ========================================================================== */
486
525void FIRCoeffs(/* Input arguments */
526 FIR_FILTER_TYPES filterType,
527 int order,
528 float cutoff1,
529 float cutoff2,
530 float sampleRate,
531 WINDOWING_FUNCTION_TYPES windowType,
532 int scalingFLAG,
533 /* Output arguments */
534 float* filter);
535
562void FIRFilterbank(/* Input arguments */
563 int order,
564 float* fc,
565 int nCutoffFreqs,
566 float sampleRate,
567 WINDOWING_FUNCTION_TYPES windowType,
568 int scalingFLAG,
569 /* Output arguments */
570 float* filterbank);
571
572
573#ifdef __cplusplus
574}/* extern "C" */
575#endif /* __cplusplus */
576
577#endif /* SAF_FILTERS_H_INCLUDED */
578
579 /* doxygen addtogroup Utilities */
void faf_IIRFilterbank_destroy(void **hFaF)
Destroys an instance of the Favrot & Faller filterbank.
WINDOWING_FUNCTION_TYPES
Windowing function types.
BUTTER_FILTER_TYPES
Butterworth Infinite Impulse Response (IIR) filter design options.
FIR_FILTER_TYPES
Finite Impulse Response (FIR) filter design options.
BIQUAD_FILTER_TYPES
Bi-quadratic (second-order) IIR filter design options.
void FIRFilterbank(int order, float *fc, int nCutoffFreqs, float sampleRate, WINDOWING_FUNCTION_TYPES windowType, int scalingFLAG, float *filterbank)
Computes a bank of FIR filter coefficients required to divide a signal into frequency bands.
void faf_IIRFilterbank_create(void **phFaF, int order, float *fc, int nCutoffFreqs, float sampleRate, int maxNumSamples)
Computes a bank of IIR filter coefficients required to divide a signal into frequency bands,...
void applyIIR(float *in_signal, int nSamples, int nCoeffs, float *b, float *a, float *wz, float *out_signal)
Applies an IIR filter to a time-domain signal (using the direct form II difference equation)
void getWindowingFunction(WINDOWING_FUNCTION_TYPES type, int winlength, float *win)
Computes the weights of a specific windowing function.
void flattenMinphase(float *x, int len)
Equalises input sequence by its minimum phase form, in order to bring its magnitude response to unity...
void evalIIRTransferFunctionf(float *b, float *a, int nCoeffs, float *freqs, int nFreqs, float fs, int mag2dB, float *magnitude, float *phase_rad)
Computes magnitude and phase response of an IIR filter from its coefficients (floats) at user-specifi...
float convertQ2BW(float Q)
Converts filter Q-factor to octave band-width.
void applyBiQuadFilter(float b[3], float a[3], float w_z_12[2], float *signal, int nSamples)
Applies biQuad filter to an input signal using the direct form II difference equation: https://en....
void biQuadCoeffs(BIQUAD_FILTER_TYPES filterType, float fc, float fs, float Q, float gain_dB, float b[3], float a[3])
Calculates 2nd order IIR filter coefficients [1].
void FIRCoeffs(FIR_FILTER_TYPES filterType, int order, float cutoff1, float cutoff2, float sampleRate, WINDOWING_FUNCTION_TYPES windowType, int scalingFLAG, float *filter)
Computes FIR filter coefficients by windowing.
void butterCoeffs(BUTTER_FILTER_TYPES filterType, int order, float cutoff1, float cutoff2, float sampleRate, double *b_coeffs, double *a_coeffs)
Computes Butterworth IIR filter coefficients [1].
void evalBiQuadTransferFunction(float b[3], float a[3], float *freqs, int nFreqs, float fs, int mag2dB, float *magnitude, float *phase_rad)
Evaluates the 2nd order IIR transfer function at one or more frequencies, returning its magnitude and...
void faf_IIRFilterbank_flushBuffers(void *hFaF)
Zeros the delay lines used during faf_IIRFilterbank_apply()
float convertBW2Q(float BW)
Converts filter octave band-width to Q-factor.
void evalIIRTransferFunction(double *b, double *a, int nCoeffs, float *freqs, int nFreqs, float fs, int mag2dB, float *magnitude, float *phase_rad)
Computes magnitude and phase response of an IIR filter from its coefficients at user-specified freque...
void interpolateFiltersH(int inFFTsize, int outFFTsize, int nFilters, float_complex *filters_in, float_complex *filters_out)
Interpolate filters (w.r.t.
void getOctaveBandCutoffFreqs(float *centreFreqs, int nCentreFreqs, float *cutoffFreqs)
Converts octave band CENTRE frequencies into CUTOFF frequencies.
void faf_IIRFilterbank_apply(void *hFaF, float *inSig, float **outBands, int nSamples)
Applies the Favrot & Faller filterbank.
@ WINDOWING_FUNCTION_RECTANGULAR
Rectangular.
@ WINDOWING_FUNCTION_BLACKMAN_NUTTALL
Blackman-Nuttall.
@ WINDOWING_FUNCTION_BLACKMAN
Blackman.
@ WINDOWING_FUNCTION_BARTLETT
Bartlett.
@ WINDOWING_FUNCTION_HANN
Hann.
@ WINDOWING_FUNCTION_HAMMING
Hamming.
@ WINDOWING_FUNCTION_NUTTALL
Nuttall.
@ WINDOWING_FUNCTION_BLACKMAN_HARRIS
Blackman-Harris.
@ BUTTER_FILTER_BSF
band-stop filter
@ BUTTER_FILTER_LPF
low-pass filter
@ BUTTER_FILTER_HPF
high-pass filter
@ BUTTER_FILTER_BPF
band-pass filter
@ FIR_FILTER_BSF
band-stop filter
@ FIR_FILTER_LPF
low-pass filter
@ FIR_FILTER_HPF
high-pass filter
@ FIR_FILTER_BPF
band-pass filter
@ BIQUAD_FILTER_LPF
low-pass filter (DAFx-Zolzer)
@ BIQUAD_FILTER_LOW_SHELF_EQCB
low-shelving filter (EQ-cookbook)
@ BIQUAD_FILTER_PEAK
peaking filter (DAFx-Zolzer)
@ BIQUAD_FILTER_HPF_EQCB
high-pass filter (EQ-cookbook)
@ BIQUAD_FILTER_PEAK_EQCB
peaking filter (EQ-cookbook)
@ BIQUAD_FILTER_LOW_SHELF
low-shelving filter (DAFx-Zolzer)
@ BIQUAD_FILTER_LPF_EQCB
low-pass filter (EQ-cookbook)
@ BIQUAD_FILTER_HI_SHELF_EQCB
high-shelving filter (EQ-cookbook)
@ BIQUAD_FILTER_HI_SHELF
high-shelving filter (DAFx-Zolzer)
@ BIQUAD_FILTER_HPF
high-pass filter (DAFx-Zolzer)
Main header for the utilities module (SAF_UTILITIES_MODULE)