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,
interleaved: bool,
quality: ResampleQuality,
) -> Self
pub fn new( in_sample_rate: u32, out_sample_rate: u32, num_channels: 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.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
,
Sourcepub fn from_custom(
resampler: impl Into<ResamplerType<T>>,
interleaved: bool,
) -> Self
pub fn from_custom( resampler: impl Into<ResamplerType<T>>, interleaved: bool, ) -> Self
Create a new realtime resampler using the given rubato resampler.
resampler
- The rubato resampler.interleaved
- If you are planning to useRtResampler::process_interleaved
, set this totrue
. Otherwise you can set this tofalse
to save a bit of memory.
Sourcepub fn num_channels(&self) -> NonZeroUsize
pub fn num_channels(&self) -> NonZeroUsize
Get the number of channels this resampler is configured for.
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 temp_frames(&self) -> usize
pub fn temp_frames(&self) -> usize
The number of frames that are currently stored in the temporary buffer.
Sourcepub fn process<Vout: AsMut<[T]>>(
&mut self,
on_frames_requested: impl FnMut(&mut [Vec<T>]),
output: &mut [Vout],
range: Range<usize>,
)
pub fn process<Vout: AsMut<[T]>>( &mut self, on_frames_requested: impl FnMut(&mut [Vec<T>]), output: &mut [Vout], range: Range<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 channels of audio data to write data to.range
- The range in each slice inoutput
to write data to. Data inside this range will be fully filled, and any data outside this range will be untouched.
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.
- Also panics if the
interleaved
argument wasfalse
when this struct was created andself.num_channels() > 1
.
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