From 58f87f14af2c55cfe04c5b66fcede7876f16ef25 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sat, 10 Feb 2024 21:25:18 +0100 Subject: [PATCH] added using callback function when sound channel is finished --- src/libgame/sound.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/libgame/sound.c b/src/libgame/sound.c index 473850dd..f911d238 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -141,6 +141,15 @@ static MusicInfo *getMusicInfoEntryFromMusicID(int); // mixer functions // ---------------------------------------------------------------------------- +static void Mixer_ChannelFinished(int channel) +{ + if (!mixer[channel].active) + return; + + mixer[channel].active = FALSE; + mixer_active_channels--; +} + void Mixer_InitChannels(void) { int i; @@ -148,6 +157,8 @@ void Mixer_InitChannels(void) for (i = 0; i < audio.num_channels; i++) mixer[i].active = FALSE; mixer_active_channels = 0; + + Mix_ChannelFinished(Mixer_ChannelFinished); } static void Mixer_ResetChannelExpiration(int channel) @@ -247,13 +258,7 @@ static void Mixer_PlayMusicChannel(void) static void Mixer_StopChannel(int channel) { - if (!mixer[channel].active) - return; - Mix_HaltChannel(channel); - - mixer[channel].active = FALSE; - mixer_active_channels--; } static void Mixer_StopMusicChannel(void) -- 2.34.1