8#include "matchers/hart_matcher.hpp"
21template<
typename SampleType>
29 PeaksAt (
double targetDb,
double toleranceLinear = 1e-3):
30 m_targetDb ((SampleType) targetDb),
32 m_toleranceLinear ((SampleType) toleranceLinear)
36 void prepare (
double , size_t , size_t )
override {}
40 SampleType observedPeakLinear = 0;
41 size_t frameOfObservedPeakLinear = 0;
42 size_t channelOfObservedPeakLinear = 0;
44 for (size_t channel = 0; channel < observedAudio.getNumChannels(); ++channel)
46 for (size_t frame = 0; frame < observedAudio.getNumFrames(); ++frame)
48 const SampleType currentPeakLinear = std::abs (observedAudio[channel][frame]);
50 if (currentPeakLinear > observedPeakLinear)
52 observedPeakLinear = currentPeakLinear;
53 frameOfObservedPeakLinear = frame;
54 channelOfObservedPeakLinear = channel;
59 if (std::abs (observedPeakLinear - m_targetLinear) > m_toleranceLinear)
61 m_failedFrame = frameOfObservedPeakLinear;
62 m_failedChannel = (
int) channelOfObservedPeakLinear;
63 m_observedPeakDb = ratioToDecibels (observedPeakLinear);
79 std::stringstream stream;
80 stream <<
dbPrecision <<
"Observed audio peaks at " << m_observedPeakDb <<
" dB";
83 details
.frame = m_failedFrame;
89 void represent (std::ostream& stream)
const override
99 const SampleType m_targetDb;
100 const SampleType m_targetLinear;
101 const SampleType m_toleranceLinear;
103 size_t m_failedFrame = 0;
104 size_t m_failedChannel = 0;
105 SampleType m_observedPeakDb = (SampleType) 0;
Checks whether the audio peaks at 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 Macther for test failure outputs.
PeaksAt(double targetDb, double toleranceLinear=1e-3)
Creates a matcher for a specific peak level.
bool canOperatePerBlock() override
Tells the host is if 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 ...
void reset() override
Resets the matcher to its initial state.
#define HART_MATCHER_DEFINE_COPY_AND_MOVE(ClassName)
Defines hart::Matcher::copy() and hart::Matcher::move() methods.
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.