Make the current position in the audio sample a fix point

This commit is contained in:
Gwilym Kuiper 2021-06-10 22:46:21 +01:00
parent 54e9498886
commit 5b1f85a619
2 changed files with 7 additions and 5 deletions

View file

@ -36,9 +36,9 @@ impl Mixer {
self.buffer_r.write_channel(some_channel);
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 {
some_channel.pos = 0;
some_channel.pos = 0.into();
} else {
has_finished = true;
}
@ -105,7 +105,7 @@ impl MixerBuffer {
}
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();
for (i, v) in data_to_copy.iter().take(SOUND_BUFFER_SIZE).enumerate() {

View file

@ -3,6 +3,8 @@ mod mixer;
pub use mixer::Mixer;
use crate::number::Num;
#[non_exhaustive]
pub struct MixerController {}
@ -18,7 +20,7 @@ impl MixerController {
pub struct SoundChannel {
data: &'static [u8],
pos: usize,
pos: Num<usize, 8>,
should_loop: bool,
}
@ -26,7 +28,7 @@ impl SoundChannel {
pub fn new(data: &'static [u8]) -> Self {
SoundChannel {
data,
pos: 0,
pos: 0.into(),
should_loop: false,
}
}