Skip to main content

Convert

Trait Convert 

Source
pub trait Convert {
    // Required method
    fn next_sample<I>(&mut self, iter: &mut I) -> Option<f64>
       where I: Iterator<Item = f64>,
             Self: Sized;

    // Provided methods
    fn process<I>(&mut self, iter: I) -> ConvertIter<'_, I, Self> 
       where I: Iterator<Item = f64>,
             Self: Sized { ... }
    fn process_block(
        &mut self,
        input: &[f64],
        output: &mut [f64],
    ) -> (usize, usize)
       where Self: Sized { ... }
    fn flush(&mut self, output: &mut [f64]) -> usize
       where Self: Sized { ... }
}

Required Methods§

Source

fn next_sample<I>(&mut self, iter: &mut I) -> Option<f64>
where I: Iterator<Item = f64>, Self: Sized,

Get the next sample converted, return None until the input samples is not enough.

Note that the output can be continued after None returned.

Provided Methods§

Source

fn process<I>(&mut self, iter: I) -> ConvertIter<'_, I, Self>
where I: Iterator<Item = f64>, Self: Sized,

Process samples and return an iterator, can be called multiple times.

Source

fn process_block(&mut self, input: &[f64], output: &mut [f64]) -> (usize, usize)
where Self: Sized,

Convert as many samples as fit in output, consuming from input.

Returns (consumed, produced).

Source

fn flush(&mut self, output: &mut [f64]) -> usize
where Self: Sized,

Continue converting by feeding zeros, writing into output.

Call this after the last input block to drain FIR delay (or the last linear interval). Returns the number of samples written.

A single call may not finish draining if output fills first. Keep calling until the return value is 0 (and provide a fresh buffer each time). A converter that has not yet seen any input writes nothing.

Default implementation: fills output by repeatedly calling Self::next_sample with zeros until the slice is full or next_sample returns None. It does not detect an empty delay line, so custom Convert types that rely on this default will keep writing for the whole buffer. Built-in sinc::Converter and linear::Converter override flush to stop once their delay line is empty (still call until 0 if the buffer was too small).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Convert for simple_src::linear::Converter

Source§

impl Convert for simple_src::sinc::Converter