aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2018-10-28 23:53:10 +0100
committerTeddy Wing2018-10-28 23:53:10 +0100
commitc54226120bdc9277f9ab6e0e54dae9062550702d (patch)
treeaf5084e4322148343ce36adcc8fbc758d7c15363 /src
parente8ba4dc878a44f14e656664fa2e9d0ea362cbc10 (diff)
downloaddome-key-map-c54226120bdc9277f9ab6e0e54dae9062550702d.tar.bz2
Add mode activated and deactivated sounds
* Remove test "activ.wav" file * Add mode activated and deactivated audio files * Add two new methods to play these two sounds without having to pass in `MODE_ACTIVATED` or `MODE_DEACTIVATED` from outside the module * Make `play_audio()` private The 'rodio' crate supports WAV, FLAC, MP3, and Vorbis file types. Tried using OGG and MP3 versions of the audio, which sound effectively the same played in an audio player, and have much better compression, but 'rodio' kept playing them choppily, in a weird staccato. Maybe the sample rate wasn't right? No idea what the problem was. Didn't really have the same problem with the WAV files. Unfortunate because the OGG files were only 16K, and the MP3 files were 32K, while the WAV files are 348K. Would much rather have smaller size files, but if the sounds play incorrectly, there's no easy way around it.
Diffstat (limited to 'src')
-rw-r--r--src/sounds.rs17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/sounds.rs b/src/sounds.rs
index e0c1093..152e7b2 100644
--- a/src/sounds.rs
+++ b/src/sounds.rs
@@ -4,12 +4,18 @@ use rodio;
use errors::*;
-// const MODE_ACTIVATED = include_bytes!("../sounds/mode_activated.ogg");
-// const MODE_DEACTIVATED = include_bytes!("../sounds/mode_deactivated.ogg");
+const MODE_ACTIVATED: &'static [u8] = include_bytes!("../sounds/mode_activated.wav");
+const MODE_DEACTIVATED: &'static [u8] = include_bytes!("../sounds/mode_deactivated.wav");
-pub const MODE_ACTIVATED: &'static [u8] = include_bytes!("../sounds/activ.wav");
+pub fn play_mode_activated() -> Result<()> {
+ play_audio(MODE_ACTIVATED)
+}
+
+pub fn play_mode_deactivated() -> Result<()> {
+ play_audio(MODE_DEACTIVATED)
+}
-pub fn play_audio<R>(r: R) -> Result<()>
+fn play_audio<R>(r: R) -> Result<()>
where R: AsRef<[u8]> + Send + 'static {
let device = rodio::default_output_device()
.chain_err(|| "could not find an audio output device")?;
@@ -31,6 +37,7 @@ mod tests {
#[test]
fn play_audio_plays_audio() {
- play_audio(MODE_ACTIVATED).unwrap();
+ play_mode_activated().unwrap();
+ play_mode_deactivated().unwrap();
}
}