pub struct Converter<S, I>where
S: Signal,
I: Interpolator,{ /* private fields */ }
Expand description
A signal type that converts the rate at which frames are yielded from some source signal to some target rate.
Other names for sample::interpolate::Converter
might include:
- Sample rate converter.
- {Up/Down}sampler.
- Sample interpolater.
- Sample decimator.
Implementations§
Source§impl<S, I> Converter<S, I>where
S: Signal,
I: Interpolator,
impl<S, I> Converter<S, I>where
S: Signal,
I: Interpolator,
Sourcepub fn from_hz_to_hz(
source: S,
interpolator: I,
source_hz: f64,
target_hz: f64,
) -> Self
pub fn from_hz_to_hz( source: S, interpolator: I, source_hz: f64, target_hz: f64, ) -> Self
Construct a new Converter
from the source frames and the source and target sample rates
(in Hz).
Sourcepub fn scale_playback_hz(source: S, interpolator: I, scale: f64) -> Self
pub fn scale_playback_hz(source: S, interpolator: I, scale: f64) -> Self
Construct a new Converter
from the source frames and the amount by which the current
playback rate (not sample rate) should be multiplied to reach the new playback
rate.
For example, if our source_frames
is a sine wave oscillating at a frequency of 2hz and
we wanted to convert it to a frequency of 3hz, the given scale
should be 1.5
.
Sourcepub fn scale_sample_hz(source: S, interpolator: I, scale: f64) -> Self
pub fn scale_sample_hz(source: S, interpolator: I, scale: f64) -> Self
Construct a new Converter
from the source frames and the amount by which the current
sample rate (not playback rate) should be multiplied to reach the new sample
rate.
If our source_frames
are being sampled at a rate of 44_100hz and we want to
convert to a sample rate of 96_000hz, the given scale
should be 96_000.0 / 44_100.0
.
This is the same as calling Converter::scale_playback_hz(source_frames, 1.0 / scale)
.
Sourcepub fn set_hz_to_hz(&mut self, source_hz: f64, target_hz: f64)
pub fn set_hz_to_hz(&mut self, source_hz: f64, target_hz: f64)
Update the source_to_target_ratio
internally given the source and target hz.
This method might be useful for changing the sample rate during playback.
Sourcepub fn set_playback_hz_scale(&mut self, scale: f64)
pub fn set_playback_hz_scale(&mut self, scale: f64)
Update the source_to_target_ratio
internally given a new playback rate multiplier.
This method is useful for dynamically changing rates.
Sourcepub fn set_sample_hz_scale(&mut self, scale: f64)
pub fn set_sample_hz_scale(&mut self, scale: f64)
Update the source_to_target_ratio
internally given a new sample rate multiplier.
This method is useful for dynamically changing rates.
Sourcepub fn source_mut(&mut self) -> &mut S
pub fn source_mut(&mut self) -> &mut S
Mutably borrow the source_frames
Iterator from the Converter
.
Sourcepub fn into_source(self) -> S
pub fn into_source(self) -> S
Drop self
and return the internal source_frames
Iterator.
Trait Implementations§
Source§impl<S, I> Signal for Converter<S, I>
impl<S, I> Signal for Converter<S, I>
Source§fn is_exhausted(&self) -> bool
fn is_exhausted(&self) -> bool
Source§fn map<M, F>(self, map: M) -> Map<Self, M, F>
fn map<M, F>(self, map: M) -> Map<Self, M, F>
Source§fn zip_map<O, M, F>(self, other: O, map: M) -> ZipMap<Self, O, M, F>
fn zip_map<O, M, F>(self, other: O, map: M) -> ZipMap<Self, O, M, F>
Source§fn add_amp<S>(self, other: S) -> AddAmp<Self, S>
fn add_amp<S>(self, other: S) -> AddAmp<Self, S>
other
and self
in lock-step. Read moreSource§fn mul_amp<S>(self, other: S) -> MulAmp<Self, S>
fn mul_amp<S>(self, other: S) -> MulAmp<Self, S>
other
and
self
in lock-step. Read moreSource§fn offset_amp(
self,
offset: <<Self::Frame as Frame>::Sample as Sample>::Signed,
) -> OffsetAmp<Self>where
Self: Sized,
fn offset_amp(
self,
offset: <<Self::Frame as Frame>::Sample as Sample>::Signed,
) -> OffsetAmp<Self>where
Self: Sized,
Source§fn scale_amp(
self,
amp: <<Self::Frame as Frame>::Sample as Sample>::Float,
) -> ScaleAmp<Self>where
Self: Sized,
fn scale_amp(
self,
amp: <<Self::Frame as Frame>::Sample as Sample>::Float,
) -> ScaleAmp<Self>where
Self: Sized,
Iterator
that scales the amplitude of the sample of each channel in every
Frame
yielded by self
by the given amplitude. Read moreSource§fn offset_amp_per_channel<F>(self, amp_frame: F) -> OffsetAmpPerChannel<Self, F>
fn offset_amp_per_channel<F>(self, amp_frame: F) -> OffsetAmpPerChannel<Self, F>
Signal
that offsets the amplitude of every Frame
in self
by the
respective amplitudes in each channel of the given amp_frame
. Read moreSource§fn scale_amp_per_channel<F>(self, amp_frame: F) -> ScaleAmpPerChannel<Self, F>
fn scale_amp_per_channel<F>(self, amp_frame: F) -> ScaleAmpPerChannel<Self, F>
Signal
that scales the amplitude of every Frame
in self
by the
respective amplitudes in each channel of the given amp_frame
. Read moreSource§fn from_hz_to_hz<I>(
self,
interpolator: I,
source_hz: f64,
target_hz: f64,
) -> Converter<Self, I>where
Self: Sized,
I: Interpolator,
fn from_hz_to_hz<I>(
self,
interpolator: I,
source_hz: f64,
target_hz: f64,
) -> Converter<Self, I>where
Self: Sized,
I: Interpolator,
Signal
are yielded using interpolation. Read moreSource§fn scale_hz<I>(self, interpolator: I, multi: f64) -> Converter<Self, I>where
Self: Sized,
I: Interpolator,
fn scale_hz<I>(self, interpolator: I, multi: f64) -> Converter<Self, I>where
Self: Sized,
I: Interpolator,
Signal
are yielded by the given value. Read moreSource§fn delay(self, n_frames: usize) -> Delay<Self>where
Self: Sized,
fn delay(self, n_frames: usize) -> Delay<Self>where
Self: Sized,
Signal
by the given number of frames. Read moreSource§fn into_interleaved_samples(self) -> IntoInterleavedSamples<Self>where
Self: Sized,
fn into_interleaved_samples(self) -> IntoInterleavedSamples<Self>where
Self: Sized,
Source§fn clip_amp(
self,
thresh: <<Self::Frame as Frame>::Sample as Sample>::Signed,
) -> ClipAmp<Self>where
Self: Sized,
fn clip_amp(
self,
thresh: <<Self::Frame as Frame>::Sample as Sample>::Signed,
) -> ClipAmp<Self>where
Self: Sized,
Frame
yielded by self
to the given
threshold amplitude. Read moreSource§fn inspect<F>(self, inspect: F) -> Inspect<Self, F>
fn inspect<F>(self, inspect: F) -> Inspect<Self, F>
Signal
that calls the enclosing function on each iteration. Read moreSource§fn fork<S>(self, ring_buffer: Bounded<S>) -> Fork<Self, S>
fn fork<S>(self, ring_buffer: Bounded<S>) -> Fork<Self, S>
Self
into two signals that produce the same frames. Read moreSource§fn take(self, n: usize) -> Take<Self> ⓘwhere
Self: Sized,
fn take(self, n: usize) -> Take<Self> ⓘwhere
Self: Sized,
Signal
into an Iterator
that will yield the given number for Frame
s
before returning None
. Read moreSource§fn until_exhausted(self) -> UntilExhausted<Self> ⓘwhere
Self: Sized,
fn until_exhausted(self) -> UntilExhausted<Self> ⓘwhere
Self: Sized,
Signal
into an Iterator
yielding frames until the signal.is_exhausted()
returns true
. Read more