Add config key to toggle sound limiter (#1617)

This commit is contained in:
ceski 2024-03-25 15:52:02 -07:00 committed by GitHub
parent 64c7dafc55
commit 8030b9faf6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 16 deletions

View File

@ -29,6 +29,7 @@
#include "i_printf.h" #include "i_printf.h"
#include "i_sndfile.h" #include "i_sndfile.h"
#include "i_sound.h" #include "i_sound.h"
#include "m_array.h"
#include "m_fixed.h" #include "m_fixed.h"
#include "sounds.h" #include "sounds.h"
#include "w_wad.h" #include "w_wad.h"
@ -40,7 +41,6 @@
#define OAL_MAP_UNITS_PER_METER (128.0f / 3.0f) #define OAL_MAP_UNITS_PER_METER (128.0f / 3.0f)
#define OAL_SOURCE_RADIUS 32.0f #define OAL_SOURCE_RADIUS 32.0f
#define OAL_DEFAULT_PITCH 1.0f #define OAL_DEFAULT_PITCH 1.0f
#define OAL_NUM_ATTRIBS 5
#define DMXHDRSIZE 8 #define DMXHDRSIZE 8
#define DMXPADSIZE 16 #define DMXPADSIZE 16
@ -58,6 +58,7 @@
#endif #endif
int snd_resampler; int snd_resampler;
boolean snd_limiter;
boolean snd_hrtf; boolean snd_hrtf;
int snd_absorption; int snd_absorption;
int snd_doppler; int snd_doppler;
@ -399,32 +400,40 @@ static void PrintDeviceInfo(ALCdevice *device)
I_Printf(VB_INFO, " Using '%s' @ %d Hz.", name, srate); I_Printf(VB_INFO, " Using '%s' @ %d Hz.", name, srate);
} }
static void GetAttribs(ALCint *attribs) static void GetAttribs(ALCint **attribs)
{ {
const boolean use_3d = (snd_module == SND_MODULE_3D); const boolean use_3d = (snd_module == SND_MODULE_3D);
int i = 0;
memset(attribs, 0, sizeof(*attribs) * OAL_NUM_ATTRIBS);
if (alcIsExtensionPresent(oal->device, "ALC_SOFT_HRTF") == ALC_TRUE) if (alcIsExtensionPresent(oal->device, "ALC_SOFT_HRTF") == ALC_TRUE)
{ {
attribs[i++] = ALC_HRTF_SOFT; array_push(*attribs, ALC_HRTF_SOFT);
attribs[i++] = use_3d ? (snd_hrtf ? ALC_TRUE : ALC_FALSE) : ALC_FALSE; array_push(*attribs, (use_3d && snd_hrtf) ? ALC_TRUE : ALC_FALSE);
} }
#ifdef ALC_OUTPUT_MODE_SOFT #ifdef ALC_OUTPUT_MODE_SOFT
if (alcIsExtensionPresent(oal->device, "ALC_SOFT_output_mode") == ALC_TRUE) if (alcIsExtensionPresent(oal->device, "ALC_SOFT_output_mode") == ALC_TRUE)
{ {
attribs[i++] = ALC_OUTPUT_MODE_SOFT; array_push(*attribs, ALC_OUTPUT_MODE_SOFT);
attribs[i++] = use_3d ? (snd_hrtf ? ALC_STEREO_HRTF_SOFT : ALC_ANY_SOFT) array_push(*attribs,
: ALC_STEREO_BASIC_SOFT; use_3d ? (snd_hrtf ? ALC_STEREO_HRTF_SOFT : ALC_ANY_SOFT)
: ALC_STEREO_BASIC_SOFT);
} }
#endif #endif
if (alcIsExtensionPresent(oal->device, "ALC_SOFT_output_limiter")
== ALC_TRUE)
{
array_push(*attribs, ALC_OUTPUT_LIMITER_SOFT);
array_push(*attribs, snd_limiter ? ALC_TRUE : ALC_FALSE);
}
// Attribute list must be zero terminated.
array_push(*attribs, 0);
} }
boolean I_OAL_InitSound(void) boolean I_OAL_InitSound(void)
{ {
ALCint attribs[OAL_NUM_ATTRIBS]; ALCint *attribs = NULL;
if (oal) if (oal)
{ {
@ -441,8 +450,9 @@ boolean I_OAL_InitSound(void)
return false; return false;
} }
GetAttribs(attribs); GetAttribs(&attribs);
oal->context = alcCreateContext(oal->device, attribs); oal->context = alcCreateContext(oal->device, attribs);
array_free(attribs);
if (!oal->context || !alcMakeContextCurrent(oal->context)) if (!oal->context || !alcMakeContextCurrent(oal->context))
{ {
I_Printf(VB_ERROR, "I_OAL_InitSound: Error creating context."); I_Printf(VB_ERROR, "I_OAL_InitSound: Error creating context.");
@ -476,7 +486,8 @@ boolean I_OAL_InitSound(void)
boolean I_OAL_ReinitSound(void) boolean I_OAL_ReinitSound(void)
{ {
LPALCRESETDEVICESOFT alcResetDeviceSOFT = NULL; LPALCRESETDEVICESOFT alcResetDeviceSOFT = NULL;
ALCint attribs[OAL_NUM_ATTRIBS]; ALCint *attribs = NULL;
ALCboolean result;
if (!oal) if (!oal)
{ {
@ -499,9 +510,10 @@ boolean I_OAL_ReinitSound(void)
return false; return false;
} }
GetAttribs(attribs); GetAttribs(&attribs);
result = alcResetDeviceSOFT(oal->device, attribs);
if (alcResetDeviceSOFT(oal->device, attribs) != ALC_TRUE) array_free(attribs);
if (result != ALC_TRUE)
{ {
I_Printf(VB_ERROR, "I_OAL_ReinitSound: Error resetting device."); I_Printf(VB_ERROR, "I_OAL_ReinitSound: Error resetting device.");
I_OAL_ShutdownSound(); I_OAL_ShutdownSound();

View File

@ -74,6 +74,7 @@ void I_ShutdownSound(void);
extern int forceFlipPan; extern int forceFlipPan;
extern int snd_resampler; extern int snd_resampler;
extern boolean snd_limiter;
extern int snd_module; extern int snd_module;
extern boolean snd_hrtf; extern boolean snd_hrtf;
extern int snd_absorption; extern int snd_absorption;

View File

@ -423,6 +423,13 @@ default_t defaults[] = {
"OpenAL resampler (0 = Nearest, 1 = Linear, 2 = Cubic)" "OpenAL resampler (0 = Nearest, 1 = Linear, 2 = Cubic)"
}, },
{
"snd_limiter",
(config_t *) &snd_limiter, NULL,
{0}, {0, 1}, number, ss_none, wad_no,
"1 to enable sound output limiter"
},
{ {
"snd_module", "snd_module",
(config_t *) &snd_module, NULL, (config_t *) &snd_module, NULL,