Audio Ambisonic
Updated
Plays a 360 soundfield as binaural audio.
- Type
ent-audio-ambisonic- Script class
AmbisonicAudioEntity- Family
- Audio
Overview
Section titled “Overview”An Audio Ambisonic entity plays a 360-degree soundfield: a recording that captures sound from every direction at once, such as a forest at dawn, a busy street or a concert hall. Instead of coming from one point, the sound surrounds the player, and as they turn their head the birds stay to the left and the traffic stays behind. The soundfield is rendered for headphones (binaurally), so the directions are heard on any pair of headphones, and it follows head rotation in a VR headset.
Its sound comes from the required Audio Ambisonic component (AudioAmbisonicComponent in scripts). The file must be an ambisonic recording in B-format with 4, 9 or 16 channels. In play, a source with autoplay on starts once it has loaded and stops when the scene is left; in the editor, selecting the entity auditions it.
Use it for an immersive ambience bed under a whole scene. Pick the global Audio for a plain stereo music or ambience file, or an Audio Positional for a sound that comes from one object. Audio Zones never mute an ambisonic source, and it does not accept an Audio Analyzer or a Media Stream.
The props that matter most:
src: the ambisonic B-format file.order: the ambisonic order of the file, 1, 2 or 3. Leave it unset (Auto) to infer it from the file’s channel count: 4 channels are first order, 9 second, 16 third.volume: the loudness, from 0 to 1.repeat:repeatloops the soundfield, which is what an ambience usually needs;onceplays it to the end.autoplay: whether it starts on its own in play.
From a script, the component has play(), pause(), stop(), setVolume(v), isPlaying() and load(). Its events are named AudioAmbisonic::….
Set it up
Section titled “Set it up”- Add an Audio Ambisonic entity to the scene and name it, for example
Forest Ambience. - Set its
srcto an ambisonic file with 4, 9 or 16 channels. Leaveorderon Auto unless you know the file’s order. - Keep
repeatonrepeatandautoplayon for a background ambience. - Lower
volumeso the ambience sits under voices and effects. - Optionally add an Audio Fade so the ambience fades in when the scene starts, and a Signal Emitter if scripts need its events.
Examples
Section titled “Examples”Log when the ambience is ready
Section titled “Log when the ambience is ready”Check that the soundfield loads and report its length.
#pragma lifecycle(startup)
// Scene: an Audio Ambisonic entity "Forest Ambience" (autoplay on, repeat)// with a Signal Emitter on the signal 'ambience'.function startup() { const forest = findEntity('Forest Ambience').getComponent(AudioAmbisonicComponent); log('Ambience volume:', forest.props.volume);
on('ambience', (event) => { if (event.eventType === EventType.AudioAmbisonic.Ready) log('Ambience loaded:', event.data.duration.toFixed(1), 's'); if (event.eventType === EventType.AudioAmbisonic.Play) log('Ambience playing'); if (event.eventType === EventType.AudioAmbisonic.Error) log('Ambience cannot load:', event.data.message); });}How it works:
getComponent(AudioAmbisonicComponent)reaches the soundfield, andprops.volumereads its authored volume.- The Signal Emitter forwards the component’s events on
ambience.AudioAmbisonic::readycarries the file’sdurationin seconds, andAudioAmbisonic::erroramessage.
Crossfade between two soundscapes
Section titled “Crossfade between two soundscapes”Blend from a day ambience to a night ambience over a few seconds.
#pragma lifecycle(startup)
// Scene: two Audio Ambisonic entities, "Day" (autoplay on, repeat)// and "Night" (autoplay off, repeat, volume 0).// Another script emits 'time/night' and 'time/day'.const LEVEL = 0.8;let day;let night;let fade;
function crossfade(from, to) { if (fade) fade.stop(); to.play(); fade = Tween.value(0, 1, (t) => { from.setVolume(LEVEL * (1 - t)); to.setVolume(LEVEL * t); }, { duration: 4, onComplete: () => from.pause() });}
function startup() { day = findEntity('Day').getComponent(AudioAmbisonicComponent); night = findEntity('Night').getComponent(AudioAmbisonicComponent); day.setVolume(LEVEL); night.setVolume(0);
on('time/night', () => crossfade(day, night)); on('time/day', () => crossfade(night, day));}How it works:
Tween.value(0, 1, …)hands a number from 0 to 1 to the callback every frame for four seconds; one soundfield’s volume goes down as the other’s goes up.to.play()starts the incoming soundfield before the fade. Its volume starts at 0, so it comes in smoothly.onCompletepauses the outgoing soundfield only when the fade finishes, not when a new crossfade interrupts it, so nothing keeps playing silently for nothing.
Quiet the ambience while a menu is open
Section titled “Quiet the ambience while a menu is open”Lower the soundfield while the player reads a menu, and restore it after.
#pragma lifecycle(startup)
// Scene: an Audio Ambisonic entity "Street" (autoplay on, repeat).// The menu script emits 'menu/open' and 'menu/close'.let street;let normal = 1;
function startup() { street = findEntity('Street').getComponent(AudioAmbisonicComponent); normal = street.props.volume;
on('menu/open', () => street.setVolume(normal * 0.3)); on('menu/close', () => street.setVolume(normal));}How it works:
normalkeeps the authored volume, read once fromprops.volume, so closing the menu restores exactly what the scene was built with.setVolumeapplies at once; for a gradual change, drive it fromTween.valueas in the previous example.
- If
orderasks for more channels than the file has, the file’s own order is used instead. Leavingorderon Auto avoids the mismatch. - A stereo or mono file is not a soundfield. For those, use an Audio entity.
- Like every sound, the soundfield stays silent until the user’s first click, tap or key press; it becomes audible then without being played again.
Components
Section titled “Components”What a new Audio Ambisonic is made of. Required components are always present and cannot be removed; the others can. Per entity says whether an entity can hold one of that component or several. Layer, Lock and Enable are on every placed entity, and Transform holds its position, rotation and scale.
| Component | Type | Role | Per entity | What it does |
|---|---|---|---|---|
| Layer | comp-layer |
Required | One | Puts the entity on a render/raycast layer so cameras and rays can include or skip it. |
| Lock | comp-lock |
Required | One | Editor-only flag that stops the entity from being selected or moved. |
| Enable | comp-enable |
Required | One | Turns the entity and its children on or off: hides them and stops their behavior. |
| Transform | comp- |
Required | One | Position, rotation and scale of the entity, with optional editor-only per-axis locks. |
| Audio Ambisonic | comp- |
Required | One | Plays a 360 soundfield as binaural audio. |
You can also add 14 optional components, such as AI Speech Capture, Animation Graph, Animation Timeline, Attribution, Audio Chorus Filter, Audio Distortion Filter.
The settings of a new entity, as the runtime creates it. Change them in the Properties panel of XR Creator, or from a script with getComponent(…).setProps({ … }).
| Prop | Default | Range |
|---|---|---|
volume |
1 |
0 ≤ x ≤ 1 |
repeat |
"repeat" |
|
autoplay |
true |
Events
Section titled “Events”With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.
AudioAmbisonic::readyAudioAmbisonic::errorAudioAmbisonic::playAudioAmbisonic::pauseAudioAmbisonic::stopAudioAmbisonic::end
Like every entity, it also reports: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.
From a script
Section titled “From a script”Find the entity by its name, check its class, and work with its components. Name the entity in the Hierarchy first; this example expects My Audio Ambisonic.
#pragma lifecycle(startup)
function startup() { // Find the entity by the name it has in the Hierarchy. const entity = findEntity('My Audio Ambisonic'); if (!(entity instanceof AmbisonicAudioEntity)) return;
// Its Audio Ambisonic component holds the settings listed under Props. const component = entity.getComponent(AudioAmbisonicComponent); log('volume is', component.props.volume); component.setProps({ volume: 1 });}