mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-26 00:56:38 +11:00
Refactor to make it a bit more obvious what the write buffer is
This commit is contained in:
parent
106e53f917
commit
e181f7a751
1 changed files with 11 additions and 13 deletions
|
@ -111,26 +111,24 @@ impl MixerBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear(&mut self) {
|
fn clear(&mut self) {
|
||||||
if self.buffer_1_active {
|
self.get_write_buffer().fill(0);
|
||||||
self.buffer2.fill(0);
|
|
||||||
} else {
|
|
||||||
self.buffer1.fill(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_channel(&mut self, channel: &SoundChannel) {
|
fn write_channel(&mut self, channel: &SoundChannel) {
|
||||||
let data_to_copy = &channel.data[channel.pos..(channel.pos + SOUND_BUFFER_SIZE)];
|
let data_to_copy = &channel.data[channel.pos..(channel.pos + SOUND_BUFFER_SIZE)];
|
||||||
|
let place_to_write_to = self.get_write_buffer();
|
||||||
|
|
||||||
|
for (i, v) in data_to_copy.iter().enumerate() {
|
||||||
|
let v = *v as i8;
|
||||||
|
place_to_write_to[i] = place_to_write_to[i].saturating_add(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_write_buffer(&mut self) -> &mut [i8; SOUND_BUFFER_SIZE] {
|
||||||
if self.buffer_1_active {
|
if self.buffer_1_active {
|
||||||
for (i, v) in data_to_copy.iter().enumerate() {
|
&mut self.buffer2
|
||||||
let v = *v as i8;
|
|
||||||
self.buffer2[i] = self.buffer2[i].saturating_add(v);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
for (i, v) in data_to_copy.iter().enumerate() {
|
&mut self.buffer1
|
||||||
let v = *v as i8;
|
|
||||||
self.buffer1[i] = self.buffer1[i].saturating_add(v);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue