Skip to content

AmbientAudio

Hans Lindetorp edited this page Apr 6, 2023 · 3 revisions

The AmbientAudio element simplifies the implementation of background sounds. It loads a sound file and takes care of smooth crossfading. The sound file itself should not have any fade-ins our fade-outs to work well. To make the loop perfect, please allow for some overlapping. 1s is default, but it can be set with the attribute "crossFade" and is expressed in seconds or milliseconds depending on the value set by "timeUnit" (default is seconds). It inherits attributes from the AudioBufferSourceNode. If the length of the loop is set to a short value, the AmbientAudio element can be used to create a granular synth. Se example 2.

Attributes:

  • src

  • loop

  • loopStart

  • loopEnd

  • trig

  • release

  • playbackRate

  • crossFade

Example 1

<?xml version="1.0" encoding="UTF-8"?>
<Audio version="1.0" timeUnit="ms">

    <AmbientAudio id="ambience1" src="audio/ambience1.mp3" crossFade="2000"></AmbientAudio>

</Audio>

Example 2

<AmbientAudio 
  src="audio/granular.mp3" 
  start="auto"
  loopStart="$loopStart"
  loopLength="$loopLength"
  fadeTime="250"
  detune="$detune"
  randomPosition="0"
  randomDuration="0"
  randomDetune="0"
/>

Read more: https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode

Clone this wiki locally