Move rodio code to stubbed-out audio thread
Getty Ritter
6 years ago
16 | 16 |
glutin = "*"
|
17 | 17 |
# panem-nostrum-quotidianum = { path = "../panem-nostrum-quotidianum/" }
|
18 | 18 |
imagefmt = "*"
|
| 19 |
rodio = "0.6.0"
|
1 | |
use std::{thread,sync};
|
| 1 |
use std::{fs,io,thread,sync};
|
| 2 |
use rodio;
|
| 3 |
use graphics::errors::Error;
|
2 | 4 |
|
3 | 5 |
#[allow(dead_code)]
|
4 | 6 |
pub struct Audio {
|
|
7 | 9 |
}
|
8 | 10 |
|
9 | 11 |
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 |
|
11 | 24 |
let (sender, receiver) = sync::mpsc::channel();
|
12 | 25 |
let thread = thread::spawn(move || {
|
13 | 26 |
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);
|
14 | 30 |
println!("should play {}", v);
|
15 | 31 |
}
|
16 | 32 |
});
|
17 | |
Audio { thread, sender }
|
| 33 |
|
| 34 |
Ok(Audio { thread, sender })
|
18 | 35 |
}
|
19 | 36 |
|
20 | 37 |
pub fn play(&self, sound: String) {
|
5 | 5 |
}
|
6 | 6 |
extern crate glutin;
|
7 | 7 |
extern crate imagefmt;
|
| 8 |
extern crate rodio;
|
8 | 9 |
|
9 | 10 |
pub mod board;
|
10 | 11 |
pub mod graphics;
|
|
28 | 29 |
/// the main loop of the game, setting up and running the window and
|
29 | 30 |
/// event loop
|
30 | 31 |
pub fn main_loop() -> Result<(), gfx::Error> {
|
31 | |
let audio = audio::Audio::init();
|
| 32 |
let audio = audio::Audio::init()?;
|
32 | 33 |
let window = gfx::Window::create()?;
|
33 | 34 |
|
34 | 35 |
let program = gfx::Program::link(vec![
|