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 (AnalysisContext<SampleType> context) override
22 {
23 const AudioBuffer<SampleType>& observedOutputAudio = context.outputAudio();
24
25 for (size_t channel = 0; channel < observedOutputAudio.getNumChannels(); ++channel)
26 {
27 if (! this->appliesToChannel (channel))
28 continue;
29
30 for (size_t frame = 0; frame < observedOutputAudio.getNumFrames(); ++frame)
31 {
32 const SampleType sample = observedOutputAudio[channel][frame];
33 const bool notZero = std::fabs (sample) > SampleType (0);
34
35 if (notZero && ! std::isnormal (sample) && ! std::isinf (sample) && ! std::isnan (sample))
36 {
37 m_failedFrame = frame;
38 m_failedChannel = channel;
39 m_observedValue = sample;
40 return false;
41 }
42 }
43 }
44
45 return true;
46 }
47
49 {
50 std::stringstream stream;
51 stream
52 << "Denormal value "
53 << std::scientific << std::setprecision (3)
54 << m_observedValue
55 << " found";
56
58 details.frame = m_failedFrame;
59 details.channel = m_failedChannel;
60 details.description = stream.str();
61
62 return details;
63 }
64
65 bool canOperatePerBlock() const override
66 {
67 return true;
68 }
69
70 void prepare (double /*sampleRateHz*/, size_t /* numInputChannels */, size_t /* numOutputChannels */, size_t /* maxBlockSizeFrames */) override {}
71
73
74private:
75 size_t m_failedFrame = 0;
76 size_t m_failedChannel = 0;
77 SampleType m_observedValue = SampleType (0);
78};
79
81
82} // namespace hart
Contains audio-related artefacts useful for analysis by matchers.
Container for audio data.
Base for audio matchers.
Checks whether the audio has no denormal values.
MatcherFailureDetails getFailureDetails() const override
Returns a description of why the match has failed.
void prepare(double, size_t, size_t, size_t) override
Prepare for processing It is guaranteed that all subsequent process() calls will be in line with the ...
bool match(AnalysisContext< SampleType > context) override
Tells the host if the piece of audio satisfies Matcher's condition or not.
bool canOperatePerBlock() const override
Tells the host if it can operate on a block-by-block basis.
#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.