-
Notifications
You must be signed in to change notification settings - Fork 171
Description
In https://webaudio.github.io/web-audio-api/#Spatialization-distance-effects we have this bit of code:
function dotProduct(v1, v2) {
var d = 0;
for (var i = 0; i < Math.min(v1.length, v2.length); i++)
d += v1[i] * v2[i];
return d;
}
var v = panner.position - listener.position;
var distance = Math.sqrt(dotProduct(v, v));
So we describe and give an algorithm for the dotProduct
. But then we also write
panner.position - listener.position
First, panner.position
and listener.position
doesn't really exist anywhere. The intent is pretty clear that these represent a 3D vector of the positions. But panner.position - listener.position
isn't really valid JS either.
And curiously, https://webaudio.github.io/web-audio-api/#Spatialization-sound-cones has yet another (identical) definition for dotProduct
and also introduces a diff
function for the difference of two vectors.
We need to decide exactly what level of detail we need and decide if the code is pseudo-code or valid JS. And remove the duplicated functions.