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

Six bands of cuts, bells, shelves and tilts over the key of a dynamics processor. More...

#include <KeyEqualizer.h>

Classes

struct  Band
 The settings of one band. More...
 
struct  Response
 The sections of a set of bands, to draw the curve they make. More...
 

Public Types

enum class  Shape {
  Off , LowCut , HighCut , Bell ,
  LowShelf , HighShelf , Tilt
}
 What a band does to the key. More...
 
enum class  Placement { Stereo , Mid , Side }
 The part of a two-channel key a band acts on (see processFrame()). More...
 

Public Member Functions

void prepare (double sampleRate) noexcept
 Prepares the equalizer for a sample rate and clears its memory.
 
void reset () noexcept
 Clears the memory of the filters (settings and glides are kept).
 
void setBand (int band, const Band &settings) noexcept
 Publishes the settings of a band.
 
Band getBand (int band) const noexcept
 The published settings of a band (a band out of range reads as Off).
 
bool hasBands () const noexcept
 Whether any published band is in the path.
 
Response getResponse (Placement part=Placement::Stereo) const noexcept
 The sections of the published bands, designed as the audio thread designs them, for a display.
 
void setLoudnessCompensation (bool on) noexcept
 Keeps the loudness (off by default): the bands' change of the K-weighted level of pink noise (as BS.1770 hears it) is taken back by a gain, which moves in 50 ms (as advance() goes) when the bands change. It reads every band, wherever it is placed.
 
bool getLoudnessCompensation () const noexcept
 
double getCompensationDb () const noexcept
 
void writeState (StateWriter &w, const char *prefix) const
 Writes the bands under keys that start with a prefix ("<prefix><band>.shape", ".freq", ".gain", ".q", ".slope", ".place"), and "<prefix>loudness".
 
void readState (const StateReader &r, const char *prefix) noexcept
 Reads the bands writeState() wrote (a band that is missing reads as Off, a placement that is missing as Stereo).
 
bool sync () noexcept
 Takes the settings published since the last call.
 
bool isActive () const noexcept
 Whether any section is in the path: processSample() and processFrame() do nothing otherwise.
 
bool isPlaced () const noexcept
 Whether a band in the path is placed on the middle or on the sides: only processFrame() gives those their part.
 
int getStretch () const noexcept
 Frames between two designs of a band on the move: advance() at least this often for a glide to be followed step by step.
 
T processSample (T input, int channel) noexcept
 One sample of one channel of the key through the equalizer.
 
void processFrame (T *frame, int channels) noexcept
 One frame of the key, every channel of it, in place.
 
void advance (int samples) noexcept
 Moves the equalizer on in time: the coefficients between two designs, the bands on the move to their next design, and a change of design to its end.
 

Static Public Attributes

static constexpr int kBands = 6
 Bands of the equalizer.
 
static constexpr int kBandSections = 5
 Most sections one band takes (a 48 dB per octave cut).
 
static constexpr int kSections = kBands * kBandSections
 
static constexpr double kRampSeconds = 0.02
 Time a new setting takes to arrive.
 
static constexpr double kStretchSeconds = 1.0 / 1500.0
 A band on the move is designed again this often.
 

Detailed Description

template<FloatType T, int MaxChannels = 16>
class dspark::KeyEqualizer< T, MaxChannels >

Six bands of cuts, bells, shelves and tilts over the key of a dynamics processor.

Template Parameters
TSample type (float or double). The filters run in double either way.
MaxChannelsLargest number of key channels.

Definition at line 89 of file KeyEqualizer.h.

Member Enumeration Documentation

◆ Placement

template<FloatType T, int MaxChannels = 16>
enum class dspark::KeyEqualizer::Placement
strong

The part of a two-channel key a band acts on (see processFrame()).

Enumerator
Stereo 

Both channels (default).

Mid 

The middle of the pair, (L + R) / 2, alone.

Side 

The sides of the pair, (L - R) / 2, alone.

Definition at line 111 of file KeyEqualizer.h.

◆ Shape

template<FloatType T, int MaxChannels = 16>
enum class dspark::KeyEqualizer::Shape
strong

What a band does to the key.

Enumerator
Off 

Out of the path.

LowCut 

High-pass: frequency, slope and q.

HighCut 

Low-pass: frequency, slope and q.

Bell 

Peak or dip: frequency, gainDb and q.

LowShelf 

gainDb under the frequency; slope 6 to 24 is its transition.

HighShelf 

gainDb over the frequency; slope 6 to 24 is its transition.

Tilt 

The same slope across the band, 0 dB at the frequency.

Definition at line 99 of file KeyEqualizer.h.

Member Function Documentation

◆ advance()

template<FloatType T, int MaxChannels = 16>
void dspark::KeyEqualizer< T, MaxChannels >::advance ( int  samples)
inlinenoexcept

Moves the equalizer on in time: the coefficients between two designs, the bands on the move to their next design, and a change of design to its end.

Parameters
samplesFrames gone by since the last call.

Definition at line 444 of file KeyEqualizer.h.

◆ getBand()

template<FloatType T, int MaxChannels = 16>
Band dspark::KeyEqualizer< T, MaxChannels >::getBand ( int  band) const
inlinenoexcept

The published settings of a band (a band out of range reads as Off).

Definition at line 234 of file KeyEqualizer.h.

◆ getCompensationDb()

template<FloatType T, int MaxChannels = 16>
double dspark::KeyEqualizer< T, MaxChannels >::getCompensationDb ( ) const
inlinenoexcept
Returns
The gain the compensation is heading for, in dB (0 when off).

Definition at line 297 of file KeyEqualizer.h.

◆ getLoudnessCompensation()

template<FloatType T, int MaxChannels = 16>
bool dspark::KeyEqualizer< T, MaxChannels >::getLoudnessCompensation ( ) const
inlinenoexcept
Returns
Whether the loudness is kept.

Definition at line 294 of file KeyEqualizer.h.

◆ getResponse()

template<FloatType T, int MaxChannels = 16>
Response dspark::KeyEqualizer< T, MaxChannels >::getResponse ( Placement  part = Placement::Stereo) const
inlinenoexcept

The sections of the published bands, designed as the audio thread designs them, for a display.

A design costs a few microseconds per section: build one Response when the settings change and read every frequency from it.

Parameters
partStereo (default): every band, wherever it is placed. Mid or Side: what that part of a two-channel key goes through, the bands on both channels and the ones placed on it.

Definition at line 267 of file KeyEqualizer.h.

◆ getStretch()

template<FloatType T, int MaxChannels = 16>
int dspark::KeyEqualizer< T, MaxChannels >::getStretch ( ) const
inlinenoexcept

Frames between two designs of a band on the move: advance() at least this often for a glide to be followed step by step.

Definition at line 382 of file KeyEqualizer.h.

◆ hasBands()

template<FloatType T, int MaxChannels = 16>
bool dspark::KeyEqualizer< T, MaxChannels >::hasBands ( ) const
inlinenoexcept

Whether any published band is in the path.

Definition at line 249 of file KeyEqualizer.h.

◆ isActive()

template<FloatType T, int MaxChannels = 16>
bool dspark::KeyEqualizer< T, MaxChannels >::isActive ( ) const
inlinenoexcept

Whether any section is in the path: processSample() and processFrame() do nothing otherwise.

Definition at line 374 of file KeyEqualizer.h.

◆ isPlaced()

template<FloatType T, int MaxChannels = 16>
bool dspark::KeyEqualizer< T, MaxChannels >::isPlaced ( ) const
inlinenoexcept

Whether a band in the path is placed on the middle or on the sides: only processFrame() gives those their part.

Definition at line 378 of file KeyEqualizer.h.

◆ prepare()

template<FloatType T, int MaxChannels = 16>
void dspark::KeyEqualizer< T, MaxChannels >::prepare ( double  sampleRate)
inlinenoexcept

Prepares the equalizer for a sample rate and clears its memory.

Allocates the two banks the first time. The published bands are kept and taken at once (with no glide and no fade) by the next sync(). An invalid rate is ignored.

Parameters
sampleRateSample rate in hertz.

Definition at line 158 of file KeyEqualizer.h.

◆ processFrame()

template<FloatType T, int MaxChannels = 16>
void dspark::KeyEqualizer< T, MaxChannels >::processFrame ( T *  frame,
int  channels 
)
inlinenoexcept

One frame of the key, every channel of it, in place.

With two channels and a band placed on the middle or on the sides, the frame is taken to its middle (L + R) / 2 and its sides (L - R) / 2, each goes through the bands on both channels and the bands placed on it, and the pair comes back as their sum and their difference. With no band placed there is no conversion: each channel goes through every band, exactly as through processSample(). A single channel is its own middle and has no sides: the bands placed on the sides leave it alone. With more than two channels every band acts on every channel.

Precondition
Finite samples.
Parameters
frameThe key of each channel, replaced in place.
channelsChannels in the frame (those over MaxChannels are left alone).

Definition at line 418 of file KeyEqualizer.h.

◆ processSample()

template<FloatType T, int MaxChannels = 16>
T dspark::KeyEqualizer< T, MaxChannels >::processSample ( T  input,
int  channel 
)
inlinenoexcept

One sample of one channel of the key through the equalizer.

Every band acts on the channel, wherever it is placed: a caller that has the key one channel at a time has no middle and no sides to give.

Precondition
channel in [0, MaxChannels) and a finite input.
Parameters
inputKey sample.
channelChannel index.
Returns
The shaped key (the input itself while no band is in the path).

Definition at line 395 of file KeyEqualizer.h.

◆ readState()

template<FloatType T, int MaxChannels = 16>
void dspark::KeyEqualizer< T, MaxChannels >::readState ( const StateReader &  r,
const char *  prefix 
)
inlinenoexcept

Reads the bands writeState() wrote (a band that is missing reads as Off, a placement that is missing as Stereo).

Definition at line 329 of file KeyEqualizer.h.

◆ reset()

template<FloatType T, int MaxChannels = 16>
void dspark::KeyEqualizer< T, MaxChannels >::reset ( )
inlinenoexcept

Clears the memory of the filters (settings and glides are kept).

A change of design in flight ends at once: the bank that was coming in is the one that stays.

Definition at line 193 of file KeyEqualizer.h.

◆ setBand()

template<FloatType T, int MaxChannels = 16>
void dspark::KeyEqualizer< T, MaxChannels >::setBand ( int  band,
const Band &  settings 
)
inlinenoexcept

Publishes the settings of a band.

Values out of range are brought into it; a field that is not finite keeps what it had. The audio thread takes the change in its next sync().

Parameters
bandBand index in [0, kBands); others are ignored.
settingsThe band.

Definition at line 214 of file KeyEqualizer.h.

◆ setLoudnessCompensation()

template<FloatType T, int MaxChannels = 16>
void dspark::KeyEqualizer< T, MaxChannels >::setLoudnessCompensation ( bool  on)
inlinenoexcept

Keeps the loudness (off by default): the bands' change of the K-weighted level of pink noise (as BS.1770 hears it) is taken back by a gain, which moves in 50 ms (as advance() goes) when the bands change. It reads every band, wherever it is placed.

Definition at line 287 of file KeyEqualizer.h.

◆ sync()

template<FloatType T, int MaxChannels = 16>
bool dspark::KeyEqualizer< T, MaxChannels >::sync ( )
inlinenoexcept

Takes the settings published since the last call.

Returns
Whether any section is in the path (see isActive()).

Definition at line 361 of file KeyEqualizer.h.

◆ writeState()

template<FloatType T, int MaxChannels = 16>
void dspark::KeyEqualizer< T, MaxChannels >::writeState ( StateWriter &  w,
const char *  prefix 
) const
inline

Writes the bands under keys that start with a prefix ("<prefix><band>.shape", ".freq", ".gain", ".q", ".slope", ".place"), and "<prefix>loudness".

Definition at line 304 of file KeyEqualizer.h.

Member Data Documentation

◆ kBands

template<FloatType T, int MaxChannels = 16>
constexpr int dspark::KeyEqualizer< T, MaxChannels >::kBands = 6
staticconstexpr

Bands of the equalizer.

Definition at line 92 of file KeyEqualizer.h.

◆ kBandSections

template<FloatType T, int MaxChannels = 16>
constexpr int dspark::KeyEqualizer< T, MaxChannels >::kBandSections = 5
staticconstexpr

Most sections one band takes (a 48 dB per octave cut).

Definition at line 93 of file KeyEqualizer.h.

◆ kRampSeconds

template<FloatType T, int MaxChannels = 16>
constexpr double dspark::KeyEqualizer< T, MaxChannels >::kRampSeconds = 0.02
staticconstexpr

Time a new setting takes to arrive.

Definition at line 95 of file KeyEqualizer.h.

◆ kSections

template<FloatType T, int MaxChannels = 16>
constexpr int dspark::KeyEqualizer< T, MaxChannels >::kSections = kBands * kBandSections
staticconstexpr

Definition at line 94 of file KeyEqualizer.h.

◆ kStretchSeconds

template<FloatType T, int MaxChannels = 16>
constexpr double dspark::KeyEqualizer< T, MaxChannels >::kStretchSeconds = 1.0 / 1500.0
staticconstexpr

A band on the move is designed again this often.

Definition at line 96 of file KeyEqualizer.h.


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