7#include "metrics/hart_metric_query.hpp"
8#include "metrics/hart_metrics_common.hpp"
60 typename MetricQuery<
double>::SingleChannelMetricEvaluator evaluator =
62 (size_t channel,
const Slice& slice,
Unit requestedUnit)
71 const size_t startBin = binIndices.first;
72 const size_t stopBin = binIndices.second;
74 if (slice
.isEmpty() || stopBin - startBin == 0)
80 const std::complex<
double>* bins = spectrum
[channel
];
81 double maxSquaredMagnitude = 0.0;
82 size_t binOfMaxSquaredMagnitude = 0;
84 for (size_t currentBin = startBin; currentBin < stopBin; ++currentBin)
86 const double currentSquaredMagnitude = std::norm (bins[currentBin]);
88 if (currentSquaredMagnitude > maxSquaredMagnitude)
90 maxSquaredMagnitude = currentSquaredMagnitude;
91 binOfMaxSquaredMagnitude = currentBin;
100 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.
double getBinFrequencyHz(size_t binIndex) const
Returns frequency corresponding to a 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 > loudestBinFrequency(const Spectrum &spectrum)
Returns the center frequency of the loudest FFT bin.
FloatType nan()
Returns a quiet NaN value for the given floating-point type.
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.