pub struct Async<T> { /* private fields */ }Expand description
An asynchronous resampler that uses either polynomial or sinc interpolation.
The fixed argument determines if input of output should be fixed size.
When the input size is fixed, the output size varies from call to call,
and when output size is fixed, the input size varies.
The number of frames on the fixed side is determined by the chunk size argument to the constructor.
This value can be changed by the set_chunk_size() method,
to let the resampler process smaller chunks of audio data.
Note that the chunk size cannot exceed the value given at creation time.
When the input size is fixed, the maximum value can be retrieved using the input_size_max() method,
and input_frames_next() gives the current value.
When the output size is fixed, the corresponding values are instead provided by the output_size_max()
and output_size_next() methods.
§Interpolation
This resampler can use either polynomial or sinc interpolation. Sinc interpolation gives the best quality, while polynomial interpolation runs significantly faster.
§Polynomial
The resampling is done by interpolating between the input samples by fitting a polynomial. The polynomial degree can be selected, see PolynomialDegree for the available options. Higher polynomial degrees give better quality but run slower.
Note that no anti-aliasing filter is used. This makes it run considerably faster than the corresponding Sinc resampler, which performs anti-aliasing filtering. The price is that the resampling creates some artefacts in the output, mainly at higher frequencies. Use a Sinc resampler if this can not be tolerated.
§Sinc
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.
§Adjusting the resampling ratio
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 (or speeding up the output), the filters can no longer suppress all aliasing and this may lead to some artefacts.
The resampling ratio can be freely adjusted within the range specified to the constructor. Higher maximum ratios require more memory to be allocated by an internal buffer, and increase the maximum length of the variable length input or output buffer.
Implementations§
Source§impl<T> Async<T>where
T: Sample,
impl<T> Async<T>where
T: Sample,
Sourcepub fn new_poly(
resample_ratio: f64,
max_resample_ratio_relative: f64,
interpolation_type: PolynomialDegree,
chunk_size: usize,
nbr_channels: usize,
fixed: FixedAsync,
) -> Result<Self, ResamplerConstructionError>
pub fn new_poly( resample_ratio: f64, max_resample_ratio_relative: f64, interpolation_type: PolynomialDegree, chunk_size: usize, nbr_channels: usize, fixed: FixedAsync, ) -> Result<Self, ResamplerConstructionError>
Create a new Async resampler that uses polynomial interpolation.
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_relativeof 10.0, the ratio can be set betweenresample_ratio * 10.0andresample_ratio / 10.0.interpolation_type: Degree of polynomial used for interpolation, see PolynomialDegree.chunk_size: Size of input data in frames.nbr_channels: Number of channels in input/output.fixed: Deciding whether input or output size is fixed.
Sourcepub fn new_sinc(
resample_ratio: f64,
max_resample_ratio_relative: f64,
parameters: &SincInterpolationParameters,
chunk_size: usize,
nbr_channels: usize,
fixed: FixedAsync,
) -> Result<Self, ResamplerConstructionError>
pub fn new_sinc( resample_ratio: f64, max_resample_ratio_relative: f64, parameters: &SincInterpolationParameters, chunk_size: usize, nbr_channels: usize, fixed: FixedAsync, ) -> Result<Self, ResamplerConstructionError>
Create a new Async resampler that uses sinc interpolation.
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_relativeof 10.0, the ratio can be set betweenresample_ratio * 10.0andresample_ratio / 10.0.parameters: Parameters for interpolation, see SincInterpolationParameters.chunk_size: Size of input data in frames.nbr_channels: Number of channels in input/output.
Trait Implementations§
Source§impl<T> Resampler<T> for Async<T>where
T: Sample,
impl<T> Resampler<T> for Async<T>where
T: Sample,
Source§fn process_into_buffer<'a>(
&mut self,
buffer_in: &dyn Adapter<'a, T>,
buffer_out: &mut dyn AdapterMut<'a, T>,
indexing: Option<&Indexing>,
) -> ResampleResult<(usize, usize)>
fn process_into_buffer<'a>( &mut self, buffer_in: &dyn Adapter<'a, T>, buffer_out: &mut dyn AdapterMut<'a, T>, indexing: Option<&Indexing>, ) -> ResampleResult<(usize, 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 nbr_channels(&self) -> usize
fn nbr_channels(&self) -> 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 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 resample_ratio(&self) -> f64
fn resample_ratio(&self) -> f64
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 set_chunk_size(&mut self, chunksize: usize) -> ResampleResult<()>
fn set_chunk_size(&mut self, chunksize: usize) -> ResampleResult<()>
Source§fn process(
&mut self,
buffer_in: &dyn Adapter<'_, T>,
input_offset: usize,
active_channels_mask: Option<&[bool]>,
) -> ResampleResult<InterleavedOwned<T>>
fn process( &mut self, buffer_in: &dyn Adapter<'_, T>, input_offset: usize, active_channels_mask: Option<&[bool]>, ) -> ResampleResult<InterleavedOwned<T>>
Source§fn process_all_into_buffer<'a>(
&mut self,
buffer_in: &dyn Adapter<'a, T>,
buffer_out: &mut dyn AdapterMut<'a, T>,
input_len: usize,
active_channels_mask: Option<&[bool]>,
) -> ResampleResult<(usize, usize)>
fn process_all_into_buffer<'a>( &mut self, buffer_in: &dyn Adapter<'a, T>, buffer_out: &mut dyn AdapterMut<'a, T>, input_len: usize, active_channels_mask: Option<&[bool]>, ) -> ResampleResult<(usize, usize)>
Source§fn process_all_needed_output_len(&mut self, input_len: usize) -> usize
fn process_all_needed_output_len(&mut self, input_len: usize) -> usize
input_len using the
process_all_into_buffer method. Read more