8#include "metrics/hart_metric_query.hpp"
9#include "metrics/hart_metrics_common.hpp"
49template <
typename SampleType>
52 MetricQuery<
double>::SingleChannelMetricEvaluator evaluator =
54 (size_t channel,
Slice ,
Unit requestedUnit)
57 hassert (channel < ir.getNumChannels());
62 const size_t numFrames = ir.getNumFrames();
67 const double sampleRateHz = ir.getSampleRateHz();
69 const double samplePeriodSeconds = 1.0 / sampleRateHz;
71 const SampleType* irChannelData = ir[channel];
76 for (size_t i = 0; i < numFrames; ++i)
78 const double h =
static_cast<
double> (irChannelData[i]);
79 const double hSquared = h * h;
80 const double t = i * samplePeriodSeconds;
82 numerator
+= t * hSquared;
83 denominator
+= hSquared;
91 switch (requestedUnit)
96 case Unit::frames:
return centreTimeSeconds * sampleRateHz;
102 const size_t numChannels = ir.getNumChannels();
104 std::move (evaluator)
,
Implements Kahan algorithm for floating point accumulations.
SampleType getValue() const
AccurateSum & operator+=(SampleType value)
Adds a value to a sum, tracking the potential floating point error.
Container for representing an impulse response (IR)
Manages the metrics calculations.
MetricQuery(SingleChannelMetricEvaluator evaluator, size_t totalNumChannels, std::vector< size_t > &&defaultChannelsToProcess)
Create a metric query object for a metric that operates on one channel at a time.
Thrown when some metric is requested to return a value in an unsupported unit.
#define hassert(condition)
Triggers a HartAssertException if the condition is false
#define HART_THROW_OR_RETURN(ExceptionType, message, returnValue)
Throws an exception if HART_DO_NOT_THROW_EXCEPTIONS is set, prints a message and returns a specified ...
MetricQuery< double > centreTime(const ImpulseResponse< SampleType > &ir)
Calculates the centre time of an impulse response.
FloatType nan()
Returns a quiet NaN value for the given floating-point type.
static SampleType floatsEqual(SampleType a, SampleType b, SampleType epsilon=(SampleType) 1e-8)
Compares two floating point numbers within a given tolerance.
Unit
Represents a physical unit.
@ seconds
Time stamps, intervals, durations.
@ native
Default (native) unit of whatever returns some value.
@ frames
Value of something in frames (samples)
Helpers to generate common default channel subsets.
static std::vector< size_t > allChannels(size_t numChannels)
Represents a slice of analysis data.