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
This commit is contained in:
avolkov
2005-04-13 04:48:12 +00:00
parent 828f74e4dd
commit aded1fa5c0
2 changed files with 16 additions and 2 deletions
+15 -1
View File
@@ -17,6 +17,7 @@
#include "options.h" #include "options.h"
#include "sound.h" #include "sound.h"
#include "libs/reslib.h" #include "libs/reslib.h"
#include <math.h>
#ifdef WIN32 #ifdef WIN32
#include <io.h> #include <io.h>
@@ -105,20 +106,33 @@ void
UpdateSoundPosition (COUNT channel, SoundPosition pos) UpdateSoundPosition (COUNT channel, SoundPosition pos)
{ {
const float ATTENUATION = 160.0f; const float ATTENUATION = 160.0f;
const float MIN_DISTANCE = 0.5f;
float fpos[3]; float fpos[3];
if (pos.positional) if (pos.positional)
{ {
float dist;
fpos[0] = pos.x / ATTENUATION; fpos[0] = pos.x / ATTENUATION;
fpos[1] = 0.0f; fpos[1] = 0.0f;
fpos[2] = pos.y / ATTENUATION; 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); audio_Sourcefv (soundSource[channel].handle, audio_POSITION, fpos);
//fprintf (stderr, "UpdateSoundPosition(): channel %d, pos %d %d, posobj %x\n", //fprintf (stderr, "UpdateSoundPosition(): channel %d, pos %d %d, posobj %x\n",
// channel, pos.x, pos.y, (unsigned int)soundSource[channel].positional_object); // channel, pos.x, pos.y, (unsigned int)soundSource[channel].positional_object);
} }
else 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); audio_Sourcefv (soundSource[channel].handle, audio_POSITION, fpos);
} }
} }
+1 -1
View File
@@ -117,7 +117,7 @@ CalcSoundPosition (ELEMENTPTR ElementPtr)
} }
pos.x -= (SPACE_WIDTH >> 1); pos.x -= (SPACE_WIDTH >> 1);
pos.y -= (SPACE_HEIGHT); pos.y -= (SPACE_HEIGHT >> 1);
pos.positional = TRUE; pos.positional = TRUE;
} }