Skip to content

Tutorials · Sound and Music · Chapter 2

Near and far

30 minutes Uses: AudioSource, AudioListener

By the end

  • torch_left with a place in the room again: heard from its side, at its Volume inside its Min Distance of 24 and gone past its Max Distance of 192, fading Linear between them, set with its two rings
  • torch_right crackling a little faster on an Inverse fall, and the well’s drip on a Logarithmic one
  • Every Rolloff defined, Custom and its curve among them, and Blend and Pan tried and put back
  • An Audio Listener on the knight, so the crypt is heard from his feet and not from the camera
On this page

A torch with a place

With Positional ticked, a sound has a place: it is louder the nearer the knight is to it, silent beyond a distance you choose, and heard from the side it is on. Two distances say how, and the Viewport draws them as two rings round the source while it is selected.

  1. Select torch_left. In its Audio Source, open Spatial and tick Positional. Max Distance brightens, and Blend, Rolloff and Min Distance appear under it.
  2. Select stone and press F over the Viewport to see the whole crypt, then click torch_left in the Hierarchy again: the view stays, and its ring is drawn round the torch: Max Distance, 512 for now, with a small square grab on its right. Min Distance is 0, so it has no ring yet.
  3. Drag that grab, the small square on the ring’s right, until Max Distance reads 192, or type 192 into it.
  4. Set Rolloff to Linear.
  5. Type 24 into Min Distance. A small ring appears round the flame, with its grab on its left: drag it to try other sizes, and leave it at 24.
  6. Press Ctrl+S.
The whole crypt at 85.5% with torch_left selected: a small pink ring round the torch on the hall’s north wall and a large pink ring centred on it that reaches across the hall, out past its west wall and just past the well room’s door below, each with a small square grab, among the pale rings of the lights; the Inspector, narrowed to audio, shows Clip torch.wav, Bus Sfx, Volume 0.60, Pitch 0.90, Looping and Autoplay ticked, and in Spatial, Positional ticked, Max Distance 192.00, Blend 1.00, Rolloff Linear, Min Distance 24.00, Pan 0.00
torch_left’s two rings: Min Distance 24 round its flame, Max Distance 192 out across the hall and just past the well room’s door.
Positional
In the Spatial group: ticked, as a source comes, the sound is quieter the farther it is from where the room is heard, and leans to the ear on its side; unticked, it is the same everywhere, as chapter 1’s torch was. The rows from Max Distance to Min Distance are about how a placed sound is heard, and are dimmed or hidden when Positional is off; Pan works either way. A sound with a place is heard from the knight’s feet once he has an Audio Listener, below, and from the camera until then.
Max Distance
How far the source is heard, in world units: past it, silent. 192 is twelve cells: across the hall, and gone just past the well room’s door. A source past its reach still plays, at nothing, so walking back brings it back where it was in its loop. The large ring, with its grab on the right. A new source’s is 512.
Min Distance
How near the source is at its full Volume, in world units: inside it, nothing is taken off for distance. 24 is a cell and a half round the flame, so under the torch he hears it as loud as chapter 1’s. The small ring, with its grab on the left; at 0 it has no ring. A new source’s is 0.
Rolloff
How the sound fades between the two rings, measured as how far across the gap he is, from 0 at Min Distance to 1 at Max Distance. Quadratic, as a source comes: falls fast at first, then eases into silence with no edge at the large ring. Linear: the same amount lost every step, so it arrives at silence still falling, an edge you can hear, which suits a sound that must be gone at a known place, as this torch is past the well room’s door. Inverse: a real fire’s fall, most of it lost in the first steps away, then hanging on faintly, and brought down to nothing at the large ring. Logarithmic: the same number of decibels lost every step, from none at the small ring to 120 at the large one, which sounds like a thing going steadily away. Custom: a curve you draw.
Custom, and its curve
The Rolloff for a shape none of the other four give: choose it and a curve row appears under it, a small picture of the curve whose fold arrow opens it into a canvas, Min Distance at its left end and Max Distance at its right. The sound’s level at each distance is the curve’s height there, from 0 to 1. Double-click the line to add a point, drag a point to shape it, and right-click it to remove it. Until it has a point, the source falls as Quadratic does. No sound in the crypt needs one; chapter 12’s gallery has a bell that carries far, and draws its curve there.

A second fire

The right torch gets the same crackle, but not the same fire. A Pitch a little over 1 plays it faster and higher, so the two are never heard as one recording copied, and an Inverse fall makes it a small flame: loud right beside it, then faint across the room.

  1. Select torch_right, press Add component and choose AudioSourceComponent.
  2. Set Clip to torch.wav, Volume to 0.6 and Pitch to 1.1, and tick Looping and Autoplay. Leave Bus on Sfx and Positional ticked.
  3. Set Max Distance to 192, Rolloff to Inverse and Min Distance to 8, the size of its flame.
  4. Press Ctrl+S.
The whole crypt at 85.5% with torch_right selected: a tiny pink ring round the right torch’s flame and a large pink ring centred on it that reaches across the hall and down into the well room; the Inspector shows Clip torch.wav, Volume 0.60, Pitch 1.10, Looping and Autoplay ticked, Positional ticked, Max Distance 192.00, Blend 1.00, Rolloff Inverse, Min Distance 8.00, Pan 0.00
torch_right: Pitch 1.1, Inverse, Min Distance 8.

At Pitch 1.1 its four-second loop plays in 3.64 s, and the left one’s in 4.44 s, so the two crackles drift past each other rather than beat as one.

The dripping well

The well room’s well drips. drip.wav, five drips in five seconds made to loop, came with the starter in audio.

  1. In Assets, click drip.wav in audio, set its Stream to Never in Details and press Save, as chapter 1 did for the crackle: it is five seconds, and plays all the while.
  2. Select well in well_room, press Add component and choose AudioSourceComponent.
  3. Set Clip to drip.wav, Volume to 0.8, and tick Looping and Autoplay.
  4. Set Max Distance to 320, Rolloff to Logarithmic and Min Distance to 16, a cell round the well.
  5. Press Ctrl+S.
The whole crypt at 85.5% with well selected: a small pink ring round the well in the well room’s west end, and a very large pink ring centred on it that reaches up through the entrance hall, out past the crypt’s west edge and east across the bridge’s chasm; the Inspector shows Clip drip.wav, Volume 0.80, Pitch 1.00, Looping and Autoplay ticked, Positional ticked, Max Distance 320.00, Blend 1.00, Rolloff Logarithmic, Min Distance 16.00
The well: Max Distance 320, Logarithmic, Min Distance 16.

The large ring reaches into the hall, and yet the drip is not heard there. Logarithmic loses the same number of decibels every step, 120 across the gap, about 0.4 a unit: by the hall, 190 from the well, more than 60 dB has gone, and that is silence. It is heard only as he comes near the well, which is what a drip in a well should do.

The Inspector’s column on torch_left with the Rolloff menu open under its box: Quadratic, Linear lit, Inverse, Logarithmic and Custom
The five shapes in Rolloff’s menu.

Quadratic is where every source starts, and no sound in this chapter keeps it: each has a fall of its own, and chapter 7’s waterfall is the sound that keeps it.

Ears for the knight

A placed sound is heard from somewhere. With no Audio Listener in the scene, that is the camera. The knight’s camera follows him, but near the crypt’s walls the confiner holds it off him, so it would hear the room from a place he is not. An Audio Listener on the knight hears from his feet.

  1. Select knight, press Add component and choose AudioListenerComponent. Its one field, Enabled, comes ticked.
  2. Press Ctrl+S.
The knight selected and drawn at 400% on the hall’s warm-lit floor, his box and handles round him and a pink ear, two arcs, drawn round him; the Inspector, narrowed to audio, shows AudioListenerComponent with Enabled ticked
The knight’s Audio Listener: the pink ear drawn round him is where the crypt is heard from.
The Audio Listener’s Enabled
Whether the crypt is heard from this node. Ticked, as it comes, every placed sound is measured from the knight’s feet and panned by his side. Unticked, or with no Audio Listener at all, the camera hears instead. By the hall’s west wall the two differ: the confiner holds the camera at x 160, east of him, so without his Listener the left torch would be heard on his left when it is on his right.

Near and far, heard

  1. Press F5 and click the Sound tab.
  2. Walk east to the end of the hall, then down through the south door into the well room and to the well.
  3. Press F5 again to stop.
He stands between the torches for two seconds, then walks east to the end of the hall. Listen for both crackles moving into your left ear as he goes, and growing fainter: at the hall’s east end both torches are west of him.
What it sounds like

Two wood-fire crackles, a little louder on the left at first; then they slide across into the left ear and drop back, and stay there, quieter, on the left.

He walks from the middle of the hall straight down through the door into the well room, then west to the well. Listen for the torches fading as he goes through the door and gone a step into the well room, a moment of nothing, and then the drip as he comes near the well.
What it sounds like

Two crackles fading fast and stopping; a moment of silence; one faint drip, then two clear drips into water close by.

The editor two seconds into Play, the Viewport looking through the knight’s camera at the hall with the knight in the middle; the Sound tab’s Voices (3): torch_left torch.wav Sfx heard at -9.1 dB, torch_right torch.wav Sfx -31.2 dB, well drip.wav Sfx silent; the Inspector shows torch_right’s Audio Source, Pitch 1.10, Rolloff Inverse, Min Distance 8.00
At his start: torch_left at -9.1 dB, torch_right at -31.2 dB on its Inverse, the well silent from the hall.

At his start the torches are each 93 from him. The left one, on Linear, is 0.41 of the way across its gap from 24 to 192, so it keeps 0.59 of its Volume: -9.1 dB. The right one, on Inverse, has lost all but a twentieth of its Volume in those few steps: -31.2 dB. Walk up under the left torch, against the wall, and it reads -4.4 dB, chapter 1’s: inside its Min Distance, nothing is taken off.

Blend and Pan, tried and put back

Two more fields in Spatial, each tried here and left as it comes, because every sound in the crypt is a thing in its room and where it stands already says how loud it is and which side it is on.

Blend
How much of the source’s place is used, from 0, none, to 1, all, as it comes. At 0.5 half the sound is placed and half is heard the same everywhere, past Max Distance too. Try it: set the well’s Blend to 0.5 and walk to the bridge’s east bank, past its reach. The drip is still heard, about 6 dB under its Volume; at 1 there is nothing there. Set it back to 1. Chapter 12’s bell uses a Blend under 1, so a tenth of its toll is heard in every room.
Pan
A lean added to the side the sound is heard from, from -1, all left, to 1, all right; 0, as it comes, adds none. The place gives its own lean: how far to his side the source is, against its Max Distance. Try it: set torch_left’s Pan to -0.75 and stand right under it, where its place gives it no side. It is heard on the left, by more than 3 dB. Set it back to 0. Chapter 4’s doors use a Pan of their own, for a recording that leans.

Near and far

NodeComponentFieldValue
torch_leftAudio SourcePositionalticked
Max Distance192
RolloffLinear
Min Distance24
torch_rightAudio SourceClip, Busaudio/torch.wav, Sfx
Volume, Pitch0.6, 1.1
Looping, Autoplay, Positionalticked, ticked, ticked
Max Distance192
RolloffInverse
Min Distance8
audio/drip.wavits DetailsStreamNever
wellAudio SourceClip, Busaudio/drip.wav, Sfx
Volume, Pitch0.8, 1
Looping, Autoplay, Positionalticked, ticked, ticked
Max Distance320
RolloffLogarithmic
Min Distance16
knightAudio ListenerEnabledticked

On all three sources, Blend is 1 and Pan 0, as they come; torch_left keeps its Clip, Volume 0.6 and Pitch 0.9 from chapter 1.

Check it works