X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=snd_main.c;h=09a132926145c3e7734188b16be3b3ee710253aa;hb=34964d5660d2c81ddbd9fa7659277e4944f972ce;hp=2f7e871af7a4ed32f33b700ab555738bc93081d8;hpb=4134bf6102c7d2c50c55658757a7e43cee244cb3;p=xonotic%2Fdarkplaces.git diff --git a/snd_main.c b/snd_main.c index 2f7e871a..09a13292 100644 --- a/snd_main.c +++ b/snd_main.c @@ -26,6 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "snd_modplug.h" #include "csprogs.h" #include "cl_collision.h" +#include "cdaudio.h" #define SND_MIN_SPEED 8000 @@ -185,6 +186,9 @@ cvar_t snd_swapstereo = {CVAR_SAVE, "snd_swapstereo", "0", "swaps left/right spe extern cvar_t v_flipped; cvar_t snd_channellayout = {0, "snd_channellayout", "0", "channel layout. Can be 0 (auto - snd_restart needed), 1 (standard layout), or 2 (ALSA layout)"}; cvar_t snd_mutewhenidle = {CVAR_SAVE, "snd_mutewhenidle", "1", "whether to disable sound output when game window is inactive"}; +cvar_t snd_maxchannelvolume = {CVAR_SAVE, "snd_maxchannelvolume", "10", "maximum volume of a single sound"}; +cvar_t snd_softclip = {CVAR_SAVE, "snd_softclip", "0", "Use soft-clipping. Soft-clipping can make the sound more smooth if very high volume levels are used. Enable this option if the dynamic range of the loudspeakers is very low. WARNING: This feature creates distortion and should be considered a last resort."}; +//cvar_t snd_softclip = {CVAR_SAVE, "snd_softclip", "0", "Use soft-clipping (when set to 2, use it even if output is floating point). Soft-clipping can make the sound more smooth if very high volume levels are used. Enable this option if the dynamic range of the loudspeakers is very low. WARNING: This feature creates distortion and should be considered a last resort."}; cvar_t snd_entchannel0volume = {CVAR_SAVE, "snd_entchannel0volume", "1", "volume multiplier of the auto-allocate entity channel of regular entities (DEPRECATED)"}; cvar_t snd_entchannel1volume = {CVAR_SAVE, "snd_entchannel1volume", "1", "volume multiplier of the 1st entity channel of regular entities (DEPRECATED)"}; cvar_t snd_entchannel2volume = {CVAR_SAVE, "snd_entchannel2volume", "1", "volume multiplier of the 2nd entity channel of regular entities (DEPRECATED)"}; @@ -341,7 +345,7 @@ static void S_SoundList_f (void) } -void S_SoundInfo_f(void) +static void S_SoundInfo_f(void) { if (snd_renderbuffer == NULL) { @@ -773,7 +777,7 @@ void S_Shutdown(void) sound_spatialized = false; } -void S_Restart_f(void) +static void S_Restart_f(void) { // NOTE: we can't free all sounds if we are running a map (this frees sfx_t that are still referenced by precaches) // So, refuse to do this if we are connected. @@ -856,6 +860,8 @@ void S_Init(void) Cvar_RegisterVariable(&snd_width); Cvar_RegisterVariable(&snd_channels); Cvar_RegisterVariable(&snd_mutewhenidle); + Cvar_RegisterVariable(&snd_maxchannelvolume); + Cvar_RegisterVariable(&snd_softclip); Cvar_RegisterVariable(&snd_startloopingsounds); Cvar_RegisterVariable(&snd_startnonloopingsounds); @@ -1215,7 +1221,7 @@ SND_PickChannel Picks a channel based on priorities, empty slots, number of channels ================= */ -channel_t *SND_PickChannel(int entnum, int entchannel) +static channel_t *SND_PickChannel(int entnum, int entchannel) { int ch_idx; int first_to_die; @@ -1288,13 +1294,14 @@ Spatializes a channel ================= */ extern cvar_t cl_gameplayfix_soundsmovewithentities; -void SND_Spatialize_WithSfx(channel_t *ch, qboolean isstatic, sfx_t *sfx) +static void SND_Spatialize_WithSfx(channel_t *ch, qboolean isstatic, sfx_t *sfx) { int i; double f; float angle_side, angle_front, angle_factor, mixspeed; vec_t dist, mastervol, intensity; vec3_t source_vec; + char vabuf[1024]; // update sound origin if we know about the entity if (ch->entnum > 0 && cls.state == ca_connected && cl_gameplayfix_soundsmovewithentities.integer) @@ -1401,7 +1408,7 @@ void SND_Spatialize_WithSfx(channel_t *ch, qboolean isstatic, sfx_t *sfx) case 5: mastervol *= snd_channel5volume.value; break; case 6: mastervol *= snd_channel6volume.value; break; case 7: mastervol *= snd_channel7volume.value; break; - default: mastervol *= Cvar_VariableValueOr(va("snd_channel%dvolume", CHAN_ENGINE2CVAR(ch->entchannel)), 1.0); break; + default: mastervol *= Cvar_VariableValueOr(va(vabuf, sizeof(vabuf), "snd_channel%dvolume", CHAN_ENGINE2CVAR(ch->entchannel)), 1.0); break; } } @@ -1409,8 +1416,11 @@ void SND_Spatialize_WithSfx(channel_t *ch, qboolean isstatic, sfx_t *sfx) if (!(ch->flags & CHANNELFLAG_FULLVOLUME)) mastervol *= volume.value; - // clamp HERE to allow to go at most 10dB past mastervolume (before clamping), when mastervolume < -10dB (so relative volumes don't get too messy) - mastervol = bound(0.0f, mastervol, 10.0f); + if(snd_maxchannelvolume.value > 0) + { + // clamp HERE to allow to go at most 10dB past mastervolume (before clamping), when mastervolume < -10dB (so relative volumes don't get too messy) + mastervol = bound(0.0f, mastervol, 10.0f * snd_maxchannelvolume.value); + } // always apply "master" mastervol *= mastervolume.value; @@ -1422,13 +1432,21 @@ void SND_Spatialize_WithSfx(channel_t *ch, qboolean isstatic, sfx_t *sfx) // Replaygain support // Con_DPrintf("Setting volume on ReplayGain-enabled track... %f -> ", fvol); mastervol *= sfx->volume_mult; - if(mastervol * sfx->volume_peak > 1.0f) - mastervol = 1.0f / sfx->volume_peak; + if(snd_maxchannelvolume.value > 0) + { + if(mastervol * sfx->volume_peak > snd_maxchannelvolume.value) + mastervol = snd_maxchannelvolume.value / sfx->volume_peak; + } // Con_DPrintf("%f\n", fvol); } - // clamp HERE to keep relative volumes of the channels correct - mastervol = bound(0.0f, mastervol, 1.0f); + if(snd_maxchannelvolume.value > 0) + { + // clamp HERE to keep relative volumes of the channels correct + mastervol = min(mastervol, snd_maxchannelvolume.value); + } + + mastervol = max(0.0f, mastervol); ch->mixspeed = mixspeed; @@ -1581,7 +1599,7 @@ void SND_Spatialize_WithSfx(channel_t *ch, qboolean isstatic, sfx_t *sfx) ch->volume[i] = 0; } } -void SND_Spatialize(channel_t *ch, qboolean isstatic) +static void SND_Spatialize(channel_t *ch, qboolean isstatic) { sfx_t *sfx = ch->sfx; SND_Spatialize_WithSfx(ch, isstatic, sfx); @@ -1592,7 +1610,7 @@ void SND_Spatialize(channel_t *ch, qboolean isstatic) // Start a sound effect // ======================================================================= -void S_PlaySfxOnChannel (sfx_t *sfx, channel_t *target_chan, unsigned int flags, vec3_t origin, float fvol, float attenuation, qboolean isstatic, int entnum, int entchannel, int startpos, float fspeed) +static void S_PlaySfxOnChannel (sfx_t *sfx, channel_t *target_chan, unsigned int flags, vec3_t origin, float fvol, float attenuation, qboolean isstatic, int entnum, int entchannel, int startpos, float fspeed) { if (!sfx) { @@ -1718,14 +1736,9 @@ int S_StartSound_StartPosition_Flags (int entnum, int entchannel, sfx_t *sfx, ve return (target_chan - channels); } -int S_StartSound_StartPosition (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation, float startposition) -{ - return S_StartSound_StartPosition_Flags(entnum, entchannel, sfx, origin, fvol, attenuation, startposition, CHANNELFLAG_NONE, 1.0f); -} - int S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation) { - return S_StartSound_StartPosition(entnum, entchannel, sfx, origin, fvol, attenuation, 0); + return S_StartSound_StartPosition_Flags(entnum, entchannel, sfx, origin, fvol, attenuation, 0, CHANNELFLAG_NONE, 1.0f); } void S_StopChannel (unsigned int channel_ind, qboolean lockmutex, qboolean freesfx) @@ -1790,7 +1803,6 @@ void S_StopSound(int entnum, int entchannel) } } -extern void CDAudio_Stop(void); void S_StopAllSounds (void) { unsigned int i; @@ -1912,7 +1924,7 @@ void S_StaticSound (sfx_t *sfx, vec3_t origin, float fvol, float attenuation) S_UpdateAmbientSounds =================== */ -void S_UpdateAmbientSounds (void) +static void S_UpdateAmbientSounds (void) { int i; float vol;