7#include "metrics/hart_metric_query.hpp"
8#include "metrics/hart_metrics_common.hpp"
62 typename MetricQuery<
double>::SingleChannelMetricEvaluator evaluator =
64 (size_t channel,
const Slice& slice,
Unit requestedUnit)
70 const size_t startBin = binIndices.first;
71 const size_t stopBin = binIndices.second;
73 if (slice
.isEmpty() || stopBin - startBin == 0)
79 const std::complex<
double>* bins = spectrum
[channel
];
80 double maxSquaredMagnitude = 0.0;
82 for (size_t bin = startBin; bin < stopBin; ++bin)
83 maxSquaredMagnitude = std::max (std::norm (bins[bin]), maxSquaredMagnitude);
85 const double maxMagnitude = sqrt (maxSquaredMagnitude);
87 switch (requestedUnit)
109 std::move (evaluator)
,
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.
const std::complex< double > * operator[](size_t channel) const
Returns pointer to read-only magnitudes of a specific channel.
std::pair< size_t, size_t > getBinIndices(const Slice &slice) const
Returns a pair of indices representing a provided slice.
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 > loudestBinMagnitude(const Spectrum &spectrum)
Calculates the magnitude of the loudest FFT bin.
FloatType nan()
Returns a quiet NaN value for the given floating-point type.
static SampleType ratioToDecibels(SampleType valueLinear)
Converts linear value (ratio) to dB.
Unit
Represents a physical unit.
@ dB
Value of something in decibels. Can represent voltage, power, or a domain-specific unit like "LUFS" o...
@ native
Default (native) unit of whatever returns some value.
@ linear
Value of a sample (voltage) in a linear domain.
Helpers to generate common default channel subsets.
static std::vector< size_t > allChannels(size_t numChannels)
Represents a slice of analysis data.