b=907986 handle zero front-right plane projection without NaNs r=padenot

The azimuth calculation in the Web Audio spec becomes undefined in this
situation as it requires normalizing a zero vector.  The panning effect should
not depend on azimuth when the source is directly above the listener (because
position does not depend on azimuth), but the specified "equalpower" panning
model does depend on azimuth even at this elevation.  Setting azimuth to zero
produces the same result as if the normalized projection were replaced with a
zero vector.

--HG--
extra : transplant_source : f%A4h%CB7%7Bp%87%AE%09%9F%2Cu%D7%CD%9D%5E%A8%EC%0D
This commit is contained in:
Karl Tomlinson 2013-09-04 21:20:59 +12:00
parent 33b9dff05b
commit 74e3f50648

View File

@ -396,8 +396,20 @@ PannerNodeEngine::ComputeAzimuthAndElevation(float& aAzimuth, float& aElevation)
ThreeDPoint up = listenerRight.CrossProduct(listenerFront);
double upProjection = sourceListener.DotProduct(up);
aElevation = 90 - 180 * acos(upProjection) / M_PI;
if (aElevation > 90) {
aElevation = 180 - aElevation;
} else if (aElevation < -90) {
aElevation = -180 - aElevation;
}
ThreeDPoint projectedSource = sourceListener - up * upProjection;
if (projectedSource.IsZero()) {
// source - listener direction is up or down.
aAzimuth = 0.0;
return;
}
projectedSource.Normalize();
// Actually compute the angle, and convert to degrees
@ -416,14 +428,6 @@ PannerNodeEngine::ComputeAzimuthAndElevation(float& aAzimuth, float& aElevation)
} else {
aAzimuth = 450 - aAzimuth;
}
aElevation = 90 - 180 * acos(upProjection) / M_PI;
if (aElevation > 90) {
aElevation = 180 - aElevation;
} else if (aElevation < -90) {
aElevation = -180 - aElevation;
}
}
// This algorithm is described in the WebAudio spec.