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"
33template <
typename SampleType>
60 double maxLatencySeconds,
65 m_maxLatencySeconds (maxLatencySeconds),
67 m_silencePolicy (silencePolicy)
69 const bool thresholdDefaultValueRequested = std::isnan (threshold);
71 if (method ==
Method::onset)
73 m_threshold = thresholdDefaultValueRequested ? -120.0 : threshold;
74 m_latencyDetector =
hart::make_unique<OnsetLatencyDetector<SampleType>> (
82 m_threshold = thresholdDefaultValueRequested ? 0.5 : threshold;
83 m_latencyDetector =
hart::make_unique<CorrelationLatencyDetector<SampleType>> (
91 hassert (m_latencyDetector !=
nullptr);
92 hassert (! std::isnan (m_threshold));
96 m_maxLatencySeconds (other.m_maxLatencySeconds),
97 m_method (other.m_method),
98 m_silencePolicy (other.m_silencePolicy),
99 m_threshold (other.m_threshold),
101 other.m_latencyDetector !=
nullptr
102 ? other.m_latencyDetector->copy()
106 hassert (other.m_latencyDetector !=
nullptr);
116 hassert (other.m_latencyDetector !=
nullptr);
118 m_maxLatencySeconds = other.m_maxLatencySeconds;
119 m_method = other.m_method;
120 m_silencePolicy = other.m_silencePolicy;
121 m_threshold = other.m_threshold;
124 other.m_latencyDetector !=
nullptr
125 ? other.m_latencyDetector->copy()
135 void prepare (
double sampleRateHz, size_t numInputChannels, size_t numOutputChannels, size_t maxBlockSizeFrames)
override
137 hassert (numInputChannels == numOutputChannels);
138 hassert (m_latencyDetector !=
nullptr);
139 m_latencyDetector->prepare (
153 hassert (m_latencyDetector !=
nullptr);
154 m_latencyDetector->reset();
159 return numInputChannels == numOutputChannels;
164 const AudioBuffer<SampleType>& inputAudio = context.inputAudio();
165 const AudioBuffer<SampleType>& observedOutputAudio = context.outputAudio();
167 hassert (m_latencyDetector !=
nullptr);
168 return m_latencyDetector->match (
171 [
this] (size_t channel) {
return this->appliesToChannel (channel); }
177 hassert (m_latencyDetector !=
nullptr);
178 return m_latencyDetector->getFailureDetails();
187 if (m_method ==
Method::onset)
195 <<
"Method::correlation, "
205 double m_maxLatencySeconds;
210 std::unique_ptr<LatencyDetector<SampleType>> m_latencyDetector;
Contains audio-related artefacts useful for analysis by matchers.
Container for audio data.
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.