From 6440d7172c90d7b6eb74f5d842c247a6bd2a3745 Mon Sep 17 00:00:00 2001 From: havoc Date: Thu, 3 Jul 2003 06:59:54 +0000 Subject: [PATCH] sounds now follow their owner (so riding a lift doesn't leave the sound at the start position, for example) static sounds now automatically loop even if they have no cue list git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3148 d7cf8633-e32d-0410-b094-e92efae38249 --- snd_dma.c | 52 +++++++++++++++++++++++++++------------------------- snd_mix.c | 4 ++-- sound.h | 1 + 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/snd_dma.c b/snd_dma.c index 152a2147..aa6a755f 100644 --- a/snd_dma.c +++ b/snd_dma.c @@ -394,8 +394,8 @@ void SND_Spatialize(channel_t *ch, int isstatic) vec3_t source_vec; sfx_t *snd; -// anything coming from the view entity will always be full volume -// LordHavoc: make sounds with ATTN_NONE have no spatialization + // anything coming from the view entity will always be full volume + // LordHavoc: make sounds with ATTN_NONE have no spatialization if (ch->entnum == cl.viewentity || ch->dist_mult == 0) { ch->leftvol = ch->master_vol; @@ -403,6 +403,15 @@ void SND_Spatialize(channel_t *ch, int isstatic) } else { + // update sound origin if we know about the entity + if (ch->entnum > 0 && cls.state == ca_connected && cl_entities[ch->entnum].state_current.active) + { + //Con_Printf("-- entnum %i origin %f %f %f neworigin %f %f %f\n", ch->entnum, ch->origin[0], ch->origin[1], ch->origin[2], cl_entities[ch->entnum].state_current.origin[0], cl_entities[ch->entnum].state_current.origin[1], cl_entities[ch->entnum].state_current.origin[2]); + VectorCopy(cl_entities[ch->entnum].state_current.origin, ch->origin); + if (cl_entities[ch->entnum].state_current.modelindex && cl.model_precache[cl_entities[ch->entnum].state_current.modelindex]->type == mod_brush) + VectorMAMAM(1.0f, ch->origin, 0.5f, cl.model_precache[cl_entities[ch->entnum].state_current.modelindex]->normalmins, 0.5f, cl.model_precache[cl_entities[ch->entnum].state_current.modelindex]->normalmaxs, ch->origin); + } + // calculate stereo seperation and distance attenuation snd = ch->sfx; VectorSubtract(ch->origin, listener_origin, source_vec); @@ -422,7 +431,7 @@ void SND_Spatialize(channel_t *ch, int isstatic) lscale = 1.0 - dot; } - // add in distance effect + // add in distance effect scale = (1.0 - dist) * rscale; ch->rightvol = (int) (ch->master_vol * scale); if (ch->rightvol < 0) @@ -433,6 +442,7 @@ void SND_Spatialize(channel_t *ch, int isstatic) if (ch->leftvol < 0) ch->leftvol = 0; } + // LordHavoc: allow adjusting volume of static sounds if (isstatic) { @@ -472,6 +482,13 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f // spatialize memset (target_chan, 0, sizeof(*target_chan)); + /* + if (cls.state == ca_connected && entnum > 0 && cl_entities[entnum].state_current.active) + { + target_chan.follow = true; + VectorSubtract(origin, cl_entities[entnum].state_current.origin, target_chan.followoriginoffset); + } + */ VectorCopy(origin, target_chan->origin); target_chan->dist_mult = attenuation / sound_nominal_clip_dist; target_chan->master_vol = vol; @@ -535,17 +552,10 @@ void S_StopSound(int entnum, int entchannel) void S_StopAllSounds(qboolean clear) { - int i; - if (!sound_started) return; total_channels = MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS; // no statics - - for (i=0 ; iloopstart == -1) - { - Con_Printf ("Sound %s not looped\n", sfx->name); - return; - } + Con_DPrintf("Quake compatibility warning: Static sound \"%s\" is not looped\n", sfx->name); + ss = &channels[total_channels++]; + memset(ss, 0, sizeof(*ss)); + ss->forceloop = true; ss->sfx = sfx; VectorCopy (origin, ss->origin); ss->master_vol = vol; @@ -777,9 +784,7 @@ void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up) break; if (j == total_channels) - { combine = NULL; - } else { if (combine != ch) @@ -914,7 +919,6 @@ console functions void S_Play(void) { - static int hash=345; int i; char name[256]; sfx_t *sfx; @@ -930,14 +934,13 @@ void S_Play(void) else strcpy(name, Cmd_Argv(i)); sfx = S_PrecacheSound(name, true); - S_StartSound(hash++, 0, sfx, listener_origin, 1.0, 1.0); + S_StartSound(-1, 0, sfx, listener_origin, 1.0, 1.0); i++; } } void S_Play2(void) { - static int hash=345; int i; char name[256]; sfx_t *sfx; @@ -953,14 +956,13 @@ void S_Play2(void) else strcpy(name, Cmd_Argv(i)); sfx = S_PrecacheSound(name, true); - S_StartSound(hash++, 0, sfx, listener_origin, 1.0, 0.0); + S_StartSound(-1, 0, sfx, listener_origin, 1.0, 0.0); i++; } } void S_PlayVol(void) { - static int hash=543; int i; float vol; char name[256]; @@ -978,7 +980,7 @@ void S_PlayVol(void) strcpy(name, Cmd_Argv(i)); sfx = S_PrecacheSound(name, true); vol = atof(Cmd_Argv(i+1)); - S_StartSound(hash++, 0, sfx, listener_origin, vol, 1.0); + S_StartSound(-1, 0, sfx, listener_origin, vol, 1.0); i+=2; } } diff --git a/snd_mix.c b/snd_mix.c index 35b9dd51..3f9f01b6 100644 --- a/snd_mix.c +++ b/snd_mix.c @@ -313,9 +313,9 @@ void S_PaintChannels(int endtime) // if at end of loop, restart if (ltime >= ch->end) { - if (sc->loopstart >= 0) + if (sc->loopstart >= 0 || ch->forceloop) { - ch->pos = sc->loopstart; + ch->pos = bound(0, sc->loopstart, sc->length - 1); ch->end = ltime + sc->length - ch->pos; } else diff --git a/sound.h b/sound.h index b93f05d5..7fd841de 100644 --- a/sound.h +++ b/sound.h @@ -66,6 +66,7 @@ typedef struct typedef struct { sfx_t *sfx; // sfx number + int forceloop; // force looping even if the sound is not looped int leftvol; // 0-255 volume int rightvol; // 0-255 volume int end; // end time in global paintsamples -- 2.39.2