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

A per-bin quantity of the last frame (a gain curve, a reduction), read at fixed points for a display from any thread. More...

#include <SpectralFilter.h>

Public Member Functions

void prepare (double binHz, int bins) noexcept
 Maps the points onto the bins of a transform and clears the curves.
 
void clear () noexcept
 Sets every point of every curve to zero.
 
template<typename V >
void publish (int channel, const V *perBin, int bins) noexcept
 Publishes one frame of a channel's per-bin values (audio thread).
 
template<typename GainAt >
T gainPoint (int point, GainAt &&gainAt) const noexcept
 One point of a frame of gains no higher than 1, in decibels: what publish() would show of their decibels, with a logarithm a point in place of one a bin. For an owner that keeps a frame's gains (as relaxed atomics, the audio thread's only work) and leaves the points to the thread that reads them.
 
template<typename V >
void publishPoints (int channel, const V *perPoint) noexcept
 Publishes one frame of a channel that is already on the points (audio thread; prepare() is not needed for it).
 
T value (int channel, int point) const noexcept
 
T extreme () const noexcept
 

Static Public Member Functions

static double frequency (int point) noexcept
 
template<typename ValueAt >
static double between (double hz, ValueAt &&valueAt) noexcept
 A curve of the points at any frequency, as a display should draw it: a cubic through the four points around it. Straight lines would lose half a decibel of a peak a 24th of an octave wide, which has four points.
 

Static Public Attributes

static constexpr int kPoints = 1024
 Points of each curve.
 
static constexpr int kChannels = 2
 Curves (channels).
 

Detailed Description

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

A per-bin quantity of the last frame (a gain curve, a reduction), read at fixed points for a display from any thread.

The points sit evenly in log frequency from 20 Hz to 20 kHz, over a hundred an octave. A point with bins within half a point of it takes the value with the largest magnitude (its sign kept), so a narrow peak or notch between two points still shows; a point with none, as in the low end, reads straight between the bins on either side of it, so the curve has no steps. prepare() maps the points onto a transform (setup thread, no allocation); publish() runs on the audio thread once a frame; value() and extreme() on any thread. The points are relaxed atomics: a reader may see a curve whose points come from two consecutive frames.

Template Parameters
TSample type (float or double).

Definition at line 510 of file SpectralFilter.h.

Member Function Documentation

◆ between()

template<FloatType T>
template<typename ValueAt >
static double dspark::SpectralReadout< T >::between ( double  hz,
ValueAt &&  valueAt 
)
inlinestaticnoexcept

A curve of the points at any frequency, as a display should draw it: a cubic through the four points around it. Straight lines would lose half a decibel of a peak a 24th of an octave wide, which has four points.

Template Parameters
ValueAtvalue(int point).
Parameters
hzThe frequency, held within the ends of the curve.
valueAtThe curve.

Definition at line 532 of file SpectralFilter.h.

◆ clear()

template<FloatType T>
void dspark::SpectralReadout< T >::clear ( )
inlinenoexcept

Sets every point of every curve to zero.

Definition at line 572 of file SpectralFilter.h.

◆ extreme()

template<FloatType T>
T dspark::SpectralReadout< T >::extreme ( ) const
inlinenoexcept
Returns
The value with the largest magnitude over both curves (its sign kept).

Definition at line 661 of file SpectralFilter.h.

◆ frequency()

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

Definition at line 517 of file SpectralFilter.h.

◆ gainPoint()

template<FloatType T>
template<typename GainAt >
T dspark::SpectralReadout< T >::gainPoint ( int  point,
GainAt &&  gainAt 
) const
inlinenoexcept

One point of a frame of gains no higher than 1, in decibels: what publish() would show of their decibels, with a logarithm a point in place of one a bin. For an owner that keeps a frame's gains (as relaxed atomics, the audio thread's only work) and leaves the points to the thread that reads them.

Template Parameters
GainAtfloat gainAt(int bin), for the bins of prepare().
Parameters
point0 to kPoints - 1 (others, or before prepare(), read 0).
gainAtThe gains, from 0 to 1 (under 1e-6: -120 dB).

Definition at line 622 of file SpectralFilter.h.

◆ prepare()

template<FloatType T>
void dspark::SpectralReadout< T >::prepare ( double  binHz,
int  bins 
)
inlinenoexcept

Maps the points onto the bins of a transform and clears the curves.

Definition at line 544 of file SpectralFilter.h.

◆ publish()

template<FloatType T>
template<typename V >
void dspark::SpectralReadout< T >::publish ( int  channel,
const V *  perBin,
int  bins 
)
inlinenoexcept

Publishes one frame of a channel's per-bin values (audio thread).

Parameters
channel0 or 1; others are ignored.
perBinOne value per bin of the transform given to prepare().
binsMust match the transform; otherwise the frame is ignored.

Definition at line 585 of file SpectralFilter.h.

◆ publishPoints()

template<FloatType T>
template<typename V >
void dspark::SpectralReadout< T >::publishPoints ( int  channel,
const V *  perPoint 
)
inlinenoexcept

Publishes one frame of a channel that is already on the points (audio thread; prepare() is not needed for it).

Parameters
channel0 or 1; others are ignored.
perPointkPoints values.

Definition at line 646 of file SpectralFilter.h.

◆ value()

template<FloatType T>
T dspark::SpectralReadout< T >::value ( int  channel,
int  point 
) const
inlinenoexcept
Returns
The value of a point of a channel's curve (0 for indices out of range).

Definition at line 654 of file SpectralFilter.h.

Member Data Documentation

◆ kChannels

template<FloatType T>
constexpr int dspark::SpectralReadout< T >::kChannels = 2
staticconstexpr

Curves (channels).

Definition at line 514 of file SpectralFilter.h.

◆ kPoints

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

Points of each curve.

Definition at line 513 of file SpectralFilter.h.


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