Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::test::audio::ThdResult Struct Reference

Total harmonic distortion result. More...

#include <audio_spectrum.hpp>

Public Member Functions

double thd_db () const
 20·log10(thd), kSilenceFloorDb at zero.
double thd_plus_n_db () const
 20·log10(thd_plus_n).
double thd_percent () const

Public Attributes

std::string analyzer = "thd"
double fundamental_hz = 0.0
Window window = Window::rectangular
int fft_length = 0
int analysis_offset = 0
double sample_rate = 0.0
double bin_hz = 0.0
bool coherent = false
 True when the tone is bin-coherent (see above).
int num_harmonics = 0
 Harmonics summed (beyond the fundamental).
double thd = 0.0
 Ratio (Σ harmonics / fundamental).
double thd_plus_n = 0.0
 Ratio (all non-fundamental / fundamental).
std::vector< Harmonic > harmonics
 [0] = fundamental, then 2nd, 3rd, ...

Detailed Description

Total harmonic distortion result.

Determinism contract (echoed into the artifact):

  • stimulus: a steady sine at fundamental_hz; for a trustworthy reading the tone MUST be bin-coherent — fundamental_hz = k * sample_rate / fft_length for integer k — so the fundamental and all harmonics land on exact bins. coherent records whether that held; a non-coherent reading is advisory only.
  • window/length: rectangular over an fft_length segment after analysis_offset when coherent (no leakage); non_coherent_window (default hann) otherwise. The chosen window is recorded in window.
  • THD = sqrt(Σ harmonic²) / fundamental (ratio); THD+N = sqrt(total energy − fundamental²) / fundamental, i.e. everything that is not the fundamental bin (harmonics + noise + leakage).
  • both ratios cancel absolute FFT scale, so they are backend-stable.

Member Function Documentation

◆ thd_db()

double pulp::test::audio::ThdResult::thd_db ( ) const

20·log10(thd), kSilenceFloorDb at zero.

◆ thd_percent()

double pulp::test::audio::ThdResult::thd_percent ( ) const
inline

◆ thd_plus_n_db()

double pulp::test::audio::ThdResult::thd_plus_n_db ( ) const

20·log10(thd_plus_n).

Member Data Documentation

◆ analysis_offset

int pulp::test::audio::ThdResult::analysis_offset = 0

◆ analyzer

std::string pulp::test::audio::ThdResult::analyzer = "thd"

◆ bin_hz

double pulp::test::audio::ThdResult::bin_hz = 0.0

◆ coherent

bool pulp::test::audio::ThdResult::coherent = false

True when the tone is bin-coherent (see above).

◆ fft_length

int pulp::test::audio::ThdResult::fft_length = 0

◆ fundamental_hz

double pulp::test::audio::ThdResult::fundamental_hz = 0.0

◆ harmonics

std::vector<Harmonic> pulp::test::audio::ThdResult::harmonics

[0] = fundamental, then 2nd, 3rd, ...

◆ num_harmonics

int pulp::test::audio::ThdResult::num_harmonics = 0

Harmonics summed (beyond the fundamental).

◆ sample_rate

double pulp::test::audio::ThdResult::sample_rate = 0.0

◆ thd

double pulp::test::audio::ThdResult::thd = 0.0

Ratio (Σ harmonics / fundamental).

◆ thd_plus_n

double pulp::test::audio::ThdResult::thd_plus_n = 0.0

Ratio (all non-fundamental / fundamental).

◆ window

Window pulp::test::audio::ThdResult::window = Window::rectangular

The documentation for this struct was generated from the following file:
  • /home/runner/work/pulp/pulp/tools/audio/analysis/include/pulp/audio/analysis/audio_spectrum.hpp