From 7fea1f33eef63ab63343ddfa9f8da1da0dafcf0a Mon Sep 17 00:00:00 2001 From: Eukara Date: Thu, 5 May 2022 23:28:33 +0000 Subject: [PATCH] OpenAL: Crush that annoying bug where volume changes creates clicks in the sound. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@6236 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/snd_al.c | 2 +- engine/client/snd_dma.c | 4 ++++ engine/client/sound.h | 7 ++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/engine/client/snd_al.c b/engine/client/snd_al.c index 6b72e231a..bdace0239 100644 --- a/engine/client/snd_al.c +++ b/engine/client/snd_al.c @@ -1074,7 +1074,7 @@ static void OpenAL_ChannelUpdate(soundcardinfo_t *sc, channel_t *chan, chanupdat if (schanged) { - if (schanged == CUR_UPDATE && chan->pos) + if (schanged & CUR_OFFSET && chan->pos) { //complex update, but not restart. pos contains an offset, rather than an absolute time. palSourcei(src, AL_SAMPLE_OFFSET, (chan->pos>>PITCHSHIFT)); } diff --git a/engine/client/snd_dma.c b/engine/client/snd_dma.c index 2cdeb9a6a..812552859 100644 --- a/engine/client/snd_dma.c +++ b/engine/client/snd_dma.c @@ -2900,6 +2900,9 @@ static void S_UpdateSoundCard(soundcardinfo_t *sc, qboolean updateonly, channel_ return; } + if (timeoffset != 0.0) + chanupdatetype |= CUR_OFFSET; + if (!ratemul) //rate of 0 ratemul = 1; ratemul *= snd_playbackrate.value; @@ -2913,6 +2916,7 @@ static void S_UpdateSoundCard(soundcardinfo_t *sc, qboolean updateonly, channel_ // spatialize if (target_chan->sfx != sfx) chanupdatetype |= CUR_SOUNDCHANGE; + memset (target_chan, 0, sizeof(*target_chan)); if (!origin) { diff --git a/engine/client/sound.h b/engine/client/sound.h index 1f75f1ecd..ff6d07a0d 100644 --- a/engine/client/sound.h +++ b/engine/client/sound.h @@ -346,10 +346,11 @@ extern sounddriver pAHI_InitCard; typedef enum { - CUR_SPACIALISEONLY = 0, //for ticking over, respacialising, etc - CUR_UPDATE = (1u<<1), //flags/rate/offset changed without changing the sound itself + CUR_SPACIALISEONLY = 0, //for ticking over, respacialising, etc + CUR_UPDATE = (1u<<1), //flags/rate changed without changing the sound itself CUR_SOUNDCHANGE = (1u<<2), //the audio file changed too. reset everything. - CUR_EVERYTHING = CUR_UPDATE|CUR_SOUNDCHANGE + CUR_OFFSET = (1u<<3), + CUR_EVERYTHING = CUR_UPDATE|CUR_SOUNDCHANGE|CUR_OFFSET } chanupdatereason_t; struct soundcardinfo_s { //windows has one defined AFTER directsound