Skip to content

Commit f98f7c5

Browse files
authored
Merge pull request #134 from anas2660/master
Add unsafe `readn` and `writen`
2 parents f13932a + 79166e1 commit f98f7c5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/pcm.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,30 @@ impl<'a, S: Copy> IO<'a, S> {
404404
acheck!(snd_pcm_readi((self.0).0, buf.as_mut_ptr() as *mut c_void, self.to_frames(buf.len()))).map(|r| r as usize)
405405
}
406406

407+
/// Write non-interleaved frames to pcm. On success, returns number of frames written.
408+
///
409+
/// # Safety
410+
///
411+
/// Caller must ensure that the length of `bufs` is at least the number of
412+
/// channels, and that each element of bufs is a valid pointer to an array
413+
/// of at least `frames` length.
414+
pub unsafe fn writen(&self, bufs: &[*const S], frames: usize) -> Result<usize> {
415+
let frames = frames as alsa::snd_pcm_uframes_t;
416+
acheck!(snd_pcm_writen((self.0).0, bufs.as_ptr() as *mut *mut c_void, frames)).map(|r| r as usize)
417+
}
418+
419+
/// Read non-interleaved frames to pcm. On success, returns number of frames read.
420+
///
421+
/// # Safety
422+
///
423+
/// Caller must ensure that the length of `bufs` is at least the number of
424+
/// channels, and that each element of bufs is a valid pointer to an array
425+
/// of at least `frames` length.
426+
pub unsafe fn readn(&self, bufs: &mut [*mut S], frames: usize) -> Result<usize> {
427+
let frames = frames as alsa::snd_pcm_uframes_t;
428+
acheck!(snd_pcm_readn((self.0).0, bufs.as_mut_ptr() as *mut *mut c_void, frames)).map(|r| r as usize)
429+
}
430+
407431
/// Wrapper around snd_pcm_mmap_begin and snd_pcm_mmap_commit.
408432
///
409433
/// You can read/write into the sound card's buffer during the call to the closure.

0 commit comments

Comments
 (0)