mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 09:31:34 +11:00
Build a special version of 'frame' for freq32768
This commit is contained in:
parent
c709455e3d
commit
a4c696ad33
|
@ -45,16 +45,29 @@ impl Mixer {
|
||||||
hw::set_sound_control_register_for_mixer();
|
hw::set_sound_control_register_for_mixer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "freq32768"))]
|
||||||
pub fn frame(&mut self) {
|
pub fn frame(&mut self) {
|
||||||
self.buffer.clear();
|
self.buffer.clear();
|
||||||
self.buffer
|
self.buffer
|
||||||
.write_channels(self.channels.iter_mut().flatten());
|
.write_channels(self.channels.iter_mut().flatten());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "freq32768"))]
|
||||||
pub fn after_vblank(&mut self) {
|
pub fn after_vblank(&mut self) {
|
||||||
self.buffer.swap();
|
self.buffer.swap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "freq32768")]
|
||||||
|
pub fn frame(&mut self) {
|
||||||
|
if self.buffer.has_swapped() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.buffer.clear();
|
||||||
|
self.buffer
|
||||||
|
.write_channels(self.channels.iter_mut().flatten());
|
||||||
|
}
|
||||||
|
|
||||||
pub fn play_sound(&mut self, new_channel: SoundChannel) -> Option<ChannelId> {
|
pub fn play_sound(&mut self, new_channel: SoundChannel) -> Option<ChannelId> {
|
||||||
for (i, channel) in self.channels.iter_mut().enumerate() {
|
for (i, channel) in self.channels.iter_mut().enumerate() {
|
||||||
if let Some(some_channel) = channel {
|
if let Some(some_channel) = channel {
|
||||||
|
@ -134,6 +147,7 @@ struct MixerBuffer {
|
||||||
buffer2: SoundBuffer,
|
buffer2: SoundBuffer,
|
||||||
|
|
||||||
buffer_1_active: bool,
|
buffer_1_active: bool,
|
||||||
|
swapped: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MixerBuffer {
|
impl MixerBuffer {
|
||||||
|
@ -145,9 +159,14 @@ impl MixerBuffer {
|
||||||
buffer2: SoundBuffer([0; constants::SOUND_BUFFER_SIZE * 2]),
|
buffer2: SoundBuffer([0; constants::SOUND_BUFFER_SIZE * 2]),
|
||||||
|
|
||||||
buffer_1_active: true,
|
buffer_1_active: true,
|
||||||
|
swapped: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn has_swapped(&self) -> bool {
|
||||||
|
self.swapped
|
||||||
|
}
|
||||||
|
|
||||||
fn swap(&mut self) {
|
fn swap(&mut self) {
|
||||||
let (left_buffer, right_buffer) =
|
let (left_buffer, right_buffer) =
|
||||||
self.write_buffer().split_at(constants::SOUND_BUFFER_SIZE);
|
self.write_buffer().split_at(constants::SOUND_BUFFER_SIZE);
|
||||||
|
@ -156,6 +175,7 @@ impl MixerBuffer {
|
||||||
hw::enable_dma_for_sound(right_buffer, LeftOrRight::Right);
|
hw::enable_dma_for_sound(right_buffer, LeftOrRight::Right);
|
||||||
|
|
||||||
self.buffer_1_active = !self.buffer_1_active;
|
self.buffer_1_active = !self.buffer_1_active;
|
||||||
|
self.swapped = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear(&mut self) {
|
fn clear(&mut self) {
|
||||||
|
@ -218,6 +238,8 @@ impl MixerBuffer {
|
||||||
unsafe {
|
unsafe {
|
||||||
agb_rs__mixer_collapse(write_buffer.as_mut_ptr(), buffer.as_ptr());
|
agb_rs__mixer_collapse(write_buffer.as_mut_ptr(), buffer.as_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.swapped = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_buffer(&mut self) -> &mut [i8; constants::SOUND_BUFFER_SIZE * 2] {
|
fn write_buffer(&mut self) -> &mut [i8; constants::SOUND_BUFFER_SIZE * 2] {
|
||||||
|
|
Loading…
Reference in a new issue