Theme:

Sound

let optionalProps = {
  autoPlay: Boolean,
  loop: Boolean,
  positional: false, // use positional audio when true
  // Optional: 0 mixes the source to mono, 1 preserves its original stereo.
  // Omit this property to use the normal audio path with no width processor.
  stereoWidth: 0.5,
  // "inherit" follows world.audio.panningModel (default: "equalpower")
  panningModel: "inherit", // "inherit", "equalpower", or "HRTF"
    // saves the sound as a url, e.g. sound.url, useful for Tone.js
  loadURL: Boolean,
  volume: 0.7
};

// Create a new U.PositionalAudio object using an asset name
const song = await Sound("melody.mp3", optionalProps);

// Load using an array buffer, this might be from a download or p2p data
const song = await Sound(arrayBuffer);

// Load from a URL
const audioClip = await Sound("https://sound.com/mp3.com");

// Example usage
song.play()

world.add(song);

// Change the engine-wide default. Existing positional sounds using
// "inherit" update immediately.
world.audio.setPanningModel("HRTF");
world.audio.panningModel = "equalpower";

// Override one positional sound without changing the global setting.
song.setPanningModel("HRTF");

// Resume following the global setting.
song.setPanningModel("inherit");

// Inspect the configured mode and effective Web Audio model.
song.getPanningModelMode(); // "inherit"
song.getPanningModel(); // "equalpower" or "HRTF"

stereoWidth is a creation parameter rather than a runtime setter. It accepts values from 0 to 1 and is useful only for source files containing stereo information. The engine creates the channel-mixing graph only when the parameter is supplied, so existing sounds have no additional processing cost.

equalpower is the engine default because it provides efficient left/right spatialization. Use HRTF when higher-quality headphone spatialization is worth the additional audio-processing cost. A sound-level override remains unchanged when the global setting changes.

For more info check three.js Audio and PositionalAudio