ECHO GARDEN / STUDY / LEVEL 6 OF 7

Sound
in space.

Your ears find a sound by small differences: it reaches the nearer ear first and louder, and the shape of your ears colours it differently from each direction. A PannerNode with panningModel = 'HRTF' imitates all of that for a sound at a position. It needs two things: where the sound is, and where your ears are and which way they face, the listener. This page uses the game's gardenAudio.js to move the listener. Wear headphones.

the note's positionshared coordinates → this headset's coordinates
→
the head's matrixposition, forward (−z) and up (y)
→
panner + listenerdirection and distance between them
→
HRTFa left signal and a right signal

The room from above

click a note to play it · drag the head to walk

The panel is at the top. The arrow is where the head faces. The faint arrow is where the browser thinks the ears are: they match only when the listener follows the head.

Listener

selected note
—
distance
—
direction, as heard
—
volume (inverse model)
—

Untick the box, then turn the head: the faint arrow stays pointing at the panel, so the note stays "in front" however you turn. This was the bug in an earlier version of the scene.

The listener

gardenAudio.js

A head matrix is turned into a pose: position from column 3, up from column 1, forward from minus column 2 (a head looks down its own −z axis). placeListener writes it into audio.listener; older browsers only have setPosition and setOrientation.


      

Where the scene uses it

echoGarden.js

followHead runs every frame. The note's position goes through model.getGlobalMatrix() and the head through worldCoords, so both are in this headset's own coordinates. Then each note gets its own HRTF panner with the inverse distance model.


      
    

What you should be able to explain

  1. Two halves. A panner says where the sound is; the listener says where the ears are. The browser only hears their difference. Moving the listener is as important as placing the sound.
  2. One set of coordinates. Notes live in shared coordinates, which both players agree on. The panner and the listener must use the same coordinates: the scene converts both into this headset's own, with getGlobalMatrix() for notes and worldCoords for the head.
  3. Reading a head matrix. Column 3 is the position, column 1 is "up", and minus column 2 is "forward". Turning the head rotates those columns, and the listener with them.
  4. Distance. The inverse model with refDistance = 0.6 keeps full volume within 0.6 m and then falls as 0.6 / d: at 1.5 m a note is at 40 %.
  5. Why it matters in VR. If the listener never moves, every sound turns with your head. Your eyes see the note on your left, your ears hear it in front, and the garden stops feeling like a place.

Exercises: ① With headphones, play a note on the far left, then turn the head 90° left: where is it now? ② Untick "follows the head" and repeat. ③ Walk the head close to one note and play it: what does the inverse model do inside 0.6 m?