PitchShifter

Struct PitchShifter 

Source
pub struct PitchShifter { /* private fields */ }
Expand description

Implementations§

Source§

impl PitchShifter

Source

pub fn new(window_duration_ms: usize, sample_rate: usize) -> Self

Phase Vocoding works by extracting overlapping windows from a buffer and processing them individually before merging the results into the output buffer.

You must set a duration in miliseconds for these windows; 50ms is a good value.

The sample rate argument must correspond to the sample rate of the buffer(s) you will provide to PitchShifter::shift_pitch, which is how many values correspond to one second of audio in the buffer.

Source

pub fn shift_pitch( &mut self, over_sampling: usize, shift: f32, in_b: &[f32], out_b: &mut [f32], )

This is where the magic happens.

The bigger over_sampling, the longer it will take to process, but the better the results. I put 16 in the shift-wav binary.

shift is how many semitones to apply to the buffer. It is signed: a negative value will lower the tone and vice-versa.

in_b is where the input buffer goes, and you must pass an output buffer of the same length in out_b.

Note: It’s actually not magic, sadly.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.