From aded1fa5c042be040a4d4d16bfeb61606b50b0f4 Mon Sep 17 00:00:00 2001 From: avolkov Date: Wed, 13 Apr 2005 04:48:12 +0000 Subject: [PATCH] Changes --stereosfx model closer to surround sound (fixes #472) git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1631 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/sc2code/libs/sound/sfx.c | 16 +++++++++++++++- sc2/src/sc2code/sounds.c | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/sc2/src/sc2code/libs/sound/sfx.c b/sc2/src/sc2code/libs/sound/sfx.c index 0f8ce73fd..a09ed67f8 100644 --- a/sc2/src/sc2code/libs/sound/sfx.c +++ b/sc2/src/sc2code/libs/sound/sfx.c @@ -17,6 +17,7 @@ #include "options.h" #include "sound.h" #include "libs/reslib.h" +#include #ifdef WIN32 #include @@ -105,20 +106,33 @@ void UpdateSoundPosition (COUNT channel, SoundPosition pos) { const float ATTENUATION = 160.0f; + const float MIN_DISTANCE = 0.5f; float fpos[3]; if (pos.positional) { + float dist; + fpos[0] = pos.x / ATTENUATION; fpos[1] = 0.0f; fpos[2] = pos.y / ATTENUATION; + dist = (float) sqrt (fpos[0] * fpos[0] + fpos[2] * fpos[2]); + if (dist < MIN_DISTANCE) + { // object is too close to listener + // move it away along the same vector + float scale = MIN_DISTANCE / dist; + fpos[0] *= scale; + fpos[2] *= scale; + } + audio_Sourcefv (soundSource[channel].handle, audio_POSITION, fpos); //fprintf (stderr, "UpdateSoundPosition(): channel %d, pos %d %d, posobj %x\n", // channel, pos.x, pos.y, (unsigned int)soundSource[channel].positional_object); } else { - fpos[0] = fpos[1] = fpos[2] = 0.0f; + fpos[0] = fpos[1] = 0.0f; + fpos[2] = -1.0f; audio_Sourcefv (soundSource[channel].handle, audio_POSITION, fpos); } } diff --git a/sc2/src/sc2code/sounds.c b/sc2/src/sc2code/sounds.c index 09cfe857c..ca07c3cc5 100644 --- a/sc2/src/sc2code/sounds.c +++ b/sc2/src/sc2code/sounds.c @@ -117,7 +117,7 @@ CalcSoundPosition (ELEMENTPTR ElementPtr) } pos.x -= (SPACE_WIDTH >> 1); - pos.y -= (SPACE_HEIGHT); + pos.y -= (SPACE_HEIGHT >> 1); pos.positional = TRUE; }