Skip to content

Commit

Permalink
[MP] Implement s_doppler from ent's jamme/q3. Doesn't work on the AL …
Browse files Browse the repository at this point in the history
…backend and really only noticed on rocket flying.
  • Loading branch information
ensiform committed Oct 22, 2013
1 parent 82f3a53 commit 69800e8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
38 changes: 36 additions & 2 deletions codemp/client/snd_dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,20 @@ cvar_t *s_language; // note that this is distinct from "g_language"
cvar_t *s_dynamix;
cvar_t *s_debugdynamic;

cvar_t *s_doppler;

typedef struct
{
unsigned char volume;
vec3_t origin;
vec3_t velocity;
/* const*/ sfx_t *sfx;
sfx_t *sfx;
int mergeFrame;
int entnum;

qboolean doppler;
float dopplerScale;

// For Open AL
bool bProcessed;
bool bRelative;
Expand Down Expand Up @@ -446,6 +451,8 @@ void S_Init( void ) {

s_language = Cvar_Get("s_language","english",CVAR_ARCHIVE | CVAR_NORESTART);

s_doppler = Cvar_Get("s_doppler", "1", CVAR_ARCHIVE);

MP3_InitCvars();

cv = Cvar_Get ("s_initsound", "1", CVAR_ROM);
Expand Down Expand Up @@ -1923,6 +1930,8 @@ void S_StopLoopingSound( int entityNum )
}
}

#define MAX_DOPPLER_SCALE 50.0f //arbitrary

/*
==================
S_AddLoopingSound
Expand All @@ -1946,7 +1955,7 @@ void S_AddLoopingSound( int entityNum, const vec3_t origin, const vec3_t velocit
}

sfx = &s_knownSfx[ sfxHandle ];
if (sfx->bInMemory == qfalse){
if (sfx->bInMemory == qfalse) {
S_memoryLoad(sfx);
}
SND_TouchSFX(sfx);
Expand All @@ -1957,9 +1966,29 @@ void S_AddLoopingSound( int entityNum, const vec3_t origin, const vec3_t velocit
assert(!sfx->pMP3StreamHeader);
VectorCopy( origin, loopSounds[numLoopSounds].origin );
VectorCopy( velocity, loopSounds[numLoopSounds].velocity );
loopSounds[numLoopSounds].doppler = qfalse;
loopSounds[numLoopSounds].dopplerScale = 1.0;
loopSounds[numLoopSounds].sfx = sfx;
loopSounds[numLoopSounds].volume = SOUND_MAXVOL;
loopSounds[numLoopSounds].entnum = entityNum;

if ( s_doppler->integer && VectorLengthSquared(velocity) > 0.0 ) {
vec3_t out;
float lena, lenb;

loopSounds[numLoopSounds].doppler = qtrue;
lena = DistanceSquared(listener_origin, loopSounds[numLoopSounds].origin);
VectorAdd(loopSounds[numLoopSounds].origin, loopSounds[numLoopSounds].velocity, out);
lenb = DistanceSquared(listener_origin, out);

loopSounds[numLoopSounds].dopplerScale = lenb/(lena*100);
if (loopSounds[numLoopSounds].dopplerScale > MAX_DOPPLER_SCALE) {
loopSounds[numLoopSounds].dopplerScale = MAX_DOPPLER_SCALE;
} else if (loopSounds[numLoopSounds].dopplerScale <= 1.0) {
loopSounds[numLoopSounds].doppler = qfalse; // don't bother doing the math
}
}

numLoopSounds++;
}

Expand Down Expand Up @@ -2002,6 +2031,8 @@ void S_AddAmbientLoopingSound( const vec3_t origin, unsigned char volume, sfxHan
Com_Error( ERR_DROP, "%s has length 0", sfx->sSoundName );
}
VectorCopy( origin, loopSounds[numLoopSounds].origin );
loopSounds[numLoopSounds].doppler = qfalse;
loopSounds[numLoopSounds].dopplerScale = 1.0;
loopSounds[numLoopSounds].sfx = sfx;
assert(!sfx->pMP3StreamHeader);

Expand Down Expand Up @@ -2069,6 +2100,9 @@ void S_AddLoopSounds (void)
ch->loopSound = qtrue; // remove next frame
ch->thesfx = loop->sfx;

ch->doppler = loop->doppler;
ch->dopplerScale = loop->dopplerScale;

// you cannot use MP3 files here because they offer only streaming access, not random
//
if (loop->sfx->pMP3StreamHeader)
Expand Down
4 changes: 4 additions & 0 deletions codemp/client/snd_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ typedef struct channel_s {
int iMP3SlidingDecodeWritePos;
int iMP3SlidingDecodeWindowPos;

qboolean doppler;
float dopplerScale;

// Open AL specific
bool bLooping; // Signifies if this channel / source is playing a looping sound
Expand Down Expand Up @@ -198,6 +200,8 @@ extern cvar_t *s_mixahead;
extern cvar_t *s_testsound;
extern cvar_t *s_separation;

extern cvar_t *s_doppler;

wavinfo_t GetWavinfo (const char *name, byte *wav, int wavlength);

sboolean S_LoadSound( sfx_t *sfx );
Expand Down
9 changes: 7 additions & 2 deletions codemp/client/snd_mix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ static void S_PaintChannelFrom16( channel_t *ch, const sfx_t *sfx, int count, in
{
portable_samplepair_t *pSamplesDest;
int iData;

float ofst = sampleOffset;

int iLeftVol = ch->leftvol * snd_vol;
int iRightVol = ch->rightvol * snd_vol;
Expand All @@ -259,10 +259,15 @@ static void S_PaintChannelFrom16( channel_t *ch, const sfx_t *sfx, int count, in

for ( int i=0 ; i<count ; i++ )
{
iData = sfx->pSoundData[ sampleOffset++ ];
iData = sfx->pSoundData[ (int)ofst ];

pSamplesDest[i].left += (iData * iLeftVol )>>8;
pSamplesDest[i].right += (iData * iRightVol)>>8;
if (ch->doppler && ch->dopplerScale > 1) {
ofst += 1 * ch->dopplerScale;
} else {
ofst++;
}
}
}

Expand Down

0 comments on commit 69800e8

Please sign in to comment.