Skip to content

Commit

Permalink
Fix another deprecation warning in Chrome
Browse files Browse the repository at this point in the history
Fixes #923
  • Loading branch information
goldfire committed Mar 30, 2018
1 parent c43ffde commit 041b4b5
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions src/plugins/howler.spatial.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// Setup default properties.
HowlerGlobal.prototype._pos = [0, 0, 0];
HowlerGlobal.prototype._orientation = [0, 0, -1, 0, 1, 0];

/** Global Methods **/
/***************************************************************************/

Expand Down Expand Up @@ -65,7 +65,14 @@

if (typeof x === 'number') {
self._pos = [x, y, z];
self.ctx.listener.setPosition(self._pos[0], self._pos[1], self._pos[2]);

if (typeof self.ctx.listener.positionX !== 'undefined') {
self.ctx.listener.positionX.setTargetAtTime(self._pos[0], Howler.ctx.currentTime, 0.1);
self.ctx.listener.positionY.setTargetAtTime(self._pos[1], Howler.ctx.currentTime, 0.1);
self.ctx.listener.positionZ.setTargetAtTime(self._pos[2], Howler.ctx.currentTime, 0.1);
} else {
self.ctx.listener.setPosition(self._pos[0], self._pos[1], self._pos[2]);
}
} else {
return self._pos;
}
Expand Down Expand Up @@ -105,7 +112,17 @@

if (typeof x === 'number') {
self._orientation = [x, y, z, xUp, yUp, zUp];
self.ctx.listener.setOrientation(x, y, z, xUp, yUp, zUp);

if (typeof self.ctx.listener.forwardX !== 'undefined') {
self.ctx.listener.forwardX.setTargetAtTime(x, Howler.ctx.currentTime, 0.1);
self.ctx.listener.forwardY.setTargetAtTime(y, Howler.ctx.currentTime, 0.1);
self.ctx.listener.forwardZ.setTargetAtTime(z, Howler.ctx.currentTime, 0.1);
self.ctx.listener.upX.setTargetAtTime(x, Howler.ctx.currentTime, 0.1);
self.ctx.listener.upY.setTargetAtTime(y, Howler.ctx.currentTime, 0.1);
self.ctx.listener.upZ.setTargetAtTime(z, Howler.ctx.currentTime, 0.1);
} else {
self.ctx.listener.setOrientation(x, y, z, xUp, yUp, zUp);
}
} else {
return or;
}
Expand Down Expand Up @@ -211,7 +228,9 @@
}

if (pannerType === 'spatial') {
sound._panner.setPosition(pan, 0, 0);
sound._panner.positionX.setValueAtTime(pan, Howler.ctx.currentTime);
sound._panner.positionY.setValueAtTime(0, Howler.ctx.currentTime);
sound._panner.positionZ.setValueAtTime(0, Howler.ctx.currentTime);
} else {
sound._panner.pan.setValueAtTime(pan, Howler.ctx.currentTime);
}
Expand Down Expand Up @@ -285,7 +304,9 @@
setupPanner(sound, 'spatial');
}

sound._panner.setPosition(x, y, z);
sound._panner.positionX.setValueAtTime(x, Howler.ctx.currentTime);
sound._panner.positionY.setValueAtTime(y, Howler.ctx.currentTime);
sound._panner.positionZ.setValueAtTime(z, Howler.ctx.currentTime);
}

self._emit('pos', sound._id);
Expand Down Expand Up @@ -363,7 +384,9 @@
setupPanner(sound, 'spatial');
}

sound._panner.setOrientation(x, y, z);
sound._panner.orientationX.setValueAtTime(x, Howler.ctx.currentTime);
sound._panner.orientationY.setValueAtTime(y, Howler.ctx.currentTime);
sound._panner.orientationZ.setValueAtTime(z, Howler.ctx.currentTime);
}

self._emit('orientation', sound._id);
Expand Down Expand Up @@ -403,7 +426,7 @@
* with `inverse` and `exponential`.
* panningModel - ('HRTF' by default) Determines which spatialization algorithm is used to position audio.
* Can be `HRTF` or `equalpower`.
*
*
* @return {Howl/Object} Returns self or current panner attributes.
*/
Howl.prototype.pannerAttr = function() {
Expand Down Expand Up @@ -578,8 +601,12 @@
sound._panner.refDistance = sound._pannerAttr.refDistance;
sound._panner.rolloffFactor = sound._pannerAttr.rolloffFactor;
sound._panner.panningModel = sound._pannerAttr.panningModel;
sound._panner.setPosition(sound._pos[0], sound._pos[1], sound._pos[2]);
sound._panner.setOrientation(sound._orientation[0], sound._orientation[1], sound._orientation[2]);
sound._panner.positionX.setValueAtTime(sound._pos[0], Howler.ctx.currentTime);
sound._panner.positionY.setValueAtTime(sound._pos[1], Howler.ctx.currentTime);
sound._panner.positionZ.setValueAtTime(sound._pos[2], Howler.ctx.currentTime);
sound._panner.orientationX.setValueAtTime(sound._orientation[0], Howler.ctx.currentTime);
sound._panner.orientationY.setValueAtTime(sound._orientation[1], Howler.ctx.currentTime);
sound._panner.orientationZ.setValueAtTime(sound._orientation[2], Howler.ctx.currentTime);
} else {
sound._panner = Howler.ctx.createStereoPanner();
sound._panner.pan.setValueAtTime(sound._stereo, Howler.ctx.currentTime);
Expand Down

0 comments on commit 041b4b5

Please sign in to comment.