pub struct PhaseVocoder { /* private fields */ }Expand description
Phase vocoder for high-quality time-stretching and pitch-shifting
Uses STFT analysis/synthesis with phase coherence preservation for artifact-free time/pitch manipulation. All operations SIMD-accelerated.
§Example
// Create vocoder: 2048 FFT, 512 hop (75% overlap)
let mut vocoder = PhaseVocoder::new(2048, 512, 44100.0, WindowType::Hann);
// Slow down by 2x (half speed, preserves pitch)
vocoder.set_time_stretch(2.0);
// Or pitch shift up 7 semitones (perfect fifth)
vocoder.set_pitch_shift(7.0);
// Process audio
let input = vec![0.0; 512];
let mut output = vec![0.0; 512];
vocoder.process(&mut output, &input);Implementations§
Source§impl PhaseVocoder
impl PhaseVocoder
Sourcepub fn new(
fft_size: usize,
hop_size: usize,
sample_rate: f32,
window_type: WindowType,
) -> Self
pub fn new( fft_size: usize, hop_size: usize, sample_rate: f32, window_type: WindowType, ) -> Self
Create a new phase vocoder
§Arguments
fft_size- FFT size (must be power of 2, typically 2048 or 4096)hop_size- Hop size in samples (typically fft_size/4 for 75% overlap)sample_rate- Audio sample rate in Hzwindow_type- Window function type
§Example
let vocoder = PhaseVocoder::new(2048, 512, 44100.0, WindowType::Hann);Sourcepub fn set_time_stretch(&mut self, ratio: f32)
pub fn set_time_stretch(&mut self, ratio: f32)
Sourcepub fn set_pitch_shift(&mut self, semitones: f32)
pub fn set_pitch_shift(&mut self, semitones: f32)
Sourcepub fn process(&mut self, output: &mut [f32], _input: &[f32])
pub fn process(&mut self, output: &mut [f32], _input: &[f32])
Process audio through the phase vocoder
§Arguments
output- Output buffer (will be filled with processed audio)input- Input audio buffer
§Example
let mut vocoder = PhaseVocoder::new(2048, 512, 44100.0, WindowType::Hann);
let input = vec![0.0; 512];
let mut output = vec![0.0; 512];
vocoder.process(&mut output, &input);Sourcepub fn time_stretch(&self) -> f32
pub fn time_stretch(&self) -> f32
Get the current time stretch ratio
Sourcepub fn pitch_shift(&self) -> f32
pub fn pitch_shift(&self) -> f32
Get the current pitch shift in semitones
Trait Implementations§
Source§impl Clone for PhaseVocoder
impl Clone for PhaseVocoder
Source§fn clone(&self) -> PhaseVocoder
fn clone(&self) -> PhaseVocoder
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for PhaseVocoder
impl !UnwindSafe for PhaseVocoder
impl Freeze for PhaseVocoder
impl Send for PhaseVocoder
impl Sync for PhaseVocoder
impl Unpin for PhaseVocoder
impl UnsafeUnpin for PhaseVocoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more