From b44a2ab51557c98d7f62f439cecd0f92af697ed0 Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Tue, 18 Oct 2016 01:20:40 -0500 Subject: [PATCH] [osx] Implement play/pause for coreaudio --- src/coreaudio/mod.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/coreaudio/mod.rs b/src/coreaudio/mod.rs index 292e03c..d60d3e0 100644 --- a/src/coreaudio/mod.rs +++ b/src/coreaudio/mod.rs @@ -87,11 +87,13 @@ impl Buffer where T: Sample { type NumChannels = usize; type NumFrames = usize; -pub struct Voice; +pub struct Voice { + playing: bool, + audio_unit: AudioUnit +} #[allow(dead_code)] // the audio_unit will be dropped if we don't hold it. pub struct SamplesStream { - audio_unit: AudioUnit, inner: Arc>, } @@ -191,20 +193,28 @@ impl Voice { try!(audio_unit.start().map_err(convert_error)); let samples_stream = SamplesStream { - audio_unit: audio_unit, inner: inner, }; - Ok((Voice, samples_stream)) + Ok((Voice { + playing: true, + audio_unit: audio_unit + }, samples_stream)) } #[inline] pub fn play(&mut self) { - // implicitly playing + if !self.playing { + self.audio_unit.start().unwrap(); + self.playing = true; + } } #[inline] pub fn pause(&mut self) { - unimplemented!() + if self.playing { + self.audio_unit.stop().unwrap(); + self.playing = false; + } } }