From e3e5bd1bdd1cc403cf3096d60ea143c400971db3 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Thu, 30 Nov 2017 08:26:39 +0100 Subject: [PATCH] Fix drop in volume when shooting into a Brains power screen. If too many of these sounds are started in one frame (for example if the player shoots with the super shotgun into the power screen of a Brain) things get too loud and OpenAL is forced to scale the volume of several other sounds and the background music down. That leads to a noticable and annoying drop in the overall volume. Work around that by limiting the number of sounds started. 16 was choosen by empirical testing. --- src/client/cl_main.c | 8 ++++++++ src/client/cl_tempentities.c | 20 +++++++++++++++++++- src/client/header/client.h | 5 +++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/client/cl_main.c b/src/client/cl_main.c index 7b74a476..41802067 100644 --- a/src/client/cl_main.c +++ b/src/client/cl_main.c @@ -92,6 +92,11 @@ centity_t cl_entities[MAX_EDICTS]; entity_state_t cl_parse_entities[MAX_PARSE_ENTITIES]; +/*Evil hack against too many power screen and power + shield impact sounds. For example if the player + fires his shotgun onto a Brain. */ +int num_power_sounds; + extern cvar_t *allow_download; extern cvar_t *allow_download_players; extern cvar_t *allow_download_models; @@ -733,6 +738,9 @@ CL_Frame(int packetdelta, int renderdelta, int timedelta, qboolean packetframe, cls.netchan.last_received = Sys_Milliseconds(); } + // Reset power shield / power screen sound counter. + num_power_sounds = 0; + if (!cl_timedemo->value) { // Don't throttle too much when connecting / loading. diff --git a/src/client/cl_tempentities.c b/src/client/cl_tempentities.c index 0cb4f696..5b3f539b 100644 --- a/src/client/cl_tempentities.c +++ b/src/client/cl_tempentities.c @@ -24,7 +24,9 @@ * ======================================================================= */ +#include #include "header/client.h" +#include "sound/header/local.h" typedef enum { @@ -716,7 +718,23 @@ CL_ParseTEnt(void) CL_ParticleEffect(pos, dir, 0xb0, 40); } - S_StartSound(pos, 0, 0, cl_sfx_lashit, 1, ATTN_NORM, 0); + num_power_sounds++; + + /* If too many of these sounds are started in one frame (for + * example if the player shoots with the super shotgun into + * the power screen of a Brain) things get too loud and OpenAL + * is forced to scale the volume of several other sounds and + * the background music down. That leads to a noticable and + * annoying drop in the overall volume. + * + * Work around that by limiting the number of sounds started. + * 16 was choosen by empirical testing. + */ + if (sound_started == SS_OAL && num_power_sounds < 16) + { + S_StartSound(pos, 0, 0, cl_sfx_lashit, 1, ATTN_NORM, 0); + } + break; case TE_SHOTGUN: /* bullet hitting wall */ diff --git a/src/client/header/client.h b/src/client/header/client.h index 9837ad46..9c58b0eb 100644 --- a/src/client/header/client.h +++ b/src/client/header/client.h @@ -249,6 +249,11 @@ typedef struct extern client_static_t cls; +/*Evil hack against too many power screen and power + shield impact sounds. For example if the player + fires his shotgun onto a Brain. */ +extern int num_power_sounds; + /* cvars */ extern cvar_t *gl_stereo_separation; extern cvar_t *gl_stereo_convergence;