2019-04-30 08:53:21 +00:00
|
|
|
use crate::backend::audio::AudioBackend;
|
|
|
|
//use generational_arena::Arena;
|
|
|
|
use swf::SoundStreamInfo;
|
|
|
|
|
|
|
|
pub struct Audio {
|
|
|
|
backend: Box<AudioBackend>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type AudioStreamHandle = generational_arena::Index;
|
2019-05-05 22:55:27 +00:00
|
|
|
pub type SoundHandle = generational_arena::Index;
|
|
|
|
|
|
|
|
type Error = Box<std::error::Error>;
|
2019-04-30 08:53:21 +00:00
|
|
|
|
|
|
|
impl Audio {
|
|
|
|
pub fn new(backend: Box<AudioBackend>) -> Audio {
|
|
|
|
Audio { backend }
|
|
|
|
}
|
|
|
|
|
2019-05-05 22:55:27 +00:00
|
|
|
pub fn register_sound(&mut self, sound: &swf::Sound) -> Result<SoundHandle, Error> {
|
|
|
|
self.backend.register_sound(sound)
|
|
|
|
}
|
|
|
|
|
2019-04-30 08:53:21 +00:00
|
|
|
pub fn register_stream(&mut self, stream_info: &SoundStreamInfo) -> AudioStreamHandle {
|
|
|
|
self.backend.register_stream(stream_info)
|
|
|
|
}
|
|
|
|
|
2019-05-05 22:55:27 +00:00
|
|
|
pub fn play_sound(&mut self, sound: SoundHandle) {
|
|
|
|
self.backend.play_sound(sound)
|
|
|
|
}
|
|
|
|
|
2019-04-30 08:53:21 +00:00
|
|
|
pub fn queue_stream_samples(&mut self, handle: AudioStreamHandle, samples: &[u8]) {
|
|
|
|
self.backend.queue_stream_samples(handle, samples)
|
|
|
|
}
|
2019-05-02 00:46:49 +00:00
|
|
|
|
|
|
|
pub fn stop_all_sounds(&mut self) {
|
|
|
|
// TODO(Herschel)
|
|
|
|
}
|
2019-04-30 08:53:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct AudioStream {
|
|
|
|
stream_info: SoundStreamInfo,
|
|
|
|
}
|