[sound] Add a function to set ambient sounds

This gets ambient sounds (in particular, water and sky) working again
for quakeworld after the recent sound changes, and again for nq after I
don't know how long.
This commit is contained in:
Bill Currie 2022-06-06 14:29:14 +09:00
parent c72b04a522
commit 330569a3fb
7 changed files with 32 additions and 0 deletions

View file

@ -38,6 +38,7 @@ typedef struct snd_render_funcs_s {
void (*init) (void);
void (*ambient_off) (void);
void (*ambient_on) (void);
void (*set_ambient) (int amb_channel, struct sfx_s *sfx);
void (*static_sound) (struct sfx_s *sfx, vec4f_t origin, float vol, float attenuation);
void (*start_sound) (int entnum, int entchannel, struct sfx_s *sfx, const vec4f_t, float vol, float attenuation);
void (*local_sound) (const char *s);

View file

@ -181,6 +181,8 @@ void S_AmbientOff (void);
*/
void S_AmbientOn (void);
void S_SetAmbient (int amb_channel, sfx_t *sfx);
/** Link sound engine builtins into the specified progs vm
\param pr the vm to link the builtins into.
*/

View file

@ -386,6 +386,8 @@ void SND_AmbientOff (snd_t *snd);
*/
void SND_AmbientOn (snd_t *snd);
void SND_SetAmbient (snd_t *snd, int amb_channel, sfx_t *sfx);
/** Update the sound engine with the client's position and orientation and
render some sound.
\param snd sound system state

View file

@ -419,6 +419,15 @@ SND_AmbientOn (snd_t *snd)
snd_ambient = true;
}
void
SND_SetAmbient (snd_t *snd, int amb_channel, sfx_t *sfx)
{
if (amb_channel < 0 || amb_channel > NUM_AMBIENTS) {
return;
}
ambient_sfx[amb_channel] = sfx;
}
static void
s_updateAmbientSounds (snd_t *snd, const byte *ambient_sound_level)
{

View file

@ -418,6 +418,14 @@ s_ambient_on (void)
SND_AmbientOn (&snd);
}
static void
s_set_ambient (int amb_channel, sfx_t *sfx)
{
if (!sound_started)
return;
SND_SetAmbient (&snd, amb_channel, sfx);
}
static void
s_static_sound (sfx_t *sfx, vec4f_t origin, float vol,
float attenuation)
@ -551,6 +559,7 @@ static snd_render_funcs_t plugin_info_render_funcs = {
.init = s_init,
.ambient_off = s_ambient_off,
.ambient_on = s_ambient_on,
.set_ambient = s_set_ambient,
.static_sound = s_static_sound,
.start_sound = s_start_sound,
.local_sound = s_local_sound,

View file

@ -148,6 +148,13 @@ S_AmbientOn (void)
snd_render_funcs->ambient_on ();
}
VISIBLE void
S_SetAmbient (int amb_channel, sfx_t *sfx)
{
if (snd_render_funcs)
snd_render_funcs->set_ambient (amb_channel, sfx);
}
VISIBLE void
S_StaticSound (sfx_t *sfx, vec4f_t origin, float vol, float attenuation)
{

View file

@ -129,6 +129,8 @@ CL_TEnts_Precache (void)
if (!cl_mod_beam) {
cl_mod_beam = cl_mod_bolt;
}
S_SetAmbient (AMBIENT_WATER, S_PrecacheSound ("ambience/water1.wav"));
S_SetAmbient (AMBIENT_SKY, S_PrecacheSound ("ambience/wind2.wav"));
}
static void