[][src]Struct soundio::InStreamReader

pub struct InStreamReader<'a> { /* fields omitted */ }

InStreamReader is passed to the read callback and can be used to read from the stream.

You start by calling begin_read() and then you can read the samples. When the InStreamReader is dropped the samples are dropped. An error at that point is written to the console and ignored.

Methods

impl<'a> InStreamReader<'a>[src]

pub fn begin_read(&mut self, frame_count: usize) -> Result<usize>[src]

Start a read. You can only call this once per callback otherwise it panics.

frame_count is the number of frames you want to read. It must be between frame_count_min and frame_count_max inclusive, or begin_read() will panic.

It returns the number of frames you can actually read. The returned value will always be less than or equal to the provided value.

Errors

  • Error::Invalid
    • frame_count < frame_count_min or frame_count > frame_count_max
  • Error::Streaming
  • Error::IncompatibleDevice - in rare cases it might just now be discovered that the device uses non-byte-aligned access, in which case this error code is returned.

pub fn end_read(&mut self)[src]

Commits the write that you began with begin_read().

Errors are currently are just printed to the console and ignored.

Errors

  • Error::Streaming
  • Error::Underflow - an underflow caused this call to fail. You might also get an underflow_callback(), and you might not get this error code when an underflow occurs. Unlike Error::Streaming, the outstream is still in a valid state and streaming can continue.

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

Get the minimum frame count that you can call begin_read() with. Retreive this value before calling begin_read() to ensure you read the correct number of frames.

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

Get the maximum frame count that you can call begin_read() with. Retreive this value before calling begin_read() to ensure you read the correct number of frames.

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

Get the actual frame count that you did call begin_read() with. Panics if you haven't called begin_read() yet.

pub fn software_latency(&self) -> f64[src]

Get latency in seconds due to software only, not including hardware.

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

Return the number of channels in this stream. Guaranteed to be at least 1.

pub fn sample_rate(&self) -> i32[src]

Get the sample rate in Hertz.

pub fn get_latency(&mut self) -> Result<f64>[src]

Obtain the number of seconds that the next frame of sound being captured will take to arrive in the buffer, plus the amount of time that is represented in the buffer. This includes both software and hardware latency.

Errors

  • Error::Streaming

pub fn sample<T: Sample>(&self, channel: usize, frame: usize) -> T[src]

Get the value of a sample. This panics if the channel or frame are out of range or if you haven't called begin_read() yet.

If you request a different type from the actual one it will be converted.

Examples

fn read_callback(stream: &mut soundio::InStreamReader) {
    let frame_count_max = stream.frame_count_max();
    stream.begin_read(frame_count_max).unwrap();
    for c in 0..stream.channel_count() {
        for f in 0..stream.frame_count() {
            do_something_with(stream.sample::<i16>(c, f));
        }
    }
}

Trait Implementations

impl<'a> Drop for InStreamReader<'a>[src]

fn drop(&mut self)[src]

This will drop all of the frames from when you called begin_read().

Errors are currently are just printed to the console and ignored.

Errors

  • Error::Streaming

Auto Trait Implementations

impl<'a> RefUnwindSafe for InStreamReader<'a>

impl<'a> !Send for InStreamReader<'a>

impl<'a> !Sync for InStreamReader<'a>

impl<'a> Unpin for InStreamReader<'a>

impl<'a> UnwindSafe for InStreamReader<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.