Probably too much in 1 commit

This commit is contained in:
Gwilym Kuiper 2021-06-06 11:50:30 +01:00
parent 72dbf2ef9c
commit 46683e42c8
2 changed files with 30 additions and 5 deletions

View file

@ -51,7 +51,7 @@ static mut GBASINGLE: single::Singleton<Gba> = single::Singleton::new(unsafe { G
pub struct Gba {
pub display: display::Display,
pub sound: sound::dmg::Sound,
pub mixer: sound::mixer::Mixer,
pub mixer: sound::mixer::MixerController,
}
impl Gba {
@ -63,7 +63,7 @@ impl Gba {
Self {
display: display::Display::new(),
sound: sound::dmg::Sound::new(),
mixer: sound::mixer::Mixer::new(),
mixer: sound::mixer::MixerController::new(),
}
}
}

View file

@ -1,14 +1,28 @@
use crate::memory_mapped::MemoryMapped;
#[non_exhaustive]
pub struct MixerController {}
impl MixerController {
pub(crate) const fn new() -> Self {
MixerController {}
}
pub fn mixer(&mut self) -> Mixer {
Mixer::new()
}
}
pub struct Mixer {
buffer: MixerBuffer,
channels: [Option<SoundChannel>; 16],
}
impl Mixer {
pub(crate) const unsafe fn new() -> Self {
fn new() -> Self {
Mixer {
buffer: MixerBuffer::new(),
channels: Default::default(),
}
}
@ -22,6 +36,17 @@ impl Mixer {
}
}
struct SoundChannel {
data: &'static [u8],
pos: usize,
}
impl SoundChannel {
fn new(data: &'static [u8]) -> Self {
SoundChannel { data, pos: 0 }
}
}
// I've picked one frequency that works nicely. But there are others that work nicely
// which we may want to consider in the future: https://web.archive.org/web/20070608011909/http://deku.gbadev.org/program/sound1.html
const SOUND_FREQUENCY: i32 = 10512;
@ -37,8 +62,8 @@ struct MixerBuffer {
impl MixerBuffer {
fn new() -> Self {
MixerBuffer {
buffer1: Default::default(),
buffer2: Default::default(),
buffer1: [0; SOUND_BUFFER_SIZE],
buffer2: [0; SOUND_BUFFER_SIZE],
buffer_1_active: true,
}