Merge pull request #65 from tomaka/buffer-len

Add UnknownBufferType::len()
This commit is contained in:
tomaka 2015-09-11 09:59:09 +02:00
commit f74f3f3151
4 changed files with 23 additions and 0 deletions

View File

@ -125,6 +125,10 @@ impl<'a, T> Buffer<'a, T> {
&mut self.buffer
}
pub fn len(&self) -> usize {
self.buffer.len()
}
pub fn finish(self) {
let written = (self.buffer.len() / self.channel.num_channels as usize)
as alsa::snd_pcm_uframes_t;

View File

@ -181,6 +181,17 @@ pub enum UnknownTypeBuffer<'a> {
F32(Buffer<'a, f32>),
}
impl<'a> UnknownTypeBuffer<'a> {
/// Returns the length of the buffer in number of samples.
pub fn len(&self) -> usize {
match self {
&UnknownTypeBuffer::U16(ref buf) => buf.target.as_ref().unwrap().len(),
&UnknownTypeBuffer::I16(ref buf) => buf.target.as_ref().unwrap().len(),
&UnknownTypeBuffer::F32(ref buf) => buf.target.as_ref().unwrap().len(),
}
}
}
/// Error that can happen when enumerating the list of supported formats.
#[derive(Debug)]
pub enum FormatsEnumerationError {

View File

@ -81,6 +81,10 @@ impl<'a, T> Buffer<'a, T> {
unreachable!()
}
pub fn len(&self) -> usize {
0
}
pub fn finish(self) {
}
}

View File

@ -322,6 +322,10 @@ impl<'a, T> Buffer<'a, T> {
}
}
pub fn len(&self) -> usize {
self.buffer_len
}
pub fn finish(self) {
// releasing buffer
unsafe {