Make it easier for the user to provide sound samples

This commit is contained in:
Gwilym Kuiper 2021-06-06 11:28:35 +01:00
parent df7a72d618
commit 9d1aeea077
2 changed files with 7 additions and 7 deletions

View file

@ -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 {}
}

View file

@ -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<u16> = unsafe { MemoryMapped::new(0x0400_0102
const SOUND_CONTROL: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0082) };
const SOUND_CONTROL_X: MemoryMapped<u16> = 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);
}