Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Introduction to ambisonic audio decoders

Read time 6 minutesLast updated 11 hours ago

An ambisonic decoder is an audio component that decodes the ambisonic audio format into a specific output format, such as stereo or surround sound. This format depends on your speaker configuration (menu: Edit >
Project Settings

?

> Audio > Default Speaker Mode), unless your platform overrides this.
Unity provides one built-in ambisonic decoder, the Unity Quad+ Ambisonic Decoder, which decodes to Quad, 5.0, 5.1, 7.1, and 7.1.4 speaker layouts. To decode to other output formats, select a third-party decoder or use your own decoder plug-in.

Built-in Quad+ ambisonic decoder

The Unity Quad+ Ambisonic Decoder decodes first, second, and third order ambisonic clips to a Quad (four-channel), 5.0, 5.1, 7.1, or 7.1.4 speaker layout, and rotates the sound field to match the listener's orientation.
The decoder requires one of these supported output layouts. How you set this up depends on the audio foundation your project uses:
  • In the Enhanced Audio Foundation, set Output Channel Layout to a supported layout (Quad, 5.0, 5.1, 7.1, or 7.1.4) (menu: Edit > Project Settings > Audio), then select Unity Quad+ Ambisonic Decoder as the Ambisonic Decoder Plugin. The audio engine always runs at the layout you select and converts the output to the device's native format, so the decoder works with any audio device.
  • In the Classic Audio Foundation, set Default Speaker Mode to a supported layout instead. Classic runs at the layout the audio device reports: if the device doesn't report support for that layout, the engine doesn't run at it and the decoder isn't used.
If the output layout isn't one of the supported layouts, the decoder logs an error and ambisonic audio sources output silence.

Set up an ambisonic audio decoder plug-in

You can set up an ambisonic audio decoder in the same way as you'd set up an Audio Spatializer. However, the following parameters in the
AudioPluginInterface.h
file are specific to ambisonic audio decoder plug-ins:

UnityAudioEffectDefinitionFlags_IsAmbisonicDecoder

During the plug-in scanning phase, the
UnityAudioEffectDefinitionFlags_IsAmbisonicDecoder
flag notifies Unity that this is an ambisonic decoder effect.
To enable a plug-in to operate as an ambisonic decoder, set a flag in the description bit-field of the effect:
definition.flags |= UnityAudioEffectDefinitionFlags_IsAmbisonicDecoder;
Unity lists your plug-in as an option in the Project Settings window (menu: Edit > Project Settings > Audio > Ambisonic Decoder Plugin).

UnityAudioEffectDefinitionFlags_UseOutputChannelCount

By default, the process callback of an ambisonic decoder receives the same channel count for its input and output buffers, which is the channel count of the ambisonic audio clip. The
UnityAudioEffectDefinitionFlags_UseOutputChannelCount
flag notifies Unity that the decoder outputs to the full channel layout of the project instead.
To enable this behavior, set the flag in the description bit-field of the effect, in addition to
UnityAudioEffectDefinitionFlags_IsAmbisonicDecoder
:
definition.flags |= UnityAudioEffectDefinitionFlags_IsAmbisonicDecoder | UnityAudioEffectDefinitionFlags_UseOutputChannelCount;
With this flag set, the
outchannels
parameter of the decoder's process callback equals the channel count of the speaker mode, which can be larger or smaller than
inchannels
. For more information, refer to Handling the number of channels.

UnityAudioAmbisonicData struct

The
UnityAudioAmbisonicData
struct is similar to the
UnityAudioSpatializerData
struct that Unity passes into spatializers, and contains an
ambisonicOutChannels
integer.

Handling the number of channels

The ambisonic decoders run early in the audio pipeline in Unity, and the
ambisonicOutChannels
variable tells the plug-in how many of the output channels Unity needs to use.
ambisonicOutChannels
is automatically set to the
DefaultSpeakerMode
’s channel count.
Unity supports up to third order ambisonics, which means the decoder can receive up to 16 input channels. The number of input channels depends on the ambisonic order of the clip:
  • First order has 4 channels
  • Second order has 9 channels
  • Third order has 16 channels
Unity passes the number of input channels to process to your plug-in via the
UnityAudioEffect_ProcessCallback
. The number of output channels depends on whether the plug-in sets the
UnityAudioEffectDefinitionFlags_UseOutputChannelCount
flag.
Without the
UnityAudioEffectDefinitionFlags_UseOutputChannelCount
flag
, the process callback receives the same value for the in and out channel counts, and the plug-in can only use the first
ambisonicOutChannels
channels of the output buffer. For example, if you play back a first order ambisonic audio clip that has 4 channels, and your speaker mode is stereo (which has only 2 channels):
  • An ambisonic decoder’s process callback passes in 4 for the in and out channel count.
  • The
    ambisonicOutChannels
    field is automatically set to 2.
  • The plug-in outputs its spatialized data to the first 2 channels of the buffer and zeroes out the other 2 channels.
For a third order ambisonic clip with 16 channels and stereo output, the process callback:
  • passes in 16 for the in and out channel count
  • sets
    ambisonicOutChannels
    to 2
  • the plug-in outputs to the first 2 channels and zeroes out the remaining 14.
With the
UnityAudioEffectDefinitionFlags_UseOutputChannelCount
flag
, the process callback receives the speaker mode's channel count for the out channel count, which is also the value of
ambisonicOutChannels
, and the plug-in must fill
length * outchannels
samples. The out channel count can be larger or smaller than the in channel count. For example, for a first order ambisonic audio clip that has 4 channels:
  • In stereo, the process callback passes in 4 for the in channel count and 2 for the out channel count. The plug-in should output to the 2 available channels of the output buffer.
  • In 7.1 (which has 8 channels), the process callback passes in 4 for the in channel count and 8 for the out channel count, so the decoder should output its spatialized data to the full 8 channels of the output buffer.

Formats that Unity ambisonics support

Unity supports up to third order ambisonics. The plug-in interface includes information to support any Unity supported outputs, but the plug-in itself determines which outputs are supported.
Ambisonic decoder plug-ins receive up to 16 input channels for third order ambisonic sources. Your decoder plug-in handles all ambisonic orders up to third order (first order: 4 channels, second order: 9 channels, third order: 16 channels).
There's nothing in the framework that's specific to any of the different ambisonic formats available. If the clip’s format matches the ambisonic decoder plug-in’s expected format, then ambisonic audio should work without issue. Unity’s preferred ambisonic format is B-format, with ACN component ordering, and SN3D normalization.

Further information

For information on how to develop a plug-in, refer to Native audio plug-in SDK and Audio spatializer SDK. You must also download the Audio plug-in SDK.

Additional resources