arduino-audio-tools
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
Filter.h File Reference
#include <math.h>
#include "AudioToolsConfig.h"
#include "AudioTools/CoreAudio/AudioLogger.h"

Go to the source code of this file.

Classes

class  BandPassFilter< T >
 Second-order band-pass filter (BiQuad DF2). Passes frequencies near the center frequency and attenuates those further away. The bandwidth is controlled by the Q factor: higher Q produces a narrower passband. Coefficients are derived from the Audio EQ Cookbook. More...
 
class  BandPassFilterDF1< T >
 Second-order band-pass filter (BiQuad DF1). Same coefficients as BandPassFilter; use this (not BandPassFilter) when T is a bounded fixed-point type like q1_14_t – see LowPassFilterDF1 for why. More...
 
struct  BiQuadCoeffs
 Biquad coefficients, always computed in float regardless of the filter's sample type T. Intermediate values like the angular cutoff frequency w0 range up to PI (~3.14) at Nyquist, which overflows bounded fixed-point sample types like q1_14_t (range ~[-2,2)); only the final, range-safe coefficients (typically within [-2,2) for a stable filter) get cast into T when assigned to a BiQuadDF1/BiQuadDF2 instance. More...
 
class  BiQuadDF1< T >
 Second-order IIR filter in Direct Form I. Maintains separate input and output histories (x and y delay lines). Requires more memory than DF2 but is less susceptible to quantization issues with fixed-point arithmetic. More...
 
class  BiQuadDF2< T >
 Second-order IIR filter in Direct Form II. Uses a single delay line, requiring less memory than DF1. This is the base class for the ready-to-use filter types (LowPassFilter, HighPassFilter, BandPassFilter, NotchFilter, LowShelfFilter, HighShelfFilter) which compute their coefficients from frequency, sample rate and Q/gain parameters. More...
 
class  Filter< T >
 Abstract filter interface definition. Subclasses implement process() to transform audio samples one at a time. Use reset() to clear internal state (e.g. delay lines) without changing the filter coefficients. More...
 
class  FilterChain< T, N >
 A cascade of N arbitrary filters applied in series. Each sample is passed through all filters in order. The caller owns the filter pointers and must ensure they outlive the chain. More...
 
class  FIR< T >
 Finite Impulse Response (FIR) filter. Performs convolution of the input signal with a set of feedforward coefficients b[]. For integer types, an optional scaling factor is applied to preserve precision. You can use https://www.arc.id.au/FilterDesign.html to design the coefficients. More...
 
class  HighPassFilter< T >
 Second-order high-pass filter (BiQuad DF2). Attenuates frequencies below the cutoff frequency. Coefficients are derived from the Audio EQ Cookbook. More...
 
class  HighPassFilterDF1< T >
 Second-order high-pass filter (BiQuad DF1). Same coefficients as HighPassFilter; use this (not HighPassFilter) when T is a bounded fixed-point type like q1_14_t – see LowPassFilterDF1 for why. More...
 
class  HighShelfFilter< T >
 Second-order high-shelf filter (BiQuad DF2). Boosts or cuts frequencies above the shelf frequency by the specified gain (in dB) while leaving lower frequencies unchanged. Commonly used in tone controls and equalization. Coefficients are derived from the Audio EQ Cookbook. More...
 
class  HighShelfFilterDF1< T >
 Second-order high-shelf filter (BiQuad DF1). Same coefficients as HighShelfFilter. NOTE: unlike the other DF1 filters here, this is NOT a working fix for q1_14_t (or similar bounded fixed-point types) – see the. More...
 
class  IIR< T >
 Infinite Impulse Response (IIR) filter. Uses both feedforward (b[]) and feedback (a[]) coefficients. The a[0] coefficient is used to normalize all other coefficients. For integer types, an optional scaling factor is applied to preserve precision. More...
 
class  LowPassFilter< T >
 Second-order low-pass filter (BiQuad DF2). Attenuates frequencies above the cutoff frequency. Coefficients are derived from the Audio EQ Cookbook. More...
 
class  LowPassFilterDF1< T >
 Second-order low-pass filter (BiQuad DF1). Same coefficients as LowPassFilter, but built on BiQuadDF1, whose separate x[]/y[] delay lines stay bounded to the actual signal range – unlike DF2's single delay line, which can need far more dynamic range than the signal for low cutoff/ sampleRate ratios. Use this (not LowPassFilter) when T is a bounded fixed-point type like q1_14_t. More...
 
class  LowShelfFilter< T >
 Second-order low-shelf filter (BiQuad DF2). Boosts or cuts frequencies below the shelf frequency by the specified gain (in dB) while leaving higher frequencies unchanged. Commonly used in tone controls and equalization. Coefficients are derived from the Audio EQ Cookbook. More...
 
class  LowShelfFilterDF1< T >
 Second-order low-shelf filter (BiQuad DF1). Same coefficients as LowShelfFilter. NOTE: switching to DF1 does NOT make this reliable for bounded fixed-point types like q1_14_t – shelf coefficients scale with the linear gain factor and can exceed the type's range even at modest gain settings; this is a coefficient headroom problem, not the DF2 state-headroom problem DF1 fixes elsewhere. Watch for the LOGE warning from checkCoeffRange() in begin(). More...
 
class  NoFilter< T >
 Passes the input through unchanged. Useful as a placeholder when a Filter is required but no processing is desired. More...
 
class  NotchFilter< T >
 Second-order notch (band-reject) filter (BiQuad DF2). Rejects frequencies near the center frequency and passes those further away. Useful for removing a specific unwanted frequency (e.g. mains hum at 50/60 Hz). Coefficients are derived from the Audio EQ Cookbook. More...
 
class  NotchFilterDF1< T >
 Second-order notch (band-reject) filter (BiQuad DF1). Same coefficients as NotchFilter; use this (not NotchFilter) when T is a bounded fixed-point type like q1_14_t – see LowPassFilterDF1 for why. More...
 
class  SOSFilter< T, N >
 Second Order Sections (SOS) filter — a cascade of N BiQuad DF2 stages. Higher-order filters should be decomposed into second-order sections to avoid numerical instability. Each section has its own b[3]/a[3] coefficients and optional gain. Tools like scipy.signal.butter(..., output='sos') or MATLAB's tf2sos produce the required coefficient arrays. More...
 

Namespaces

namespace  audio_tools
 Generic Implementation of sound input and output for desktop environments using portaudio.
 

Functions

BiQuadCoeffs calculateBandPassCoeffs (float frequency, float sampleRate, float q)
 Computes the b0/b1/b2/a1/a2 biquad coefficients for a band-pass filter.
 
BiQuadCoeffs calculateHighPassCoeffs (float frequency, float sampleRate, float q)
 Computes the b0/b1/b2/a1/a2 biquad coefficients for a high-pass filter.
 
BiQuadCoeffs calculateHighShelfCoeffs (float frequency, float sampleRate, float gain, float slope)
 Computes the b0/b1/b2/a1/a2 biquad coefficients for a high-shelf filter.
 
BiQuadCoeffs calculateLowPassCoeffs (float frequency, float sampleRate, float q)
 Computes the b0/b1/b2/a1/a2 biquad coefficients for a low-pass filter.
 
BiQuadCoeffs calculateLowShelfCoeffs (float frequency, float sampleRate, float gain, float slope)
 Computes the b0/b1/b2/a1/a2 biquad coefficients for a low-shelf filter.
 
BiQuadCoeffs calculateNotchCoeffs (float frequency, float sampleRate, float q)
 
template<typename T >
void checkCoeffRange (const BiQuadCoeffs &c)
 Warns (once per call, via LOGE) about any coefficient that doesn't survive being stored in T. This is expected/harmless for float or double (T can represent the value, roundtrip is exact); it's a real problem for a bounded fixed-point type like q1_14_t (range ~[-2,2)), where a coefficient outside that range silently saturates instead of erroring, quietly producing a wrong filter – e.g. shelf filters, whose coefficients scale with the linear gain factor and can exceed +-2 even at modest gains (a limitation of q1_14_t's 1-bit-of-headroom range, not of DF1 vs DF2; see LowShelfFilterDF1/HighShelfFilterDF1).