From 74d766d988365a1c1eb69656367162e5d6c9319d Mon Sep 17 00:00:00 2001 From: terminx Date: Sat, 12 Jan 2019 00:22:05 +0000 Subject: [PATCH] Create new MV_CleanupVoice() function to handle most of what was in MV_StopVoice() plus the MV_CallBackFunc() functionality git-svn-id: https://svn.eduke32.com/eduke32@7307 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/audiolib/src/multivoc.cpp | 56 +++++++++----------------------- 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/source/audiolib/src/multivoc.cpp b/source/audiolib/src/multivoc.cpp index 096ec0266..ff60602da 100644 --- a/source/audiolib/src/multivoc.cpp +++ b/source/audiolib/src/multivoc.cpp @@ -212,15 +212,10 @@ void MV_PlayVoice(VoiceNode *voice) RestoreInterrupts(); } -static void MV_StopVoice(VoiceNode *voice) +static void MV_CleanupVoice(VoiceNode *voice) { - DisableInterrupts(); - - // move the voice from the play list to the free list - LL_Remove(voice, next, prev); - LL_Add((VoiceNode*) &VoicePool, voice, next, prev); - - RestoreInterrupts(); + if (MV_CallBackFunc) + MV_CallBackFunc(voice->callbackval); switch (voice->wavetype) { @@ -240,6 +235,17 @@ static void MV_StopVoice(VoiceNode *voice) voice->handle = 0; } +static void MV_StopVoice(VoiceNode *voice) +{ + MV_CleanupVoice(voice); + + DisableInterrupts(); + // move the voice from the play list to the free list + LL_Remove(voice, next, prev); + LL_Add((VoiceNode*) &VoicePool, voice, next, prev); + RestoreInterrupts(); +} + /*--------------------------------------------------------------------- JBF: no synchronisation happens inside MV_ServiceVoc nor the supporting functions it calls. This would cause a deadlock @@ -317,30 +323,10 @@ static void MV_ServiceVoc(void) // Is this voice done? if (!MV_Mix(voice, MV_MixPage)) { - //JBF: prevent a deadlock caused by MV_StopVoice grabbing the mutex again - //MV_StopVoice( voice ); + MV_CleanupVoice(voice); + LL_Remove(voice, next, prev); LL_Add((VoiceNode*) &VoicePool, voice, next, prev); - - switch (voice->wavetype) - { -#ifdef HAVE_VORBIS - case FMT_VORBIS: MV_ReleaseVorbisVoice(voice); break; -#endif -#ifdef HAVE_FLAC - case FMT_FLAC: MV_ReleaseFLACVoice(voice); break; -#endif - case FMT_XA: MV_ReleaseXAVoice(voice); break; -#ifdef HAVE_XMP - case FMT_XMP: MV_ReleaseXMPVoice(voice); break; -#endif - default: break; - } - - voice->handle = 0; - - if (MV_CallBackFunc) - MV_CallBackFunc(voice->callbackval); } } while ((voice = next) != &VoiceList); @@ -438,15 +424,9 @@ int32_t MV_Kill(int32_t handle) if (voice == NULL) return MV_Error; - uint32_t const callbackval = voice->callbackval; - MV_StopVoice(voice); - MV_EndService(); - if (MV_CallBackFunc) - MV_CallBackFunc(callbackval); - return MV_Ok; } @@ -846,11 +826,7 @@ static void MV_StopPlayback(void) for (VoiceNode *voice = VoiceList.next, *next; voice != &VoiceList; voice = next) { next = voice->next; - MV_StopVoice(voice); - - if (MV_CallBackFunc) - MV_CallBackFunc(voice->callbackval); } RestoreInterrupts();