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 struct Gba {
pub display: display::Display, pub display: display::Display,
pub sound: sound::dmg::Sound, pub sound: sound::dmg::Sound,
pub mixer: sound::mixer::Mixer, pub mixer: sound::mixer::MixerController,
} }
impl Gba { impl Gba {
@ -63,7 +63,7 @@ impl Gba {
Self { Self {
display: display::Display::new(), display: display::Display::new(),
sound: sound::dmg::Sound::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; use crate::memory_mapped::MemoryMapped;
#[non_exhaustive] #[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 { pub struct Mixer {
buffer: MixerBuffer, buffer: MixerBuffer,
channels: [Option<SoundChannel>; 16],
} }
impl Mixer { impl Mixer {
pub(crate) const unsafe fn new() -> Self { fn new() -> Self {
Mixer { Mixer {
buffer: MixerBuffer::new(), 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 // 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 // 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; const SOUND_FREQUENCY: i32 = 10512;
@ -37,8 +62,8 @@ struct MixerBuffer {
impl MixerBuffer { impl MixerBuffer {
fn new() -> Self { fn new() -> Self {
MixerBuffer { MixerBuffer {
buffer1: Default::default(), buffer1: [0; SOUND_BUFFER_SIZE],
buffer2: Default::default(), buffer2: [0; SOUND_BUFFER_SIZE],
buffer_1_active: true, buffer_1_active: true,
} }