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

◆ transform_spectral_filter() [2/2]

template<OperationReadyData DataType>
DataType MayaFlux::Yantra::transform_spectral_filter ( DataType &  input,
double  low_freq,
double  high_freq,
double  sample_rate = 48000.0,
uint32_t  window_size = 1024,
uint32_t  hop_size = 256 
)

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

Template Parameters
DataTypeOperationReadyData type
Parameters
inputInput data - WILL 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
Returns
Filtered data

Definition at line 181 of file SpectralHelper.hpp.

187{
188 auto [target_data, structure_info] = OperationHelper::extract_structured_double(input);
189
190 auto processor = [low_freq, high_freq, sample_rate](Eigen::VectorXcd& spectrum, size_t) {
191 auto bin_indices = std::views::iota(0, static_cast<int>(spectrum.size()));
192 std::ranges::for_each(bin_indices, [&](int bin) {
193 double freq = (bin * sample_rate) / (2.0 * (double)spectrum.size());
194 if (freq < low_freq || freq > high_freq) {
195 spectrum[bin] = 0.0;
196 }
197 });
198 };
199
200 for (auto& span : target_data) {
201 auto result = process_spectral_windows(span, window_size, hop_size, processor);
202 std::ranges::copy(result, span.begin());
203 }
204
205 auto reconstructed_data = target_data
206 | std::views::transform([](const auto& span) {
207 return std::vector<double>(span.begin(), span.end());
208 })
209 | std::ranges::to<std::vector>();
210
211 return OperationHelper::reconstruct_from_double<DataType>(reconstructed_data, structure_info);
212}
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 MayaFlux::Yantra::OperationHelper::extract_structured_double(), and process_spectral_windows().

Referenced by MayaFlux::Yantra::SpectralTransformer< InputType, OutputType >::transform_implementation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: