Table of Contents

Class SpectralSubtractionEnhancer<T>

Namespace
AiDotNet.Audio.Enhancement
Assembly
AiDotNet.dll

Audio enhancer using spectral subtraction for noise reduction.

public class SpectralSubtractionEnhancer<T> : AudioEnhancerBase<T>, IAudioEnhancer<T>

Type Parameters

T

The numeric type used for calculations.

Inheritance
SpectralSubtractionEnhancer<T>
Implements
Inherited Members

Remarks

Spectral subtraction is a classic noise reduction technique that: 1. Estimates the noise spectrum during silent periods 2. Subtracts the noise spectrum from the noisy signal spectrum 3. Reconstructs the cleaned signal

For Beginners: Think of it like this:

Imagine you're in a cafe trying to hear a friend:

  • Noisy signal = friend's voice + cafe background noise
  • If we know what the cafe sounds like alone (noise estimate)
  • We can "subtract" the cafe sound to hear just the friend

Advantages:

  • Simple and fast
  • Low latency (good for real-time)
  • Works well for stationary noise (AC hum, fan noise)

Limitations:

  • Can introduce "musical noise" artifacts (twinkling sounds)
  • Struggles with non-stationary noise (traffic, other speakers)
  • May reduce speech quality if over-applied

This implementation includes:

  • Adaptive noise estimation
  • Spectral flooring (prevents negative magnitudes)
  • Smoothing to reduce musical noise

Constructors

SpectralSubtractionEnhancer(int, int, int, double, double, double, bool, double)

Initializes a new SpectralSubtractionEnhancer with default parameters.

public SpectralSubtractionEnhancer(int sampleRate = 16000, int fftSize = 512, int hopSize = 128, double alpha = 2, double beta = 0.01, double smoothingFactor = 0.98, bool adaptiveNoiseEstimation = true, double enhancementStrength = 0.7)

Parameters

sampleRate int

Audio sample rate (default: 16000 Hz).

fftSize int

FFT size (default: 512).

hopSize int

Hop size (default: 128).

alpha double

Over-subtraction factor (default: 2.0).

beta double

Spectral floor factor (default: 0.01).

smoothingFactor double

Noise estimate smoothing (default: 0.98).

adaptiveNoiseEstimation bool

Enable adaptive noise tracking (default: true).

enhancementStrength double

Overall enhancement strength 0-1 (default: 0.7).

Methods

ProcessSpectralFrame(T[], T[])

Processes a single spectral frame.

protected override T[] ProcessSpectralFrame(T[] magnitudes, T[] phases)

Parameters

magnitudes T[]

Magnitude spectrum.

phases T[]

Phase spectrum.

Returns

T[]

Enhanced magnitude spectrum.

ResetState()

Resets internal state for streaming mode.

public override void ResetState()