diff --git a/src/alsa/mod.rs b/src/alsa/mod.rs index b184fe3..e21f059 100644 --- a/src/alsa/mod.rs +++ b/src/alsa/mod.rs @@ -112,6 +112,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 5d8d2d4..93a30be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -359,6 +359,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 1b0c0f3..aeb852a 100644 --- a/src/null/mod.rs +++ b/src/null/mod.rs @@ -81,6 +81,10 @@ impl Voice { #[inline] 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 f5083e6..ec71af0 100644 --- a/src/wasapi/voice.rs +++ b/src/wasapi/voice.rs @@ -301,6 +301,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 {