pub enum ResamplerType<T: Sample> {
Fast(FastFixedIn<T>),
Fft(FftFixedIn<T>),
ArbitraryRatioSinc(SincFixedIn<T>),
}
Expand description
The resampling algorithm used in fixed_resample
.
Variants§
Fast(FastFixedIn<T>)
Ok quality, fast performance
Fft(FftFixedIn<T>)
Great quality, medium performance
ArbitraryRatioSinc(SincFixedIn<T>)
Similar quality to ResamplerType::Fft
, low performance.
Use this if you need a non-integer ratio (i.e. repitching a sample).
Implementations§
Source§impl<T: Sample> ResamplerType<T>
impl<T: Sample> ResamplerType<T>
pub fn from_quality( in_sample_rate: u32, out_sample_rate: u32, num_channels: NonZeroUsize, quality: ResampleQuality, ) -> Self
Sourcepub fn arbitrary_ratio_sinc(ratio: f64, num_channels: NonZeroUsize) -> Self
pub fn arbitrary_ratio_sinc(ratio: f64, num_channels: NonZeroUsize) -> Self
Create a new resampler that uses the SincFixedIn
resampler from rubato.
This has similar quality to the rubato::FftFixedIn
resampler used
for ResampleQuality::High
, but with much lower performance. Use
this if you need a non-integer ratio (i.e. repitching a sample).
ratio
- The resampling ratio (output / input
)num_channels
- The number of channels
More specifically, this creates a resampler with the following parameters:
SincInterpolationParameters {
sinc_len: 128,
f_cutoff: rubato::calculate_cutoff(128, WindowFunction::Blackman2),
interpolation: SincInterpolationType::Cubic,
oversampling_factor: 512,
window: WindowFunction::Blackman2,
}
§Panics
Panics if:
ratio <= 0.0
num_channels > MAX_CHANNELS
Sourcepub fn num_channels(&self) -> usize
pub fn num_channels(&self) -> usize
Get the number of channels this Resampler is configured for.
Sourcepub fn input_frames_next(&mut self) -> usize
pub fn input_frames_next(&mut self) -> usize
Get the number of frames per channel needed for the next call to
[ResamplerRefMut::process_into_buffer
].
Sourcepub fn input_frames_max(&mut self) -> usize
pub fn input_frames_max(&mut self) -> usize
Get the maximum number of input frames per channel the resampler could require.
Sourcepub fn output_delay(&mut self) -> usize
pub fn output_delay(&mut self) -> usize
Get the delay for the resampler, reported as a number of output frames.
Sourcepub fn output_frames_max(&mut self) -> usize
pub fn output_frames_max(&mut self) -> usize
Get the max number of output frames per channel.
Sourcepub 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)>
pub 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)>
Resample a buffer of audio to a pre-allocated output buffer. Use this in real-time applications where the unpredictable time required to allocate memory from the heap can cause glitches. If this is not a problem, you may use the process method instead.
The input and output buffers are used in a non-interleaved format.
The input is a slice, where each element of the slice is itself referenceable
as a slice (AsRef<[T]>) which contains the samples for a single channel.
Because [Vec<T>]
implements AsRef<\[T\]>
, the input may be Vec<Vec<T>>
.
The output data is a slice, where each element of the slice is a [T]
which contains
the samples for a single channel. If the output channel slices do not have sufficient
capacity for all output samples, the function will return an error with the expected
size. You could allocate the required output buffer with
output_buffer_allocate before calling this function
and reuse the same buffer for each call.
The active_channels_mask
is optional.
Any channel marked as inactive by a false value will be skipped during processing
and the corresponding output will be left unchanged.
If None
is given, all channels will be considered active.
Before processing, it checks that the input and outputs are valid.
If either has the wrong number of channels, or if the buffer for any channel is too short,
a [ResampleError] is returned.
Both input and output are allowed to be longer than required.
The number of input samples consumed and the number output samples written
per channel is returned in a tuple, (input_frames, output_frames)
.