Struct rubato::SincFixedOut
source · [−]pub struct SincFixedOut<T> { /* private fields */ }
Expand description
An asynchronous resampler that return a fixed number of audio frames. The number of input frames required is given by the input_frames_next function.
The resampling is done by creating a number of intermediate points (defined by oversampling_factor) by sinc interpolation. The new samples are then calculated by interpolating between these points.
The resampling ratio can be freely adjusted within the range specified to the constructor. Adjusting the ratio does not recalculate the sinc functions used by the anti-aliasing filter. This causes no issue when increasing the ratio (which slows down the output). However when decreasing more than a few percent (i.e. speeding up the output), the filters can no longer suppress all aliasing and this may lead to some artefacts. Higher maximum ratios require more memory to be allocated by input_buffer_allocate and an internal buffer.
Implementations
sourceimpl<T> SincFixedOut<T> where
T: Sample,
impl<T> SincFixedOut<T> where
T: Sample,
sourcepub fn new(
resample_ratio: f64,
max_resample_ratio_relative: f64,
parameters: InterpolationParameters,
chunk_size: usize,
nbr_channels: usize
) -> Result<Self, ResamplerConstructionError>
pub fn new(
resample_ratio: f64,
max_resample_ratio_relative: f64,
parameters: InterpolationParameters,
chunk_size: usize,
nbr_channels: usize
) -> Result<Self, ResamplerConstructionError>
Create a new SincFixedOut
Parameters are:
resample_ratio
: Starting ratio between output and input sample rates, must be > 0.max_resample_ratio_relative
: Maximum ratio that can be set with Resampler::set_resample_ratio relative toresample_ratio
, must be >= 1.0. The minimum relative ratio is the reciprocal of the maximum. For example, withmax_resample_ratio_relative
of 10.0, the ratio can be set betweenresample_ratio * 10.0
andresample_ratio / 10.0
.parameters
: Parameters for interpolation, seeInterpolationParameters
chunk_size
: size of output data in framesnbr_channels
: number of channels in input/output
sourcepub fn new_with_interpolator(
resample_ratio: f64,
max_resample_ratio_relative: f64,
interpolation_type: InterpolationType,
interpolator: Box<dyn SincInterpolator<T>>,
chunk_size: usize,
nbr_channels: usize
) -> Result<Self, ResamplerConstructionError>
pub fn new_with_interpolator(
resample_ratio: f64,
max_resample_ratio_relative: f64,
interpolation_type: InterpolationType,
interpolator: Box<dyn SincInterpolator<T>>,
chunk_size: usize,
nbr_channels: usize
) -> Result<Self, ResamplerConstructionError>
Create a new SincFixedOut using an existing Interpolator
Parameters are:
resample_ratio
: Starting ratio between output and input sample rates, must be > 0.max_resample_ratio_relative
: Maximum ratio that can be set with Resampler::set_resample_ratio relative toresample_ratio
, must be >= 1.0. The minimum relative ratio is the reciprocal of the maximum. For example, withmax_resample_ratio_relative
of 10.0, the ratio can be set betweenresample_ratio
* 10.0 andresample_ratio
/ 10.0.interpolation_type
: Parameters for interpolation, seeInterpolationParameters
interpolator
: The interpolator to usechunk_size
: size of output data in framesnbr_channels
: number of channels in input/output
Trait Implementations
sourceimpl<T> Resampler<T> for SincFixedOut<T> where
T: Sample,
impl<T> Resampler<T> for SincFixedOut<T> where
T: Sample,
sourcefn process_into_buffer<V: AsRef<[T]>>(
&mut self,
wave_in: &[V],
wave_out: &mut [Vec<T>],
active_channels_mask: Option<&[bool]>
) -> ResampleResult<()>
fn process_into_buffer<V: AsRef<[T]>>(
&mut self,
wave_in: &[V],
wave_out: &mut [Vec<T>],
active_channels_mask: Option<&[bool]>
) -> ResampleResult<()>
sourcefn input_frames_max(&self) -> usize
fn input_frames_max(&self) -> usize
Get the maximum number of input frames per channel the resampler could require
sourcefn input_frames_next(&self) -> usize
fn input_frames_next(&self) -> usize
Get the number of frames per channel needed for the next call to process_into_buffer or process Read more
sourcefn nbr_channels(&self) -> usize
fn nbr_channels(&self) -> usize
Get the maximum number of channels this Resampler is configured for
sourcefn output_frames_max(&self) -> usize
fn output_frames_max(&self) -> usize
Get the max number of output frames per channel
sourcefn output_frames_next(&self) -> usize
fn output_frames_next(&self) -> usize
Get the number of frames per channel that will be output from the next call to process_into_buffer or process Read more
sourcefn set_resample_ratio(&mut self, new_ratio: f64) -> ResampleResult<()>
fn set_resample_ratio(&mut self, new_ratio: f64) -> ResampleResult<()>
Update the resample ratio Read more
sourcefn set_resample_ratio_relative(&mut self, rel_ratio: f64) -> ResampleResult<()>
fn set_resample_ratio_relative(&mut self, rel_ratio: f64) -> ResampleResult<()>
Update the resample ratio as a factor relative to the original one Read more
sourcefn process<V: AsRef<[T]>>(
&mut self,
wave_in: &[V],
active_channels_mask: Option<&[bool]>
) -> ResampleResult<Vec<Vec<T>>>
fn process<V: AsRef<[T]>>(
&mut self,
wave_in: &[V],
active_channels_mask: Option<&[bool]>
) -> ResampleResult<Vec<Vec<T>>>
This is a convenience wrapper for process_into_buffer that allocates the output buffer with each call. For realtime applications, use process_into_buffer with a buffer allocated by output_buffer_allocate instead of this function. Read more
sourcefn input_buffer_allocate(&self) -> Vec<Vec<T>>
fn input_buffer_allocate(&self) -> Vec<Vec<T>>
Convenience method for allocating an input buffer suitable for use with process_into_buffer. The buffer’s capacity is big enough to prevent allocating additional heap memory before any call to process_into_buffer regardless of the current resampling ratio. Read more
sourcefn output_buffer_allocate(&self) -> Vec<Vec<T>>
fn output_buffer_allocate(&self) -> Vec<Vec<T>>
Convenience method for allocating an output buffer suitable for use with process_into_buffer. The buffer’s capacity is big enough to prevent allocating additional heap memory during any call to process_into_buffer regardless of the current resampling ratio. Read more
Auto Trait Implementations
impl<T> !RefUnwindSafe for SincFixedOut<T>
impl<T> Send for SincFixedOut<T> where
T: Send,
impl<T> !Sync for SincFixedOut<T>
impl<T> Unpin for SincFixedOut<T> where
T: Unpin,
impl<T> !UnwindSafe for SincFixedOut<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T, U> VecResampler<T> for U where
U: Resampler<T>,
impl<T, U> VecResampler<T> for U where
U: Resampler<T>,
sourcefn process(
&mut self,
wave_in: &[Vec<T, Global>],
active_channels_mask: Option<&[bool]>
) -> Result<Vec<Vec<T, Global>, Global>, ResampleError>
fn process(
&mut self,
wave_in: &[Vec<T, Global>],
active_channels_mask: Option<&[bool]>
) -> Result<Vec<Vec<T, Global>, Global>, ResampleError>
Refer to Resampler::process
sourcefn process_into_buffer(
&mut self,
wave_in: &[Vec<T, Global>],
wave_out: &mut [Vec<T, Global>],
active_channels_mask: Option<&[bool]>
) -> Result<(), ResampleError>
fn process_into_buffer(
&mut self,
wave_in: &[Vec<T, Global>],
wave_out: &mut [Vec<T, Global>],
active_channels_mask: Option<&[bool]>
) -> Result<(), ResampleError>
Refer to Resampler::process_into_buffer
sourcefn output_buffer_allocate(&self) -> Vec<Vec<T, Global>, Global>
fn output_buffer_allocate(&self) -> Vec<Vec<T, Global>, Global>
Refer to Resampler::output_buffer_allocate
sourcefn output_frames_next(&self) -> usize
fn output_frames_next(&self) -> usize
Refer to Resampler::output_frames_next
sourcefn output_frames_max(&self) -> usize
fn output_frames_max(&self) -> usize
Refer to Resampler::output_frames_max
sourcefn input_frames_next(&self) -> usize
fn input_frames_next(&self) -> usize
Refer to Resampler::input_frames_next
sourcefn nbr_channels(&self) -> usize
fn nbr_channels(&self) -> usize
Refer to Resampler::nbr_channels
sourcefn input_frames_max(&self) -> usize
fn input_frames_max(&self) -> usize
Refer to Resampler::input_frames_max
sourcefn input_buffer_allocate(&self) -> Vec<Vec<T, Global>, Global>
fn input_buffer_allocate(&self) -> Vec<Vec<T, Global>, Global>
Refer to Resampler::input_buffer_allocate
sourcefn set_resample_ratio(&mut self, new_ratio: f64) -> Result<(), ResampleError>
fn set_resample_ratio(&mut self, new_ratio: f64) -> Result<(), ResampleError>
Refer to Resampler::set_resample_ratio