mirror of
https://github.com/fabiangreffrath/woof.git
synced 2025-08-03 12:47:01 -04:00
Smoother volume ramping for ambient sounds (#2347)
Assume the player won't typically travel faster than 23.57 mu/tic (SR50) * 2 (wallrunning factor). If ambient sounds attempt to start every 200 ms (7 tics), then the player can travel up to 330 mu during that time. To keep volume ramping seamless, use this as the keep-alive distance. That is, allow ambient sounds to start at zero volume and a little further away than usual.
This commit is contained in:
parent
15c5049e36
commit
fde1dbf4a7
@ -210,16 +210,34 @@ static void CalcDistance(const mobj_t *listener, const mobj_t *source,
|
||||
}
|
||||
}
|
||||
|
||||
static void UpdatePriority(sfxparams_t *params)
|
||||
{
|
||||
// Decrease priority with volume attenuation.
|
||||
params->priority += (127 - params->volume);
|
||||
|
||||
if (params->priority > 255)
|
||||
{
|
||||
params->priority = 255;
|
||||
}
|
||||
}
|
||||
|
||||
static boolean CalcVolumePriority(int dist, sfxparams_t *params)
|
||||
{
|
||||
if (dist == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (dist >= params->clipping_dist)
|
||||
else if (dist >= params->stop_dist)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (dist >= params->clipping_dist)
|
||||
{
|
||||
// Special case for zero-volume sounds that are allowed to stay active.
|
||||
params->volume = 0;
|
||||
UpdatePriority(params);
|
||||
return true;
|
||||
}
|
||||
else if (dist > params->close_dist)
|
||||
{
|
||||
// OpenAL inverse distance model never reaches zero volume. Gradually
|
||||
@ -228,14 +246,7 @@ static boolean CalcVolumePriority(int dist, sfxparams_t *params)
|
||||
/ (params->clipping_dist - params->close_dist);
|
||||
}
|
||||
|
||||
// Decrease priority with volume attenuation.
|
||||
params->priority += (127 - params->volume);
|
||||
|
||||
if (params->priority > 255)
|
||||
{
|
||||
params->priority = 255;
|
||||
}
|
||||
|
||||
UpdatePriority(params);
|
||||
return (params->volume > 0);
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,17 @@
|
||||
|
||||
static boolean force_flip_pan;
|
||||
|
||||
static void UpdatePriority(sfxparams_t *params)
|
||||
{
|
||||
// haleyjd 09/27/06: decrease priority with volume attenuation
|
||||
params->priority += (127 - params->volume);
|
||||
|
||||
if (params->priority > 255) // cap to 255
|
||||
{
|
||||
params->priority = 255;
|
||||
}
|
||||
}
|
||||
|
||||
static boolean I_MBF_AdjustSoundParams(const mobj_t *listener,
|
||||
const mobj_t *source,
|
||||
sfxparams_t *params)
|
||||
@ -96,11 +107,17 @@ static boolean I_MBF_AdjustSoundParams(const mobj_t *listener,
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (dist >= params->clipping_dist)
|
||||
else if (dist >= params->stop_dist)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (dist >= params->clipping_dist)
|
||||
{
|
||||
// Special case for zero-volume sounds that are allowed to stay active.
|
||||
params->volume = 0;
|
||||
UpdatePriority(params);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (source->x != players[displayplayer].mo->x
|
||||
|| source->y != players[displayplayer].mo->y)
|
||||
@ -126,14 +143,7 @@ static boolean I_MBF_AdjustSoundParams(const mobj_t *listener,
|
||||
/ (params->clipping_dist - params->close_dist);
|
||||
}
|
||||
|
||||
// haleyjd 09/27/06: decrease priority with volume attenuation
|
||||
params->priority += (127 - params->volume);
|
||||
|
||||
if (params->priority > 255) // cap to 255
|
||||
{
|
||||
params->priority = 255;
|
||||
}
|
||||
|
||||
UpdatePriority(params);
|
||||
return (params->volume > 0);
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "z_zone.h"
|
||||
|
||||
#define AMB_UPDATE_TICS 7 // 200 ms
|
||||
#define AMB_KEEP_ALIVE_DIST 330 // 23.57 mu/tic (SR50) * 2 (wallrun) * 7 tics
|
||||
|
||||
int zmt_ambientsound = ZMT_UNDEFINED;
|
||||
|
||||
@ -52,6 +53,7 @@ void P_GetAmbientSoundParams(ambient_t *ambient, sfxparams_t *params)
|
||||
{
|
||||
params->close_dist = ambient->data.close_dist;
|
||||
params->clipping_dist = ambient->data.clipping_dist;
|
||||
params->stop_dist = params->clipping_dist + AMB_KEEP_ALIVE_DIST;
|
||||
params->volume_scale = ambient->data.volume_scale;
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,7 @@ typedef struct channel_s
|
||||
ambient_t *ambient; // Ambient sound source using this channel.
|
||||
int close_dist; // Sounds at or under this distance are full volume.
|
||||
int clipping_dist; // Sounds at or over this distance are zero volume.
|
||||
int stop_dist; // Sounds at or over this distance are stopped.
|
||||
int volume_scale; // volume scale value for effect -- haleyjd 05/29/06
|
||||
int handle; // handle of the sound being played
|
||||
int o_priority; // haleyjd 09/27/06: stored priority value
|
||||
@ -471,6 +472,7 @@ static boolean StartSoundEx(const mobj_t *origin, int sfx_id,
|
||||
{
|
||||
params.close_dist = S_CLOSE_DIST;
|
||||
params.clipping_dist = S_CLIPPING_DIST;
|
||||
params.stop_dist = params.clipping_dist;
|
||||
params.volume_scale = 127;
|
||||
}
|
||||
|
||||
@ -523,6 +525,7 @@ static boolean StartSoundEx(const mobj_t *origin, int sfx_id,
|
||||
channels[cnum].ambient = ambient;
|
||||
channels[cnum].close_dist = params.close_dist;
|
||||
channels[cnum].clipping_dist = params.clipping_dist;
|
||||
channels[cnum].stop_dist = params.stop_dist;
|
||||
channels[cnum].volume_scale = params.volume_scale;
|
||||
channels[cnum].o_priority = o_priority; // original priority
|
||||
channels[cnum].priority = params.priority; // scaled priority
|
||||
@ -869,6 +872,7 @@ void S_UpdateSounds(const mobj_t *listener)
|
||||
sfxparams_t params;
|
||||
params.close_dist = c->close_dist;
|
||||
params.clipping_dist = c->clipping_dist;
|
||||
params.stop_dist = c->stop_dist;
|
||||
params.volume_scale = c->volume_scale;
|
||||
params.priority = c->o_priority; // haleyjd 09/27/06: priority
|
||||
|
||||
|
@ -27,6 +27,7 @@ typedef struct sfxparams_s
|
||||
{
|
||||
int close_dist;
|
||||
int clipping_dist;
|
||||
int stop_dist;
|
||||
int volume_scale;
|
||||
int volume;
|
||||
int separation;
|
||||
|
Loading…
x
Reference in New Issue
Block a user