from Hacker News

Show HN: Spatial audio in the browser with head tracking

by matheist on 5/1/24, 9:12 PM with 0 comments

Listen to a Bach chorale with four instruments in different directions. Uses your webcam to track your head and render the instruments in space.

The interaural time and intensity differences are relatively straightforward to do — the sound source is here, the ears are there, introduce delay for speed of sound and attenuate by inverse of distance.

For the direction-dependent frequency attenuation and emphasis, I used a very small neural network to learn an HRTF (head-related transfer function) interpolating between head-related impulse responses at fixed directions.

Everything's running in the browser.