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
TThe 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
sampleRateintAudio sample rate (default: 16000 Hz).
fftSizeintFFT size (default: 512).
hopSizeintHop size (default: 128).
alphadoubleOver-subtraction factor (default: 2.0).
betadoubleSpectral floor factor (default: 0.01).
smoothingFactordoubleNoise estimate smoothing (default: 0.98).
adaptiveNoiseEstimationboolEnable adaptive noise tracking (default: true).
enhancementStrengthdoubleOverall 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
magnitudesT[]Magnitude spectrum.
phasesT[]Phase spectrum.
Returns
- T[]
Enhanced magnitude spectrum.
ResetState()
Resets internal state for streaming mode.
public override void ResetState()