DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
dspark::SpectralDenoiser< T > Class Template Reference

Learn-a-profile spectral noise reduction (hiss/hum/room-tone). More...

#include <SpectralDenoiser.h>

Public Member Functions

void prepare (const AudioSpec &spec, int fftSize=2048)
 Prepares the STFT pipeline and the per-channel bin state.
 
void reset () noexcept
 Clears signal state and per-bin gain memories (keeps profile).
 
void clearProfile () noexcept
 Forgets the learned noise profile (stream-owner thread).
 
void setLearning (bool learning) noexcept
 While true, incoming audio trains the noise profile.
 
void setReduction (T db) noexcept
 Maximum attenuation of noise bins in dB [0, 40] (default 18): the floor of the per-bin gain. Non-finite values are ignored.
 
void setThreshold (T factor) noexcept
 Noise over-subtraction factor over the learned profile, in magnitude [1, 8] (default 2): the gain rule sees the learned noise scaled by it, so higher values remove more noise and more low-level signal. Non-finite values are ignored.
 
void setDetail (T octaves) noexcept
 The detail: the band, in octaves, in which the signal and the noise are read at each bin, from 1 (broad, the steadiest residual) down to 0 (default: each bin by itself, the finest there is, between the partials of a note). A band is never narrower than a bin. It moves while playing, at the same latency, and the profile learned holds at any detail.
 
void setGainRelease (T ms) noexcept
 Release of each bin's gain at 1 kHz, 0 (off, default) to 2000 ms; slower below, faster above.
 
void setSensitivityBand (int index, const typename KeyEqualizer< T, 2 >::Band &band) noexcept
 One band of the sensitivity curve: the reduction is scaled by its gain in dB / 12 + 1, clamped 0 to 2.
 
KeyEqualizer< T, 2 >::Band getSensitivityBand (int index) const noexcept
 
void setRemovalListen (bool on) noexcept
 Outputs what is taken out instead of what is kept.
 
void setFilterMode (bool on) noexcept
 Spreads no further ahead of an attack than one short frame of 5 ms (see the file comment): the default path, with those frames where an attack is ahead and for 11 ms after it. The latency is the same, and it can be switched while playing.
 
void setLink (T amount) noexcept
 In filter mode, how far the power each channel is read by goes to the mean of the pair, 0 (each its own, default) to 1 (one detector and one filter).
 
T getDetail () const noexcept
 
T getDisplayGain (int point) const noexcept
 
T getGainRelease () const noexcept
 
bool getRemovalListen () const noexcept
 
bool getFilterMode () const noexcept
 
T getLink () const noexcept
 
bool getLearning () const noexcept
 
T getReduction () const noexcept
 
T getThreshold () const noexcept
 
int getLatency () const noexcept
 Latency in samples (the STFT pipeline's); 0 before prepare() succeeds, while the instance passes audio through.
 
std::vector< uint8_t > getState () const
 Serializes the parameter state (the learned profile is material- dependent content, not a preset, and is intentionally not included).
 
bool setState (const uint8_t *data, size_t size)
 Restores parameters from a blob (tolerant; rejects foreign ids). The smoothing of the first version, which was in bins, becomes the band as wide at 1 kHz.
 
void processBlock (AudioBufferView< T > buffer) noexcept
 Processes a block in-place. Pass-through until prepare() succeeds.
 

Static Public Member Functions

static double getDisplayFrequency (int point) noexcept
 

Static Public Attributes

static constexpr int kDisplayPoints = SpectralReadout<T>::kPoints
 Points of the display curve, evenly in log frequency from 20 Hz to 20 kHz.
 

Detailed Description

template<FloatType T>
class dspark::SpectralDenoiser< T >

Learn-a-profile spectral noise reduction (hiss/hum/room-tone).

Template Parameters
TSample type (float or double).

Definition at line 100 of file SpectralDenoiser.h.

Member Function Documentation

◆ clearProfile()

template<FloatType T>
void dspark::SpectralDenoiser< T >::clearProfile ( )
inlinenoexcept

Forgets the learned noise profile (stream-owner thread).

Definition at line 187 of file SpectralDenoiser.h.

◆ getDetail()

template<FloatType T>
T dspark::SpectralDenoiser< T >::getDetail ( ) const
inlinenoexcept
Returns
The detail, in octaves.

Definition at line 265 of file SpectralDenoiser.h.

◆ getDisplayFrequency()

template<FloatType T>
static double dspark::SpectralDenoiser< T >::getDisplayFrequency ( int  point)
inlinestaticnoexcept
Returns
The frequency of a display point, in hertz.

Definition at line 269 of file SpectralDenoiser.h.

◆ getDisplayGain()

template<FloatType T>
T dspark::SpectralDenoiser< T >::getDisplayGain ( int  point) const
inlinenoexcept
Returns
The gain applied to the first channel at a display point, in dB (any thread).

Definition at line 271 of file SpectralDenoiser.h.

◆ getFilterMode()

template<FloatType T>
bool dspark::SpectralDenoiser< T >::getFilterMode ( ) const
inlinenoexcept

Definition at line 277 of file SpectralDenoiser.h.

◆ getGainRelease()

template<FloatType T>
T dspark::SpectralDenoiser< T >::getGainRelease ( ) const
inlinenoexcept

Definition at line 275 of file SpectralDenoiser.h.

◆ getLatency()

template<FloatType T>
int dspark::SpectralDenoiser< T >::getLatency ( ) const
inlinenoexcept

Latency in samples (the STFT pipeline's); 0 before prepare() succeeds, while the instance passes audio through.

Definition at line 286 of file SpectralDenoiser.h.

◆ getLearning()

template<FloatType T>
bool dspark::SpectralDenoiser< T >::getLearning ( ) const
inlinenoexcept

Definition at line 280 of file SpectralDenoiser.h.

◆ getLink()

template<FloatType T>
T dspark::SpectralDenoiser< T >::getLink ( ) const
inlinenoexcept

Definition at line 278 of file SpectralDenoiser.h.

◆ getReduction()

template<FloatType T>
T dspark::SpectralDenoiser< T >::getReduction ( ) const
inlinenoexcept

Definition at line 281 of file SpectralDenoiser.h.

◆ getRemovalListen()

template<FloatType T>
bool dspark::SpectralDenoiser< T >::getRemovalListen ( ) const
inlinenoexcept

Definition at line 276 of file SpectralDenoiser.h.

◆ getSensitivityBand()

template<FloatType T>
KeyEqualizer< T, 2 >::Band dspark::SpectralDenoiser< T >::getSensitivityBand ( int  index) const
inlinenoexcept
Returns
One band of the sensitivity curve.

Definition at line 247 of file SpectralDenoiser.h.

◆ getState()

template<FloatType T>
std::vector< uint8_t > dspark::SpectralDenoiser< T >::getState ( ) const
inline

Serializes the parameter state (the learned profile is material- dependent content, not a preset, and is intentionally not included).

Definition at line 293 of file SpectralDenoiser.h.

◆ getThreshold()

template<FloatType T>
T dspark::SpectralDenoiser< T >::getThreshold ( ) const
inlinenoexcept

Definition at line 282 of file SpectralDenoiser.h.

◆ prepare()

template<FloatType T>
void dspark::SpectralDenoiser< T >::prepare ( const AudioSpec &  spec,
int  fftSize = 2048 
)
inline

Prepares the STFT pipeline and the per-channel bin state.

Invalid specs (non-positive/non-finite rate, block size or channel count) are ignored: the previous state is kept and an unprepared instance stays pass-through. fftSize is sanitized by the STFT engine (power of two in [4, 1 << 20]).

Parameters
specAudio environment specification.
fftSizeSTFT size (default 2048; larger = finer hum notching; 0 = by the rate: 2048 at 44.1 and 48 kHz, doubling by octaves). One over the rate's own runs its frames a sixteenth of it apart in place of a quarter, at some four times the cost: a quarter apart, gains that differ from bin to bin leave images of a line between the lines.

Definition at line 121 of file SpectralDenoiser.h.

◆ processBlock()

template<FloatType T>
void dspark::SpectralDenoiser< T >::processBlock ( AudioBufferView< T >  buffer)
inlinenoexcept

Processes a block in-place. Pass-through until prepare() succeeds.

Definition at line 338 of file SpectralDenoiser.h.

◆ reset()

template<FloatType T>
void dspark::SpectralDenoiser< T >::reset ( )
inlinenoexcept

Clears signal state and per-bin gain memories (keeps profile).

Definition at line 172 of file SpectralDenoiser.h.

◆ setDetail()

template<FloatType T>
void dspark::SpectralDenoiser< T >::setDetail ( T  octaves)
inlinenoexcept

The detail: the band, in octaves, in which the signal and the noise are read at each bin, from 1 (broad, the steadiest residual) down to 0 (default: each bin by itself, the finest there is, between the partials of a note). A band is never narrower than a bin. It moves while playing, at the same latency, and the profile learned holds at any detail.

Definition at line 229 of file SpectralDenoiser.h.

◆ setFilterMode()

template<FloatType T>
void dspark::SpectralDenoiser< T >::setFilterMode ( bool  on)
inlinenoexcept

Spreads no further ahead of an attack than one short frame of 5 ms (see the file comment): the default path, with those frames where an attack is ahead and for 11 ms after it. The latency is the same, and it can be switched while playing.

Definition at line 256 of file SpectralDenoiser.h.

◆ setGainRelease()

template<FloatType T>
void dspark::SpectralDenoiser< T >::setGainRelease ( T  ms)
inlinenoexcept

Release of each bin's gain at 1 kHz, 0 (off, default) to 2000 ms; slower below, faster above.

Definition at line 235 of file SpectralDenoiser.h.

◆ setLearning()

template<FloatType T>
void dspark::SpectralDenoiser< T >::setLearning ( bool  learning)
inlinenoexcept

While true, incoming audio trains the noise profile.

Definition at line 198 of file SpectralDenoiser.h.

◆ setLink()

template<FloatType T>
void dspark::SpectralDenoiser< T >::setLink ( T  amount)
inlinenoexcept

In filter mode, how far the power each channel is read by goes to the mean of the pair, 0 (each its own, default) to 1 (one detector and one filter).

Definition at line 258 of file SpectralDenoiser.h.

◆ setReduction()

template<FloatType T>
void dspark::SpectralDenoiser< T >::setReduction ( T  db)
inlinenoexcept

Maximum attenuation of noise bins in dB [0, 40] (default 18): the floor of the per-bin gain. Non-finite values are ignored.

Definition at line 205 of file SpectralDenoiser.h.

◆ setRemovalListen()

template<FloatType T>
void dspark::SpectralDenoiser< T >::setRemovalListen ( bool  on)
inlinenoexcept

Outputs what is taken out instead of what is kept.

Definition at line 249 of file SpectralDenoiser.h.

◆ setSensitivityBand()

template<FloatType T>
void dspark::SpectralDenoiser< T >::setSensitivityBand ( int  index,
const typename KeyEqualizer< T, 2 >::Band &  band 
)
inlinenoexcept

One band of the sensitivity curve: the reduction is scaled by its gain in dB / 12 + 1, clamped 0 to 2.

Definition at line 241 of file SpectralDenoiser.h.

◆ setState()

template<FloatType T>
bool dspark::SpectralDenoiser< T >::setState ( const uint8_t *  data,
size_t  size 
)
inline

Restores parameters from a blob (tolerant; rejects foreign ids). The smoothing of the first version, which was in bins, becomes the band as wide at 1 kHz.

Definition at line 313 of file SpectralDenoiser.h.

◆ setThreshold()

template<FloatType T>
void dspark::SpectralDenoiser< T >::setThreshold ( T  factor)
inlinenoexcept

Noise over-subtraction factor over the learned profile, in magnitude [1, 8] (default 2): the gain rule sees the learned noise scaled by it, so higher values remove more noise and more low-level signal. Non-finite values are ignored.

Definition at line 215 of file SpectralDenoiser.h.

Member Data Documentation

◆ kDisplayPoints

template<FloatType T>
constexpr int dspark::SpectralDenoiser< T >::kDisplayPoints = SpectralReadout<T>::kPoints
staticconstexpr

Points of the display curve, evenly in log frequency from 20 Hz to 20 kHz.

Definition at line 267 of file SpectralDenoiser.h.


The documentation for this class was generated from the following file: