8#include "metrics/hart_metric_query.hpp"
9#include "metrics/hart_metrics_common.hpp"
39template <
typename SampleType>
42 typename MetricQuery<
double>::SingleChannelMetricEvaluator evaluator =
44 (size_t channel,
Slice slice,
Unit requestedUnit)
47 hassert (channel < buffer.getNumChannels());
52 const auto sliceFrameIndices = buffer.getFrameIndices (slice);
53 const size_t sliceStart = sliceFrameIndices.first;
54 const size_t sliceStop = sliceFrameIndices.second;
55 const size_t numFrames = sliceStop - sliceStart;
57 hassert (sliceStart < sliceStop);
58 hassert (sliceStop <= buffer.getNumFrames());
60 const SampleType* channelData = buffer[channel];
63 for (size_t frame = sliceStart; frame < sliceStop; ++frame)
65 const SampleType x = channelData[frame];
69 const double rmsLinear = std::sqrt (sumSquares.
template get<
double>() / numFrames);
71 switch (requestedUnit)
82 const size_t numChannels = buffer.getNumChannels();
84 std::move (evaluator)
,
Implements Kahan algorithm for floating point accumulations.
Container for audio data.
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 ...
FloatType nan()
Returns a quiet NaN value for the given floating-point type.
static SampleType ratioToDecibels(SampleType valueLinear)
Converts linear value (ratio) to dB.
MetricQuery< double > rms(const AudioBuffer< SampleType > &buffer)
Calculates root mean square (RMS) of a signal.
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.