0

I've been trying to find more information about setting the listener orientation using Web Audio API. I've checked the api documentation but I'm not completely clear on how it should be used. https://docs.webplatform.org/wiki/apis/webaudio/AudioListener/setOrientation

Describes which direction the listener is pointing in the 3D cartesian coordinate space. Both a front vector and an up vector are provided. In human terms, the front vector represents which direction the person's nose is pointing. The up vector represents the direction the top of a person's head is pointing. These values are expected to be linearly independent (at right angles to each other). The x, y, z parameters represent a front direction vector in 3D space, with the default value being (0,0,-1). The xUp, yUp, zUp parameters represent an up direction vector in 3D space, with the default value being (0,1,0).

I need to use the orientation rotation to help the user determine whether the source sound is behind or in front, how could I turn the listener orientation 90 degrees to the right or left?

Many thanks

  • As @brandon-keith-biggs said, `setOrientation` has been deprecated. Now you have to set each param one at a time (answer has been edited accordingly). – Touffy Jun 16 '19 at 09:52

1 Answers1

1

First, make sure that you understand that you're rotating the listener, not the source, by doing this. You're basically telling the software to correct for the user not facing their screen (assuming a standard configuration where the screen is "front").

According to the spec, rotating the user 90° would mean changing the "nose" vector (forwardX, forwardY, forwardZ) to 1,0,0 (listener facing right) or -1,0,0 (listener facing left). Facing 45° left would be:

context.listener.forwardX.value = -1
context.listener.forwardY.value = 0
context.listener.forwardZ.value = -1

(the vector will be normalized, of course; length doesn't matter).

Touffy
  • 6,309
  • 22
  • 28