mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 08:41:34 +11:00
Make it easier for the user to provide sound samples
This commit is contained in:
parent
df7a72d618
commit
9d1aeea077
|
@ -3,11 +3,10 @@
|
||||||
|
|
||||||
extern crate agb;
|
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
|
// 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] =
|
const I_WILL_NOT_LET_YOU_LET_ME_DOWN: &[u8] = include_bytes!("i-will-not-let-you-let-me-down.raw");
|
||||||
include_bytes!("i-will-not-let-you-let-me-down.raw");
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn main() -> ! {
|
pub fn main() -> ! {
|
||||||
|
@ -15,7 +14,7 @@ pub fn main() -> ! {
|
||||||
let mixer = gba.mixer;
|
let mixer = gba.mixer;
|
||||||
mixer.enable();
|
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 {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ impl Mixer {
|
||||||
set_sound_control_register_for_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);
|
set_timer_counter_for_frequency_and_enable(SOUND_FREQUENCY);
|
||||||
enable_dma1_for_sound(sound_memory);
|
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: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0082) };
|
||||||
const SOUND_CONTROL_X: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0084) };
|
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 dest_fixed: u16 = 2 << 5; // dest addr control = fixed
|
||||||
let repeat: u16 = 1 << 9;
|
let repeat: u16 = 1 << 9;
|
||||||
let transfer_type: u16 = 1 << 10; // transfer in words
|
let transfer_type: u16 = 1 << 10; // transfer in words
|
||||||
let dma_start_timing: u16 = 3 << 12; // sound fifo timing
|
let dma_start_timing: u16 = 3 << 12; // sound fifo timing
|
||||||
let enable: u16 = 1 << 15; // enable
|
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_DEST_ADDR.set(FIFOA_DEST_ADDR);
|
||||||
DMA1_CONTROL.set(dest_fixed | repeat | transfer_type | dma_start_timing | enable);
|
DMA1_CONTROL.set(dest_fixed | repeat | transfer_type | dma_start_timing | enable);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue