pub struct Resampler { /* private fields */ }Expand description
A samplerate converter.
This is a wrapper around libsamplerate’s SRC_STATE.
§Example
use resample::{Resampler, ResampleType};
// Generate a 880Hz sine wave for 1 second in 44100Hz with one channel.
let freq = PI * 880_f32 / 44100_f32;
let mut input = (0..44100).map(|i| (freq * i as f32).sin()).collect::<Vec<f32>>();
let mut output = vec![0.0; 48000];
// Instantiate a new resampler.
let mut resampler = Resampler::new(ResampleType::SincBestQuality, 1, 44100, 48000).unwrap();
// Resample the input from 44100Hz to 48000Hz.
let processed = resampler.finalize(&input, &mut output).unwrap();
assert_eq!(processed.read, 44100);
assert_eq!(processed.written, 48000);Implementations§
Source§impl Resampler
impl Resampler
Sourcepub fn new(
converter_type: ResampleType,
channels: u8,
from_rate: u32,
to_rate: u32,
) -> Result<Self, Error>
pub fn new( converter_type: ResampleType, channels: u8, from_rate: u32, to_rate: u32, ) -> Result<Self, Error>
Create a new samplerate converter assuming the given channel count and sample rates.
Sourcepub fn finalize(
&mut self,
input: &[f32],
output: &mut [f32],
) -> Result<Processed, Error>
pub fn finalize( &mut self, input: &[f32], output: &mut [f32], ) -> Result<Processed, Error>
Perform a samplerate conversion on last block of given input data (which may be empty).
If the number of channels used was not 1 (Mono), the samples
are expected to be stored interleaved.
If the returned Processed::written value equals the size of
the output buffer this way indicate that more data is available
for consumption and that the method should be invoked again with
potentially remaining input.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Resampler
impl RefUnwindSafe for Resampler
impl !Send for Resampler
impl !Sync for Resampler
impl Unpin for Resampler
impl UnwindSafe for Resampler
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