HART  0.2.0
High level Audio Regression and Testing
Loading...
Searching...
No Matches
hart_no_denormals.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cmath> // fabs(), isnormal(), isinf(), isnan()
4#include <iomanip>
5#include <sstream>
6
7#include "matchers/hart_matcher.hpp"
9
10namespace hart
11{
12
13/// @brief Checks whether the audio has no denormal values
14/// @details This matcher scans the audio signal for denormal (subnormal) floating-point values.
15/// @ingroup Matchers
16template<typename SampleType>
18 public Matcher<SampleType, NoDenormals<SampleType>>
19{
20public:
21 bool match (const AudioBuffer<SampleType>& /* inputAudio */, const AudioBuffer<SampleType>& observedOutputAudio) override
22 {
23 for (size_t channel = 0; channel < observedOutputAudio.getNumChannels(); ++channel)
24 {
25 if (! this->appliesToChannel (channel))
26 continue;
27
28 for (size_t frame = 0; frame < observedOutputAudio.getNumFrames(); ++frame)
29 {
30 const SampleType sample = observedOutputAudio[channel][frame];
31 const bool notZero = std::fabs (sample) > SampleType (0);
32
33 if (notZero && ! std::isnormal (sample) && ! std::isinf (sample) && ! std::isnan (sample))
34 {
35 m_failedFrame = frame;
36 m_failedChannel = channel;
37 m_observedValue = sample;
38 return false;
39 }
40 }
41 }
42
43 return true;
44 }
45
47 {
48 std::stringstream stream;
49 stream
50 << "Denormal value "
51 << std::scientific << std::setprecision (3)
52 << m_observedValue
53 << " found";
54
56 details.frame = m_failedFrame;
57 details.channel = m_failedChannel;
58 details.description = stream.str();
59
60 return details;
61 }
62
63 bool canOperatePerBlock() const override
64 {
65 return true;
66 }
67
68 void prepare (double /*sampleRateHz*/, size_t /* numChannels */, size_t /* maxBlockSizeFrames */) override {}
69
71
72private:
73 size_t m_failedFrame = 0;
74 size_t m_failedChannel = 0;
75 SampleType m_observedValue = SampleType (0);
76};
77
79
80} // namespace hart
Container for audio data.
Base for audio matchers.
Checks whether the audio has no denormal values.
bool match(const AudioBuffer< SampleType > &, const AudioBuffer< SampleType > &observedOutputAudio) override
Tells the host if the piece of audio satisfies Matcher's condition or not.
MatcherFailureDetails getFailureDetails() const override
Returns a description of why the match has failed.
bool canOperatePerBlock() const override
Tells the host if it can operate on a block-by-block basis.
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 ...
#define HART_DEFINE_GENERIC_REPRESENT(ClassName)
Defines a basic string representation of your class.
#define HART_MATCHER_DECLARE_ALIASES_FOR(ClassName)
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.