mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 08:41:34 +11:00
Merge pull request #62 from gwilymk/allow-channels-to-loop
Allow channels to loop
This commit is contained in:
commit
2a0192de51
|
@ -43,9 +43,13 @@ impl Mixer {
|
||||||
some_channel.pos += SOUND_BUFFER_SIZE;
|
some_channel.pos += SOUND_BUFFER_SIZE;
|
||||||
|
|
||||||
if some_channel.pos >= some_channel.data.len() {
|
if some_channel.pos >= some_channel.data.len() {
|
||||||
|
if some_channel.should_loop {
|
||||||
|
some_channel.pos = 0;
|
||||||
|
} else {
|
||||||
has_finished = true;
|
has_finished = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if has_finished {
|
if has_finished {
|
||||||
channel.take();
|
channel.take();
|
||||||
|
@ -70,11 +74,21 @@ impl Mixer {
|
||||||
pub struct SoundChannel {
|
pub struct SoundChannel {
|
||||||
data: &'static [u8],
|
data: &'static [u8],
|
||||||
pos: usize,
|
pos: usize,
|
||||||
|
should_loop: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SoundChannel {
|
impl SoundChannel {
|
||||||
pub fn new(data: &'static [u8]) -> Self {
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue