From 27a470c64885f61f9dc47c8110a69c82bcfcfcb8 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Fri, 25 Jun 2021 21:38:10 +0100 Subject: [PATCH] Return a way to get back at the channel --- agb/src/sound/mixer/sw_mixer.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/agb/src/sound/mixer/sw_mixer.rs b/agb/src/sound/mixer/sw_mixer.rs index 97a37f5..aef9acf 100644 --- a/agb/src/sound/mixer/sw_mixer.rs +++ b/agb/src/sound/mixer/sw_mixer.rs @@ -6,15 +6,17 @@ use crate::number::Num; pub struct Mixer { buffer: MixerBuffer, channels: [Option; 16], + indices: [i32; 16], } -pub struct ChannelId(usize); +pub struct ChannelId(usize, i32); impl Mixer { pub(super) fn new() -> Self { Mixer { buffer: MixerBuffer::new(), channels: Default::default(), + indices: Default::default(), } } @@ -40,7 +42,8 @@ impl Mixer { } channel.replace(new_channel); - return Some(ChannelId(i)); + self.indices[i] += 1; + return Some(ChannelId(i, self.indices[i])); } if new_channel.priority == SoundPriority::Low { @@ -53,7 +56,8 @@ impl Mixer { } channel.replace(new_channel); - return Some(ChannelId(i)); + self.indices[i] += 1; + return Some(ChannelId(i, self.indices[i])); } panic!("Cannot play more than 16 sounds at once");