Use more correct doppler shift calculations
This commit is contained in:
@@ -1336,20 +1336,33 @@ static void CalcAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *prop
|
|||||||
if(DopplerFactor > 0.0f)
|
if(DopplerFactor > 0.0f)
|
||||||
{
|
{
|
||||||
const aluVector *lvelocity = &Listener->Params.Velocity;
|
const aluVector *lvelocity = &Listener->Params.Velocity;
|
||||||
ALfloat SpeedOfSound = Listener->Params.SpeedOfSound;
|
const ALfloat SpeedOfSound = Listener->Params.SpeedOfSound;
|
||||||
ALfloat VSS, VLS;
|
ALfloat vss, vls;
|
||||||
|
|
||||||
if(SpeedOfSound < 1.0f)
|
vss = aluDotproduct(&Velocity, &SourceToListener) * DopplerFactor;
|
||||||
|
vls = aluDotproduct(lvelocity, &SourceToListener) * DopplerFactor;
|
||||||
|
|
||||||
|
if(!(vls < SpeedOfSound))
|
||||||
{
|
{
|
||||||
DopplerFactor *= 1.0f/SpeedOfSound;
|
/* Listener moving away from the source at the speed of sound.
|
||||||
SpeedOfSound = 1.0f;
|
* Sound waves can't catch it.
|
||||||
|
*/
|
||||||
|
Pitch = 0.0f;
|
||||||
|
}
|
||||||
|
else if(!(vss < SpeedOfSound))
|
||||||
|
{
|
||||||
|
/* Source moving toward the listener at the speed of sound. Sound
|
||||||
|
* waves bunch up to extreme frequencies.
|
||||||
|
*/
|
||||||
|
Pitch = HUGE_VALF;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Source and listener movement is nominal. Calculate the proper
|
||||||
|
* doppler shift.
|
||||||
|
*/
|
||||||
|
Pitch *= (SpeedOfSound-vls) / (SpeedOfSound-vss);
|
||||||
}
|
}
|
||||||
|
|
||||||
VSS = aluDotproduct(&Velocity, &SourceToListener) * DopplerFactor;
|
|
||||||
VLS = aluDotproduct(lvelocity, &SourceToListener) * DopplerFactor;
|
|
||||||
|
|
||||||
Pitch *= clampf(SpeedOfSound-VLS, 1.0f, SpeedOfSound*2.0f - 1.0f) /
|
|
||||||
clampf(SpeedOfSound-VSS, 1.0f, SpeedOfSound*2.0f - 1.0f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Adjust pitch based on the buffer and output frequencies, and calculate
|
/* Adjust pitch based on the buffer and output frequencies, and calculate
|
||||||
|
|||||||
+7
-2
@@ -1,6 +1,7 @@
|
|||||||
#ifndef AL_MATH_DEFS_H
|
#ifndef AL_MATH_DEFS_H
|
||||||
#define AL_MATH_DEFS_H
|
#define AL_MATH_DEFS_H
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
#ifdef HAVE_FLOAT_H
|
#ifdef HAVE_FLOAT_H
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -13,7 +14,11 @@
|
|||||||
#define FLT_EPSILON (1.19209290e-07f)
|
#define FLT_EPSILON (1.19209290e-07f)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEG2RAD(x) ((ALfloat)(x) * (F_PI/180.0f))
|
#ifndef HUGE_VALF
|
||||||
#define RAD2DEG(x) ((ALfloat)(x) * (180.0f/F_PI))
|
#define HUGE_VALF (1.0f/0.0f)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define DEG2RAD(x) ((float)(x) * (F_PI/180.0f))
|
||||||
|
#define RAD2DEG(x) ((float)(x) * (180.0f/F_PI))
|
||||||
|
|
||||||
#endif /* AL_MATH_DEFS_H */
|
#endif /* AL_MATH_DEFS_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user