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

◆ transform_by_energy() [1/2]

template<OperationReadyData DataType, typename TransformFunc >
requires std::invocable<TransformFunc, double>
DataType MayaFlux::Yantra::transform_by_energy ( DataType &  input,
double  energy_threshold,
TransformFunc  transform_func,
uint32_t  window_size,
uint32_t  hop_size,
std::vector< std::vector< double > > &  working_buffer 
)

Energy-based transformation using existing EnergyAnalyzer (OUT-OF-PLACE)

Template Parameters
DataTypeOperationReadyData type
TransformFuncFunction type for transformation
Parameters
inputInput data - will NOT be modified
energy_thresholdEnergy threshold for transformation
transform_funcTransformation function
window_sizeAnalysis window size
hop_sizeHop size between windows
working_bufferBuffer for operations (will be resized if needed)
Returns
Transformed data

Definition at line 189 of file MatrixHelper.hpp.

195{
196 auto [target_data, structure_info] = OperationHelper::setup_operation_buffer(input, working_buffer);
197
198 auto energy_analyzer = std::make_shared<StandardEnergyAnalyzer>(window_size, hop_size);
199 energy_analyzer->set_energy_method(EnergyMethod::RMS);
200 auto energy_result = energy_analyzer->analyze_energy(input);
201
202 for (size_t ch = 0; ch < energy_result.channels.size() && ch < target_data.size(); ++ch) {
203 const auto& channel_energy = energy_result.channels[ch];
204 auto& target_channel = target_data[ch];
205
206 for (size_t i = 0; i < channel_energy.energy_values.size(); ++i) {
207 if (channel_energy.energy_values[i] > energy_threshold && i < channel_energy.window_positions.size()) {
208 auto [start_idx, end_idx] = channel_energy.window_positions[i];
209
210 if (start_idx < target_channel.size() && end_idx <= target_channel.size()) {
211 auto window_span = target_channel.subspan(start_idx, end_idx - start_idx);
212 std::ranges::transform(window_span, window_span.begin(), transform_func);
213 }
214 }
215 }
216 }
217
218 return OperationHelper::reconstruct_from_double<DataType>(working_buffer, structure_info);
219}

References RMS, and MayaFlux::Yantra::OperationHelper::setup_operation_buffer().

+ Here is the call graph for this function: