From e221c6b5ca8f00e5f6a5fff4b50874daae82f99b Mon Sep 17 00:00:00 2001 From: Spoike Date: Mon, 5 Mar 2018 11:34:20 +0000 Subject: [PATCH] make snd_inactive work for drivers other than just the directsound one. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5220 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/snd_dma.c | 11 ++++++++--- engine/client/snd_mix.c | 4 +++- engine/client/snd_ov.c | 15 +++++++++++++-- engine/client/sound.h | 1 + 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/engine/client/snd_dma.c b/engine/client/snd_dma.c index 6662172b3..b78dc4186 100644 --- a/engine/client/snd_dma.c +++ b/engine/client/snd_dma.c @@ -2689,6 +2689,9 @@ static void SND_Spatialize(soundcardinfo_t *sc, channel_t *ch) else volscale = volume.value * voicevolumemod; + if (!vid.activeapp && !snd_inactive.ival && !(ch->flags & CF_INACTIVE)) + volscale = 0; + if (sc->seat == -1) { seat = 0; @@ -3282,8 +3285,10 @@ void S_UpdateAmbientSounds (soundcardinfo_t *sc) } if (chan->sfx) { - chan->flags = CF_ABSVOLUME|CF_NOSPACIALISE|CF_NOREVERB; //bypasses volume cvar completely. + chan->flags = /*CF_INACTIVE|*/CF_ABSVOLUME|CF_NOSPACIALISE|CF_NOREVERB; //bypasses volume cvar completely. vol = 255*bgmvolume.value*voicevolumemod; + if (!vid.activeapp && !snd_inactive.ival && !(chan->flags & CF_INACTIVE)) + vol = 0; vol = bound(0, vol, 255); vol = Media_CrossFade(i-MUSIC_FIRST, vol, (chan->pos>>PITCHSHIFT) / (float)snd_speed); if (vol < 0) @@ -3953,7 +3958,7 @@ void S_LocalSound2 (const char *sound, int channel, float volume) Con_Printf ("S_LocalSound: can't cache %s\n", sound); return; } - S_StartSound (0, channel, sfx, NULL, NULL, volume, 0, 0, 0, CF_NOSPACIALISE|CF_NOREVERB); + S_StartSound (0, channel, sfx, NULL, NULL, volume, 0, 0, 0, CF_INACTIVE|CF_NOSPACIALISE|CF_NOREVERB); } void S_LocalSound (const char *sound) { @@ -4164,7 +4169,7 @@ void S_RawAudio(int sourceid, qbyte *data, int speed, int samples, int channels, channel_t *c = SND_PickChannel(si, -1, 0); if (c) { - c->flags = CF_ABSVOLUME|CF_NOSPACIALISE; + c->flags = (sourceid>=0?CF_INACTIVE:0)|CF_ABSVOLUME|CF_NOSPACIALISE; c->entnum = 0; c->entchannel = 0; c->dist_mult = 0; diff --git a/engine/client/snd_mix.c b/engine/client/snd_mix.c index 2e57c36d1..dcfdfa50b 100644 --- a/engine/client/snd_mix.c +++ b/engine/client/snd_mix.c @@ -192,7 +192,9 @@ void S_PaintChannels(soundcardinfo_t *sc, int endtime) //does it still make a sound if it cannot be heard?... //technically no... //this code is hacky. - if (s->decoder.decodedata) + if (s->decoder.querydata) + s->decoder.querydata(s, scache=&scachebuf, NULL, 0); + else if (s->decoder.decodedata) scache = s->decoder.decodedata(s, &scachebuf, ch->pos>>PITCHSHIFT, 0); /*1 for luck - balances audio termination below*/ else scache = s->decoder.buf; diff --git a/engine/client/snd_ov.c b/engine/client/snd_ov.c index 85b99e3ec..47c4e6e6d 100644 --- a/engine/client/snd_ov.c +++ b/engine/client/snd_ov.c @@ -72,6 +72,8 @@ typedef struct { int decodedbytestart; int decodedbytecount; + quintptr_t pcmtotal; + float timetotal; OggVorbis_File vf; sfx_t *s; @@ -127,11 +129,18 @@ float QDECL OV_Query(struct sfx_s *sfx, struct sfxcache_s *buf, char *name, size ovdecoderbuffer_t *dec = sfx->decoder.buf; if (!dec) return -1; + + if (dec->timetotal < 0) + { + dec->pcmtotal = p_ov_pcm_total(&dec->vf, -1); + dec->timetotal = p_ov_time_total(&dec->vf, -1); + } + if (buf) { buf->data = NULL; //you're not meant to actually be using the data here buf->soundoffset = 0; - buf->length = p_ov_pcm_total(&dec->vf, -1); + buf->length = dec->pcmtotal; buf->numchannels = dec->srcchannels; buf->speed = dec->srcspeed; buf->width = 2; @@ -155,7 +164,7 @@ float QDECL OV_Query(struct sfx_s *sfx, struct sfxcache_s *buf, char *name, size else if (title) Q_snprintfz(name, namesize, "%s", title); } - return p_ov_time_total(&dec->vf, -1); + return dec->timetotal; } static sfxcache_t *QDECL OV_DecodeSome(struct sfx_s *sfx, struct sfxcache_s *buf, ssamplepos_t start, int length) @@ -502,6 +511,8 @@ static qboolean OV_StartDecode(unsigned char *start, unsigned long length, ovdec buffer->start = BZ_Malloc(length); memcpy(buffer->start, start, length); + buffer->timetotal = -1; + return true; } #endif diff --git a/engine/client/sound.h b/engine/client/sound.h index 0621dfc4e..b06cfa265 100644 --- a/engine/client/sound.h +++ b/engine/client/sound.h @@ -121,6 +121,7 @@ typedef struct //client-internal #define CF_AUTOSOUND 1024 // generated from q2 entities, which avoids breaking regular sounds, using it outside the sound system will probably break things. +#define CF_INACTIVE 2048 // try to play even when inactive //server only #define CF_RELIABLE 1 // serverside only. yeah, evil. screw you.