6#include "matchers/hart_correlation_latency_detector.hpp"
7#include "matchers/hart_latency_detector.hpp"
8#include "matchers/hart_matcher.hpp"
9#include "matchers/hart_onset_latency_detector.hpp"
34template <
typename SampleType>
61 double maxLatencySeconds,
66 m_maxLatencySeconds (maxLatencySeconds),
68 m_silencePolicy (silencePolicy)
70 const bool thresholdDefaultValueRequested = std::isnan (threshold);
72 if (method ==
Method::onset)
74 m_threshold = thresholdDefaultValueRequested ? -120.0 : threshold;
75 m_latencyDetector =
hart::make_unique<OnsetLatencyDetector<SampleType>> (
83 m_threshold = thresholdDefaultValueRequested ? 0.5 : threshold;
84 m_latencyDetector =
hart::make_unique<CorrelationLatencyDetector<SampleType>> (
92 hassert (m_latencyDetector !=
nullptr);
93 hassert (! std::isnan (m_threshold));
97 m_maxLatencySeconds (other.m_maxLatencySeconds),
98 m_method (other.m_method),
99 m_silencePolicy (other.m_silencePolicy),
100 m_threshold (other.m_threshold),
102 other.m_latencyDetector !=
nullptr
103 ? other.m_latencyDetector->copy()
107 hassert (other.m_latencyDetector !=
nullptr);
117 hassert (other.m_latencyDetector !=
nullptr);
119 m_maxLatencySeconds = other.m_maxLatencySeconds;
120 m_method = other.m_method;
121 m_silencePolicy = other.m_silencePolicy;
122 m_threshold = other.m_threshold;
125 other.m_latencyDetector !=
nullptr
126 ? other.m_latencyDetector->copy()
136 void prepare (
double sampleRateHz, size_t numInputChannels, size_t numOutputChannels, size_t maxBlockSizeFrames)
override
138 hassert (numInputChannels == numOutputChannels);
139 hassert (m_latencyDetector !=
nullptr);
140 m_latencyDetector->prepare (
154 hassert (m_latencyDetector !=
nullptr);
155 m_latencyDetector->reset();
160 return numInputChannels == numOutputChannels;
165 const AudioBuffer<SampleType>& inputAudio = context.inputAudio();
166 const AudioBuffer<SampleType>& observedOutputAudio = context.outputAudio();
168 hassert (m_latencyDetector !=
nullptr);
169 return m_latencyDetector->match (
172 [
this] (size_t channel) {
return this->appliesToChannel (channel); }
178 hassert (m_latencyDetector !=
nullptr);
179 return m_latencyDetector->getFailureDetails();
188 if (m_method ==
Method::onset)
196 <<
"Method::correlation, "
206 double m_maxLatencySeconds;
211 std::unique_ptr<LatencyDetector<SampleType>> m_latencyDetector;
Contains audio-related artefacts useful for analysis by matchers.
Checks whether the output signal latency is below a specified amount.
LatencyBelow(LatencyBelow &&other) noexcept=default
Method
Selects the method used to detect latency.
@ correlation
Detect latency using best waveform alignment via cross-correlation.
@ onset
Detect latency from the first threshold crossing in input and output.
MatcherFailureDetails getFailureDetails() const override
Returns a description of why the match has failed.
void represent(std::ostream &stream) const override
Makes a text representation of this Matcher for test failure outputs.
void prepare(double sampleRateHz, size_t numInputChannels, size_t numOutputChannels, size_t maxBlockSizeFrames) 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.
LatencyBelow(double maxLatencySeconds, Method method=Method::onset, double threshold=hart::nan< double >(), SilencePolicy silencePolicy=SilencePolicy::strict)
Creates a matcher that expects latency between input and output below a specified value.
bool canOperatePerBlock() const override
Tells the host if it can operate on a block-by-block basis.
LatencyBelow(const LatencyBelow &other)
~LatencyBelow() override=default
LatencyBelow & operator=(const LatencyBelow &other)
LatencyBelow & operator=(LatencyBelow &&other) noexcept=default
void reset() override
Resets the matcher to its initial state.
bool supportsChannelLayout(size_t numInputChannels, size_t numOutputChannels) const override
Tells the host whether this Matcher is capable of operating on audio with a specific number of channe...
#define hassert(condition)
Triggers a HartAssertException if the condition is false
std::ostream & secPrecision(std::ostream &stream)
Sets number of decimal places for values in seconds.
static std::ostream & correlationPrecision(std::ostream &stream)
Sets number of decimal places for correlation values.
std::ostream & dbPrecision(std::ostream &stream)
Sets number of decimal places for values in decibels.
FloatType nan()
Returns a quiet NaN value for the given floating-point type.
SilencePolicy
Defines how silence in various algorithms.
#define HART_MATCHER_DECLARE_ALIASES_FOR(ClassName)
Details about matcher failure.