mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-22 23:26:33 +11:00
Make the current position in the audio sample a fix point
This commit is contained in:
parent
54e9498886
commit
5b1f85a619
2 changed files with 7 additions and 5 deletions
|
@ -36,9 +36,9 @@ impl Mixer {
|
||||||
self.buffer_r.write_channel(some_channel);
|
self.buffer_r.write_channel(some_channel);
|
||||||
some_channel.pos += SOUND_BUFFER_SIZE;
|
some_channel.pos += SOUND_BUFFER_SIZE;
|
||||||
|
|
||||||
if some_channel.pos >= some_channel.data.len() {
|
if some_channel.pos.floor() >= some_channel.data.len() {
|
||||||
if some_channel.should_loop {
|
if some_channel.should_loop {
|
||||||
some_channel.pos = 0;
|
some_channel.pos = 0.into();
|
||||||
} else {
|
} else {
|
||||||
has_finished = true;
|
has_finished = true;
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ impl MixerBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_channel(&mut self, channel: &SoundChannel) {
|
fn write_channel(&mut self, channel: &SoundChannel) {
|
||||||
let data_to_copy = &channel.data[channel.pos..];
|
let data_to_copy = &channel.data[channel.pos.floor()..];
|
||||||
let place_to_write_to = self.get_write_buffer();
|
let place_to_write_to = self.get_write_buffer();
|
||||||
|
|
||||||
for (i, v) in data_to_copy.iter().take(SOUND_BUFFER_SIZE).enumerate() {
|
for (i, v) in data_to_copy.iter().take(SOUND_BUFFER_SIZE).enumerate() {
|
||||||
|
|
|
@ -3,6 +3,8 @@ mod mixer;
|
||||||
|
|
||||||
pub use mixer::Mixer;
|
pub use mixer::Mixer;
|
||||||
|
|
||||||
|
use crate::number::Num;
|
||||||
|
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub struct MixerController {}
|
pub struct MixerController {}
|
||||||
|
|
||||||
|
@ -18,7 +20,7 @@ impl MixerController {
|
||||||
|
|
||||||
pub struct SoundChannel {
|
pub struct SoundChannel {
|
||||||
data: &'static [u8],
|
data: &'static [u8],
|
||||||
pos: usize,
|
pos: Num<usize, 8>,
|
||||||
should_loop: bool,
|
should_loop: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +28,7 @@ impl SoundChannel {
|
||||||
pub fn new(data: &'static [u8]) -> Self {
|
pub fn new(data: &'static [u8]) -> Self {
|
||||||
SoundChannel {
|
SoundChannel {
|
||||||
data,
|
data,
|
||||||
pos: 0,
|
pos: 0.into(),
|
||||||
should_loop: false,
|
should_loop: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue