pub struct PacketResampler<T: Sample, B: PacketResamplerBuffer<T>> { /* private fields */ }Expand description
A wrapper around rubato’s Resampler that accepts inputs of any size and sends
resampled output packets to a given closure.
When using the Sequential PacketResamplerBuffer, the output packets will
be in de-interleaved format (using &SequentialOwned). When using the
Interleaved PacketResamplerBuffer, the output packets be be in interleaved
format (using &[T]).
This only supports synchronous resampling.
Implementations§
Source§impl<T: Sample, B: PacketResamplerBuffer<T>> PacketResampler<T, B>
impl<T: Sample, B: PacketResamplerBuffer<T>> PacketResampler<T, B>
Sourcepub fn new(
num_channels: usize,
in_sample_rate: u32,
out_sample_rate: u32,
config: ResamplerConfig,
) -> Self
pub fn new( num_channels: usize, in_sample_rate: u32, out_sample_rate: u32, config: ResamplerConfig, ) -> Self
Create a new PacketResampler.
num_channels- The number of audio channels.in_sample_rate- The sample rate of the input data.out_sample_rate- The sample rate of the output data.config- Extra configuration for the resampler.
§Panics
Panics if:
num_channels == 0in_sample_rate == 0out_sample_rate == 0config.chunk_size == 0config.sub_chunks == 0
Sourcepub fn from_custom(resampler: Box<dyn Resampler<T>>) -> Self
pub fn from_custom(resampler: Box<dyn Resampler<T>>) -> Self
Create a new PacketResampler using a custom Resampler.
This can be used, for example, to create a PacketResampler with non-integer input and/or output sample rates.
Sourcepub fn nbr_channels(&self) -> usize
pub fn nbr_channels(&self) -> usize
The number of channels configured for this resampler.
Sourcepub fn max_input_block_frames(&self) -> usize
pub fn max_input_block_frames(&self) -> usize
The number of frames (samples in a single channel of audio) that appear in a single packet of input data in the internal resampler.
Sourcepub fn max_output_block_frames(&self) -> usize
pub fn max_output_block_frames(&self) -> usize
The maximum number of frames (samples in a single channel of audio) that can
appear in a single call to the on_output_packet closure in
PacketResampler::process.
Sourcepub fn output_delay(&self) -> usize
pub fn output_delay(&self) -> usize
The delay introduced by the internal resampler in number of output frames ( samples in a single channel of audio).
Sourcepub fn out_alloc_frames(&self, input_frames: u64) -> u64
pub fn out_alloc_frames(&self, input_frames: u64) -> u64
The number of frames (samples in a single channel of audio) that are needed for an output buffer given the number of input frames.
Sourcepub fn process(
&mut self,
buffer_in: &dyn Adapter<'_, T>,
input_range: Option<Range<usize>>,
active_channels_mask: Option<&[bool]>,
on_output_packet: impl FnMut(&B::Output, usize),
last_packet: Option<LastPacketInfo>,
trim_delay: bool,
)
pub fn process( &mut self, buffer_in: &dyn Adapter<'_, T>, input_range: Option<Range<usize>>, active_channels_mask: Option<&[bool]>, on_output_packet: impl FnMut(&B::Output, usize), last_packet: Option<LastPacketInfo>, trim_delay: bool, )
Process the given input data and return packets of resampled output data.
buffer_in- The input data. You can use one of the types in thedirectmodule to wrap your input data into a type that implementsAdapter.input_range- The range in each input channel to read from. If this isNone, then the entire input buffer will be read.active_channels_mask- An optional mask that selects which channels inbuffer_into use. Channels marked withfalsewill be skipped and the output channel filled with zeros. IfNone, then all of the channels will be active.on_output_packet- Gets called whenever there is a new packet of resampled output data.(buffer, output_frames)- When using
Sequentialoutput buffers, the output will be of type &SequentialOwned. Note, the length of this buffer may be less thanoutput_frames. Only read up tooutput_framesdata from the buffer. - When using
Interleavedoutput buffers, the output will be of type&[T]. The number of frames in this slice will always be equal tooutput_frames.
- When using
last_packet- If this isSome, then any leftover input samples in the buffer will be flushed out and the resampler reset. Use this if this is the last/only packet of input data.trim_delay- Iftrue, then the initial padded zeros introduced by the internal resampler will be trimmed off.
This method is realtime-safe.
§Panics
Panics if:
- The
input_rangeis out of bounds for any of the input channels.