pub enum ResamplerType<T: Sample> {
Fast(FastFixedIn<T>),
Fft(FftFixedIn<T>),
}
Expand description
The type of resampling algorithm used in fixed_resample
.
Variants§
Fast(FastFixedIn<T>)
Low quality, fast performance
Fft(FftFixedIn<T>)
Great quality, medium performance
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: usize, quality: ResampleQuality, ) -> Self
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)
.
Sourcepub 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)>
pub 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)>
This is a convenience method for processing the last frames at the end of a stream.
Use this when there are fewer frames remaining than what the resampler requires as input.
Calling this function is equivalent to padding the input buffer with zeros
to make it the right input length, and then calling process_into_buffer.
This method can also be called without any input frames, by providing 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.