initial sound

This commit is contained in:
gallant 2022-05-05 13:06:09 -05:00
parent 01b2f0bfc1
commit 7d26d56132
8 changed files with 52 additions and 23 deletions

40
Cargo.lock generated
View file

@ -28,6 +28,7 @@ name = "game_test"
version = "0.1.0"
dependencies = [
"cat-box",
"play",
"rand",
"sdl2",
]
@ -55,6 +56,45 @@ version = "0.2.125"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b"
[[package]]
name = "mpg123-sys"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75c26239d85c1423091c109fcdabbcfaac868576dc018b0e959137217907610"
dependencies = [
"bitflags",
"libc",
"pkg-config",
]
[[package]]
name = "out123-sys"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5da977be7c4b44e2ad26be779aafc1761a89bd2ee6e363770bb71eb67a00d2e5"
dependencies = [
"libc",
"mpg123-sys",
"pkg-config",
]
[[package]]
name = "pkg-config"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae"
[[package]]
name = "play"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c570085654588139e9ea2f452fe7dcb78d576da4f1c04d58b98b32fc42744ff0"
dependencies = [
"libc",
"mpg123-sys",
"out123-sys",
]
[[package]]
name = "ppv-lite86"
version = "0.2.16"

View file

@ -8,4 +8,5 @@ edition = "2021"
[dependencies]
cat-box = "0.1.6"
sdl2 = "0.35.2"
rand = "0.8.5"
rand = "0.8.5"
play = "0.5.3"

BIN
sound.mp3 Normal file

Binary file not shown.

BIN
sound.ogg Normal file

Binary file not shown.

View file

@ -1,18 +0,0 @@
use std::fs::File;
use std::io::BufReader;
use rodio::{Decoder, OutputStream, source::Source};
pub fn play() {
let (_stream, stream_handle) = OutputStream::try_default().unwrap();
// Load a sound from a file, using a path relative to Cargo.toml
let file = BufReader::new(File::open("sound.ogg").unwrap());
// Decode that sound file into a source
let source = Decoder::new(file).unwrap();
// Play the sound directly on the device
stream_handle.play_raw(source.convert_samples());
// The sound plays in a separate audio thread,
// so we need to keep the main thread alive while it's playing.
std::thread::sleep(std::time::Duration::from_secs(5));
}

View file

@ -1,6 +1,6 @@
use cat_box::{draw_text, Game, Sprite};
use std::{thread, time, fs::File, io::BufReader};
pub mod balls;
use std::{thread, time, fs::File, io::BufReader, process::Command};
use play;
fn main() {
let game = Game::new("catbox testing", 500, 500);
@ -10,7 +10,7 @@ fn main() {
let mut i2 = 0u8;
let sleep = thread::sleep;
game.run(|ctx| {
let mut s = Sprite::new(sprite1, 250, 150).unwrap();
@ -42,9 +42,15 @@ fn main() {
colour: (i2,i2,i2),
}
).unwrap();
s.draw(ctx).unwrap();
s1.draw(ctx).unwrap();
s2.draw(ctx).unwrap();
Command::new("play")
.arg("./sound.mp3")
.output()
.expect("fucked up");
}).unwrap();
}

Binary file not shown.