Skip to content

Commit

Permalink
Fixed build config for multiple linux targets.
Browse files Browse the repository at this point in the history
  • Loading branch information
ionarevamp committed Apr 5, 2024
1 parent e82e623 commit 1a80c83
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
8 changes: 4 additions & 4 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ rustflags = [
"-C", "linker=g++",
]

[dependencies.sdl2]
version = "0.36"
default-features = false


[target.x86_64-unknown-linux-musl]
rustflags = [
"-C", "linker=g++",
]

[target.'cfg(not(target-family "android"))'.dependencies.sdl2]
git = "https://github.com/rust-sdl2/rust-sdl2"
default-features = false
features = ["static-link","bundled"]
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ ratatui = "0.26.1"
[dependencies.sdl2]
git = "https://github.com/rust-sdl2/rust-sdl2"
default-features = false
features = ["ttf","image","gfx","mixer","bundled","static-link"]
features = ["ttf","image","gfx","mixer"]
50 changes: 50 additions & 0 deletions src/extras/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ impl Sound {
pub fn volume(&self) -> f32 {
self.volume.clone()
}
pub fn pos(&self) -> usize {
self.pos
}
pub fn fade_in(&mut self, rate: f32, max: f32) {
if self.volume < max {
self.volume += rate;
Expand Down Expand Up @@ -151,3 +154,50 @@ pub fn generate_sound(
}

// ^ This returns a device and an audio spec...
//



#[allow(dead_code)]
#[test]
pub fn loop_test() -> Result<()> {

println!("Loading...");
let sdl_context = sdl2::init().expect("Unable to initialize SDL2"); println!("SDL2 initialized.");
let audio_subsystem = sdl_context
.audio()
.expect("Unable to initialize audio subsystem");
println!("Audio subsystem initialized.");

let wav = Cow::from(Path::new("Ominous.wav"));
let mut device = generate_sound(&audio_subsystem, &wav, 0.5, 0).unwrap().0;

device.resume();
let (mut loop_count, loop_limit) = (0,2);
loop {
device.lock().fade_percent(0.05, 1.0);
if device.lock().pos() >= 1154609*2 {
device.lock().restart();
device.lock().set_volume(0.5);
loop_count += 1;
if loop_count >= loop_limit { break; }
}
}

let wav = Cow::from(Path::new("Mysterious_Cyborg.wav"));
device = generate_sound(&audio_subsystem, &wav, 0.3, 0).unwrap().0;

device.resume(); loop_count = 0;
loop {
device.lock().fade_percent(0.02, 1.0);
if device.lock().pos() >= (44100 as f64 * 21.33) as usize *2 {
device.lock().restart();
device.lock().set_volume(0.5);
loop_count += 1;
if loop_count >= loop_limit { break; }
}
}

Ok(())

}

0 comments on commit 1a80c83

Please sign in to comment.