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

Bands uniform in Bark over a power spectrum, with the loudness law. More...

#include <AuditoryBands.h>

Public Member Functions

void prepare (double sampleRate, int fftSize, int numBands=72, double loHz=20.0, double hiHz=20000.0)
 Lays the bands out.
 
void prepareDetailed (double sampleRate, int fftSize, int barkBands, double loHz, double hiHz, double bandsPerOctave)
 Lays the bands out with more of them in the low end.
 
void prepareLike (const AuditoryBands &other, double sampleRate, int fftSize)
 Takes the bands of another instance over a spectrum of its own.
 
void setReferenceSpl (double dbSpl) noexcept
 The SPL of a full-scale sine for the loudness law (60 to 130 dB).
 
int getNumBands () const noexcept
 
int getNumBins () const noexcept
 
double getCentre (int band) const noexcept
 
double getBark (int band) const noexcept
 
double getSpacing () const noexcept
 
double getWidthBark (int band) const noexcept
 
bool isUniform () const noexcept
 
double getExponent (int band) const noexcept
 
double getThreshold (int band) const noexcept
 
double getThresholdLoudness (int band) const noexcept
 
void bandPowers (const T *binPower, T *out) const noexcept
 Band powers from a power spectrum.
 
template<int Lanes>
void bandPowersInterleaved (const T *binPower, T *out) const noexcept
 The band powers of several spectra at once: each what bandPowers() gives for its own.
 
void specificLoudness (const T *bandPower, T *out) const noexcept
 Specific loudness of band powers: (P + P_th)^a - P_th^a, with the band's exponent and threshold.
 
T totalLoudness (const T *specific) const noexcept
 

Static Public Member Functions

static void smoothAcross (T *v, int n, T coeff) noexcept
 Smooths values across bands in both directions with a one-pole (forward, then backward): a spread like the ear's masking.
 

Detailed Description

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

Bands uniform in Bark over a power spectrum, with the loudness law.

Template Parameters
TSample type of the spectra (float or double).

Definition at line 143 of file AuditoryBands.h.

Member Function Documentation

◆ bandPowers()

template<FloatType T>
void dspark::AuditoryBands< T >::bandPowers ( const T *  binPower,
T *  out 
) const
inlinenoexcept

Band powers from a power spectrum.

Parameters
binPowernumBins powers (|X[k]|^2 scaled so a full-scale sine reads 1 in its bin, or any consistent scale).
outgetNumBands() powers.

Definition at line 338 of file AuditoryBands.h.

◆ bandPowersInterleaved()

template<FloatType T>
template<int Lanes>
void dspark::AuditoryBands< T >::bandPowersInterleaved ( const T *  binPower,
T *  out 
) const
inlinenoexcept

The band powers of several spectra at once: each what bandPowers() gives for its own.

Template Parameters
LanesHow many spectra (1 to 8).
Parameters
binPowernumBins groups of Lanes powers, one of each spectrum.
outgetNumBands() groups of Lanes powers, the same way.

Definition at line 351 of file AuditoryBands.h.

◆ getBark()

template<FloatType T>
double dspark::AuditoryBands< T >::getBark ( int  band) const
inlinenoexcept
Returns
The centre of a band in Bark.

Definition at line 312 of file AuditoryBands.h.

◆ getCentre()

template<FloatType T>
double dspark::AuditoryBands< T >::getCentre ( int  band) const
inlinenoexcept
Returns
The centre of a band in hertz.

Definition at line 310 of file AuditoryBands.h.

◆ getExponent()

template<FloatType T>
double dspark::AuditoryBands< T >::getExponent ( int  band) const
inlinenoexcept
Returns
The loudness exponent of a band.

Definition at line 326 of file AuditoryBands.h.

◆ getNumBands()

template<FloatType T>
int dspark::AuditoryBands< T >::getNumBands ( ) const
inlinenoexcept

Definition at line 307 of file AuditoryBands.h.

◆ getNumBins()

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

Definition at line 308 of file AuditoryBands.h.

◆ getSpacing()

template<FloatType T>
double dspark::AuditoryBands< T >::getSpacing ( ) const
inlinenoexcept
Returns
The spacing of the bands in Bark (of the Bark layout: the widest a band is).

Definition at line 314 of file AuditoryBands.h.

◆ getThreshold()

template<FloatType T>
double dspark::AuditoryBands< T >::getThreshold ( int  band) const
inlinenoexcept
Returns
The threshold in quiet of a band, as a power relative to a full-scale sine.

Definition at line 328 of file AuditoryBands.h.

◆ getThresholdLoudness()

template<FloatType T>
double dspark::AuditoryBands< T >::getThresholdLoudness ( int  band) const
inlinenoexcept
Returns
The threshold to the exponent of a band: what specificLoudness() takes off.

Definition at line 330 of file AuditoryBands.h.

◆ getWidthBark()

template<FloatType T>
double dspark::AuditoryBands< T >::getWidthBark ( int  band) const
inlinenoexcept
Returns
The stretch of the Bark axis a band stands for: from half way to the band below to half way to the band above (the first and the last take the half toward their only neighbour), which is its weight in a sum over the bands that stands for an integral over Bark.

Definition at line 322 of file AuditoryBands.h.

◆ isUniform()

template<FloatType T>
bool dspark::AuditoryBands< T >::isUniform ( ) const
inlinenoexcept
Returns
Whether the bands are uniform in Bark (prepare(), not prepareDetailed()).

Definition at line 324 of file AuditoryBands.h.

◆ prepare()

template<FloatType T>
void dspark::AuditoryBands< T >::prepare ( double  sampleRate,
int  fftSize,
int  numBands = 72,
double  loHz = 20.0,
double  hiHz = 20000.0 
)
inline

Lays the bands out.

Parameters
sampleRateRate of the spectrum (invalid values are ignored).
fftSizeSize of the transform (the spectrum has fftSize / 2 + 1 bins).
numBandsNumber of bands, 2 to 512.
loHzCentre of the lowest band.
hiHzCentre of the highest band (at most 0.49 of the rate).

Definition at line 154 of file AuditoryBands.h.

◆ prepareDetailed()

template<FloatType T>
void dspark::AuditoryBands< T >::prepareDetailed ( double  sampleRate,
int  fftSize,
int  barkBands,
double  loHz,
double  hiHz,
double  bandsPerOctave 
)
inline

Lays the bands out with more of them in the low end.

Starts from the layout of prepare() (barkBands bands uniform in Bark from loHz to hiHz) and lets no band be wider than 1 / bandsPerOctave of an octave: the density of bands along frequency is the larger of the two, so the bands follow the octave in the low end and the Bark scale from where a band of that scale is the narrower one. The number of bands follows from it (getNumBands()).

Parameters
sampleRateRate of the spectrum (invalid values are ignored).
fftSizeSize of the transform.
barkBandsBands of the Bark layout it starts from, 2 to 512.
loHzCentre of the lowest band.
hiHzCentre of the highest band (at most 0.49 of the rate).
bandsPerOctaveBands per octave at least; 0 or less is prepare().

Definition at line 216 of file AuditoryBands.h.

◆ prepareLike()

template<FloatType T>
void dspark::AuditoryBands< T >::prepareLike ( const AuditoryBands< T > &  other,
double  sampleRate,
int  fftSize 
)
inline

Takes the bands of another instance over a spectrum of its own.

The centres, the thresholds and the exponents are those of the other instance; the bins are those of this rate and this transform. A band over half this rate reads nothing that means anything.

Parameters
otherThe instance whose bands are taken (already prepared).
sampleRateRate of this spectrum (invalid values are ignored).
fftSizeSize of this transform.

Definition at line 278 of file AuditoryBands.h.

◆ setReferenceSpl()

template<FloatType T>
void dspark::AuditoryBands< T >::setReferenceSpl ( double  dbSpl)
inlinenoexcept

The SPL of a full-scale sine for the loudness law (60 to 130 dB).

Definition at line 295 of file AuditoryBands.h.

◆ smoothAcross()

template<FloatType T>
static void dspark::AuditoryBands< T >::smoothAcross ( T *  v,
int  n,
T  coeff 
)
inlinestaticnoexcept

Smooths values across bands in both directions with a one-pole (forward, then backward): a spread like the ear's masking.

Parameters
vThe values, in place.
nHow many.
coeffPole, 0 (none) to just under 1.

Definition at line 405 of file AuditoryBands.h.

◆ specificLoudness()

template<FloatType T>
void dspark::AuditoryBands< T >::specificLoudness ( const T *  bandPower,
T *  out 
) const
inlinenoexcept

Specific loudness of band powers: (P + P_th)^a - P_th^a, with the band's exponent and threshold.

Definition at line 417 of file AuditoryBands.h.

◆ totalLoudness()

template<FloatType T>
T dspark::AuditoryBands< T >::totalLoudness ( const T *  specific) const
inlinenoexcept
Returns
The total loudness: the specific loudness integrated over Bark (trapezoids).

Definition at line 428 of file AuditoryBands.h.


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