MayaFlux 0.3.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 191 of file MatrixHelper.hpp.

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

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

+ Here is the call graph for this function: