8#include "matchers/hart_matcher.hpp"
24template<
typename SampleType>
32 PeaksAt (
double targetDb,
double toleranceLinear = 1e-3):
33 m_targetDb ((SampleType) targetDb),
35 m_toleranceLinear ((SampleType) toleranceLinear)
39 void prepare (
double , size_t , size_t )
override {}
43 SampleType observedPeakLinear = 0;
44 size_t frameOfObservedPeakLinear = 0;
45 size_t channelOfObservedPeakLinear = 0;
47 for (size_t channel = 0; channel < observedOutputAudio.getNumChannels(); ++channel)
49 if (!
this->appliesToChannel (channel))
52 for (size_t frame = 0; frame < observedOutputAudio.getNumFrames(); ++frame)
54 const SampleType currentPeakLinear = std::abs (observedOutputAudio[channel][frame]);
56 if (currentPeakLinear > observedPeakLinear)
58 observedPeakLinear = currentPeakLinear;
59 frameOfObservedPeakLinear = frame;
60 channelOfObservedPeakLinear = channel;
65 if (std::abs (observedPeakLinear - m_targetLinear) > m_toleranceLinear)
67 m_failedFrame = frameOfObservedPeakLinear;
68 m_failedChannel = (
int) channelOfObservedPeakLinear;
69 m_observedPeakDb = ratioToDecibels (observedPeakLinear);
83 std::stringstream stream;
84 stream <<
dbPrecision <<
"Observed audio peaks at " << m_observedPeakDb <<
" dB";
87 details
.frame = m_failedFrame;
93 void represent (std::ostream& stream)
const override
101 const SampleType m_targetDb;
102 const SampleType m_targetLinear;
103 const SampleType m_toleranceLinear;
105 size_t m_failedFrame = 0;
106 size_t m_failedChannel = 0;
107 SampleType m_observedPeakDb = (SampleType) 0;
Container for audio data.
Checks whether the audio peaks at specific level.
bool match(const AudioBuffer< SampleType > &, const AudioBuffer< SampleType > &observedOutputAudio) 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.
PeaksAt(double targetDb, double toleranceLinear=1e-3)
Creates a matcher for a specific peak level.
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.
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 ...
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.