From 9d1aeea077da2fa6f8d315bf3bd6551cc1aef0ed Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sun, 6 Jun 2021 11:28:35 +0100 Subject: [PATCH] Make it easier for the user to provide sound samples --- agb/examples/mixer_basic.rs | 7 +++---- agb/src/sound/mixer.rs | 7 ++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/agb/examples/mixer_basic.rs b/agb/examples/mixer_basic.rs index 37b8c28..00864b1 100644 --- a/agb/examples/mixer_basic.rs +++ b/agb/examples/mixer_basic.rs @@ -3,11 +3,10 @@ extern crate agb; -use agb::sound; +use core::mem; // Music - "I will not let you let me down" by Josh Woodward, free download at http://joshwoodward.com -const I_WILL_NOT_LET_YOU_LET_ME_DOWN: &'static [u8] = - include_bytes!("i-will-not-let-you-let-me-down.raw"); +const I_WILL_NOT_LET_YOU_LET_ME_DOWN: &[u8] = include_bytes!("i-will-not-let-you-let-me-down.raw"); #[no_mangle] pub fn main() -> ! { @@ -15,7 +14,7 @@ pub fn main() -> ! { let mixer = gba.mixer; mixer.enable(); - mixer.play_sound_starting_at(&I_WILL_NOT_LET_YOU_LET_ME_DOWN[0]); + mixer.play_sound_starting_at(I_WILL_NOT_LET_YOU_LET_ME_DOWN); loop {} } diff --git a/agb/src/sound/mixer.rs b/agb/src/sound/mixer.rs index 52aea0f..d2a439c 100644 --- a/agb/src/sound/mixer.rs +++ b/agb/src/sound/mixer.rs @@ -12,7 +12,7 @@ impl Mixer { set_sound_control_register_for_mixer(); } - pub fn play_sound_starting_at(&self, sound_memory: *const u8) { + pub fn play_sound_starting_at(&self, sound_memory: &[u8]) { set_timer_counter_for_frequency_and_enable(SOUND_FREQUENCY); enable_dma1_for_sound(sound_memory); } @@ -35,14 +35,15 @@ const TIMER0_CONTROL: MemoryMapped = unsafe { MemoryMapped::new(0x0400_0102 const SOUND_CONTROL: MemoryMapped = unsafe { MemoryMapped::new(0x0400_0082) }; const SOUND_CONTROL_X: MemoryMapped = unsafe { MemoryMapped::new(0x0400_0084) }; -fn enable_dma1_for_sound(sound_memory: *const u8) { +fn enable_dma1_for_sound(sound_memory: &[u8]) { let dest_fixed: u16 = 2 << 5; // dest addr control = fixed let repeat: u16 = 1 << 9; let transfer_type: u16 = 1 << 10; // transfer in words let dma_start_timing: u16 = 3 << 12; // sound fifo timing let enable: u16 = 1 << 15; // enable - DMA1_SOURCE_ADDR.set(sound_memory as u32); + let address: *const u8 = &sound_memory[0]; + DMA1_SOURCE_ADDR.set(address as u32); DMA1_DEST_ADDR.set(FIFOA_DEST_ADDR); DMA1_CONTROL.set(dest_fixed | repeat | transfer_type | dma_start_timing | enable); }