Spatial sound in Unity

This topic describes how to use Spatial Sound in your Unity projects. It covers the required plugin files as well as the Unity components and properties that enable Spatial Sound.

Enabling Spatial Sound in Unity

Spatial Sound, in Unity, is enabled using an audio spatializer plugin. The plugin files are bundled directly into Unity so enabling spatial sound is as easy as going to Edit > Audio > Spatializer and enabling the Microsoft HRTF extension. Since Microsoft Spatial Sound only supports 48000 currently, you should also set your System Sample Rate to 48000 to prevent an HRTF failure in the rare case that your system output device is not set to 48000 already:

Inspector for AudioManager

Your Unity project is now configured to use Spatial Sound.

Note that, while the Windows 10 SDK may be used to build HoloLens apps on Windows versions prior to Windows 10, if you aren't using Windows 10, you will not get Spatial Sound in the editor nor on the device.

Using Spatial Sound in Unity

Spatial Sound is used in your Unity project by adjusting three settings on your Audio Source components. The following steps will configure your Audio Source components for Spatial Sound.

  • In the Hierarchy panel, select the game object that has an attached Audio Source.
  • In the Inspector panel, under the Audio Source component
    • Check the Spatialize option.
    • Set Spatial Blend to 3D (numeric value 1).
    • For best results, expand 3D Sound Settings and set Volume Rolloff to Custom Rolloff.

Inspector panel in Unity showing the Audio Source

Your sounds now realistically exist inside your project's environment!

It is strongly recommended that you become familiar with the Spatial Sound design guidelines. These guidelines help to integrate your audio seamlessly into your project and to further immerse your users into the experience you have created.

Setting Spatial Sound Settings

The Microsoft Spatial Sound plugin provides additional parameters that can be set, on a per Audio Source basis, to allow additional control of the audio simulation. These parameters are the minimum and maximum gain, the unity gain distance and the size of the simulated room.

Minimum Gain

The minimum gain applied (from -96 to +12 decibels) at any distance. The default value is -96 decibels.

Maximum Gain

The maximum gain applied (from -96 to +12 decibels) at any distance. The default value is +12 decibels.

Unity Gain Distance

The distance, in meters (from 0.05 to infinity), at which the gain is 0 decibels. The default value is 1 meter.

Room Size

The size of room that is being simulated by Spatial Sound. The approximate sizes of the rooms are; small (an office to a small conference room), medium (a large conference room) and large (an auditorium). You can also specify a room size of none to simulate an outdoor environment. The default room size is small.


The HoloToolkit for Unity provides a static class that makes setting the Spatial Sound settings easy. This class can be found in the HoloToolkit\SpatialSound folder and can be called from any script in your project. It is recommended that you set these parameters on each Audio Source component in your project. The following example shows selecting the medium room size for an attached Audio Source.

AudioSource audioSource = gameObject.GetComponent<AudioSource>()

if (audioSource != null) {
    SpatialSoundSettings.SetRoomSize(audioSource, SpatialMappingRoomSizes.Medium);

Directly Accessing Parameters from Unity

If you don't want to use the excellent Audio tools in HoloToolkit, here is how you would change HRTF Parameters. You can copy/paste this into a script called SetHRTF.cs that you will want to attach to every HRTF AudioSource. It lets you change parameters important to HRTF.

using UnityEngine;
   using System.Collections;
   public class SetHRTF : MonoBehaviour    {
       public enum ROOMSIZE { Small, Medium, Large, None };
       public ROOMSIZE room = ROOMSIZE.Small;  // Small is regarded as the "most average"
       // defaults and docs from MSDN
       public float mingain = -96f; // The minimum gain limit applied at any distance, from -96 to + 12
       public float maxgain = 12f;  // The maximum gain applied at any distance, from -96 to + 12
       public float unityGainDistance = 1; // The distance at which the gain applied is 0dB, from 0.05 to infinity
       public float bypassCurves = 1; // if > 0, will bypass Unity's volume attenuation and make a more accurate volume simulation automatically in the plugin
       AudioSource audiosource;
       void Awake()
           audiosource = this.gameObject.GetComponent<AudioSource>();
           if (audiosource == null)
               print("SetHRTFParams needs an audio source to do anything.");
           audiosource.spatialize = 1; // we DO want spatialized audio
           audiosource.spread = 0; // we dont want to reduce our angle of hearing
           audiosource.spatialBlend = 1;   // we do want to hear spatialized audio
           audiosource.SetSpatializerFloat(1, (float)room);    // 1 is the roomsize param
           audiosource.SetSpatializerFloat(2, mingain); // 2 is the mingain param
           audiosource.SetSpatializerFloat(3, maxgain); // 3 is the maxgain param
           audiosource.SetSpatializerFloat(4, unityGainDistance); // 4 is the unitygain param
           audiosource.SetSpatializerFloat(5, bypassCurves );    // 5 is bypassCurves, which is usually a good idea

See also