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

◆ transform_pitch_shift() [2/2]

template<OperationReadyData DataType>
DataType MayaFlux::Yantra::transform_pitch_shift ( DataType &  input,
double  semitones,
uint32_t  window_size = 1024,
uint32_t  hop_size = 256 
)

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

Template Parameters
DataTypeOperationReadyData type
Parameters
inputInput data - WILL BE MODIFIED
semitonesPitch shift in semitones
window_sizeFFT window size
hop_sizeHop size for overlap-add
Returns
Pitch-shifted data

Definition at line 265 of file SpectralHelper.hpp.

269{
270 auto [target_data, structure_info] = OperationHelper::extract_structured_double(input);
271
272 if (semitones == 0.0) {
273 return input;
274 }
275
276 double pitch_ratio = std::pow(2.0, semitones / 12.0);
277
278 auto processor = [pitch_ratio](Eigen::VectorXcd& spectrum, size_t) {
279 Eigen::VectorXcd shifted_spectrum = Eigen::VectorXcd::Zero(spectrum.size());
280 auto bin_indices = std::views::iota(0, static_cast<int>(spectrum.size()));
281
282 std::ranges::for_each(bin_indices, [&](int bin) {
283 int shifted_bin = static_cast<int>(bin * pitch_ratio);
284 if (shifted_bin < shifted_spectrum.size()) {
285 shifted_spectrum[shifted_bin] = spectrum[bin];
286 }
287 });
288
289 spectrum = std::move(shifted_spectrum);
290 };
291
292 for (auto& span : target_data) {
293 auto result = process_spectral_windows(span, window_size, hop_size, processor);
294 std::ranges::copy(result, span.begin());
295 }
296
297 auto reconstructed_data = target_data
298 | std::views::transform([](const auto& span) {
299 return std::vector<double>(span.begin(), span.end());
300 })
301 | std::ranges::to<std::vector>();
302
303 return OperationHelper::reconstruct_from_double<DataType>(reconstructed_data, structure_info);
304}
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: