From c5e2cdd3c5d551541929069faa7f5b26c59e8cac Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Thu, 10 Sep 2015 21:03:40 +0200 Subject: [PATCH] Add an underflow() method to Voice --- src/alsa/mod.rs | 4 ++++ src/lib.rs | 6 ++++++ src/null/mod.rs | 4 ++++ src/wasapi/voice.rs | 10 ++++++++++ 4 files changed, 24 insertions(+) diff --git a/src/alsa/mod.rs b/src/alsa/mod.rs index 2e9dbe1..7bd77ff 100644 --- a/src/alsa/mod.rs +++ b/src/alsa/mod.rs @@ -107,6 +107,10 @@ impl Voice { pub fn pause(&mut self) { unimplemented!() } + + pub fn underflowed(&self) -> bool { + false // TODO: + } } unsafe impl Send for Voice {} diff --git a/src/lib.rs b/src/lib.rs index 7e77b94..dfec780 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -339,6 +339,12 @@ impl Voice { pub fn pause(&mut self) { self.0.pause() } + + /// Returns true if the voice has finished reading all the data you sent to it. + #[inline] + pub fn underflowed(&self) -> bool { + self.0.underflowed() + } } impl<'a, T> Deref for Buffer<'a, T> where T: Sample { diff --git a/src/null/mod.rs b/src/null/mod.rs index ff5e1db..866276e 100644 --- a/src/null/mod.rs +++ b/src/null/mod.rs @@ -70,6 +70,10 @@ impl Voice { pub fn pause(&mut self) { } + + pub fn underflowed(&self) -> bool { + false + } } pub struct Buffer<'a, T: 'a> { diff --git a/src/wasapi/voice.rs b/src/wasapi/voice.rs index f8abb04..2a7d309 100644 --- a/src/wasapi/voice.rs +++ b/src/wasapi/voice.rs @@ -296,6 +296,16 @@ impl Voice { self.playing = false; } + + pub fn underflowed(&self) -> bool { + unsafe { + let mut padding = mem::uninitialized(); + let hresult = (*self.audio_client).GetCurrentPadding(&mut padding); + check_result(hresult).unwrap(); + + padding == 0 + } + } } impl Drop for Voice {