gdritter repos chenoska / 2552505
Move rodio code to stubbed-out audio thread Getty Ritter 3 years ago
4 changed file(s) with 23 addition(s) and 4 deletion(s). Collapse all Expand all
1616 glutin = "*"
1717 # panem-nostrum-quotidianum = { path = "../panem-nostrum-quotidianum/" }
1818 imagefmt = "*"
19 rodio = "0.6.0"
Binary diff not shown
1 use std::{thread,sync};
1 use std::{fs,io,thread,sync};
2 use rodio;
3 use graphics::errors::Error;
24
35 #[allow(dead_code)]
46 pub struct Audio {
79 }
810
911 impl Audio {
10 pub fn init() -> Audio {
12 pub fn init() -> Result<Audio, Error> {
13 use self::io::BufReader; // Used for audio file reading
14
15 let endpoint = match rodio::default_endpoint() {
16 Some(t) => t,
17 None => return Err(
18 Error::OtherError("Unable to find default sound device".to_owned())),
19 };
20
21 let mut audio_queue = rodio::Sink::new(&endpoint);
22 audio_queue.set_volume(0.5);
23
1124 let (sender, receiver) = sync::mpsc::channel();
1225 let thread = thread::spawn(move || {
1326 while let Ok(v) = receiver.recv() {
27 let file = fs::File::open("assets/testing.wav").unwrap();
28 let testing_wav = rodio::Decoder::new(BufReader::new(file)).unwrap();
29 audio_queue.append(testing_wav);
1430 println!("should play {}", v);
1531 }
1632 });
17 Audio { thread, sender }
33
34 Ok(Audio { thread, sender })
1835 }
1936
2037 pub fn play(&self, sound: String) {
55 }
66 extern crate glutin;
77 extern crate imagefmt;
8 extern crate rodio;
89
910 pub mod board;
1011 pub mod graphics;
2829 /// the main loop of the game, setting up and running the window and
2930 /// event loop
3031 pub fn main_loop() -> Result<(), gfx::Error> {
31 let audio = audio::Audio::init();
32 let audio = audio::Audio::init()?;
3233 let window = gfx::Window::create()?;
3334
3435 let program = gfx::Program::link(vec![