8#include "matchers/hart_matcher.hpp"
25template<
typename SampleType>
33 PeaksBelow (
double thresholdDb,
double toleranceLinear = 1e-3):
34 m_thresholdDb ((SampleType) thresholdDb),
35 m_thresholdLinear (
static_cast<SampleType> (
decibelsToRatio (thresholdDb
) + toleranceLinear)),
36 m_toleranceLinear (
static_cast<SampleType> (toleranceLinear))
40 void prepare (
double , size_t , size_t , size_t )
override {}
44 const AudioBuffer<SampleType>& observedOutputAudio = context.outputAudio();
46 for (size_t channel = 0; channel < observedOutputAudio.getNumChannels(); ++channel)
48 if (!
this->appliesToChannel (channel))
51 for (size_t frame = 0; frame < observedOutputAudio.getNumFrames(); ++frame)
53 const SampleType observedPeakLinear = std::abs (observedOutputAudio[channel][frame]);
55 if (observedPeakLinear > m_thresholdLinear)
57 m_failedFrame = frame;
58 m_failedChannel = channel;
59 m_observedPeakDb = ratioToDecibels (observedPeakLinear);
75 std::stringstream stream;
76 stream <<
"Observed audio peaks at at least "
80 details
.frame = m_failedFrame;
86 void represent (std::ostream& stream)
const override
88 stream <<
"PeaksBelow ("
94 const SampleType m_thresholdDb;
95 const SampleType m_thresholdLinear;
96 const SampleType m_toleranceLinear;
98 size_t m_failedFrame = 0;
99 size_t m_failedChannel = 0;
100 SampleType m_observedPeakDb = (SampleType) 0;
Contains audio-related artefacts useful for analysis by matchers.
Container for audio data.
Checks whether the audio peaks below specific level.
void represent(std::ostream &stream) const override
Makes a text representation of this Matcher for test failure outputs.
void prepare(double, size_t, size_t, size_t) override
Prepare for processing It is guaranteed that all subsequent process() calls will be in line with the ...
bool match(AnalysisContext< SampleType > context) override
Tells the host if the piece of audio satisfies Matcher's condition or not.
bool canOperatePerBlock() const override
Tells the host if it can operate on a block-by-block basis.
virtual MatcherFailureDetails getFailureDetails() const override
Returns a description of why the match has failed.
PeaksBelow(double thresholdDb, double toleranceLinear=1e-3)
Creates a matcher for a specific peak level.
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.
static SampleType decibelsToRatio(SampleType valueDb)
Converts dB to linear value (ratio)
#define HART_MATCHER_DECLARE_ALIASES_FOR(ClassName)
Details about matcher failure.
size_t channel
Index of channel at which the failure was detected.
std::string description
Readable description of why the match has failed.
size_t frame
Index of frame at which the match has failed.