Struct oxcable::wrappers::Buffered [] [src]

pub struct Buffered<D> where D: AudioDevice {
    pub device: D,
    pub inputs: Vec<Sample>,
    pub outputs: Vec<Sample>,
}

Bundles an AudioDevice with allocated input and output buffers.

To use the device, input samples must first be manually dropped into the inputs buffer, then tick may be called to generate outputs. The output samples can be found in the outputs buffer.

Example

use oxcable::types::{AudioDevice, Sample, Time};
struct IdentityFilter;
impl AudioDevice for IdentityFilter {
    fn num_inputs(&self) -> usize { 1 }
    fn num_outputs(&self) -> usize { 1 }
    fn tick(&mut self, _: Time, inputs: &[Sample], outputs: &mut[Sample]) {
        outputs[0] = inputs[0];
    }
}

use oxcable::wrappers::Buffered;
let mut filter = Buffered::from(IdentityFilter);

for i in 0..8 {
    filter.inputs[0] = i as f32;
    filter.tick(i);
    assert_eq!(i as f32, filter.outputs[0]);
}

Fields

device

The AudioDevice being wrapped.

inputs

The input buffer.

outputs

The output buffer.

Methods

impl<D> Buffered<D> where D: AudioDevice

fn tick(&mut self, t: Time)

Calls the device's tick method using the wrapper's buffers.

Trait Implementations

impl<D> From<D> for Buffered<D> where D: AudioDevice

fn from(device: D) -> Self

impl<D> Deref for Buffered<D> where D: AudioDevice

type Target = D

fn deref(&self) -> &D

impl<D> DerefMut for Buffered<D> where D: AudioDevice

fn deref_mut(&mut self) -> &mut D