HART  0.2.0
High level Audio Regression and Testing
Loading...
Searching...
No Matches
Spectrum Class Reference

Frequency-domain representation of a multi-channel audio signal. More...

#include <hart_spectrum.hpp>

Public Member Functions

template<typename SampleType >
 Spectrum (const AudioBuffer< SampleType > &buffer)
 Constructs spectrum from an audio buffer.
 
size_t getNumChannels () const
 Returns number of channels.
 
size_t getNumBins () const
 Returns number of frequency bins per channel.
 
size_t getFFTSize () const
 Returns FFT size.
 
double getSampleRateHz () const
 Returns sample rate in Hz.
 
double getBinFrequencyHz (size_t binIndex) const
 Returns frequency corresponding to a bin index.
 
double getBinWidthHz () const
 
std::complex< double > getBinValue (size_t channel, size_t binIndex) const
 Returns complex value of a frequency bin, by bin index.
 
std::complex< double > getBinValue (size_t channel, double frequencyHz) const
 Returns complex value of a frequency bin, by frequency.
 
double getBinMagnitude (size_t channel, size_t binIndex) const
 Returns magnitude of a frequency bin, by bin index.
 
double getBinMagnitude (size_t channel, double frequencyHz) const
 Returns magnitude of a frequency bin, by frequency.
 
const std::complex< double > * operator[] (size_t channel) const
 Returns pointer to read-only magnitudes of a specific channel.
 
std::complex< double > * operator[] (size_t channel)
 Returns pointer to mutable magnitudes of a specific channel.
 
size_t findClosestBin (double frequencyHz) const
 Finds closest FFT bin to a given frequency.
 
std::pair< size_t, size_t > getBinIndices (const Slice &slice) const
 Returns a pair of indices representing a provided slice.
 

Static Public Member Functions

static Spectrum zeros (size_t numChannels, size_t signalDurationFrames, double sampleRateHz)
 

Detailed Description

Frequency-domain representation of a multi-channel audio signal.

Stores complex spectra for each channel independently. Spectrum is constructed by performing FFT on the entire signal, zero-padding to the next power-of-two size if necessary.

Current implementation assumptions:

  • Rectangular window (no windowing)
  • Real-valued input signal
  • One-sided spectrum only (fftSize / 2 + 1 bins)
  • Double floating-point precision, regardless of input signal value types

Definition at line 29 of file hart_spectrum.hpp.

Constructor & Destructor Documentation

◆ Spectrum()

template<typename SampleType >
Spectrum ( const AudioBuffer< SampleType > &  buffer)
inline

Constructs spectrum from an audio buffer.

Parameters
bufferAudio buffer to perform FFT on
Exceptions
hart::SampleRateErrorif the audio buffer has no sample rate metadata

Definition at line 36 of file hart_spectrum.hpp.

Member Function Documentation

◆ zeros()

static Spectrum zeros ( size_t  numChannels,
size_t  signalDurationFrames,
double  sampleRateHz 
)
inlinestatic

Definition at line 69 of file hart_spectrum.hpp.

◆ getNumChannels()

size_t getNumChannels ( ) const
inline

Returns number of channels.

Definition at line 100 of file hart_spectrum.hpp.

◆ getNumBins()

size_t getNumBins ( ) const
inline

Returns number of frequency bins per channel.

Definition at line 106 of file hart_spectrum.hpp.

◆ getFFTSize()

size_t getFFTSize ( ) const
inline

Returns FFT size.

Definition at line 112 of file hart_spectrum.hpp.

◆ getSampleRateHz()

double getSampleRateHz ( ) const
inline

Returns sample rate in Hz.

Definition at line 118 of file hart_spectrum.hpp.

◆ getBinFrequencyHz()

double getBinFrequencyHz ( size_t  binIndex) const
inline

Returns frequency corresponding to a bin index.

Definition at line 124 of file hart_spectrum.hpp.

◆ getBinWidthHz()

double getBinWidthHz ( ) const
inline

Definition at line 132 of file hart_spectrum.hpp.

◆ getBinValue() [1/2]

std::complex< double > getBinValue ( size_t  channel,
size_t  binIndex 
) const
inline

Returns complex value of a frequency bin, by bin index.

Definition at line 138 of file hart_spectrum.hpp.

◆ getBinValue() [2/2]

std::complex< double > getBinValue ( size_t  channel,
double  frequencyHz 
) const
inline

Returns complex value of a frequency bin, by frequency.

Definition at line 150 of file hart_spectrum.hpp.

◆ getBinMagnitude() [1/2]

double getBinMagnitude ( size_t  channel,
size_t  binIndex 
) const
inline

Returns magnitude of a frequency bin, by bin index.

Definition at line 156 of file hart_spectrum.hpp.

◆ getBinMagnitude() [2/2]

double getBinMagnitude ( size_t  channel,
double  frequencyHz 
) const
inline

Returns magnitude of a frequency bin, by frequency.

Definition at line 162 of file hart_spectrum.hpp.

◆ operator[]() [1/2]

const std::complex< double > * operator[] ( size_t  channel) const
inline

Returns pointer to read-only magnitudes of a specific channel.

Definition at line 168 of file hart_spectrum.hpp.

◆ operator[]() [2/2]

std::complex< double > * operator[] ( size_t  channel)
inline

Returns pointer to mutable magnitudes of a specific channel.

Definition at line 177 of file hart_spectrum.hpp.

◆ findClosestBin()

size_t findClosestBin ( double  frequencyHz) const
inline

Finds closest FFT bin to a given frequency.

Definition at line 186 of file hart_spectrum.hpp.

◆ getBinIndices()

std::pair< size_t, size_t > getBinIndices ( const Slice slice) const
inline

Returns a pair of indices representing a provided slice.

Parameters
sliceA Slice instance. Valid slice types are Slice::Type::whole Slice::Type::bins and Slice::Type::freq
Return values
firstIndex representing the beginning of the range, inclusive
secondIndex representing the end of the range, non-inclusive

Definition at line 200 of file hart_spectrum.hpp.


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