Struct rubato::SincFixedOut
source · pub struct SincFixedOut<T> { /* private fields */ }
Expand description
An asynchronous resampler that returns 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§
source§impl<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: SincInterpolationParameters,
chunk_size: usize,
nbr_channels: usize
) -> Result<Self, ResamplerConstructionError>
pub fn new( resample_ratio: f64, max_resample_ratio_relative: f64, parameters: SincInterpolationParameters, 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, seeSincInterpolationParameters
.chunk_size
: Size of output data in frames.nbr_channels
: Number of channels in input/output.
sourcepub fn new_with_interpolator(
resample_ratio: f64,
max_resample_ratio_relative: f64,
interpolation_type: SincInterpolationType,
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: SincInterpolationType, 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, seeSincInterpolationParameters
.interpolator
: The interpolator to use.chunk_size
: Size of output data in frames.nbr_channels
: Number of channels in input/output.
Trait Implementations§
source§impl<T> Resampler<T> for SincFixedOut<T>where
T: Sample,
impl<T> Resampler<T> for SincFixedOut<T>where
T: Sample,
source§fn process_into_buffer<Vin: AsRef<[T]>, Vout: AsMut<[T]>>(
&mut self,
wave_in: &[Vin],
wave_out: &mut [Vout],
active_channels_mask: Option<&[bool]>
) -> ResampleResult<(usize, usize)>
fn process_into_buffer<Vin: AsRef<[T]>, Vout: AsMut<[T]>>( &mut self, wave_in: &[Vin], wave_out: &mut [Vout], active_channels_mask: Option<&[bool]> ) -> ResampleResult<(usize, usize)>
source§fn input_frames_max(&self) -> usize
fn input_frames_max(&self) -> usize
source§fn input_frames_next(&self) -> usize
fn input_frames_next(&self) -> usize
source§fn nbr_channels(&self) -> usize
fn nbr_channels(&self) -> usize
source§fn output_frames_max(&self) -> usize
fn output_frames_max(&self) -> usize
source§fn output_frames_next(&self) -> usize
fn output_frames_next(&self) -> usize
source§fn output_delay(&self) -> usize
fn output_delay(&self) -> usize
source§fn set_resample_ratio(
&mut self,
new_ratio: f64,
ramp: bool
) -> ResampleResult<()>
fn set_resample_ratio( &mut self, new_ratio: f64, ramp: bool ) -> ResampleResult<()>
source§fn set_resample_ratio_relative(
&mut self,
rel_ratio: f64,
ramp: bool
) -> ResampleResult<()>
fn set_resample_ratio_relative( &mut self, rel_ratio: f64, ramp: bool ) -> ResampleResult<()>
source§fn 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>>>
source§fn process_partial_into_buffer<Vin: AsRef<[T]>, Vout: AsMut<[T]>>(
&mut self,
wave_in: Option<&[Vin]>,
wave_out: &mut [Vout],
active_channels_mask: Option<&[bool]>
) -> ResampleResult<(usize, usize)>
fn process_partial_into_buffer<Vin: AsRef<[T]>, Vout: AsMut<[T]>>( &mut self, wave_in: Option<&[Vin]>, wave_out: &mut [Vout], active_channels_mask: Option<&[bool]> ) -> ResampleResult<(usize, usize)>
None
as input buffer.
This can be utilized to push any remaining delayed frames out from the internal buffers.
Note that this method allocates space for a temporary input buffer.
Real-time applications should instead call process_into_buffer
with a zero-padded pre-allocated input buffer.