8#include "matchers/hart_matcher.hpp"
24template<
typename SampleType>
32 PeaksBelow (
double thresholdDb,
double toleranceLinear = 1e-3):
33 m_thresholdDb ((SampleType) thresholdDb),
34 m_thresholdLinear (
static_cast<SampleType> (
decibelsToRatio (thresholdDb
) + toleranceLinear))
38 void prepare (
double , size_t , size_t )
override {}
42 for (size_t channel = 0; channel < observedAudio.getNumChannels(); ++channel)
44 if (!
this->appliesToChannel (channel))
47 for (size_t frame = 0; frame < observedAudio.getNumFrames(); ++frame)
49 const SampleType observedPeakLinear = std::abs (observedAudio[channel][frame]);
51 if (observedPeakLinear > m_thresholdLinear)
53 m_failedFrame = frame;
54 m_failedChannel = channel;
55 m_observedPeakDb = ratioToDecibels (observedPeakLinear);
73 std::stringstream stream;
74 stream <<
"Observed audio peaks at at least "
75 << dbPrecision << m_observedPeakDb <<
" dB";
78 details
.frame = m_failedFrame;
84 void represent (std::ostream& stream)
const override
86 stream <<
"PeaksBelow ("
87 << dbPrecision << m_thresholdDb <<
"_dB, "
88 << linPrecision << m_thresholdLinear <<
')';
92 const SampleType m_thresholdDb;
93 const SampleType m_thresholdLinear;
95 size_t m_failedFrame = 0;
96 size_t m_failedChannel = 0;
97 SampleType m_observedPeakDb = (SampleType) 0;
Checks whether the audio peaks below specific level.
bool match(const AudioBuffer< SampleType > &observedAudio) override
Tells the host if the piece of audio satisfies Matcher's condition or not.
void represent(std::ostream &stream) const override
Makes a text representation of this Matcher for test failure outputs.
bool canOperatePerBlock() 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.
void prepare(double, size_t, size_t) override
Prepare for processing It is guaranteed that all subsequent process() calls will be in line with the ...
void reset() override
Resets the matcher to its initial state.
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.