Merge pull request #65 from tomaka/buffer-len
Add UnknownBufferType::len()
This commit is contained in:
commit
f74f3f3151
|
@ -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;
|
||||
|
|
11
src/lib.rs
11
src/lib.rs
|
@ -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 {
|
||||
|
|
|
@ -81,6 +81,10 @@ impl<'a, T> Buffer<'a, T> {
|
|||
unreachable!()
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
0
|
||||
}
|
||||
|
||||
pub fn finish(self) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue