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

A frame's spectrum read through a window that shortens as frequency rises, from the one transform of the whole window. More...

#include <SpectralEnvelope.h>

Public Member Functions

void prepare (const double *window, int windowSize, int transform, double widthOctaves=1.0/3.0, double minBins=1.0)
 Sets the window, the transform and the width.
 
int getNumBins () const noexcept
 
double getGain (int bin) const noexcept
 
void smooth (const double *spectrum, double *re, double *im) const noexcept
 The smoothed complex spectrum of a frame.
 
void power (const double *spectrum, T *out) noexcept
 The power of each bin through its own window, scaled to read as through the whole one.
 

Detailed Description

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

A frame's spectrum read through a window that shortens as frequency rises, from the one transform of the whole window.

Smoothing a complex spectrum across frequency is the same as multiplying the frame by a weight in time: the wider the smoothing, the narrower the weight. With the time origin moved to the window's peak, a smoothing whose width grows with frequency (as SpectralEnvelope's, a one-pole run both ways) weighs the low bins by nearly the whole window and the high ones by a short stretch around its peak: the low end keeps its resolution in frequency and the top gains it in time, where the ear has it. The weight of a smoothing of coefficient c is (1 - c)^2 / (1 - 2 c cos(theta) + c^2) at the angle theta = 2 pi (t - peak) / transform.

power() gives the power of each bin scaled so that a noise, or a tone summed over its lobe, reads what it reads through the whole window (each bin by the energy of the window over the energy of its own shorter one).

Threading: prepare() on the setup thread (allocates); smooth() and power() on the owner's thread, with no allocation.

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

Definition at line 224 of file SpectralEnvelope.h.

Member Function Documentation

◆ getGain()

template<FloatType T>
double dspark::SpectralFocus< T >::getGain ( int  bin) const
inlinenoexcept
Returns
The scale of a bin's power (see power()).

Definition at line 304 of file SpectralEnvelope.h.

◆ getNumBins()

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

Definition at line 302 of file SpectralEnvelope.h.

◆ power()

template<FloatType T>
void dspark::SpectralFocus< T >::power ( const double *  spectrum,
T *  out 
)
inlinenoexcept

The power of each bin through its own window, scaled to read as through the whole one.

Parameters
spectrumThe frame's transform, interleaved, getNumBins() pairs.
outgetNumBins() powers.

Definition at line 341 of file SpectralEnvelope.h.

◆ prepare()

template<FloatType T>
void dspark::SpectralFocus< T >::prepare ( const double *  window,
int  windowSize,
int  transform,
double  widthOctaves = 1.0 / 3.0,
double  minBins = 1.0 
)
inline

Sets the window, the transform and the width.

Parameters
windowThe analysis window the frames are made with.
windowSizeIts length, at least 2.
transformThe transform's size (windowSize or more, for a zero-padded frame that starts at the window's start).
widthOctavesWidth of the smoothing, 0.05 to 4 octaves.
minBinsNarrowest smoothing, in bins (1 by default).

Definition at line 236 of file SpectralEnvelope.h.

◆ smooth()

template<FloatType T>
void dspark::SpectralFocus< T >::smooth ( const double *  spectrum,
double *  re,
double *  im 
) const
inlinenoexcept

The smoothed complex spectrum of a frame.

Parameters
spectrumThe frame's transform, interleaved (real, imaginary), getNumBins() pairs.
regetNumBins() values: the real parts.
imgetNumBins() values: the imaginary parts.

Definition at line 312 of file SpectralEnvelope.h.


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