Browse Source

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.

console
Nico de Poel 5 years ago
parent
commit
0d4043e444
  1. 8
      Assets/Scripts/AudioManager.cs
  2. 14
      engine/Quake/snd_fmod.c

8
Assets/Scripts/AudioManager.cs

@ -6,7 +6,8 @@ using UnityEngine;
public class AudioManager : MonoBehaviour 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; private FMOD.System fmodSystem;
public FMOD.System FmodSystem => fmodSystem; public FMOD.System FmodSystem => fmodSystem;
@ -79,7 +80,10 @@ public class AudioManager : MonoBehaviour
Debug.Log($"[FMOD] Using output type: {output}"); 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"); CheckFmodResult(result, "FMOD.System.init");
} }

14
engine/Quake/snd_fmod.c

@ -52,6 +52,20 @@ void S_Startup(void)
return; 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; fmod_ownership = true;
} }

Loading…
Cancel
Save