MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ compute_dynamic_range_energy()

std::vector< double > MayaFlux::Yantra::compute_dynamic_range_energy ( std::span< const double >  data,
const size_t  num_windows,
const uint32_t  hop_size,
const uint32_t  window_size 
)

Compute dynamic range energy using zero-copy processing.

This function computes the dynamic range energy for a given data span. It calculates the maximum and minimum absolute values in each window, then computes the dynamic range in decibels.

Parameters
dataInput data span
num_windowsNumber of windows to process
hop_sizeHop size for windowing
window_sizeSize of each window
Returns
Vector of dynamic range energy values

Definition at line 11 of file AnalysisHelper.cpp.

12{
13 std::vector<double> dr_values(num_windows);
14
15 std::vector<size_t> indices(num_windows);
16 std::iota(indices.begin(), indices.end(), 0);
17
18 MayaFlux::Parallel::for_each(MayaFlux::Parallel::par_unseq, indices.begin(), indices.end(),
19 [&](size_t i) {
20 const size_t start_idx = i * hop_size;
21 const size_t end_idx = std::min(start_idx + window_size, data.size());
22 auto window = data.subspan(start_idx, end_idx - start_idx);
23
24 double min_val = std::numeric_limits<double>::max();
25 double max_val = std::numeric_limits<double>::lowest();
26
27 for (double sample : window) {
28 double abs_sample = std::abs(sample);
29 min_val = std::min(min_val, abs_sample);
30 max_val = std::max(max_val, abs_sample);
31 }
32
33 if (min_val < 1e-10)
34 min_val = 1e-10;
35 dr_values[i] = 20.0 * std::log10(max_val / min_val);
36 });
37
38 return dr_values;
39}

Referenced by MayaFlux::Yantra::EnergyAnalyzer< InputType, OutputType >::compute_energy_values().

+ Here is the caller graph for this function: