[osx] Implement play/pause for coreaudio

This commit is contained in:
Ronald Kinard 2016-10-18 01:20:40 -05:00
parent bb65200745
commit b44a2ab515
1 changed files with 16 additions and 6 deletions

View File

@ -87,11 +87,13 @@ impl<T> Buffer<T> where T: Sample {
type NumChannels = usize; type NumChannels = usize;
type NumFrames = 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. #[allow(dead_code)] // the audio_unit will be dropped if we don't hold it.
pub struct SamplesStream { pub struct SamplesStream {
audio_unit: AudioUnit,
inner: Arc<Mutex<SamplesStreamInner>>, inner: Arc<Mutex<SamplesStreamInner>>,
} }
@ -191,20 +193,28 @@ impl Voice {
try!(audio_unit.start().map_err(convert_error)); try!(audio_unit.start().map_err(convert_error));
let samples_stream = SamplesStream { let samples_stream = SamplesStream {
audio_unit: audio_unit,
inner: inner, inner: inner,
}; };
Ok((Voice, samples_stream)) Ok((Voice {
playing: true,
audio_unit: audio_unit
}, samples_stream))
} }
#[inline] #[inline]
pub fn play(&mut self) { pub fn play(&mut self) {
// implicitly playing if !self.playing {
self.audio_unit.start().unwrap();
self.playing = true;
}
} }
#[inline] #[inline]
pub fn pause(&mut self) { pub fn pause(&mut self) {
unimplemented!() if self.playing {
self.audio_unit.stop().unwrap();
self.playing = false;
}
} }
} }