pub struct RtResampler<T: Sample> { /* private fields */ }
Expand description
An easy to use resampler that can be used in realtime applications.
Implementations§
Source§impl<T: Sample> RtResampler<T>
impl<T: Sample> RtResampler<T>
Sourcepub fn new(
in_sample_rate: u32,
out_sample_rate: u32,
num_channels: usize,
max_out_frames: usize,
interleaved: bool,
quality: ResampleQuality,
) -> Self
pub fn new( in_sample_rate: u32, out_sample_rate: u32, num_channels: usize, max_out_frames: usize, interleaved: bool, quality: ResampleQuality, ) -> Self
Create a new realtime resampler.
in_sample_rate
- The sample rate of the input stream.out_sample_rate
- The sample rate of the output stream.num_channels
- The number of channels.max_out_frames
- The maximum number of output frames that can appear in a single call toRtResampler::process
.interleaved
- If you are planning to useRtResampler::process_interleaved
, set this totrue
. Otherwise you can set this tofalse
to save a bit of memory.quality
- The quality of the resampling algorithm.
§Panics
Panics if:
in_sample_rate == 0
out_sample_rate == 0
num_channels == 0
,max_out_frames == 0
Sourcepub fn from_custom(
resampler: impl Into<ResamplerType<T>>,
max_out_frames: usize,
interleaved: bool,
) -> Self
pub fn from_custom( resampler: impl Into<ResamplerType<T>>, max_out_frames: usize, interleaved: bool, ) -> Self
Create a new realtime resampler using the given rubato resampler.
resampler
- The rubato resampler.max_out_frames
- The maximum number of output frames that can appear in a single call toRtResampler::process
.interleaved
- If you are planning to useRtResampler::process_interleaved
, set this totrue
. Otherwise you can set this tofalse
to save a bit of memory.
§Panics
Panics if max_out_frames == 0
.
Sourcepub fn num_channels(&self) -> NonZeroUsize
pub fn num_channels(&self) -> NonZeroUsize
Get the number of channels this resampler is configured for.
Sourcepub fn max_out_frames(&self) -> usize
pub fn max_out_frames(&self) -> usize
The maximum number of output frames that can appear in a single call to
RtResampler::process
.
Sourcepub fn request_frames(&self) -> usize
pub fn request_frames(&self) -> usize
The number of frames in each call to on_frames_requested
in RtResampler::process
.
Sourcepub fn output_delay(&self) -> usize
pub fn output_delay(&self) -> usize
Get the delay of the internal resampler, reported as a number of output frames.
Sourcepub fn process<Vout: AsMut<[T]>>(
&mut self,
on_frames_requested: impl FnMut(&mut [Vec<T>]),
output: &mut [Vout],
out_frames: usize,
)
pub fn process<Vout: AsMut<[T]>>( &mut self, on_frames_requested: impl FnMut(&mut [Vec<T>]), output: &mut [Vout], out_frames: usize, )
Resample the input stream and process into a block of data for the output stream.
This method is realtime-safe.
on_frames_requested
- This gets called whenever the resampler needs more data from the input stream. The given buffer must be fully filled with new samples. If there is not enough data to fill the buffer (i.e. an underflow occured), then fill the rest of the frames with zeros. Do NOT resize theVec
s.output
- The output buffers to write the resampled data to.out_frames
- The number of frames to write tooutput
. If the given value is greater thanRtResampler::max_out_frames
, then this will panic.
§Panics
- Panics if the number of output channels does not equal the number of channels in this resampler.
- Panics if the number of frames in the output buffers is greater than
RtResampler::max_out_frames
.
Sourcepub fn process_interleaved(
&mut self,
on_frames_requested: impl FnMut(&mut [T]),
output: &mut [T],
)
pub fn process_interleaved( &mut self, on_frames_requested: impl FnMut(&mut [T]), output: &mut [T], )
Resample the input stream and process into an interleaved block of data for the output stream.
on_frames_requested
- This gets called whenever the resampler needs more data from the input stream. The given buffer is in interleaved format, and it must be completely filled with new data. If there is not enough data to fill the buffer (i.e. an underflow occured), then fill the rest of the frames with zeros.output
- The interleaved output buffer to write the resampled data to.
§Panics
- Panics if the number of output channels does not equal the number of channels in this resampler.
- Panics if the number of frames in the output buffers is greater than
RtResampler::max_out_frames
. - Also panics if the
interleaved
argument wasfalse
when this struct was created.
pub fn resampler_type(&self) -> &ResamplerType<T>
pub fn resampler_type_mut(&mut self) -> &mut ResamplerType<T>
Trait Implementations§
Source§impl<T: Sample> Into<ResamplerType<T>> for RtResampler<T>
impl<T: Sample> Into<ResamplerType<T>> for RtResampler<T>
Source§fn into(self) -> ResamplerType<T>
fn into(self) -> ResamplerType<T>
Converts this type into the (usually inferred) input type.
Auto Trait Implementations§
impl<T> Freeze for RtResampler<T>
impl<T> !RefUnwindSafe for RtResampler<T>
impl<T> Send for RtResampler<T>
impl<T> Sync for RtResampler<T>
impl<T> Unpin for RtResampler<T>where
T: Unpin,
impl<T> !UnwindSafe for RtResampler<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more