Skip to content

Commit

Permalink
Bring over a few extra sound tweaks from Q3e
Browse files Browse the repository at this point in the history
  • Loading branch information
ensiform committed Jan 24, 2019
1 parent b497fb1 commit abda805
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/client/snd_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ static byte buffer2[ 0x10000 ]; // for muted painting

// only begin attenuating sound volumes when outside the FULLVOLUME range
#define SOUND_FULLVOLUME 80

#define SOUND_ATTENUATE 0.0008f
#define SOUND_RANGE_DEFAULT 1250

channel_t s_channels[MAX_CHANNELS];
Expand Down Expand Up @@ -688,6 +686,7 @@ static void S_Base_MainStartSoundEx( vec3_t origin, int entityNum, int entchanne
channel_t *ch;
sfx_t *sfx;
int i, time;
int inplay, allowed;
qboolean fullVolume;

if ( !s_soundStarted || s_soundMuted ) {
Expand Down Expand Up @@ -715,15 +714,44 @@ static void S_Base_MainStartSoundEx( vec3_t origin, int entityNum, int entchanne

time = Com_Milliseconds();

// borrowed from cnq3
// a UNIQUE entity starting the same sound twice in a frame is either a bug,
// a timedemo, or a shitmap (eg q3ctf4) giving multiple items on spawn.
// even if you can create a case where it IS "valid", it's still pointless
// because you implicitly can't DISTINGUISH between the sounds:
// all that happens is the sound plays at double volume, which is just annoying

if ( entityNum != ENTITYNUM_WORLD ) {
ch = s_channels;
for ( i = 0; i < MAX_CHANNELS; i++, ch++ ) {
if ( ch->entnum != entityNum )
continue;
if ( ch->allocTime != time )
continue;
if ( ch->thesfx != sfx )
continue;
sfx->lastTimeUsed = time;
//Com_Printf( S_COLOR_YELLOW "double sound start: %d %s\n", entityNum, sfx->soundName);
return;
}
}

// Com_Printf("playing %s\n", sfx->soundName);
// pick a channel to play on

// try to limit sound duplication
if ( entityNum == listener_number )
allowed = 16;
else
allowed = 8;

fullVolume = qfalse;
if (localSound || S_Base_HearingThroughEntity(entityNum, origin)) {
fullVolume = qtrue;
}

ch = s_channels;
inplay = 0;

for (i = 0; i < MAX_CHANNELS ; i++, ch++)
{
Expand All @@ -737,9 +765,18 @@ static void S_Base_MainStartSoundEx( vec3_t origin, int entityNum, int entchanne
{
S_ChannelFree(ch);
}
else
{
inplay++;
}
}
}

// too much duplicated sounds, ignore
if ( inplay > allowed ) {
return;
}

sfx->lastTimeUsed = time;

ch = S_ChannelMalloc();
Expand Down Expand Up @@ -1060,6 +1097,7 @@ void S_Base_AddLoopingSound( const vec3_t origin, const vec3_t velocity, const i
vec3_t out;
float lena, lenb;

// don't do the doppler effect when trumpets of train and station are at the same position
if (!VectorCompare(entityPositions[listener_number], entityPositions[numLoopSounds])) {
loopSounds[numLoopSounds].doppler = qtrue;
} else {
Expand Down

0 comments on commit abda805

Please sign in to comment.