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

◆ transform_pitch_shift() [1/2]

template<OperationReadyData DataType>
DataType MayaFlux::Yantra::transform_pitch_shift ( DataType &  input,
double  semitones,
uint32_t  window_size,
uint32_t  hop_size,
std::vector< std::vector< double > > &  working_buffer 
)

Pitch shifting using existing FFT from AnalysisHelper with C++20 ranges (OUT-OF-PLACE)

Template Parameters
DataTypeOperationReadyData type
Parameters
inputInput data - will NOT be modified
semitonesPitch shift in semitones
window_sizeFFT window size
hop_sizeHop size for overlap-add
working_bufferBuffer for operations (will be resized if needed)
Returns
Pitch-shifted data

Definition at line 317 of file SpectralHelper.hpp.

322{
323 auto [target_data, structure_info] = OperationHelper::setup_operation_buffer(input, working_buffer);
324
325 if (semitones == 0.0) {
326 return input;
327 }
328
329 double pitch_ratio = std::pow(2.0, semitones / 12.0);
330
331 auto processor = [pitch_ratio](Eigen::VectorXcd& spectrum, size_t) {
332 Eigen::VectorXcd shifted_spectrum = Eigen::VectorXcd::Zero(spectrum.size());
333 auto bin_indices = std::views::iota(0, static_cast<int>(spectrum.size()));
334
335 std::ranges::for_each(bin_indices, [&](int bin) {
336 int shifted_bin = static_cast<int>(bin * pitch_ratio);
337 if (shifted_bin < shifted_spectrum.size()) {
338 shifted_spectrum[shifted_bin] = spectrum[bin];
339 }
340 });
341
342 spectrum = std::move(shifted_spectrum);
343 };
344
345 working_buffer.resize(target_data.size());
346 for (size_t i = 0; i < target_data.size(); ++i) {
347 working_buffer[i] = process_spectral_windows(target_data[i], window_size, hop_size, processor);
348 }
349
350 return OperationHelper::reconstruct_from_double<DataType>(working_buffer, structure_info);
351}
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: