3D Sound Settings
This is general Unity AudioSource
techniques, not only for Tiny Ambience. But to make positional ambience sounds like you think it should, I feel like Tiny Ambience should provide some guidances here.
Here's what above the graph :
Here's the graph below :
Spatial is mono, stereo does not exist
This may not make sense at first! As soon as you move that "Spatial Blend" slider to far right (3D), suddenly the AudioClip
that we have meticulously recorded in stereo turns into mono, moreover only blasting on the left ear. What's going on? It feels like a bug.
In real world, you hear things in stereo only because you have got 2 ears. The birds in front of you cannot emit 2 channels audio. It is mono. Stereo effect was created by human's (or cats, dogs, etc.) ability having 2 listeners on the sides of the head, listening to everything in the world that are all mono.
The data inside AudioClip
(.wav
) is a "workaround" somewhat. We capture audio with 2 microphones (that simulates the ear), then listen to that file on headphones, which has an ability to pump each of microphone's ear directly to each of our ears separately without any blending. But since it is already blended at record-time, we can restore that "ear experience" at later time. (Not perfectly, but acceptable.)
Using the same thinking, if you ditch the headphone and use stereo speakers instead, now your ears are more able to stereorize the audio. But now it is also a little bit unrealistic because we are stereo-ing stereo speakers! (Which sounds great anyways.)
In Unity, we can only have 1 AudioListener
so the "automatic stereo" ability we have in real world does not exist here. Unity must throw a setting and a default behaviour at you how you would like to work with a single ear. And it just decided that the default is far left. (Because "left" happens to be universally considered to come before "right"?)
Spatial Blend's dilemma
- When Spatial Blend is at full 2D, stereo baked in the
AudioClip
is in full effect (hears beautiful audio), but volume rolloff curve (red graph) is completely ignored. - When Spatial Blend is at full 3D,
AudioClip
turns into mono, then how that positions depends on Spread (slider, or blue graph). 0 is far left, 180 is dead center, 360 is far right. (Those are numbers on the slider, as a curve, it is 0, 0.5, and 1.0 respectively.) Spread curve (blue graph) can be thought as : "You have 1 ear in Unity. Please model that ear how it hear things based on distance to the source." None of which compares to if we hear the clip in stereo as recorded. - When Spatial Blend is at full 3D, we can use volume rolloff to make it fade away when listener is further away, increasing realism of locality. But that realism is compromised when listener get close to the source and can perfectly hear it, it is so flat because it has been turned into mono and you bears the curse of 1-ear. (This is assuming you use Spread as 180, so the mono is shared for both ears, but this is still disappointing sound.)
In the official documentation it highlights these behaviors : "Spatial Blend: 2D (original channel mapping) to 3D (all channels downmixed to mono and attenuated according to distance and direction)."
What I want in my simple, top-down non-ambisonic game : "Original channel mapping and attenuated according to distance and direction". Looks like we cannot both have cake and eat it too...
Simple tactics
Now that you know there are good stuffs at both 2D (beautiful stereo) and 3D (fades away on distance) Spatial Blend, we can counter-graph it to get both goodies like the picture here, assuming we want to use the built-in distance system in Unity.
(You can also roll your own MonoBehaviour
that fades in and out full 2D audio based on roll-your-own distance checking, but I would rather have this nice default graph to edit the distance differently depending on the audio content.)
What this contraption will do is that when you are further away, you want the positional property and care less about preserving recorded stereo. When it is quiet, ugly and flat audio is not so noticable anyways. (And we keep Spread at constant 0.5 or 180, to make it center at long distance.)
When you do get close, the real stereo we recorded comes back and the mono fades away. Losing positional property does not matter when we are dead-close to the source. Therefore, we have achieved all we wanted with these graphs.
This tech is also highligted in the official documentation : "Morphing between the 2 modes is useful for sounds that should be progressively heard as normal 2D sounds the closer they are to the listener.".
More techniques, gotchas
The Spatial Blend (green) graph is hidden under the Reverb Zone Mix (yellow) graph.
Select node and press Enter to precisely key in values, like in Animation tab.
F
key to fit only selected nodes works, like in Animation tab. But seems likeA
key to show all nodes doesn't work. However, pressingF
while not selecting any node will do the same thing asA
.You can click on the legends below the graph to solo only what you want. (Shift-click to further add to the solo.)
The reason why Volume graph (red) and Spatial blend (green) graph are not linear (straight X cross) but curved (exponential) in my example wasn't just for artistic purpose. It is because this
0.0
to1.0
volume graph value is applied to decibel-based volume, which is logarithmic. If I do it linearly, the initial fade-in from silence will appears to be suddenly loud rather than smoothly fading in. By making the curve exponential (less steep on the right edge), we have nullified the logarithm with exponential and get an expected gentle fade-in when the character walks into the cut-off boundary of positional ambience's range.The "Max Distance" is able to keep the shape of graph, while modifying the value of far right of the graph area, and this graph area is common to 4+ lines, not just the attenuation (red). This is useful to keep the graph shape consistent for the game, then you make a prefab inheritance that overrides only Max Distance number to polish how far this thing could reach. But it seems like this number is applied only once, modifying it live in Play Mode seems to not update the graph like you actually change the graph.
When you select a game object that has children with positional
AudioSource
, a sphere gizmo is displayed on the screen. That gizmo has draggable little squares, it adjusts the "Max Distance" mentioned earlier. This is yet another reason to utilize Max Distance to scale the right edge rather than hand-crafting the graph, because you (or the sound designer) can do it visually. (But you have to imagine the non-linear falloff that you used on your own. The sphere can't show that.)In the API, all things in the curve could be get and set with
GetCustomCurve
andSetCustomCurve
. But they also have accessors for non-graph single value. (e.g.spread
) When you use the accessor, it will overwrites the graph (AnimationCurve
) with a single key flat graph. When you use the graph's set API, the single value one became 0.Right click on the Inspector tab header and select "Debug" will let you see each line in the graph individually, along with correct prefab override bolding and blue bars. This is very useful in organizing your prefab variant chain which respect the parent and which is specialized.