From 0d4043e4441dd0a46f9f1e1d720c506a68d1bb06 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Tue, 13 Apr 2021 13:21:03 +0200 Subject: [PATCH] Properly set max real and virtual channels on FMOD initialization. Fixes sounds noticeably cutting out when the default max of 64 real channels is exceeded. --- Assets/Scripts/AudioManager.cs | 8 ++++++-- engine/Quake/snd_fmod.c | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/AudioManager.cs b/Assets/Scripts/AudioManager.cs index 82fa7fe..2916995 100644 --- a/Assets/Scripts/AudioManager.cs +++ b/Assets/Scripts/AudioManager.cs @@ -6,7 +6,8 @@ using UnityEngine; public class AudioManager : MonoBehaviour { - private const int MaxChannels = 128; // Should match MAX_CHANNELS in sound.h + private const int MaxVirtualChannels = 1024; // Should match MAX_CHANNELS in q_sound.h + private const int MaxRealChannels = 128; // Should match MAX_DYNAMIC_CHANNELS in q_sound.h private FMOD.System fmodSystem; public FMOD.System FmodSystem => fmodSystem; @@ -79,7 +80,10 @@ public class AudioManager : MonoBehaviour Debug.Log($"[FMOD] Using output type: {output}"); - result = fmodSystem.init(MaxChannels, FMOD.INITFLAGS.NORMAL, IntPtr.Zero); + result = fmodSystem.setSoftwareChannels(MaxRealChannels); + CheckFmodResult(result, "FMOD.System.setSoftwareChannels"); + + result = fmodSystem.init(MaxVirtualChannels, FMOD.INITFLAGS.NORMAL, IntPtr.Zero); CheckFmodResult(result, "FMOD.System.init"); } diff --git a/engine/Quake/snd_fmod.c b/engine/Quake/snd_fmod.c index 249bbe1..eb4de56 100644 --- a/engine/Quake/snd_fmod.c +++ b/engine/Quake/snd_fmod.c @@ -52,6 +52,20 @@ void S_Startup(void) return; } + result = FMOD_System_SetSoftwareChannels(fmod_system, MAX_DYNAMIC_CHANNELS); + if (result != FMOD_OK) + { + Con_Printf("Failed to set number of FMOD software channels: %s\n", FMOD_ErrorString(result)); + return; + } + + result = FMOD_System_Init(fmod_system, MAX_CHANNELS, FMOD_INIT_NORMAL, NULL); + if (result != FMOD_OK) + { + Con_Printf("Failed to initialize FMOD System: %s\n", FMOD_ErrorString(result)); + return; + } + fmod_ownership = true; }