Flutu Audio System
Sound data, playback and volume control on Unity's built-in audio, without middleware
Technical Audio · Unity tooling · Whitepaper · 14 min read
Unity AudioSources play clips, but variations, fades, routing and stop ownership often become scattered across scripts and prefabs.
Flutu Audio System centralizes those behaviors in sound assets, generated bank IDs, AudioManager playback and mixer VCAs, using Unity's built-in audio.
TL;DR
- 01Sounds are assetsSoundEffectSO and MusicSO define playback. Banks validate names and clips, then generate compile-time C# IDs.
- 02Two players, two contractsOneShot overlaps and cannot stop; Tracked returns a stop handle. Music handles intro, loops, outro and crossfades.
- 03Volume controls that multiplyVCAs multiply exposed mixer-group gains and release the fader to Unity snapshots at unity gain.
- 04Shared playback controlsSound assets, playback, routing and volume controls share one authoring and runtime workflow.
When every AudioSource is its own system
Footsteps randomize in a prefab, doors manage their own AudioSources and UI scripts call PlayOneShot. Each feature ends up owning different rules for variation, fades and stopping.
This duplicates logic and lets settings sliders, cutscenes and gameplay compete for mixer parameters.
The solution is clear ownership: sound definitions in assets, playback lifecycle in AudioManager and trigger decisions in game code.
Sounds as data, playback in one place
Sound assets hold variations, pitch, gain, fades, spatial settings and cooldown. Callers select an ID and optional emitter Transform.
AudioClips → SoundEffectSO / MusicSO → bank → AudioManager → Audio Mixer. VCAs scale group gain without carrying audio.
- AudioClipsVariations
- Sound assetClips + settings
- BankGenerated IDs
- AudioManagerPlays from any trigger
- Mixer groupWhere it is mixed
- VCAsVolume faders, no audio
Banks defines groups, mixers and VCAs in Resources. Editor tools generate bank assets and C# IDs; AudioManager resolves them at runtime.
Unity owns mixer effects, snapshots and AudioListener. The team owns game triggers, mix design, clip imports and settings persistence.
| Area | The package handles | The game team keeps |
|---|---|---|
| Sound definition | Asset format, Inspector, preview, validation | Clips, settings and how sounds are split into banks |
| Triggering | Components for UI buttons, UnityEvents, lifecycle and collider events, Animation Events and Timeline Signals; a code API | Which trigger to use and where; gameplay logic; keeping the handle of a Tracked sound to stop it |
| Mixing | Routing to the sound's or bank's group; VCA gain and fades | Mixer design, effects, snapshots and exposing group volumes |
| Player settings | Applying VCA values while the game runs | Saving settings and setting the VCAs on startup |
| Memory and loading | Loading a bank asset from Resources when a sound is requested by bank and ID | Clip import settings (load type, compression) and the memory budget |
Authoring: sounds, banks and generated IDs
Create Sound Effect From Selected Clips builds one asset with naturally sorted variations and a suggested shared name; Per Selected Clip creates separate assets.
Sound effect settings
| Setting | Values | Behavior |
|---|---|---|
| Bank / ID | A bank declared in Banks; an ID of letters, digits and underscores | The ID is unique inside its bank. At runtime a sound is found by bank and ID together. |
| Output Group | A mixer group, or empty | Empty plays through the bank's default group. |
| Clips | One or more variations | Random or Sequential selection. |
| Never Repeat Last | On or off, with a history count (minimum 1) | Random selection avoids the last picks. The count is capped at the number of clips minus one. |
| Playback Mode | OneShot or Tracked | OneShot cannot be stopped. Tracked can be stopped and can loop. |
| Volume Range | 0 to 1 | A random linear value inside the range on every play. |
| Pitch Range | -12 to +12 semitones | A random whole number of semitones on every play, converted to a pitch ratio. |
| Fade In / Fade Out | Seconds and a curve | Curves: Linear, EaseOut, SmoothStep (default) and Logarithmic. |
| Spatial Blend | 0 (2D) to 1 (3D) | A constant value per sound. |
| Doppler, spread, stereo pan, reverb zone mix | A constant, or a curve over the clip's duration | Curves are evaluated every frame against the clip's playback position. |
| Min / Max Distance | Defaults 1 and 50 | Passed to the AudioSource. |
| Rolloff | Linear (default), Logarithmic or a custom curve | Passed to the AudioSource. |
| Priority | 0 to 256, default 128 | Unity's source priority, used when the engine runs out of real voices. |
| Cooldown | Seconds | Minimum time between two plays of the same asset. |
Music settings
| Setting | Behavior |
|---|---|
| Intro | Plays once at the start. Only used when Resume Mode is FromStart. |
| Clips | The loop section. Clips play one after another, in Random or Sequential order. |
| Loop | On: clips keep cycling until Stop. Off: the music plays as many clips as the list holds, then the outro, or it ends. |
| Outro | Plays when Stop is called, or after the last clip when Loop is off. |
| Gain | A trim in dB for the loop clips, from -50 dB to 0 dB. Separate intro and outro trims are added to it. |
| Crossfade Time / Fade Curve | Used when this music fades in from silence or crossfades in from another music. Default 1 second, SmoothStep. |
| Resume Mode | FromStart; RandomStart, which begins on a random position in the clip list; Resume, which returns to the saved position in the current clip. |
| Spatial settings | The same fields as sound effects. Music can also follow an emitter. |
Banks and generated IDs
Rebuild Banks (F7) validates banks and emits bank assets, per-bank ID constants and a bank-name class. Mistyped constants fail compilation.
Validation is atomic: any invalid name, ID or clip blocks all writes and reports the affected asset in Console.
| Check | Rule |
|---|---|
| Clip slots | No sound has an empty clip slot. |
| Bank assignment | Every sound points to a bank declared in Banks. |
| ID format | Starts with a letter or underscore; contains only letters, digits and underscores. |
| Reserved words | Not a C# keyword, and not "all", which the generated scripts reserve. |
| Duplicate IDs | No two sounds share an ID inside the same bank. |
| Bank names | Same format rules; no two names that differ only in case; no clash with the generated bank list class. |
| Class name clashes | An ID cannot equal the name of its bank's generated ID class. |
A preview lists changed and obsolete files. New files are written before old ones are deleted.
ID renames require confirmation; broken bank or sound references remain visible in red. Name collisions receive distinct IDs (HIT, HIT_2).
Editor tools
| Tool | Purpose |
|---|---|
| Rebuild Banks (F7) | Validate, then regenerate banks and ID classes. |
| Create Default Mixer | Copy a template mixer into the project, route each bank to it and create the default VCAs. |
| Add SFX Bank / Add Music Bank | Add a bank name and rebuild. |
| Bank Viewer | List banks and sounds with preview; set the log level. |
| Audio SO Scanner | Show where each sound is used in scenes, prefabs and banks; list unused sounds and output groups. |
| Audio Events Folder Tree | Browse sounds by folder, preview and edit them in place. |
| UI Button Sound Manager | Find Buttons in open scenes and prefabs that have no click sound component and add it. |
| Open Audio Workspace | Open the tools above as tabs, plus the Audio Mixer. |
Inspector preview works without Play Mode; multi-edit changes only selected settings.
The default mixer exposes Master, Music, SFX, Voice, Gameplay, UI and Ambience at 0 dB, without prescribing the final mix.
Playback runtime
One persistent AudioManager owns both players. Play reports failures; CanPlay and CanStop expose the same failure reasons in advance.
Sound effects: pooled sources and emitters
Non-emitter sounds use ObjectPool: default capacity 8, up to 32 idle sources. It expands as needed, warns above 8 active and leaves voice limits to Unity.
With an emitter, child AudioSources follow its Transform and are reused locally; destroying the emitter ends their playback.
| Behavior | OneShot | Tracked |
|---|---|---|
| Can be stopped | No | Yes, with its fade out |
| Can loop | No | Yes |
| Simultaneous plays of the same asset | Yes, limited only by cooldown | One at a time; a second Play returns false while the first is active |
| Handle | Not needed | Play returns an instance to pass to Stop |
| Typical use | Clicks, impacts, footsteps | Engine loops, ambience beds, long sounds that need a fade out |
Every play gets an ownership ID. Stop, fades and per-frame cleanup must match it, preventing stale handles from affecting reused sources.
SFX fades use unscaled time, independent of timeScale.
Clip selection
Sequential wraps; Random can exclude recent picks. History is capped at clip count minus one, so two clips alternate. Selection state is shared per asset.
Music: segments, crossfades and resume
Two AudioSources handle the current and outgoing music. Intro, loop clips and outro use the incoming track's crossfade settings.
Play on another music crossfades from any segment.
| Request | System behavior |
|---|---|
| Play while idle | Starts with the intro (FromStart) or with the loop clips, fading in over the music's crossfade time. |
| Play another music | Crossfades: the outgoing track fades out while the new one fades in. |
| Play during a crossfade | The request waits. The latest request wins and starts when the current crossfade ends. |
| Play the music already playing | Returns false and the music continues. During its outro, Play brings it back. |
| Stop, music has an outro | The outro starts immediately. A second Stop does not restart it. |
| Stop, music has no outro | Fades out over 1 second with SmoothStep. |
| Pause / Resume | Freezes clips and fades, including the outgoing track during a crossfade. The position is saved for Resume mode. |
| Play or Stop while paused | Leaves the paused state. The paused track fades out silently. |
| Emitter destroyed | Ends the music. A music waiting for the crossfade still starts. |
Music segments advance on an unscaled frame clock, including during fades. Beat-locked stems require DSP scheduling, which this player does not provide.
Resume positions persist in memory per music asset, not on disk.
How sounds end
| Pattern | Ends when | Cleanup |
|---|---|---|
| OneShot from the pool | The clip finishes | The source returns to the pool on the next cleanup pass |
| Tracked from the pool | Stop is called, or a non-looping clip finishes | Fade out if set, then the source returns to the pool |
| Any sound on an emitter | As above, or the emitter is destroyed | The source is disabled and stays on the emitter for reuse, or is destroyed with it |
| Trigger component | Its configured stop event: Start, OnEnable, OnDisable, OnDestroy or collider exit | Calls Stop on the instance it started; OneShot sounds ignore it |
| Music | Stop, the end of the clip list with Loop off, or a destroyed emitter | Outro if present, otherwise a fade out; sources are released |
For a broader look at trigger ownership and playback lifecycles, read Sound Call Models.
Triggers, routing and VCAs
Six ways to trigger a sound
| Option | Component or API | Use it for | Code needed |
|---|---|---|---|
| UI button | UIButtonSound | A click sound on a Button | No |
| Event component | SoundEffectEvent or MusicEvent | Any UnityEvent: OnClick, toggles, sliders, custom events | No |
| Automatic trigger | SoundEffectEventTrigger or MusicEventTrigger | Play or stop on Start, OnEnable, OnDisable, OnDestroy, or on entering and leaving a trigger collider (3D or 2D, filtered by tag, default Player) | No |
| Animation Event | An event component on the object that has the Animator | A sound on an animation frame | No |
| Timeline Signal | A Signal Receiver calling the event component | Cutscenes and sequences | No |
| Code | soundEffectPlayer.Play or musicPlayer.Play on the AudioManager | Gameplay logic | One line |
Triggers accept an optional 3D emitter. Use one Animation Event component per object to avoid duplicate callbacks; Timeline Signal Receiver selects reactions from a list.
Routing
Routing priority: sound Output Group → bank default → AudioListener. The Banks inspector can clear redundant per-sound overrides.
VCAs
VCAs scale exposed mixer-group Volumes without carrying audio. AudioManager.SetVcaVolume accepts gain 0–1 and optional fade; defaults cover Master, Music, SFX and Voice.
| Rule | Behavior |
|---|---|
| Relative to the mix | The gain is applied in dB on top of the level the mixer had before the first override. 1 keeps that level, 0.5 is about 6 dB below, 0.1 is 20 dB below, 0 is -80 dB. |
| VCAs multiply | A group in several VCAs gets the product of their gains: Music at 0.5 and Cutscene at 0.3 give 0.15. |
| Hand back at full volume | When every VCA on a group is at 1 and unmuted, the override is cleared and the mixer, including its snapshots, controls the fader again. |
| Mute | Sets the gain to 0 and keeps the volume for unmute. |
| Fades | Linear in gain, in unscaled time, so they continue while timeScale is 0. |
| Startup | Values set during Awake are applied again when the AudioManager starts, because the mixer can ignore them before it initializes. |
| Persistence | None. The game stores player settings and sets the VCAs on startup. |
| Requirement | Only groups with an exposed Volume can be assigned to a VCA. |
At unity gain, releasing the exposed Volume returns control to Unity snapshots.
Technical contracts and boundaries
Four contracts define the boundary between authoring, runtime, mixing and gameplay.
- Authoring and playback
- Sound assets and validated IDs define behavior; players and triggers execute it.
- Runtime ownership
- AudioManager owns sources and transitions; gameplay owns timing; Unity owns the mix and voice budget.
- Defined capabilities
- Sound data, playback, routing and gain.
- Profiling requirements
- CPU, memory and voice cost depend on content and hardware; profile representative scenes.
Integration requirements
Unity voice budget and runtime cost
Unity handles voice limits and priority. AudioManager bookkeeping and spatial curves scale with active sounds.
Banks in Resources
Bank assets load on request; no bank unload or streaming. Clip import settings determine memory use.
Parameter-driven behavior
Parameter-driven switches, blends and nested containers require custom logic or middleware.
Editor separation and platform checks
Editor code stays out of player builds. Unity 6.3 LTS or later; profile and validate each target device.
Design principles behind Flutu Audio System
Five engineering decisions make the system predictable.
- 01Define sound assets
Move variations, fades, routing and cooldown out of call sites.
- 02Separate stop contracts
OneShot overlaps; Tracked owns a handle and one active play per asset.
- 03Validate and generate IDs
Reject invalid bank names, collisions and clip slots before generating C#.
- 04Protect reused AudioSources
Use per-play IDs so stale handles cannot stop new playback.
- 05Control mix without fighting snapshots
Route by bank, multiply VCA gains and release Volume overrides at unity gain.
Validate the contracts with a focused test scene.
| Test case | Expected result |
|---|---|
| The same Tracked loop requested on two emitters | The second Play returns false with a reason |
| A OneShot played twice inside its cooldown | The second Play returns false |
| Stop called on an old handle after its source was reused | Returns false; the other sound keeps playing |
| An emitter destroyed while its sound plays | No errors; the instance is released |
| Music B requested during a crossfade from A, then music C | When the first crossfade ends, B crossfades to C |
| Pause, then Play another music | The paused track fades out silently and the new music fades in |
| Music VCA at 0.5 and Cutscene VCA at 0.3 on the same group | The group sits about 16.5 dB below its designed level, and returns to the mixer's value when both are back at 1 |
| Rebuild Banks with a duplicate ID | Nothing is written; both assets are listed in the Console |
| A music with Loop off and an outro | After the last clip the outro plays, then the player returns to idle |
These cases check ownership, transitions, IDs and VCAs.
Questions We Can Answer
Why put sound behavior in assets rather than gameplay scripts?
Assets hold variation, fades, routing and cooldown; triggers call stable IDs.
The same definition works across UI, animations, gameplay and Timeline.
Gameplay decides when to play; AudioManager owns the lifecycle.
How can a Unity project get FMOD-style VCAs without middleware?
Expose mixer-group Volume. AudioManager.SetVcaVolume multiplies VCA gains against the original level; at unity gain, the override is cleared so snapshots regain control.
What is the difference between OneShot and Tracked sounds?
OneShot can overlap but cannot stop or loop. Tracked returns a handle, supports loops and fade-out, and permits one active play per asset.
Why generate sound IDs as C# constants?
Generated constants catch bad IDs at compile time. Validation prevents invalid C#; intentional ID renames break references.
How does the music player handle intro, loop and outro?
Music supports optional intro/outro, loop clips, crossfades and FromStart, RandomStart or Resume modes.
References
- Unity Technologies. AudioMixer.SetFloat, Unity 6.0 Scripting API. Documents exposed mixer parameters and snapshot interactions.