Merge pull request #62 from gwilymk/allow-channels-to-loop

Allow channels to loop
This commit is contained in:
Corwin 2021-06-06 15:56:25 +01:00 committed by GitHub
commit 2a0192de51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -43,9 +43,13 @@ impl Mixer {
some_channel.pos += SOUND_BUFFER_SIZE;
if some_channel.pos >= some_channel.data.len() {
if some_channel.should_loop {
some_channel.pos = 0;
} else {
has_finished = true;
}
}
}
if has_finished {
channel.take();
@ -70,11 +74,21 @@ impl Mixer {
pub struct SoundChannel {
data: &'static [u8],
pos: usize,
should_loop: bool,
}
impl SoundChannel {
pub fn new(data: &'static [u8]) -> Self {
SoundChannel { data, pos: 0 }
SoundChannel {
data,
pos: 0,
should_loop: false,
}
}
pub fn should_loop(mut self) -> Self {
self.should_loop = true;
self
}
}