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
|
&mut self.buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn len(&self) -> usize {
|
||||||
|
self.buffer.len()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn finish(self) {
|
pub fn finish(self) {
|
||||||
let written = (self.buffer.len() / self.channel.num_channels as usize)
|
let written = (self.buffer.len() / self.channel.num_channels as usize)
|
||||||
as alsa::snd_pcm_uframes_t;
|
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>),
|
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.
|
/// Error that can happen when enumerating the list of supported formats.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum FormatsEnumerationError {
|
pub enum FormatsEnumerationError {
|
||||||
|
|
|
@ -81,6 +81,10 @@ impl<'a, T> Buffer<'a, T> {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn len(&self) -> usize {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
pub fn finish(self) {
|
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) {
|
pub fn finish(self) {
|
||||||
// releasing buffer
|
// releasing buffer
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
Loading…
Reference in New Issue