pub struct Samplerate { /* private fields */ }Expand description
A samplerate converter. This is a wrapper around libsamplerate’s SRC_STATE which also
stores the source and target samplerates.
§Example
use samplerate_rs::{Samplerate, ConverterType};
// Generate a 880Hz sine wave for 1 second in 44100Hz with one channel.
let freq = std::f32::consts::PI * 880f32 / 44100f32;
let mut input: Vec<f32> = (0..44100).map(|i| (freq * i as f32).sin()).collect();
// Instanciate a new converter.
let mut converter = Samplerate::new(ConverterType::SincBestQuality, 44100, 48000, 1).unwrap();
// Resample the input from 44100Hz to 48000Hz.
let resampled = converter.process_last(&input).unwrap();
assert_eq!(resampled.len(), 48000);Implementations§
Source§impl Samplerate
impl Samplerate
Sourcepub fn new(
converter_type: ConverterType,
from_rate: u32,
to_rate: u32,
channels: usize,
) -> Result<Samplerate, Error>
pub fn new( converter_type: ConverterType, from_rate: u32, to_rate: u32, channels: usize, ) -> Result<Samplerate, Error>
Create a new samplerate converter with the given rates and channels.
Sourcepub fn set_from_rate(&mut self, from_rate: u32)
pub fn set_from_rate(&mut self, from_rate: u32)
Change the source samplerate.
Sourcepub fn set_to_rate(&mut self, to_rate: u32)
pub fn set_to_rate(&mut self, to_rate: u32)
Change the target samplerate.
Sourcepub fn ratio(&self) -> f64
pub fn ratio(&self) -> f64
Calculate the ratio (target samplerate divided by source samplerate).
Trait Implementations§
Source§impl Clone for Samplerate
impl Clone for Samplerate
Source§fn clone(&self) -> Samplerate
fn clone(&self) -> Samplerate
Might panic if the underlying src_clone method from libsamplerate returns an error.
1.0.0 · 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 Freeze for Samplerate
impl RefUnwindSafe for Samplerate
impl !Send for Samplerate
impl !Sync for Samplerate
impl Unpin for Samplerate
impl UnwindSafe for Samplerate
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