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

Minimum-phase filtering by a gain curve designed every hop. More...

#include <SpectralFilter.h>

Public Member Functions

void prepare (const AudioSpec &spec, int windowSize=2048, int padding=2, int overlap=4)
 Allocates for a layout.
 
void setLinked (bool on) noexcept
 One filter for every channel, designed on their mean power.
 
bool isLinked () const noexcept
 
void setRemovalListen (bool on) noexcept
 Applies one minus the filter (what it takes out).
 
bool isRemovalListen () const noexcept
 
void setShortKernel (bool on) noexcept
 Cuts the filter's impulse response to half the transform and tapers it over its whole length (off by default: the response keeps the room the padding leaves, with only its tail tapered). A cut then rings for a shorter time after the event: of the response of a cut of 24 dB at a window of 1024, the energy past half a window falls from -33 to -43 dB, at the same depth.
 
bool isShortKernel () const noexcept
 
void setTimeFocus (bool on) noexcept
 Gives the design each bin's power through a stretch of the window of its own, shorter as frequency rises (SpectralFocus; off by default: the whole window at every frequency). The filter itself is applied as before. A noise reads the same (within 0.1 dB by octaves, padding included); a tone that starts at the top shows whole from one frame to the next, where the whole window shows part of it for a frame; a held tone stands less above what surrounds it.
 
bool isTimeFocus () const noexcept
 
void setTimeFocusWidth (double octaves) noexcept
 The width the focus smooths the spectrum by, 1/24 to 1 octave (1/6 by default). Read at prepare().
 
double getTimeFocusWidth () const noexcept
 
int getLatency () const noexcept
 
int getWindowSize () const noexcept
 
int getTransformSize () const noexcept
 
int getHopSize () const noexcept
 
int getNumBins () const noexcept
 
double getBinHz () const noexcept
 
double getSampleRate () const noexcept
 
const T * getFramePower (int channel) const noexcept
 
void reset () noexcept
 Clears the input, the output and the hop phase.
 
template<typename Design >
void processBlock (AudioBufferView< T > buffer, Design &&design) noexcept
 Filters a block in place.
 
template<typename Design >
void processBlock (AudioBufferView< T > buffer, const AudioBufferView< T > *key, Design &&design) noexcept
 Filters a block in place, the callback reading the power of a key (the same length or longer; its last channel serves the programme's extra ones; nullptr, or the programme's own channels, reads the programme with no second transform).
 

Static Public Attributes

static constexpr int kMinWindow = 64
 Shortest analysis window.
 
static constexpr int kMaxWindow = 32768
 Longest analysis window.
 

Detailed Description

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

Minimum-phase filtering by a gain curve designed every hop.

Template Parameters
TSample type (float or double); the transforms run in double.

Definition at line 125 of file SpectralFilter.h.

Member Function Documentation

◆ getBinHz()

template<FloatType T>
double dspark::SpectralFilter< T >::getBinHz ( ) const
inlinenoexcept

Definition at line 233 of file SpectralFilter.h.

◆ getFramePower()

template<FloatType T>
const T * dspark::SpectralFilter< T >::getFramePower ( int  channel) const
inlinenoexcept
Returns
The power of a channel's frame this hop (getNumBins() values), for the design callback of an unlinked filter: the frames of every channel are read before the first design runs. nullptr for a channel out of range.

Definition at line 241 of file SpectralFilter.h.

◆ getHopSize()

template<FloatType T>
int dspark::SpectralFilter< T >::getHopSize ( ) const
inlinenoexcept

Definition at line 231 of file SpectralFilter.h.

◆ getLatency()

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

Definition at line 228 of file SpectralFilter.h.

◆ getNumBins()

template<FloatType T>
int dspark::SpectralFilter< T >::getNumBins ( ) const
inlinenoexcept

Definition at line 232 of file SpectralFilter.h.

◆ getSampleRate()

template<FloatType T>
double dspark::SpectralFilter< T >::getSampleRate ( ) const
inlinenoexcept

Definition at line 234 of file SpectralFilter.h.

◆ getTimeFocusWidth()

template<FloatType T>
double dspark::SpectralFilter< T >::getTimeFocusWidth ( ) const
inlinenoexcept

Definition at line 226 of file SpectralFilter.h.

◆ getTransformSize()

template<FloatType T>
int dspark::SpectralFilter< T >::getTransformSize ( ) const
inlinenoexcept

Definition at line 230 of file SpectralFilter.h.

◆ getWindowSize()

template<FloatType T>
int dspark::SpectralFilter< T >::getWindowSize ( ) const
inlinenoexcept

Definition at line 229 of file SpectralFilter.h.

◆ isLinked()

template<FloatType T>
bool dspark::SpectralFilter< T >::isLinked ( ) const
inlinenoexcept

Definition at line 191 of file SpectralFilter.h.

◆ isRemovalListen()

template<FloatType T>
bool dspark::SpectralFilter< T >::isRemovalListen ( ) const
inlinenoexcept

Definition at line 194 of file SpectralFilter.h.

◆ isShortKernel()

template<FloatType T>
bool dspark::SpectralFilter< T >::isShortKernel ( ) const
inlinenoexcept

Definition at line 204 of file SpectralFilter.h.

◆ isTimeFocus()

template<FloatType T>
bool dspark::SpectralFilter< T >::isTimeFocus ( ) const
inlinenoexcept

Definition at line 217 of file SpectralFilter.h.

◆ prepare()

template<FloatType T>
void dspark::SpectralFilter< T >::prepare ( const AudioSpec &  spec,
int  windowSize = 2048,
int  padding = 2,
int  overlap = 4 
)
inline

Allocates for a layout.

Parameters
specRate and channels (an invalid spec is ignored).
windowSizeAnalysis window, rounded up to a power of two (64 to 32768).
paddingTransform over window: 2, 4 or 8 (others are rounded down).
overlapFrames per window: 2 to 16 (rounded down to a power of two).

Definition at line 138 of file SpectralFilter.h.

◆ processBlock() [1/2]

template<FloatType T>
template<typename Design >
void dspark::SpectralFilter< T >::processBlock ( AudioBufferView< T >  buffer,
const AudioBufferView< T > *  key,
Design &&  design 
)
inlinenoexcept

Filters a block in place, the callback reading the power of a key (the same length or longer; its last channel serves the programme's extra ones; nullptr, or the programme's own channels, reads the programme with no second transform).

Definition at line 278 of file SpectralFilter.h.

◆ processBlock() [2/2]

template<FloatType T>
template<typename Design >
void dspark::SpectralFilter< T >::processBlock ( AudioBufferView< T >  buffer,
Design &&  design 
)
inlinenoexcept

Filters a block in place.

Template Parameters
Designvoid(int channel, const T* power, T* gain, int numBins): reads the power of each bin of the frame (a full-scale sine reads about 1 in its bin) and writes the gain wanted there (linear, preset to 1; a gain under -120 dB is taken as -120). The channel is -1 when linked. Must not throw.

Definition at line 266 of file SpectralFilter.h.

◆ reset()

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

Clears the input, the output and the hop phase.

Definition at line 247 of file SpectralFilter.h.

◆ setLinked()

template<FloatType T>
void dspark::SpectralFilter< T >::setLinked ( bool  on)
inlinenoexcept

One filter for every channel, designed on their mean power.

Definition at line 190 of file SpectralFilter.h.

◆ setRemovalListen()

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

Applies one minus the filter (what it takes out).

Definition at line 193 of file SpectralFilter.h.

◆ setShortKernel()

template<FloatType T>
void dspark::SpectralFilter< T >::setShortKernel ( bool  on)
inlinenoexcept

Cuts the filter's impulse response to half the transform and tapers it over its whole length (off by default: the response keeps the room the padding leaves, with only its tail tapered). A cut then rings for a shorter time after the event: of the response of a cut of 24 dB at a window of 1024, the energy past half a window falls from -33 to -43 dB, at the same depth.

Definition at line 203 of file SpectralFilter.h.

◆ setTimeFocus()

template<FloatType T>
void dspark::SpectralFilter< T >::setTimeFocus ( bool  on)
inlinenoexcept

Gives the design each bin's power through a stretch of the window of its own, shorter as frequency rises (SpectralFocus; off by default: the whole window at every frequency). The filter itself is applied as before. A noise reads the same (within 0.1 dB by octaves, padding included); a tone that starts at the top shows whole from one frame to the next, where the whole window shows part of it for a frame; a held tone stands less above what surrounds it.

Definition at line 216 of file SpectralFilter.h.

◆ setTimeFocusWidth()

template<FloatType T>
void dspark::SpectralFilter< T >::setTimeFocusWidth ( double  octaves)
inlinenoexcept

The width the focus smooths the spectrum by, 1/24 to 1 octave (1/6 by default). Read at prepare().

Definition at line 222 of file SpectralFilter.h.

Member Data Documentation

◆ kMaxWindow

template<FloatType T>
constexpr int dspark::SpectralFilter< T >::kMaxWindow = 32768
staticconstexpr

Longest analysis window.

Definition at line 129 of file SpectralFilter.h.

◆ kMinWindow

template<FloatType T>
constexpr int dspark::SpectralFilter< T >::kMinWindow = 64
staticconstexpr

Shortest analysis window.

Definition at line 128 of file SpectralFilter.h.


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