3d Sound Example May 2026
π₯ (wear headphones) Search YouTube for: "Virtual Barbershop" β a classic 3D audio example where scissors, clippers, and voices move around your head. π» Code Example: Simple 3D Sound in JavaScript (Web Audio API) Below is a complete, runnable 3D sound example. It creates a sound source that circles around the listener.
// Animate: move sound in a circle around listener let angle = 0; const radius = 2; function moveSound() const x = Math.cos(angle) * radius; const z = Math.sin(angle) * radius; panner.setPosition(x, 0, z); angle += 0.02; // rotation speed requestAnimationFrame(moveSound); moveSound(); 3d sound example
// Create a panner node for 3D positioning const panner = audioCtx.createPanner(); panner.panningModel = 'HRTF'; // most realistic 3D panner.distanceModel = 'inverse'; panner.refDistance = 1; panner.maxDistance = 10; panner.rolloffFactor = 1; // Animate: move sound in a circle around