New issue
Advanced search Search tips

Issue 893983 link

Starred by 1 user

Issue metadata

Status: Started
Owner:
Components:
EstimatedDays: ----
NextAction: ----
OS: Mac
Pri: 3
Type: Bug



Sign in to add a comment

PannerNode HRTF Y-axis panning incorrect when both listener and panner are at the same positionZ

Reported by j4kub.fi...@gmail.com, Oct 10

Issue description

Chrome Version       : 71.0.3569.0 (Official Build) canary (64-bit)
OS Version: OS X 10.13
URLs (if applicable) : https://codepen.io/anon/pen/qJrQZq?editors=1010
Other browsers tested:
  Add OK or FAIL after other browsers where you have tested this issue:
     Safari:
    Firefox: OK
    IE/Edge:

What steps will reproduce the problem?
1. Create an <audio> element where id="sound" and loop="true"
2. Add the following JavaScript:

```
const mediaElement = document.getElementById('sound');

const startPlaying = () => {
  const context = new AudioContext();
  const source = new MediaElementAudioSourceNode(context, { mediaElement });
  
  const panner = new PannerNode(context);
  panner.panningModel = 'HRTF';

  panner.positionY.setValueAtTime(2, context.currentTime + 2);
  panner.positionY.setValueAtTime(-2, context.currentTime + 4);
  panner.positionY.setValueAtTime(0, context.currentTime + 6);
  
  panner.positionZ.setValueAtTime(1, context.currentTime + 8);

  panner.positionY.setValueAtTime(2, context.currentTime + 10);
  panner.positionY.setValueAtTime(-2, context.currentTime + 12);
  panner.positionY.setValueAtTime(0, context.currentTime + 14);

  source.connect(panner)
     .connect(context.destination);
}

mediaElement.play().then(startPlaying);
```


What is the expected result?

For the first 8 seconds, your listener should be positioned at 0,0,0 and your sound should be panned up, then down, then back to the centre.

The same should repeat in the next 8 seconds, with a slight timbral/volume change because your sound is now further from you in the Z direction.


What happens instead of that?

In the first 8 seconds, the sound is actually panned to the *right*, then further right, then back to the centre.

After setting positionZ to 1 (at T+8 seconds), the sound doesn't pan to the right anymore, and pans up, down and back to the centre as expected.


Please provide any additional information below. Attach a screenshot if
possible.

It seems like the HRTF functions don't work as expected when both the listener and the panner are at the same positionZ – this applies also when both are at positionZ=1.

This might be a problem for applications where only positionY should change, for whatever reason, as it then introduces unintended horizontal panning.


 
Components: Blink>WebAudio
Status: Available (was: Unconfirmed)
Thanks for the report.  The codepen example illustrates the strange behavior very well.
Let's do the math (just to record my thoughts on this).  For reference, the algorithm is https://webaudio.github.io/web-audio-api/#azimuth-elevation.

At time 2
sourcePosition = (0,2,0)
listenerPosition = (0,0,0)
sourceListener = (0,2,0).normalize = (0,1,0)

listenerForward = (0,0,-1)
listenerUp = (0,1,0)
listenerRight = (0,0,-1) cross (0,1,0) = (1,0,0)
listenerRightNorm = (1,0,0)
listenerForwardNorm = (0,0,-1)
up = (1,0,0) cross (0,0,-1) = (0,1,0)

upProjection = (0,1,0) dot (0,1,0) = 1
projectedSource = ((0,1,0)-(0,1,0)*1).normalize = (0,0,0).normalize = (0,0,0)

azimuth = 180/pi * acos((0,0,0) dot (1,0,0)) = 180/pi*pi/2=90

frontBack = (0,0,0) dot (0,0,-1) = 0
azimuth unchanged.

azimuth >= 0 and <= 270 so azimuth = 90 - azimuth = 0.

elevation = 90 - acos((0,1,0) dot (0,1,0)) = 90 - 0 = 90

Assuming I did all the math correctly, azimuth = 0 and elevation = 90.  I think this means that source is directly pointed at the listener and the source is 90 deg above the listener.

So the sound should come from the center (neither left nor right) and definitely above.

Chrome is apparently doing something wrong here.
I think chrome currently returns an azimuth = 90 and elevation = 90.  That would, I think make the sound come from the right.  Which explains the odd sound.
Owner: rtoy@chromium.org
Status: Started (was: Available)
Modified the codepen test example to work with Chrome's autoplay policy:

https://codepen.io/rtoy/pen/jXJyQg

Sign in to add a comment