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 unsafe fn writen(&self, bufs: &[*const S], frames: usize) -> Result<usize>
pub unsafe fn writen(&self, bufs: &[*const S], frames: usize) -> Result<usize>
Write non-interleaved frames to pcm. On success, returns number of frames written.
§Safety
Caller must ensure that the length of bufs is at least the number of
channels, and that each element of bufs is a valid pointer to an array
of at least frames length.
Sourcepub unsafe fn readn(&self, bufs: &mut [*mut S], frames: usize) -> Result<usize>
pub unsafe fn readn(&self, bufs: &mut [*mut S], frames: usize) -> Result<usize>
Read non-interleaved frames to pcm. On success, returns number of frames read.
§Safety
Caller must ensure that the length of bufs is at least the number of
channels, and that each element of bufs is a valid pointer to an array
of at least frames length.
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>
Available on crate feature std only.
impl<'a, S: Copy> Read for IO<'a, S>
std only.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 more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
Source§impl<'a, S: Copy> Write for IO<'a, S>
Available on crate feature std only.
impl<'a, S: Copy> Write for IO<'a, S>
std only.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)