diff options
Diffstat (limited to 'graphics/src/audio.rs')
| -rw-r--r-- | graphics/src/audio.rs | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/graphics/src/audio.rs b/graphics/src/audio.rs index 8cf155f..3a20f62 100644 --- a/graphics/src/audio.rs +++ b/graphics/src/audio.rs @@ -2,14 +2,27 @@ use raylib::audio::RaylibAudio; -#[expect(dead_code)] +macro_rules! load_audio { + ($handle:expr, $filepath:expr) => { + if cfg!(feature = "static") { + let bytes = include_bytes!(concat!("../../", $filepath)); + let wave = $handle.new_wave_from_memory(".ogg", bytes)?; + $handle.new_sound_from_wave(&wave)? + } else { + $handle.new_sound($filepath)? + } + }; +} + type Sound = raylib::audio::Sound<'static>; /// The `Audio` container initalizes the audio subsystem /// for raylib, leaks it (to gurentee audio is statically loaded), /// then loads all needed audio samples #[derive(Debug)] -pub struct Audio {} +pub struct Audio { + pub speak: Sound, +} impl Audio { pub(crate) fn load() -> crate::Result<Self> { // Phantom handle to the raylib audio subsystem @@ -21,12 +34,13 @@ impl Audio { // // NOTE: would this cause issues if `Audio::load` was // called multiple times? - let _handle = Box::leak(Box::new(RaylibAudio::init_audio_device()?)); - - // TODO: load audio samples + let handle = Box::leak(Box::new(RaylibAudio::init_audio_device()?)); - //let example = handle.new_sound("example.ogg")?; + // yes i know this is sans undertale, it was funny + // and i cannot think of anything better yet, haha + // - freya + let speak = load_audio!(handle, "assets/speak.ogg"); - Ok(Self {}) + Ok(Self { speak }) } } |