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

◆ transform_spectral_filter() [1/2]

template<OperationReadyData DataType>
DataType MayaFlux::Yantra::transform_spectral_filter ( DataType &  input,
double  low_freq,
double  high_freq,
double  sample_rate,
uint32_t  window_size,
uint32_t  hop_size,
std::vector< std::vector< double > > &  working_buffer 
)

Spectral filtering using existing FFT infrastructure with C++20 ranges (OUT-OF-PLACE)

Template Parameters
DataTypeOperationReadyData type
Parameters
inputInput data - will NOT be modified
low_freqLow cutoff frequency (Hz)
high_freqHigh cutoff frequency (Hz)
sample_rateSample rate (Hz)
window_sizeFFT window size
hop_sizeHop size for overlap-add
working_bufferBuffer for operations (will be resized if needed)
Returns
Filtered data

Definition at line 227 of file SpectralHelper.hpp.

234{
235 auto [target_data, structure_info] = OperationHelper::setup_operation_buffer(input, working_buffer);
236
237 auto processor = [low_freq, high_freq, sample_rate](Eigen::VectorXcd& spectrum, size_t) {
238 auto bin_indices = std::views::iota(0, static_cast<int>(spectrum.size()));
239 std::ranges::for_each(bin_indices, [&](int bin) {
240 double freq = (bin * sample_rate) / (2.0 * (double)spectrum.size());
241 if (freq < low_freq || freq > high_freq) {
242 spectrum[bin] = 0.0;
243 }
244 });
245 };
246
247 working_buffer.resize(target_data.size());
248 for (size_t i = 0; i < target_data.size(); ++i) {
249 working_buffer[i] = process_spectral_windows(target_data[i], window_size, hop_size, processor);
250 }
251
252 return OperationHelper::reconstruct_from_double<DataType>(working_buffer, structure_info);
253}
std::vector< double > process_spectral_windows(std::span< double > data, uint32_t window_size, uint32_t hop_size, ProcessorFunc &&processor)
Common spectral processing helper to eliminate code duplication.

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

+ Here is the call graph for this function: