5#include "metrics/hart_metric_query.hpp"
6#include "metrics/hart_metrics_common.hpp"
57 typename MetricQuery<
double>::SingleChannelMetricEvaluator evaluator =
58 [&spectrum, weighting]
59 (size_t channel,
const Slice& slice,
Unit requestedUnit)
69 const size_t startBin = binIndices.first;
70 const size_t stopBin = binIndices.second;
72 if (slice
.isEmpty() || stopBin - startBin == 0)
83 for (size_t bin = startBin; bin < stopBin; ++bin)
88 numerator
+= magnitudeLinear * frequencyHz;
89 denominator
+= magnitudeLinear;
94 for (size_t bin = startBin; bin < stopBin; ++bin)
97 const double powerLinear = magnitudeLinear * magnitudeLinear;
100 numerator
+= powerLinear * frequencyHz;
101 denominator
+= powerLinear;
113 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.
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.
Frequency-domain representation of a multi-channel audio signal.
double getSampleRateHz() const
Returns sample rate in Hz.
std::pair< size_t, size_t > getBinIndices(const Slice &slice) const
Returns a pair of indices representing a provided slice.
double getBinFrequencyHz(size_t binIndex) const
Returns frequency corresponding to a bin index.
double getBinMagnitude(size_t channel, size_t binIndex) const
Returns magnitude of a frequency bin, by bin index.
size_t getNumBins() const
Returns number of frequency bins per channel.
size_t getNumChannels() const
Returns number of channels.
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 > spectralCentroid(const Spectrum &spectrum, SpectralCentroid::Weighting weighting=SpectralCentroid::Weighting::magnitude)
Calculates spectral centroid.
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.
@ native
Default (native) unit of whatever returns some value.
Helpers to generate common default channel subsets.
static std::vector< size_t > allChannels(size_t numChannels)
Represents a slice of analysis data.