Audio (4.7)
Headless runs use the Dummy audio driver, so code paths execute but nothing is heard. Ask the user to listen.
Bus layout (default_bus_layout.tres)
Master ← Music, SFX (← UI, Footsteps), Voice, Ambience. Players pick a bus (bus = &"SFX"). Put effects on buses, not per player: Reverb on an SFX_Reverb bus fed by sends, a Compressor on Music with a voice sidechain (ducking), and AudioEffectHardLimiter on Master (AudioEffectLimiter is deprecated).
Code: AudioServer.get_bus_index(&"Music"), set_bus_volume_linear(i, 0.8) (4.4+; use it for sliders), set_bus_volume_db, set_bus_mute, add_bus_effect and set_bus_effect_enabled.
Settings sliders should be linear 0..1. linear_to_db()/db_to_linear() convert when needed. Never put dB on a slider directly.
Players
AudioStreamPlayer(UI and music),AudioStreamPlayer2DandAudioStreamPlayer3D(positional).volume_linearexists too.- Overlapping SFX (gunshots, footsteps): raise
max_polyphonyon one player instead of spawning players. UseAudioStreamRandomizer(random pitch in semitones, 4.7random_pitch_semitones, random volume, several variations) as the stream. - Fire and forget: spawn a player,
play(), thenfinished.connect(queue_free). Pool them for heavy use (see the reference). - 3D: tune
unit_sizeandmax_distance,attenuation_model(inverse, inverse square, log, disabled),attenuation_filter_cutoff_hz(muffles distance),doppler_trackingon the player and theAudioListener3D/camera, andpanning_strength. Reverb zones:Area3D.reverb_bus_enabled+reverb_bus_name, oraudio_bus_override. - 4.7 change:
AudioStreamPlayer2D/3D.area_maskdefaults to 0. If you rely on Area bus overrides, set the mask to the areas' layer.
Music systems (no code-side crossfading hacks)
AudioStreamInteractive: clips (intro, explore, combat, boss) plus transition rules (add_transition(from, to, from_time, to_time, fade_mode, fade_beats, …)) with beat- or bar-synced switches. Switch at runtime with(player.get_stream_playback() as AudioStreamPlaybackInteractive).switch_to_clip_by_name(&"combat"). Set BPM, beat count and bar beats on the imported Ogg/WAV for musical timing.AudioStreamSynchronized: layered stems that play in sync. Fade layers withset_sync_stream_volume(i, db)(vertical layering).AudioStreamPlaylist: sequential or shuffled tracks with fades.- Keep music on its own player under the
Musicbus. Setprocess_mode = PROCESS_MODE_ALWAYSif it should keep playing in pause menus.
Import
Use Ogg Vorbis for music and long ambience (streamed) and WAV for short SFX (low latency). Set loops in the Import dock (loop for Ogg, edit/loop_mode for WAV) instead of in code. Trim silence on import for snappy SFX.
Procedural and analysis
AudioStreamGenerator+push_frame()/push_buffer()in_process, for synths and retro beeps.AudioEffectCaptureon a bus records or streams audio.AudioEffectSpectrumAnalyzer+get_magnitude_for_frequency_rangemakes visualizers.- Microphone:
AudioStreamMicrophoneneedsaudio/driver/enable_input = trueand OS permission on mobile.
Web and mobile
- Web: browsers block audio until the first user input, so start music after a click or tap. The default playback type can be set to Sample (
audio/general/default_playback_type, experimental) for lower latency on web. - Mobile: keep simultaneous voices low. Pause audio on
NOTIFICATION_APPLICATION_PAUSED.
Bus volume settings, SFX pool, adaptive music controller, procedural beep (compiled by the tests): references/patterns.md


