pub struct IO<'a, S: Copy>(/* private fields */);
Expand description
Sample format dependent struct for reading from and writing data to a PCM
.
Also implements std::io::Read
and std::io::Write
.
Note: Only one IO object is allowed in scope at a time (for mmap safety).
Implementations§
source§impl<'a, S: Copy> IO<'a, S>
impl<'a, S: Copy> IO<'a, S>
sourcepub fn writei(&self, buf: &[S]) -> Result<usize>
pub fn writei(&self, buf: &[S]) -> Result<usize>
On success, returns number of frames written. (Multiply with number of channels to get number of items in buf successfully written.)
sourcepub fn readi(&self, buf: &mut [S]) -> Result<usize>
pub fn readi(&self, buf: &mut [S]) -> Result<usize>
On success, returns number of frames read. (Multiply with number of channels to get number of items in buf successfully read.)
sourcepub fn mmap<F: FnOnce(&mut [S]) -> usize>(
&self,
frames: usize,
func: F
) -> Result<usize>
pub fn mmap<F: FnOnce(&mut [S]) -> usize>( &self, frames: usize, func: F ) -> Result<usize>
Wrapper around snd_pcm_mmap_begin and snd_pcm_mmap_commit.
You can read/write into the sound card’s buffer during the call to the closure. According to alsa-lib docs, you should call avail_update before calling this function.
All calculations are in frames, i e, the closure should return number of frames processed. Also, there might not be as many frames to read/write as requested, and there can even be an empty buffer supplied to the closure.
Note: This function works only with interleaved access mode.
Trait Implementations§
source§impl<'a, S: Copy> Read for IO<'a, S>
impl<'a, S: Copy> Read for IO<'a, S>
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read more1.0.0 · source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moresource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moresource§impl<'a, S: Copy> Write for IO<'a, S>
impl<'a, S: Copy> Write for IO<'a, S>
source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)