aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-10-28 17:51:39 +0100
committerTeddy Wing2018-10-28 17:58:22 +0100
commiteb261f29d0ae15c2f941c2d84972bd321bf764ac (patch)
tree49b4db718f13d0d901b1485b41329197e80300c4
parent641d94c357b23ad23ad8b67228071a12e619bded (diff)
downloaddome-key-map-eb261f29d0ae15c2f941c2d84972bd321bf764ac.tar.bz2
Test of playing an audio file
Success! Using the 'rodio' crate to play an audio file. Include the audio file in the binary using `include_bytes!`. This makes it so we get a single self-contained binary. Struggled a bit with getting the reader/array to `Seek`, but finally figured out `Cursor` and got it working. Cool.
-rw-r--r--Cargo.toml1
-rw-r--r--sounds/activ.wavbin0 -> 382190 bytes
-rw-r--r--src/lib.rs2
-rw-r--r--src/map.rs27
-rw-r--r--src/sounds.rs4
5 files changed, 34 insertions, 0 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 426371f..a2f9c23 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -14,6 +14,7 @@ libc = "0.2.43"
log = "0.4.5"
magic-crypt = "2.1.2"
quick-error = "1.2.2"
+rodio = "0.8.1"
serde = "1.0.58"
serde_derive = "1.0.58"
stderrlog = "0.4.1"
diff --git a/sounds/activ.wav b/sounds/activ.wav
new file mode 100644
index 0000000..d2a05c9
--- /dev/null
+++ b/sounds/activ.wav
Binary files differ
diff --git a/src/lib.rs b/src/lib.rs
index 20f4fb6..f685dfe 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -19,6 +19,7 @@ extern crate magic_crypt;
#[macro_use]
extern crate quick_error;
+extern crate rodio;
#[macro_use]
extern crate serde_derive;
@@ -36,6 +37,7 @@ mod ffi;
mod key_code;
mod map;
mod parser;
+mod sounds;
mod trial;
use parser::{Action, HeadphoneButton, MapAction, MapGroup, MapKind};
diff --git a/src/map.rs b/src/map.rs
index 0591db9..750a728 100644
--- a/src/map.rs
+++ b/src/map.rs
@@ -1,9 +1,13 @@
use std::env;
use std::ffi::OsString;
+use std::io::BufReader;
use std::process::Command;
+use rodio::{self, Source};
+
use {Action, HeadphoneButton, MapAction, MapKind};
use ffi::State;
+use sounds;
pub fn run_key_action_for_mode<'a>(
state: &mut State,
@@ -75,3 +79,26 @@ fn run_action(map_action: &MapAction) {
}
}
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn play_audio() {
+ let mode_activated = include_bytes!("../sounds/activ.wav");
+ // let mut sound = sounds::MODE_ACTIVATED;
+ // let mut reader = BufReader::new(sounds::MODE_ACTIVATED);
+ let file = ::std::fs::File::open("sounds/activ.wav").unwrap();
+ // let reader = BufReader::new(&mode_activated[..]);
+ // let reader = BufReader::new(mode_activated);
+ // let reader = BufReader::new(file);
+ let reader = ::std::io::Cursor::new(sounds::MODE_ACTIVATED);
+let device = rodio::default_output_device().unwrap();
+// let source = rodio::Decoder::new(reader).unwrap();
+// rodio::play_raw(&device, source.convert_samples());
+// ::std::thread::sleep_ms(2000);
+let sink = rodio::play_once(&device, reader).unwrap();
+sink.sleep_until_end();
+sink.play();
+ }
+}
diff --git a/src/sounds.rs b/src/sounds.rs
new file mode 100644
index 0000000..8cb6b51
--- /dev/null
+++ b/src/sounds.rs
@@ -0,0 +1,4 @@
+// const MODE_ACTIVATED = include_bytes!("../sounds/mode_activated.ogg");
+// const MODE_DEACTIVATED = include_bytes!("../sounds/mode_deactivated.ogg");
+
+pub const MODE_ACTIVATED: &'static [u8] = include_bytes!("../sounds/activ.wav");