Configure FFT Size and Window in FFmpeg firequalizer

The firequalizer filter in FFmpeg uses finite impulse response (FIR) filtering via Fast Fourier Transform (FFT) convolution to shape audio frequencies. This article explains how to select the FFT window function using the wfunc option and how to control the effective FFT size using the accuracy parameter to balance frequency resolution against processing latency.

Understanding FFT Size in firequalizer

Unlike some frequency filters that accept an explicit sample count for the FFT buffer, firequalizer manages its FFT size indirectly using the accuracy parameter. The accuracy parameter defines the frequency resolution in Hertz (Hz).

FFmpeg calculates the required FFT length based on the audio sample rate divided by the target accuracy:

\[\text{FFT Size} \approx \frac{\text{Sample Rate}}{\text{Accuracy}}\]

  • Default Value: accuracy=5 (5 Hz resolution).
  • Smaller Values (e.g., accuracy=1): Produce a larger FFT size, giving fine-grained control over low frequencies at the cost of higher latency and increased CPU usage.
  • Larger Values (e.g., accuracy=20): Produce a smaller FFT size, lowering latency and CPU load, but reducing low-frequency precision.

For a 48,000 Hz audio stream, an accuracy of 5 results in an internal FFT size of approximately 16,384 samples (rounded to the nearest power of two suitable for convolution).

Selecting the Window Function

The wfunc parameter dictates the spectral leakage and dynamic range of the filter by specifying which mathematical window to apply to the FIR coefficients.

Supported values for wfunc include:

  • rectangular: No smoothing; offers the narrowest main lobe but high spectral leakage.
  • hann: Default option; offers a good balance between transition bandwidth and sidelobe suppression.
  • hamming: Similar to Hann, optimized to cancel the first sidelobe.
  • blackman: Higher attenuation of sidelobes, minimizing frequency bleed between adjacent equalization bands.
  • nuttall: Very low sidelobe levels for high dynamic range precision.
  • flattop: Best amplitude accuracy, commonly used for calibration.
  • kaiser: Tunable tradeoff between resolution and dynamic range.
  • tukey: Tapered cosine window.

Configuration Examples

Example 1: High-Resolution Mastering Filter

To create an equalization curve with a Blackman window and a fine 2 Hz frequency resolution (translating to a large FFT size for precise low-end adjustments):

ffmpeg -i input.wav -af "firequalizer=gain='if(lt(f,100), 4, 0)':wfunc=blackman:accuracy=2" output.wav

Example 2: Low-Latency, Fast Processing

To minimize delay and resource usage, increase the accuracy value (yielding a smaller FFT size) and use a standard Hann window:

ffmpeg -i input.wav -af "firequalizer=gain='gain_interpolate(f)':gain_entry='0 0, 1000 -3, 8000 2':wfunc=hann:accuracy=20" output.wav

Example 3: Flat-Top Window for Linear Calibration

If maintaining flat band responses without ripple is critical:

ffmpeg -i input.wav -af "firequalizer=gain='0':wfunc=flattop:accuracy=4" output.wav

Trade-Offs to Consider

  1. Pre-Echo and Delay: Lowering accuracy increases FFT length, which introduces higher processing latency and potential time-domain pre-ringing (pre-echo) around sharp transients.
  2. Frequency Smearing: Raising accuracy too high results in coarse frequency bins, causing narrow equalization curves (like notch filters) to spread wider than intended.