diff options
author | Chris Robinson <[email protected]> | 2017-05-20 03:28:40 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2017-05-20 03:28:40 -0700 |
commit | c234b25ac7ace092867cc3348e7ea2b2754a7284 (patch) | |
tree | 7a1be43b6c8f3423ef56027f8bbe1f73e4f84641 /Alc | |
parent | 492050b8168b04ef6df0030739969685a62d6929 (diff) |
Use more correct doppler shift calculations
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/ALu.c | 35 |
1 files changed, 24 insertions, 11 deletions
@@ -1336,20 +1336,33 @@ static void CalcAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *prop if(DopplerFactor > 0.0f) { const aluVector *lvelocity = &Listener->Params.Velocity; - ALfloat SpeedOfSound = Listener->Params.SpeedOfSound; - ALfloat VSS, VLS; + const ALfloat SpeedOfSound = Listener->Params.SpeedOfSound; + ALfloat vss, vls; - if(SpeedOfSound < 1.0f) + vss = aluDotproduct(&Velocity, &SourceToListener) * DopplerFactor; + vls = aluDotproduct(lvelocity, &SourceToListener) * DopplerFactor; + + if(!(vls < SpeedOfSound)) { - DopplerFactor *= 1.0f/SpeedOfSound; - SpeedOfSound = 1.0f; + /* Listener moving away from the source at the speed of sound. + * 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 |