Struct dsp::rate::Converter [] [src]

pub struct Converter<I> where I: Iterator, I::Item: Frame {
    // some fields omitted
}

An iterator that converts the rate at which frames are yielded from some given frame Iterator via some given ratio.

Other names for sample::rate::Converter might include:

At the moment, Converter only supports basic linear amplitude interpolation between frames and is far from the most precise algorithm available. The current form of interpolation also requires that samples are either in f64 format or can be converted to and from f64 format. In terms of audio quality, it is not recommended for use in pro-audio applications or professional sound design. However if you are simply reading audio files and need to do a single conversion from their sample rate to your own domain for basic playback, Converter might be sufficient and fast at the very least.

That said, the aim is to provide higher quality interpolation types soon and change Converters interface to a generic API compatible with a range of interpolation types.

Methods

impl<I> Converter<I> where I: Iterator, I::Item: Frame

fn from_hz_to_hz(source_frames: I, source_hz: f64, target_hz: f64) -> Converter<I>

Construct a new Converter from the source frames and the source and target sample rates (in Hz).

fn scale_playback_hz(source_frames: I, scale: f64) -> Converter<I>

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.

fn scale_sample_hz(source_frames: I, scale: f64) -> Converter<I>

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).

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.

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.

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.

fn source(&self) -> &I

Borrow the source_frames Iterator from the Converter.

fn source_mut(&mut self) -> &I

Mutably borrow the source_frames Iterator from the Converter.

fn into_source(self) -> I

Drop self and return the internal source_frames Iterator.

fn next_frame(&mut self) -> Option<I::Item> where I::Item::Sample: Duplex<f64>

Yields the next interpolated target frame.

Trait Implementations

impl<I> Iterator for Converter<I> where I: Iterator, I::Item: Frame, I::Item::Sample: Duplex<f64>

type Item = I::Item

fn next(&mut self) -> Option<Converter<I>::Item>

fn size_hint(&self) -> (usize, Option<usize>)

Derived Implementations

impl<I> Clone for Converter<I> where I: Clone + Iterator, I::Item: Frame, I::Item: Clone

fn clone(&self) -> Converter<I>

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)
1.0.0

Performs copy-assignment from source. Read more