HART  0.2.0
High level Audio Regression and Testing
Loading...
Searching...
No Matches
hart Namespace Reference

Namespaces

namespace  aliases_double
 
namespace  aliases_float
 
namespace  SpectralCentroid
 

Classes

class  AccurateSum
 Implements Kahan algorithm for floating point accumulations. More...
 
class  AdditiveNoise
 Mixes additive white noise to the signal. More...
 
struct  allFloatsEqualTo
 Returns true if all the values in the range are equal to a specific value within provided tolerance, false otherwise. More...
 
struct  allFloatsEqualToEachOther
 Returns true if all the values in the range are equal to each other within provided tolerance, false otherwise. More...
 
struct  allNaN
 Returns true if all elements in the range are NaN More...
 
class  AnalysisContext
 Contains audio-related artefacts useful for analysis by matchers. More...
 
struct  anyNaN
 Returns true if at least one element in the range is NaN More...
 
struct  argmax
 Returns the zero-based index of the largest element in the range. More...
 
struct  argmin
 Returns the zero-based index of the smallest element in the range. More...
 
class  AudioBuffer
 Container for audio data. More...
 
class  AudioBufferSignal
 Plays audio from a pre-rendered AudioBuffer. More...
 
class  AudioTestBuilder
 A DSP host used for building and running tests inside a test case. More...
 
class  ChannelFlags
 A set of boolean flags mapped to each audio channel. More...
 
class  ChannelLayoutError
 Thrown when a numbers of channels is mismatched. More...
 
struct  ChannelSubsets
 Helpers to generate common default channel subsets. More...
 
struct  CLIConfig
 Holds values set by the user via CLI interface. More...
 
struct  collect
 Forwards the entire range as an std::vector, preserving the original order. More...
 
class  Condition
 A class representing some condition. More...
 
class  ConfigurationError
 Thrown when the test runner is misconfigured. More...
 
class  DC
 Produces a DC signal. More...
 
class  DSP
 Base for DSP effects. More...
 
class  DSPBase
 Polymorphic base for all DSP. More...
 
class  DSPFunction
 A DSP processor defined by a user-provided function. More...
 
class  DSPSequence
 A DSP unit that renders audio through a linear sequence of DSP instances. More...
 
class  Envelope
 Represents an Envelope curve for DSP parameters. More...
 
class  EqualsTo
 Checks whether the audio is identical to some signal. More...
 
struct  first
 Returns the first element in the range. More...
 
class  FundamentalEquals
 Checks the fundamental frequency of the signal. More...
 
class  GainDb
 Applies gain in decibels to the signal. More...
 
class  GainLinear
 Applies linear gain (not decibels) to the signal. More...
 
class  HardClip
 Applies symmetrical hard clipping (no knee) to the signal. More...
 
class  HartAssertException
 Thrown when hassert() or hassertfalse are triggered. More...
 
class  Impulse
 Produces a {1, 0, 0, 0, ...} sequence. More...
 
class  IndexError
 Thrown when a container index is out of range. More...
 
class  IOError
 Thrown when some I/O operation fails. More...
 
struct  last
 Returns the last element in the range. More...
 
class  LatencyBelow
 Checks whether the output signal latency is below a specified amount. More...
 
class  Matcher
 Base for audio matchers. More...
 
class  MatcherBase
 Polymorphic base for all matchers. More...
 
struct  MatcherFailureDetails
 Details about matcher failure. More...
 
class  MatcherFunction
 Matcher defined by a user-provided function. More...
 
struct  max
 Returns the largest element in the range. More...
 
struct  mean
 Returns the arithmetic mean of all elements in the range. More...
 
class  MetricQuery
 Manages the metrics calculations. More...
 
struct  min
 Returns the smallest element in the range. More...
 
class  MixedSignal
 Produces a mix of multiple signals. More...
 
class  Mute
 Mutes selected channels in the signal. More...
 
class  NoDenormals
 Checks whether the audio has no denormal values. More...
 
struct  nth
 Returns the nth element in the range (zero-based) More...
 
class  NullPointerError
 Thrown when a nullptr could be handled gracefully. More...
 
class  NyquistSignal
 Produces a Nyquist signal. More...
 
class  PeaksAt
 Checks whether the audio peaks at specific level. More...
 
class  PeaksBelow
 Checks whether the audio peaks below specific level. More...
 
struct  percentile
 Returns the percentile value. More...
 
class  PolarityPreserved
 Checks whether the output signal preserves the polarity of the input signal. More...
 
struct  range
 Returns the difference between largest and smallest values in the range. More...
 
class  SampleRateError
 Thrown when sample rate is mismatched. More...
 
class  Sawtooth
 Produces a bandlimited sawtooth wave at fixed frequency. More...
 
class  SegmentedEnvelope
 A simple envelope constructed from semgents. More...
 
class  Signal
 Base class for signals. More...
 
class  SignalBase
 Polymorphic base for all signals. More...
 
class  SignalFunction
 Signal defined by a user-provided function. More...
 
class  Silence
 Produces silence (zeros) More...
 
class  SineSweep
 Produces a sine sweep. More...
 
class  SineWave
 Produces a sine wave at fixed frequency. More...
 
struct  size
 Returns the number of elements (values) in the range. More...
 
class  SizeError
 Thrown when an unexpected container size is encountered. More...
 
struct  Slice
 Represents a slice of analysis data. More...
 
class  Spectrum
 Frequency-domain representation of a multi-channel audio signal. More...
 
class  StateError
 Thrown when some unexpected state is encountered. More...
 
class  StereoToMidSide
 Converts regular stereo signal into mid-side signal. More...
 
struct  sum
 Returns the sum of all elements in the range. More...
 
class  TestAssertException
 Thrown by test asserts like HART_ASSERT_TRUE() and AudioTestBuilder::assertFalse() More...
 
class  TestRegistry
 Runs the test cases. More...
 
class  TimeIt
 Helper class for measuring duration of some block of code over multiple runs. More...
 
class  TimeShift
 Shifts an audio signal forward in time by a fixed amount. More...
 
class  TruePeaksBelow
 Checks whether the audio true-peaks below specific level. More...
 
class  UnitError
 Thrown when some metric is requested to return a value in an unsupported unit. More...
 
class  UnsupportedError
 Thrown when some parameter has an unsupported value. More...
 
class  ValueError
 Thrown when an inappropriate value is encountered. More...
 
class  WavFile
 Produces audio from a wav file. More...
 
class  WavWriter
 Helper class for writing audio buffers to wav files. More...
 
class  WhiteNoise
 Produces deterministic white noise. More...
 

Typedefs

using EnvelopeBuffers = std::unordered_map< int, std::vector< double > >
 Hash table of automation envelope sequences mapped to param ids.
 
template<typename IteratorType >
using IteratedValueType = typename std::iterator_traits< IteratorType >::value_type
 Value of the elements in a range that reducer is supposed to reduce.
 

Enumerations

enum class  Preparation { none , reset , prepare , resetAndPrepare }
 Describes whether to call reset() and/or prepare() before rendering through DSP or a Signal. More...
 
enum class  Save { always , whenFails , never }
 Determines when to save a file. More...
 
enum class  ResetSignal { no , yes }
 Determines whether to reset the Signal in a given context. More...
 
enum class  SilencePolicy { strict , relaxed }
 Defines how silence in various algorithms. More...
 
enum class  Unit {
  native , linear , dB , frames ,
  seconds , Hz , ratio , none
}
 Represents a physical unit. More...
 
enum  Channel { left = 0 , right = 1 }
 Helper values for channel indices. More...
 
enum  MidSideChannel { mid = 0 , side = 1 }
 Helper values for mid-side channel indices. More...
 
enum class  Loop { no , yes }
 Helper values for something that could loop, like a Signal. More...
 
enum  Oversampling { x4 = 4 , x8 = 8 , x16 = 16 }
 Oversampling ratio. More...
 
enum class  Interpolation { nearest , linear }
 Interpolation method. More...
 
enum class  WavFormat { pcm16 , pcm24 , pcm32 , float32 }
 Audio data storage format for the wav files. More...
 
enum  CorrelationSearchMode { bestSignedCorrelation , bestAbsoluteCorrelation }
 Describes how to look for best cross-correlation. More...
 

Functions

 HART_DSP_DECLARE_ALIASES_FOR (DSPSequence)
 
 HART_DSP_DECLARE_ALIASES_FOR (DSPSequenceBuilder)
 
std::ostream & linPrecision (std::ostream &stream)
 Sets number of decimal places for linear (sample) values.
 
std::ostream & dbPrecision (std::ostream &stream)
 Sets number of decimal places for values in decibels.
 
std::ostream & secPrecision (std::ostream &stream)
 Sets number of decimal places for values in seconds.
 
std::ostream & hzPrecision (std::ostream &stream)
 Sets number of decimal places for values in hertz.
 
std::ostream & radPrecision (std::ostream &stream)
 Sets number of decimal places for values in radians.
 
std::ostream & centsPrecision (std::ostream &stream)
 Sets number of decimal places for values in cents (frequency deviation)
 
static std::ostream & correlationPrecision (std::ostream &stream)
 Sets number of decimal places for correlation values.
 
template<typename DSPType >
AudioTestBuilder< typename std::decay< DSPType >::type::SampleTypePublicAlias > processAudioWith (DSPType &&dsp)
 Call this to start building your test using a DSP object.
 
template<typename DSPType >
AudioTestBuilder< typename DSPType::SampleTypePublicAlias > processAudioWith (std::unique_ptr< DSPType > &&dsp)
 Call this to start building your test using a smart pointer to a DSP object.
 
std::ostream & operator<< (std::ostream &os, Oversampling oversampling)
 
template<typename FloatType >
FloatType nan ()
 Returns a quiet NaN value for the given floating-point type.
 
template<typename NumericType >
NumericType clamp (const NumericType &value, const NumericType &low, const NumericType &high)
 std::clamp() replacement for C++11
 
template<typename SampleType >
static SampleType decibelsToRatio (SampleType valueDb)
 Converts dB to linear value (ratio)
 
template<typename SampleType >
static SampleType ratioToDecibels (SampleType valueLinear)
 Converts linear value (ratio) to dB.
 
template<typename SampleType >
static SampleType decibelsToPower (SampleType valueDb)
 Converts dB to linear value (power)
 
template<typename SampleType >
static SampleType powerToDecibels (SampleType valueLinear)
 Converts linear value (power) to dB.
 
template<typename SampleType >
static SampleType floatsEqual (SampleType a, SampleType b, SampleType epsilon=(SampleType) 1e-8)
 Compares two floating point numbers within a given tolerance.
 
template<typename SampleType >
static SampleType floatsNotEqual (SampleType a, SampleType b, SampleType epsilon=(SampleType) 1e-8)
 Compares two floating point numbers within a given tolerance.
 
template<typename SampleType >
static size_t roundToSizeT (SampleType x)
 Rounds a floating point value to a size_t value.
 
double addCents (double baseFrequencyHz, double cents)
 Anns an offset in cents to a frequency in Hz.
 
template<typename SampleType >
SampleType wrapPhase (const SampleType phaseRadians)
 Keeps phase in 0..twoPi range.
 
static bool isAbsolutePath (const std::string &path)
 Checks if the provided file path is absolute.
 
static std::string toAbsolutePath (const std::string &path)
 Converts path to absolute, if it's relative.
 
template<typename KeyType , typename ValueType >
static bool contains (const std::unordered_map< KeyType, ValueType > &map, const KeyType &key)
 std::unordered_map::contains() replacement for C++11
 
template<typename ObjectType , typename... Args>
std::unique_ptr< ObjectType > make_unique (Args &&... args)
 std::make_unique() replacement for C++11
 
static bool isExceptionUnwinding ()
 Returns true if an exception is currently being unwound.
 
template<typename SampleType >
MetricQuery< double > channelCorrelation (const AudioBuffer< SampleType > &buffer)
 Calculates zero-lag normalized cross-correlation between two channels of an audio buffer.
 
template<typename SampleType >
MetricQuery< double > crestFactor (const AudioBuffer< SampleType > &buffer)
 Calculates linear crest factor for a single channel of an audio buffer.
 
template<typename SampleType >
MetricQuery< double > esr (const AudioBuffer< SampleType > &referenceBuffer, const AudioBuffer< SampleType > &estimatedBuffer)
 Calculates error-to-signal ratio (ESR)
 
MetricQuery< double > interpolatedPeakFrequency (const Spectrum &spectrum)
 Returns the center frequency of the loudest FFT bin.
 
template<typename SampleType >
MetricQuery< double > lagAtMaxCrossCorrelation (const AudioBuffer< SampleType > &bufferA, const AudioBuffer< SampleType > &bufferB, double maxLagSeconds, double minAbsBestCorrelation=0.5, CorrelationSearchMode searchMode=bestAbsoluteCorrelation)
 Calculates lag corresponding to maximum normalized cross-correlation between two audio buffers.
 
MetricQuery< double > loudestBinFrequency (const Spectrum &spectrum)
 Returns the center frequency of the loudest FFT bin.
 
MetricQuery< double > loudestBinMagnitude (const Spectrum &spectrum)
 Calculates the magnitude of the loudest FFT bin.
 
template<typename SampleType >
MetricQuery< double > maxCrossCorrelation (const AudioBuffer< SampleType > &bufferA, const AudioBuffer< SampleType > &bufferB, double maxLagSeconds, CorrelationSearchMode searchMode=bestAbsoluteCorrelation)
 Calculates maximum normalized cross-correlation between two audio buffers.
 
MetricQuery< double > quinns2 (const Spectrum &spectrum)
 Returns somewhat accurate loudest frequency in the spectrum.
 
template<typename SampleType >
MetricQuery< double > rms (const AudioBuffer< SampleType > &buffer)
 Calculates root mean square (RMS) of a signal.
 
template<typename SampleType >
MetricQuery< double > samplePeak (const AudioBuffer< SampleType > &audioBuffer)
 Calculates Sample Peak of an audio buffer.
 
MetricQuery< double > spectralCentroid (const Spectrum &spectrum, SpectralCentroid::Weighting weighting=SpectralCentroid::Weighting::magnitude)
 Calculates spectral centroid.
 
MetricQuery< double > spectralFlatness (const Spectrum &spectrum, double floorLinear=1e-16)
 Calculates spectral flatness, also known as Wiener entropy, or tonality coefficient.
 
template<typename SampleType >
MetricQuery< double > truePeak (const AudioBuffer< SampleType > &audioBuffer, Oversampling oversamplingRatio=Oversampling::x4, typename TruePeak< SampleType >::FilterQuality filterQuality=TruePeak< SampleType >::FilterQuality::low)
 Estimates true peak (inter-sample peak) level.
 
template<typename SampleType >
MetricQuery< double > zcr (const AudioBuffer< SampleType > &buffer)
 Calculates zero-crossing rate (ZCR) of a signal.
 

Variables

static const char * hartAsciiArt = "88 \n88 ,d \n88 88 \n88,dPPYba, ,adPPYYba, 8b,dPPYba, MM88MMM\n88P' \"8a \"\" `Y8 88P' \"Y8 88 \n88 88 ,adPPPPP88 88 88 \n88 88 88, ,88 88 88, \n88 88 `\"8bbdP\"Y8 88 \"Y888\n"
 
static const char * passAsciiArt = "8b,dPPYba, ,adPPYYba, ,adPPYba, ,adPPYba,\n88P' \"8a \"\" `Y8 I8[ \"\" I8[ \"\"\n88 d8 ,adPPPPP88 `\"Y8ba, `\"Y8ba, \n88b, ,a8\" 88, ,88 aa ]8I aa ]8I\n88`YbbdP\"' `\"8bbdP\"Y8 `\"YbbdP\"' `\"YbbdP\"'\n88 \n88\n"
 
static const char * failAsciiArt = " ad88 88 88\n d8\" \"\" 88\n 88 88\nMM88MMM ,adPPYYba, 88 88\n 88 \"\" `Y8 88 88\n 88 ,adPPPPP88 88 88\n 88 88, ,88 88 88\n 88 `\"8bbdP\"Y8 88 88\n"
 
constexpr double inf = std::numeric_limits<double>::infinity()
 Infinity.
 
constexpr double oo = inf
 Infinity.
 
constexpr double pi = 3.14159265358979323846
 pi
 
constexpr double twoPi = 2.0 * pi
 2 * pi
 
constexpr double halfPi = pi / 2.0
 pi / 2
 

Enumeration Type Documentation

◆ Preparation

enum class Preparation
strong

Describes whether to call reset() and/or prepare() before rendering through DSP or a Signal.

Enumerator
none 
reset 
prepare 
resetAndPrepare 

Definition at line 7 of file hart_preparation.hpp.

◆ Unit

enum class Unit
strong

Represents a physical unit.

You might want to use those without namespace, like someMetric (...).as (dB). If you're on C++17 or earlier, you can use the HART_DECLARE_ALIASES_FOR_UNITS macro. For C++20 an on, you can just use using enum Unit.

Note
New units may be introduced here, whenever necessary
Enumerator
native 

Default (native) unit of whatever returns some value.

linear 

Value of a sample (voltage) in a linear domain.

dB 

Value of something in decibels. Can represent voltage, power, or a domain-specific unit like "LUFS" or "dB TP".

frames 

Value of something in frames (samples)

seconds 

Time stamps, intervals, durations.

Hz 

Hertz.

ratio 

Generic ratio.

none 

Unitless value.

Definition at line 20 of file hart_units.hpp.

◆ WavFormat

enum class WavFormat
strong

Audio data storage format for the wav files.

Enumerator
pcm16 
pcm24 
pcm32 
float32 

Definition at line 7 of file hart_wavformat.hpp.

◆ CorrelationSearchMode

Describes how to look for best cross-correlation.

Enumerator
bestSignedCorrelation 
bestAbsoluteCorrelation 

Definition at line 107 of file hart_metrics_common.hpp.

Function Documentation

◆ HART_DSP_DECLARE_ALIASES_FOR() [1/2]

HART_DSP_DECLARE_ALIASES_FOR ( DSPSequence  )

◆ HART_DSP_DECLARE_ALIASES_FOR() [2/2]

HART_DSP_DECLARE_ALIASES_FOR ( DSPSequenceBuilder  )

◆ esr()

template<typename SampleType >
MetricQuery< double > esr ( const AudioBuffer< SampleType > &  referenceBuffer,
const AudioBuffer< SampleType > &  estimatedBuffer 
)

Calculates error-to-signal ratio (ESR)

ESR is a useful way to express the degree of similarity between two signals or waveforms, calculated as:

\[ ESR=\frac{\sum_{k=0}^{N-1} (x - y) ^ 2}{\sum_{k=0}^{N-1} x^2}$$ \]

(sum ((x - y) ** 2) / sum (x ** 2))

Where x is a signal represented by referenceBuffer and y is represented by estimatedBuffer. It's a ratio, so appropriate units are Unit::native and Unit::ratio. ESR = 0 means two signals are identical.

Parameters
referenceBufferA buffer representing x in the formula above
estimatedBufferA buffer representing y in the formula above
Returns
Chainable MetricQuery, which calculates per-channel ESR values

Definition at line 34 of file hart_esr.hpp.

◆ rms()

template<typename SampleType >
MetricQuery< double > rms ( const AudioBuffer< SampleType > &  buffer)

Calculates root mean square (RMS) of a signal.

RMS a metric that expresses the average magnitude, or effective energy level, of an audio signal over time. It is commonly used to estimate perceived loudness, and to measure overall signal level.

RMS is calculated this way:

\[ \mathrm{RMS} = \sqrt{\frac{1}{N} \sum_{n=0}^{N-1} x[n]^2} \]

(RMS = sqrt((1 / N) * sum(x[n] ** 2))),

where x[n] is audio sample value from one channel, and N is number of frames in the provided buffer.

Can be expressed as ratio or decibels, supports Unit:native, Unit::linear, Unit::dB units. Value in decibels is calculated as a ratio, not power.

Template Parameters
SampleType
Parameters
bufferAudio buffer to calculate RMS at
Returns
Chainable MetricQuery object, which calculates RMS as linear ratio or decibels

Definition at line 40 of file hart_rms.hpp.

◆ zcr()

template<typename SampleType >
MetricQuery< double > zcr ( const AudioBuffer< SampleType > &  buffer)

Calculates zero-crossing rate (ZCR) of a signal.

Useful to estimate frequency of stationary monophonic signals. Supports Unit::native and Unit::Hz units, which both result in the same value.

Template Parameters
SampleTypetype of audio buffer data, typically float or double
Parameters
bufferAudio buffer to calculate ZCR at
Returns
Chainable MetricQuery object, which calculates RMS as linear ratio or decibels

Definition at line 22 of file hart_zcr.hpp.

Variable Documentation

◆ hartAsciiArt

const char* hartAsciiArt = "88 \n88 ,d \n88 88 \n88,dPPYba, ,adPPYYba, 8b,dPPYba, MM88MMM\n88P' \"8a \"\" `Y8 88P' \"Y8 88 \n88 88 ,adPPPPP88 88 88 \n88 88 88, ,88 88 88, \n88 88 `\"8bbdP\"Y8 88 \"Y888\n"
static

Definition at line 8 of file hart_ascii_art.hpp.

◆ passAsciiArt

const char* passAsciiArt = "8b,dPPYba, ,adPPYYba, ,adPPYba, ,adPPYba,\n88P' \"8a \"\" `Y8 I8[ \"\" I8[ \"\"\n88 d8 ,adPPPPP88 `\"Y8ba, `\"Y8ba, \n88b, ,a8\" 88, ,88 aa ]8I aa ]8I\n88`YbbdP\"' `\"8bbdP\"Y8 `\"YbbdP\"' `\"YbbdP\"'\n88 \n88\n"
static

Definition at line 9 of file hart_ascii_art.hpp.

◆ failAsciiArt

const char* failAsciiArt = " ad88 88 88\n d8\" \"\" 88\n 88 88\nMM88MMM ,adPPYYba, 88 88\n 88 \"\" `Y8 88 88\n 88 ,adPPPPP88 88 88\n 88 88, ,88 88 88\n 88 `\"8bbdP\"Y8 88 88\n"
static

Definition at line 10 of file hart_ascii_art.hpp.