From 52510cfecc4e39d367b707f1d4bc02ecd202c928 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Tue, 13 Apr 2021 13:56:01 +0200 Subject: [PATCH] Some cleanup and extra housekeeping --- engine/Quake/snd_fmod.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/engine/Quake/snd_fmod.c b/engine/Quake/snd_fmod.c index 7dcc4b9..f7608c8 100644 --- a/engine/Quake/snd_fmod.c +++ b/engine/Quake/snd_fmod.c @@ -114,7 +114,9 @@ void S_Shutdown(void) { Con_DPrintf("[FMOD] Shutdown\n"); - // Destroy any SFX channels still in use + S_StopAllSounds(true); + + // TODO: destroy all FMOD_SOUNDs that are attached to sfx_t's // If we created the FMOD System (and consequently own it), destroy it here if (fmod_ownership) @@ -243,20 +245,10 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f if (!sfx->sound) return; - // Find channel group for entity number (or create) => note entnum can also be some random hash value - // ChannelControl::setMode => set to 3D - // Can use channel group per entity to store entity-specific userdata, with maybe 8-16 fixed channel slots - // Note: entnum <0 is used by temporary entities, means there's no tie to any entity info at all: just play on any free channel - + // Choose a slot to play the sound on, and stop any conflicting sound on the same entchannel + // Do this before playing the new sound, so that any previous sound will be stopped in time userdata = SND_PickSoundSlot(entnum, entchannel); - // Pre-define channels for each entity (could be an array of ints, probably array of entchannel_t structs) - // For entchannel 0, dynamically select a free channel (or just play without doing anything, let FMOD handle it) - // If channel at index entchannel >0 is already playing: stop - // Set userdata pointer to entchannel_t so we can check if the FMOD channel still belongs to this entity & entchannel, before checking if it's already playing - // Special case entchannel -1 => just play locally on listener, no 3D (also override any sound already playing on entity) - - // System::playSound with paused = true result = FMOD_System_PlaySound(fmod_system, sfx->sound, sfx_channelGroup, 1, &channel); if (result != FMOD_OK) { @@ -282,7 +274,7 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f FMOD_Channel_SetPriority(channel, 64); // Ensure local sounds always get priority over other entities } - // Use ChannelControl::setDelay and ChannelControl::getDSPClock to add a delay to move sounds out of phase if necessary + // TODO: Use ChannelControl::setDelay and ChannelControl::getDSPClock to add a delay to move sounds out of phase if necessary FMOD_Channel_SetPaused(channel, 0); } @@ -355,8 +347,7 @@ void S_StopAllSounds(qboolean clear) if (!fmod_system) return; - // TODO Use this to remove per-entity channel group and clear all userdata? => should already be handled by Stop (but double check!) - + // Stopping all sounds also ensures that any associated zone memory is freed FMOD_ChannelGroup_Stop(sfx_channelGroup); if (clear) @@ -399,6 +390,9 @@ void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up) void S_ExtraUpdate(void) { + if (!fmod_system) + return; + FMOD_System_Update(fmod_system); }