MrxSoundCategories
Module: mrxsoundcategories.lua
Overview
The MrxSoundCategories module manages audio ducking, fading, and pitch adjustments for different sound categories in the game. It provides functions to set fade levels, apply fades, manage pitch settings, and handle master volume ducks.
Inheritance
- Inherits from:
none — base/utility module - Imports:
none
Instance pattern
This is a stateless manager utility module (no per-instance tables). All the real work is thin wrappers over the engine Sound namespace (Sound.FadeCategoryDown/Up, Sound.PitchCategoryActivate/Deactivate, Sound.SetMasterVolume). It tracks these key fields:
_tFadeSettings: Fade settings keyed by mode, then category. Pre-declared with these empty mode buckets (each is{}until populated):vosequence,credits,actionhijack,survivalmode,fanfare,satelliteview. IndexingFade/SetFadeCategorywith any other mode string errors (see gotcha below)._tPitchSettings: Pitch settings keyed by mode, then category. Pre-declares only one bucket:survivalmode._bDuckOnGlobalTableLoad: A boolean flag indicating whether to duck the master volume when the sound database loads._nMasterVolumeRefCount: A reference count for managing master volume ducks.
Functions
SetFadeCategory(sMode, sCategory, fLevel, fEnterLength, fExitLength)
Sets the fade settings for a specific category in a given mode. The settings include the fade level and enter/exit lengths.
Fade(sMode, bDown)
Applies fades to all categories in the specified mode. If bDown is true, it applies a fade down; otherwise, it applies a fade up.
_AdditionalFadeSetup()
Registers the two credits-roll fades: SetFadeCategory("credits", "sfx", 0, 0.5, 0.5) and SetFadeCategory("credits", "vo", 0, 0.5, 0.5) — i.e. fade sfx and vo to level 0 over 0.5s on enter and 0.5s on exit. Called once from MrxSound.Initialize. This is the model for registering your own mode’s categories before you Fade(...) them.
SetPitchCategory(sMode, sCategory, fLevel, fEnterLength, fExitLength)
Sets the pitch settings for a specific category in a given mode. The settings include the pitch level and enter/exit lengths.
Pitch(sMode, bDown)
Applies pitch adjustments to all categories in the specified mode. If bDown is true, it activates the pitch adjustment; otherwise, it deactivates it.
SetDuckOnGlobalTableLoad(bDuck)
Sets a flag indicating whether to duck the master volume when the sound database loads.
_DuckGlobalTable()
Ducks the master volume to 0 over 0.3 seconds if the global table load ducking is enabled.
DuckMasterVolume(fLength)
Ref-counted function to duck the master volume over a specified length of time.
UnduckMasterVolume(fLength)
Ref-counted function to unduck the master volume over a specified length of time.
Events
No Event.* references anywhere in this file — this module is not event-driven. _AdditionalFadeSetup and _DuckGlobalTable are plain functions (note the leading underscore, this codebase’s usual “internal/private” convention), called directly by whatever other script wants this behavior — there are no call sites for either inside this file itself, so triggering is entirely external (no call sites found in the decompiled corpus for either from this side).
Notes for modders
- Use
SetFadeCategoryandFadeto manage audio fades for different categories and modes. - Customize pitch adjustments using
SetPitchCategoryandPitch. - Control master volume ducks with
SetDuckOnGlobalTableLoad,DuckMasterVolume, andUnduckMasterVolume. - Be aware that the master volume ducking is ref-counted to ensure proper state management — call
DuckMasterVolume/UnduckMasterVolumein matched pairs, or the ref count drifts and the volume never restores. Fade/Pitchiterate_tFadeSettings[sMode]/_tPitchSettings[sMode]withpairs()— ifsModewas never registered viaSetFadeCategory/SetPitchCategory(or via the module’s own_tFadeSettings/_tPitchSettingstable literals, which only pre-declarevosequence,credits,actionhijack,survivalmode,fanfare,satelliteviewfor fade andsurvivalmodefor pitch), indexing_tFadeSettings[sMode]with an unknown mode returnsniland thepairs(nil)call errors.