Trait rotary::ReadBuf[][src]

pub trait ReadBuf {
    pub fn remaining(&self) -> usize;
pub fn advance(&mut self, n: usize); pub fn has_remaining(&self) -> bool { ... } }

Trait used to govern sequential reading of an audio buffer.

This is the “in” part of “buffered I/O”. It allows for buffers to govern which slice of frames in them has been read so that operations can be performed in multiple stages.

This can be accomplished manually using available buffer combinators such as Buf::tail. But buffered I/O allows us to do this in a much more structured fashion.

Examples

use rotary::ReadBuf as _;
use rotary::{io, wrap};

// A simple mutable buffer we want to write to. Fits 2 channels with 64
// frames each.
let mut to = [0i16; 128];

// A buffer we want to read from. 2 channels with 512 frames each.
let from = rotary::interleaved![[0i16; 512]; 2];
let mut from = io::Read::new(from);

let mut steps = 0;

while from.has_remaining() {
    // Wrap the output buffer according to format so it can be written to
    // correctly.
    io::copy_remaining(&mut from, wrap::interleaved(&mut to[..], 2));

    send_data(&mut to[..]);

    steps += 1;
}

// We needed to write 8 times to copy our entire buffer.
assert_eq!(steps, 8);

Required methods

pub fn remaining(&self) -> usize[src]

Get the number of frames remaining that can be read from the buffer.

Examples

use rotary::ReadBuf as _;

let buffer = rotary::wrap::interleaved(&[0, 1, 2, 3, 4, 5, 6, 7][..], 2);

assert_eq!(buffer.remaining(), 4);

pub fn advance(&mut self, n: usize)[src]

Advance the read number of frames by n.

Examples

use rotary::ReadBuf as _;

let mut buffer = rotary::wrap::interleaved(&[0, 1, 2, 3, 4, 5, 6, 7][..], 2);

assert_eq!(buffer.remaining(), 4);
buffer.advance(2);
assert_eq!(buffer.remaining(), 2);
Loading content...

Provided methods

pub fn has_remaining(&self) -> bool[src]

Test if there are any remaining frames to read.

Examples

use rotary::ReadBuf as _;

let mut buffer = rotary::wrap::interleaved(&[0, 1, 2, 3, 4, 5, 6, 7][..], 2);

assert!(buffer.has_remaining());
assert_eq!(buffer.remaining(), 4);
buffer.advance(4);
assert_eq!(buffer.remaining(), 0);
Loading content...

Implementations on Foreign Types

impl<'_, B> ReadBuf for &'_ mut B where
    B: ReadBuf
[src]

Loading content...

Implementors

impl<B> ReadBuf for Read<B>[src]

impl<B> ReadBuf for ReadWrite<B>[src]

impl<T> ReadBuf for Interleaved<&[T]>[src]

impl<T> ReadBuf for Interleaved<&mut [T]>[src]

Loading content...