Skip to content

Tutorials · Sound and Music · Chapter 6

The mix

By the end

  • An Audio Mix for the crypt: a Compressor on Master as a safety, a Gain of -4 dB on Music, a Compressor on Sfx, and a Panner after it, tried and left unticked
  • The Compressor heard and read on the Sound tab’s meters, by switching it off and on
  • The title’s own mix, and why a room needs one
  • Three scripts that set the game’s Master, Music and Sfx volumes from the options screen’s sliders, and save them
  • The title’s sounds: a click as a button is pressed, a blip as the focus moves, a tick as a slider steps
On this page

Four interface sounds

Part 1 placed every sound in the crypt. Part 2 mixes them: what each bus does to what passes through it, what each room sounds like, what dips under what, and what the pause does. It starts with the mix itself, and with the one screen where the player sets it: the title’s options. The title gets four sounds from Kenney’s Interface Sounds: a click, a blip, a softer click for the way back, and a tick.

  1. Download Interface Sounds from its page below. Copy the four files into your project’s audio folder, each from where the list says, and press Refresh in the Assets panel.
  2. Click each in Assets and press Play in Details: each is a tenth of a second or less.

Leave their Stream on Auto: each is far under three seconds, so Auto holds it whole, and a click sounds the moment it is asked for.

The crypt’s mix

Every sound the game plays goes through one of three buses, Master, Music and Sfx, chosen by its source’s Bus; Music and Sfx both go through Master last. An Audio Mix says what each bus does to the sound on its way: a chain of effects, run first to last. A scene has one, and the game takes it up as the scene opens: the crypt’s mix is the crypt’s, from the moment the crypt opens to the moment it closes.

  1. With crypt.ron open, select Crypt, the root. Press + Add node and choose Audio Mix. Rename the new node mix.
  2. In its AudioMixComponent, open Effects, then Master. Press the + beside Slots: a slot, numbered 1, as a slot comes, a Gain of 0 dB with Enabled ticked, which changes nothing. Open it, set its Effect to Compressor, and set Threshold to -1, Ratio to 20, Attack to 0 and Release to 0.1.
  3. Open Music and press + beside its Slots. Leave its Effect on Gain, and set its Gain to -4.
  4. Open Sfx and press + beside its Slots. Set its Effect to Compressor, with Threshold -15, Ratio 4, Attack 0.001 and Release 0.15.
  5. Press + beside Sfx’s Slots again: a second slot, a Gain of 0 dB as a slot comes. Set its Effect to Panner, with Pan 0.5 and Width 0.5, and untick its Enabled.
  6. Press Ctrl+S.
The Inspector’s column, widened and narrowed to audio, on mix: AudioMixComponent, Effects open; Master, its Slots with one item, slot 1 Compressor open: Effect Compressor, Threshold -1.0 dB, Ratio 20.0, Attack 0.000 s, Release 0.10 s, Enabled ticked; Music, slot 1 Gain open: Effect Gain, Gain -4.0 dB, Enabled ticked; Sfx, two slots: 1 Compressor, Threshold -15.0 dB, Ratio 4.0, Attack 0.001 s, Release 0.15 s, Enabled ticked; 2 Panner, Pan 0.500, Width 0.500, Enabled unticked; then Snapshots, Ducking and Sends with no items
The crypt’s mix: a slot on each bus, every slot open.
The Audio Mix’s Effects
A chain of effects for each bus: Master, Music and Sfx. A sound passes through its own bus’s chain, first slot to last, and then through Master’s. An empty chain changes nothing, as each bus’s is until you add a slot. The mix’s other three lists, Snapshots, Ducking and Sends, are chapters 7 and 8.
The Master chain, and its Slots
What every sound passes through last, whatever its bus. Its Slots are its effects, first to last: here one, the safety. Each slot is numbered by its place; the arrows on its row move it, and the bin removes it.
The Music chain, and its Slots
What the music passes through: the room’s own track, the alcove’s calm, any music the crypt plays. Here one slot, the Gain that sets the music under the room.
The Sfx chain, and its Slots
What every sound that is not music passes through: the torches, the steps, the doors, the box. Here two slots, the Compressor and, after it, the Panner.
A Master slot’s Effect and Enabled
Its Effect is which effect the slot applies, chosen from nine: LowPass, HighPass, BandPass, Delay, Distortion, Gain, Compressor, Reverb and Panner. Choosing one shows that effect’s own fields under it. Enabled switches it on; unticked, the slot is still there with its fields, and passes the sound as it came. Master’s one slot is a Compressor, ticked.
A Music slot’s Effect and Enabled
The same two on Music’s chain: its one slot is a Gain, ticked. Chapter 9 adds a LowPass after it, unticked, for the pause.
An Sfx slot’s Effect and Enabled
The same two on Sfx’s chain: a Compressor, ticked, and a Panner, unticked. An unticked slot is how an effect is kept to try again, its fields as you left them: tick it, listen, untick it. Chapter 7 adds a Reverb and a Delay here, each unticked, which a room switches on.

The three effects the crypt uses here, each with its fields:

The Compressor, and its Threshold
A Compressor pulls down whatever goes over its Threshold, so the loud moments come down and the quiet ones are left. Threshold is where it starts, in decibels under full scale, 0 dB being the loudest a game can play: Master’s at -1, Sfx’s at -15.
The Compressor’s Ratio
How much of each decibel over the Threshold comes out, the other way up: at 4, four decibels over come out as one; at 20, twenty as one, which is all but a wall. From 1, which does nothing, to 100.
The Compressor’s Attack and Release
How fast it clamps down once the sound goes over, and how fast it lets go once it falls back, in seconds. Master’s Attack of 0 clamps on the very sample that goes over; Sfx’s 0.001 is a thousandth of a second. Each Release is a tenth of a second or so, so the sound comes back up between hits.
The Gain’s Gain
A flat change of level, in decibels: -4 takes four off whatever passes, +6 doubles it. From -96 to 24. A new slot is a Gain of 0, which changes nothing. It is the mix’s, not the player’s: the options screen’s volumes, below, sit after it.
The Panner’s Pan and Width
Where a whole bus sits between your ears, and how wide it is. Pan goes from -1, all left, through 0 to 1, all right; at 0.5 the left ear is halved. Width is 0 for both ears the same, 1 as recorded and 2 doubled; at 0.5 the difference between the ears is halved. It moves every sound on the bus at once, where a source’s own Pan moves one.

The Compressor, heard and seen

The doors’ creak was recorded within a decibel of full scale. At the doors’ Volume of 0.5 it still goes some ten decibels over Sfx’s Threshold of -15, and the Compressor pulls it down; the torches’ crackle is far under it, and passes as it was.

  1. Press F5 and click the Sound tab.
  2. Walk the knight to the bridge room’s east bank, below the cave’s door, and then up into the doorway: the door creaks open.
  3. Press F5 to stop. Untick the Compressor’s Enabled on Sfx, press F5 and do the same. Then tick it again, and press Ctrl+S.
Below the cave’s door, he walks up into the doorway; the door creaks open at about one second. Listen to the creak at its loudest, and compare it with the clip below.
What it sounds like

Three of his steps, and the door’s creak as it opens, about a sixth of a second long, over the calm music.

The same, with Sfx’s Compressor unticked. Listen for the creak a few decibels louder at its loudest; his steps and the music are the same in both.
What it sounds like

The same three steps, and the door’s creak, louder at its peak, over the same calm music.

The Sound tab’s meters 1.07 s into Play, at the creak’s loudest: Master -19.7 dB, peak -8.7; Music -29.7 dB, peak -23.6; Sfx -20.2 dB, peak -9.6
The Sound tab at the creak’s loudest, as the chapter has it: Sfx’s bar at -20.2 dB.
The same meters with Sfx’s Compressor unticked: Master -15.3 dB, peak -5.0; Music -29.7 dB, peak -23.6; Sfx -15.5 dB, peak -5.3
The same moment with the Compressor unticked: Sfx’s bar at -15.5 dB, Music the same.
A meter’s bar
How loud the bus is now, over the last moment of sound, about a fiftieth of a second, with its reading beside it in decibels. It is the bar that shows a Compressor at work: it is how loud the sound is held, and the Compressor holds the loud part down.
A meter’s peak tick
The loudest single moment of the last second, held there for that second, then let fall. It says how near the bus came to 0 dB, where a game clips, which is what Master’s safety watches for.

The two pictures are the same moment of the same walk: Music reads the same in both, and Sfx reads the creak some four to five decibels lower with the Compressor on. That is what the mix is for: the creak still a creak, and no longer the loudest thing in the crypt by far.

The title’s own mix

The title is a scene of its own, and a room with no mix of its own keeps the mix the game was playing. The game opens on the title, so it would open on no mix at all; but back on the title from the crypt, by the pause menu’s Title, it would keep the crypt’s, and its music would come back four decibels down, the crypt’s Gain. So the title gets its own: the same safety, and nothing else.

  1. Open title.ron. Select Title, its root, press + Add node and choose Audio Mix. Rename it mix.
  2. On Master, press + beside Slots and make it a Compressor: Threshold -1, Ratio 20, Attack 0, Release 0.1. Leave Music and Sfx with no slots.
  3. Press Ctrl+S.
The Inspector’s column, widened and narrowed to audio, on the title’s mix: Effects; Master, its one slot open, Effect Compressor, Threshold -1.0 dB, Ratio 20.0, Attack 0.000 s, Release 0.10 s, Enabled ticked; Music and Sfx, each with Slots of no items; Snapshots, Ducking and Sends with no items
The title’s mix: the safety, and no more.

Each room now opens on its own mix: the title on the title’s, the crypt on the crypt’s, and the title again on the title’s, its music the same each time.

Three sliders

The options panel, behind the title’s Options, has three sliders, master, music and sfx, as the starter built them, each with its Action of the same name: a move of the slider presses that action. Nothing listens to them yet. Each gets a script that sets its bus’s volume: the player’s, over the mix.

  1. In Assets, click Assets in the path bar, so the script is written at the project’s top, then click Create, choose New script, type master_volume and press Enter. In the Code tab, replace everything in master_volume.rgs with the script below, and press Ctrl+S.
  2. Do the same for music_volume and sfx_volume.
  3. In title.ron, select master, under options_panel’s master_row. Press Add component and choose MasterVolume. Give music MusicVolume and sfx SfxVolume the same way. Press Ctrl+S.
rgs master_volume.rgs
/// The Master slider: everything the game plays, at once. It opens where the
/// saved volume is, and sets the game's Master to it; each move the player
/// makes sets Master's volume, saves it, and ticks. The volume is the game's,
/// not the title's: it holds in the crypt, and the next time the game opens.
component MasterVolume {
    fn on_create() {
        // 0.8 until the player has chosen one, so there is room to turn it
        // up. Writing the slider moves it and presses nothing, so it opens on
        // the saved volume without a tick.
        let level = saved_number("master_volume", 0.8);
        set_number("SliderComponent", "value", level);
        set_master_volume(level);
    }

    fn loop() {
        // A drag, a click on its bar, or A and D, or the Left and Right
        // arrows, while it holds the focus moves it, and presses master on
        // that step; amount() answers where it now is.
        if pressed("master") {
            let level = amount("master");
            set_master_volume(level);
            save_number("master_volume", level);
            play_sound("tick");
        }
    }
}
rgs music_volume.rgs
/// The Music slider: the Music bus, the title's music and the crypt's. It
/// opens where the saved volume is, and sets the game's music to it; each move
/// the player makes sets the Music bus's volume, saves it, and ticks. The
/// volume is the game's, not the title's: it holds in the crypt, and the next
/// time the game opens.
component MusicVolume {
    fn on_create() {
        // 0.8 until the player has chosen one, so there is room to turn it
        // up. Writing the slider moves it and presses nothing, so it opens on
        // the saved volume without a tick.
        let level = saved_number("music_volume", 0.8);
        set_number("SliderComponent", "value", level);
        set_music_volume(level);
    }

    fn loop() {
        // A drag, a click on its bar, or A and D, or the Left and Right
        // arrows, while it holds the focus moves it, and presses music on
        // that step; amount() answers where it now is.
        if pressed("music") {
            let level = amount("music");
            set_music_volume(level);
            save_number("music_volume", level);
            play_sound("tick");
        }
    }
}
rgs sfx_volume.rgs
/// The Sfx slider: the Sfx bus, every sound that is not music, these menus'
/// clicks included. It opens where the saved volume is, and sets the game's
/// Sfx to it; each move the player makes sets the Sfx bus's volume, saves it,
/// and ticks, on Sfx too, so the tick is heard at the volume it sets. The
/// volume is the game's, not the title's: it holds in the crypt, and the next
/// time the game opens.
component SfxVolume {
    fn on_create() {
        // 0.8 until the player has chosen one, so there is room to turn it
        // up. Writing the slider moves it and presses nothing, so it opens on
        // the saved volume without a tick.
        let level = saved_number("sfx_volume", 0.8);
        set_number("SliderComponent", "value", level);
        set_sfx_volume(level);
    }

    fn loop() {
        // A drag, a click on its bar, or A and D, or the Left and Right
        // arrows, while it holds the focus moves it, and presses sfx on that
        // step; amount() answers where it now is.
        if pressed("sfx") {
            let level = amount("sfx");
            set_sfx_volume(level);
            save_number("sfx_volume", level);
            play_sound("tick");
        }
    }
}
set_master_volume, set_music_volume and set_sfx_volume
Set the game’s volume for one bus, from 0, silent, to 1, full. Each is the bus’s fader, after its chain, and it is the game’s, not a room’s: it holds through a change of scene, until a script sets it again. A volume and a mix multiply, and neither reads the other back.
saved_number
Reads a number saved under a name, as it was when the step began, or the number after the name if nothing was ever saved: here 0.8, so a slider opens with room to turn it up.
save_number
Saves a number under a name, to the game’s own saved file, where it lasts from one opening of the game to the next. It lands at the end of the step.
set_number
Writes a number onto another component of the script’s node: here the slider’s Value. Writing it moves the slider and presses nothing, so a slider opens on its saved volume without a tick.
amount
How far a slider for an action stands, in its own range: here from 0 to 1, in steps of a tenth. Asked on the step its action is pressed, it is where the player has just moved it.
pressed
Whether an action went down on this step. A slider presses its action on every step it moves: a drag, a click on its bar, or A and D while it holds the focus.
The game’s title: The Music Box in orange letters over a brown panel headed Options, with three rows, Master, Music and Sfx, each a slider; Master and Sfx at eight tenths, Music at half, outlined in orange as it holds the focus; and a Back button with Esc in its corner
The options panel, the Music slider turned down to half by A.

Clicks, blips and ticks

Each of the title’s sounds is a trigger on the Audio Source of the node that plays it: the menu’s click and blip on title_frame, the panel’s way back and its blip on options_panel, and each slider’s tick on the slider. None has a place in the room: each is on Sfx, heard the same from both ears.

  1. In title.ron, select title_frame. Press Add component and choose AudioSourceComponent. Leave Clip empty, Bus on Sfx and Volume at 1. In Spatial, untick Positional. Add a trigger click, its Clip click_001.ogg, and a trigger select, its Clip select_001.ogg.
  2. Give options_panel the same, with the triggers back, back_001.ogg, and select, select_001.ogg.
  3. Give each of master, music and sfx the same, with one trigger tick, tick_001.ogg.
  4. Replace everything in title_menu.rgs and in options.rgs with the scripts below. Press Ctrl+S.
The Inspector’s column, widened and narrowed to audio, on title_frame: AudioSourceComponent with Clip (none), Bus Sfx, Volume 1.000, Pitch 1.00, Looping and Autoplay unticked, Spatial with Positional unticked, Max Distance 512.00 dimmed and Pan 0.000, Max Voices 0; Triggers with two items: 1 click open, Name click, Clip click_001.ogg, Clips with no items, Mode Shuffle, Pitch and Volume each Min 1.00 and Max 1.00; and 2 select, shut
The menu’s Audio Source: no sound of its own, and two triggers, click and select.
NodeTriggerClipPlayed when
title_frameclickclick_001.oggPlay or Options is pressed
selectselect_001.oggthe focus moves round the menu
options_panelbackback_001.oggBack is pressed, or Escape
selectselect_001.oggthe focus moves round the panel
master, music, sfxticktick_001.oggthe slider moves
rgs title_menu.rgs
/// The title's menu: Play opens the crypt, and Options swaps this menu for the
/// options panel, whose Back swaps it back. A press clicks, and a move of the
/// focus round the menu blips: the triggers of this node's Audio Source.
component TitleMenu {
    /// Whether the menu is showing, so that it blips for its own focus moves
    /// and not for the options panel's.
    #[hidden]
    shown: bool = true,

    fn loop() {
        // A click on Play or Options, or Enter or Space while it holds the
        // focus, presses its action on the game's next step. A sound asked
        // for on the step that changes scene plays on after it.
        if pressed("play") {
            play_sound("click");
            change_scene("crypt");
        }
        if pressed("options") {
            play_sound("click");
            hide();
            shown = false;
        }
        // A click on the options panel's Back, Enter or Space while it holds
        // the focus, or Escape through its Shortcut.
        if pressed("back") {
            show();
            shown = true;
        }
        // W or S, or the Up and Down arrows, move the focus round the menu.
        if shown && (pressed("ui_up") || pressed("ui_down")) {
            play_sound("select");
        }
    }
}
rgs options.rgs
/// The options panel: hidden as the title opens, shown by the menu's Options,
/// and hidden again by its own Back, which clicks the way back. A move of the
/// focus round its sliders and Back blips. Each slider sets its own bus, by a
/// script of its own.
component Options {
    /// Whether the panel is showing, so that it blips for its own focus moves
    /// and not for the menu's.
    #[hidden]
    shown: bool = false,

    fn loop() {
        // A click on Options, or Enter or Space while it holds the focus.
        if pressed("options") {
            show();
            shown = true;
        }
        // A click on Back, Enter or Space while it holds the focus, or Escape
        // through its Shortcut.
        if pressed("back") {
            play_sound("back");
            hide();
            shown = false;
        }
        // W or S, or the Up and Down arrows, move the focus round the panel.
        if shown && (pressed("ui_up") || pressed("ui_down")) {
            play_sound("select");
        }
    }
}

The menu and the panel both hear W and S, ui_up and ui_down, whichever is showing: a hidden node’s script still runs. So each keeps a shown flag, and blips only for its own focus. #[hidden] keeps the flag out of the Inspector.

Press Run game. On the title, press S, then Enter on Options, S again to the Music slider, and A three times, the music a step quieter at each; then Escape. The game saves the slider where you leave it, and every later Run game opens on it, so leave it where you can still hear the music.

The game opened on its title, its music playing. Listen for a blip as the focus moves down to Options, a click as Options opens, a blip as the focus moves down to Music; then a tick at each press of A, the music a step quieter at each. The clip goes on past your three, to eight presses, so every step is heard: gone at the eighth. And, at seven seconds, Escape: the panel’s click for the way back.
What it sounds like

The title’s music, the Abandoned Castle loop; a short blip, a click, another blip; then eight light ticks, the music fading a step at each until it is silent; a pause; one more click.

Each sound is heard at its Volume times the game’s volumes: 1 times Sfx’s 0.8 times Master’s 0.8, 0.64 of the take as recorded. The Sfx slider’s tick is on Sfx too, and its script sets the volume before it ticks, so the tick is heard at the volume it sets. Play’s click, asked for on the step that opens the crypt, plays on into it.

Who decides what you hear

The mix

NodeComponentFieldValue
mix, under CryptAudio MixMaster slot 1Compressor: -1 dB, 20, 0 s, 0.1 s; ticked
Music slot 1Gain: -4 dB; ticked
Sfx slot 1Compressor: -15 dB, 4, 0.001 s, 0.15 s; ticked
Sfx slot 2Panner: Pan 0.5, Width 0.5; unticked
mix, under TitleAudio MixMaster slot 1Compressor: -1 dB, 20, 0 s, 0.1 s; ticked
master, music, sfxMasterVolume, MusicVolume, SfxVolumemaster_volume.rgs, music_volume.rgs, sfx_volume.rgs
Audio SourceBus, Volume, PositionalSfx, 1, unticked
trigger ticktick_001.ogg
title_frameAudio SourceBus, Volume, PositionalSfx, 1, unticked
triggers click, selectclick_001.ogg, select_001.ogg
TitleMenutitle_menu.rgs, rewritten
options_panelAudio SourceBus, Volume, PositionalSfx, 1, unticked
triggers back, selectback_001.ogg, select_001.ogg
Optionsoptions.rgs, rewritten

Check it works