7#include "matchers/hart_matcher.hpp"
9#include "signals/hart_signal.hpp"
21template<
typename SampleType>
32 EqualsTo (std::unique_ptr<
SignalBase<SampleType>>&& referenceSignal,
double toleranceLinear = (SampleType) 1e-5):
33 m_referenceSignal (std::move (referenceSignal)),
34 m_toleranceLinear ((SampleType) toleranceLinear)
44 EqualsTo (
const SignalBase<SampleType>& referenceSignal,
double toleranceLinear = (SampleType) 1e-5):
45 EqualsTo (referenceSignal.copy(), toleranceLinear)
56 EqualsTo (referenceSignal.move(), toleranceLinear)
62 m_referenceSignal (std::move (other.m_referenceSignal)),
63 m_toleranceLinear (other.m_toleranceLinear)
69 m_referenceSignal (other.m_referenceSignal !=
nullptr ? other.m_referenceSignal->copy() :
nullptr),
70 m_toleranceLinear (other.m_toleranceLinear)
81 m_referenceSignal = other.m_referenceSignal !=
nullptr ? other.m_referenceSignal->copy() :
nullptr;
82 m_toleranceLinear = other.m_toleranceLinear;
96 m_referenceSignal = std::move(other.m_referenceSignal);
97 m_toleranceLinear = other.m_toleranceLinear;
104 void prepare (
double sampleRateHz, size_t numChannels, size_t maxBlockSizeFrames)
override
106 m_referenceSignal->prepareWithDSPChain (sampleRateHz, numChannels, maxBlockSizeFrames);
111 auto referenceAudio =
AudioBuffer<SampleType>::emptyLike (observedAudio);
112 m_referenceSignal->renderNextBlockWithDSPChain (referenceAudio);
114 for (size_t channel = 0; channel < referenceAudio.getNumChannels(); ++channel)
116 if (!
this->appliesToChannel (channel))
119 for (size_t frame = 0; frame < referenceAudio.getNumFrames(); ++frame)
121 if (notEqual (observedAudio[channel][frame], referenceAudio[channel][frame]))
123 m_failedFrame = frame;
124 m_failedChannel = (
int) channel;
125 m_failedObservedValue = observedAudio[channel][frame];
126 m_failedExpectedValue = referenceAudio[channel][frame];
142 m_referenceSignal->resetWithDSPChain();
147 const SampleType m_differenceLinear = std::abs (m_failedExpectedValue - m_failedObservedValue);
148 std::stringstream stream;
149 stream <<
linPrecision <<
"Expected sample value: " << m_failedExpectedValue
150 <<
dbPrecision <<
" (" << ratioToDecibels (m_failedExpectedValue) <<
" dB)"
151 <<
linPrecision <<
", difference: " << m_differenceLinear
152 <<
dbPrecision <<
" (" << ratioToDecibels (m_differenceLinear) <<
" dB)";
155 details
.frame = m_failedFrame;
163 stream <<
"EqualsTo (" << *m_referenceSignal
168 std::unique_ptr<
SignalBase<SampleType>> m_referenceSignal;
169 const SampleType m_toleranceLinear;
171 size_t m_failedFrame = 0;
172 size_t m_failedChannel = 0;
173 SampleType m_failedObservedValue = (SampleType) 0;
174 SampleType m_failedExpectedValue = (SampleType) 0;
176 inline bool notEqual (SampleType x, SampleType y)
178 return std::abs (x - y) > m_toleranceLinear;
Checks whether the audio is identical to some signal.
EqualsTo(std::unique_ptr< SignalBase< SampleType > > &&referenceSignal, double toleranceLinear=(SampleType) 1e-5)
Creates a matcher for a specific signal by transfering smart pointer details The reference signal can...
bool match(const AudioBuffer< SampleType > &observedAudio) override
Tells the host if the piece of audio satisfies Matcher's condition or not.
EqualsTo(SignalBase< SampleType > &&referenceSignal, double toleranceLinear=(SampleType) 1e-5)
Creates a matcher for a specific signal by moving it details The reference signal can be something si...
~EqualsTo() override=default
void represent(std::ostream &stream) const override
Makes a text representation of this Matcher for test failure outputs.
EqualsTo & operator=(const EqualsTo &other)
EqualsTo(const SignalBase< SampleType > &referenceSignal, double toleranceLinear=(SampleType) 1e-5)
Creates a matcher for a specific signal by copying it details The reference signal can be something s...
EqualsTo(EqualsTo &&other) noexcept
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.
EqualsTo(const EqualsTo &other)
void reset() override
Resets the matcher to its initial state.
void prepare(double sampleRateHz, size_t numChannels, size_t maxBlockSizeFrames) override
Prepare for processing It is guaranteed that all subsequent process() calls will be in line with the ...
EqualsTo & operator=(EqualsTo &&other) noexcept
Polymorphic base for all signals.
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.
#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.