Skip to content

SpatialAudioPlayer3D

A drop-in replacement for AudioStreamPlayer3D that adds distance falloff, room reverb, wall occlusion, air absorption and sound speed delay.

Inherits: AudioStreamPlayer3D
Script: addons/spatial_audio_extended/spatial_audio_player_3d.gd

Each player makes its own audio bus with a reverb and a lowpass filter, and sends it to the bus you set in bus. Every update_frequency seconds it casts rays to measure the room and find walls, then eases the reverb, filter and volume toward the new values. Distance falloff, panning and air absorption follow the listener every frame.

The Inspector hides settings that don't apply: turn a feature off and its settings disappear.

Enums

RayDistribution

How the room rays are spread around the source.

Value Rays
CLASSIC 10 fixed directions: the sides, the diagonals, up and down. Cheapest and predictable
FIBONACCI_SPHERE Spread evenly over a sphere. Better in odd-shaped rooms, and can bounce
SHAPE_SCATTER Cast outward from a shape you choose. For large or irregular sources

AttenuationFunction

The shape of the fade between the inner radius and the outer edge.

Value Fade
LINEAR Steady drop with distance
LOGARITHMIC Drops quickly near the source, then tails off slowly
INVERSE Like Logarithmic but stronger: only loud up close
LOG_REVERSE Stays loud, then drops sharply near the edge
NATURAL_SOUND Between Logarithmic and Inverse, closest to real life
USER_DEFINED Your own Curve in user_attenuation_curve

Properties

Ray Distribution

Property Type Default Description
ray_distribution RayDistribution CLASSIC How the room rays are spread
fibonacci_ray_count int, 4 to 128 8 Rays in Fibonacci Sphere mode. More is more accurate and costs more
fibonacci_ray_reflections int, 0 to 8 0 Bounces per ray in Fibonacci Sphere mode. Helps in L-shaped rooms and corridors
scatter_shape Node3D none The shape rays come from in Shape Scatter mode
shape_ray_count int, 1 to 256 32 Rays in Shape Scatter mode
shape_scatter_randomness int, 0 to 50 0 0 casts straight out from the shape, 50 is fully random
max_raycast_distance float, m 50 How far every ray reaches. Keep it close to max_distance. Can be changed while the scene runs

Room Size Reverb

Property Type Default Description
room_size_reverb bool on Sets the reverb from the room around the source
max_reverb_wetness float, 0 to 1 0.5 The most reverb any room can add
surface_absorption bool on Lets the materials the rays hit change the reverb
absorption_wetness_influence float, 0 to 2 1 How much absorption lowers the reverb level
absorption_damping_influence float, 0 to 2 1 How much high-band absorption dulls the reverb
absorption_bass_influence float, 0 to 2 1 How much low-band absorption thins out the reverb's bass
ignore_floor bool off Leaves downward rays out, so the floor doesn't make the room seem small
floor_angle_threshold float, 5 to 90° 30 How close to straight down a ray must be to count as a floor ray
reverb_collision_mask physics layers 1 The layers room rays hit. Can be changed while the scene runs

Occlusion

Property Type Default Description
audio_occlusion bool on Muffles the sound when walls are in the way
occlusion_strength float, 0 to 5 1 How strongly walls muffle. Above 1 pushes toward 20 Hz
max_occlusion_hits int, 1 to 16 4 The most walls counted. Each one muffles more, by how little sound its material lets through
fallback_transmission float, 0 to 1 0.03 How much sound passes through surfaces with no AcousticBody
occlusion_volume_strength float, 0 to 1 0.35 How much walls lower the volume, on top of the muffling
max_occlusion_volume_reduction float, 0 to 60 dB 18 The most walls can lower the volume, so many walls don't mean silence. Soundproof materials ignore this
occlusion_collision_mask physics layers 1 The layers the ray to the listener hits
ignore_listener_body bool on Leaves the first CharacterBody3D above the camera out of occlusion

Attenuation

Property Type Default Description
enable_volume_attenuation bool on Uses this falloff instead of Godot's. Turning it off while the scene runs brings back your attenuation_model
inner_radius float, m 2 Full volume inside this distance
falloff_distance float, m 20 How far past the inner radius the sound fades to silence
attenuation_function AttenuationFunction LINEAR The shape of the fade
user_attenuation_curve Curve none Used with USER_DEFINED. X is distance through the fade (0 to 1), Y is volume (1 to 0)
inner_radius_panning_strength float, 0 to 2 1 Panning inside the inner radius. 0 is centred, 1 is normal, 2 is exaggerated

Air Absorption

Property Type Default Description
enable_air_absorption bool off Rolls off high frequencies with distance
air_absorption_min_distance float, m 2 Where the roll-off starts
air_absorption_max_distance float, m 100 Where it's strongest
air_absorption_cutoff_freq_min int, Hz 20000 The filter cutoff at the minimum distance
air_absorption_cutoff_freq_max int, Hz 4000 The filter cutoff at the maximum distance
air_absorption_log_frequency_scaling bool on Moves the cutoff on a log scale, which sounds more even

Sound Speed Delay

Property Type Default Description
enable_sound_delay bool off Makes play_with_delay() wait distance / speed_of_sound seconds
speed_of_sound float, 10 to 2000 m/s 343 Lower values make the delay longer

Advanced

Property Type Default Description
minimum_volume_db float, dB -80 The quietest the sound gets, and where autoplay fades in from
autoplay_fade_in bool on With autoplay, starts silent and fades in after the first room scan
autoplay_fade_in_speed float, 0.1 to 40 6 How fast the autoplay fade-in is
lerp_speed float, 1 to 20 15 How fast reverb, filter and volume move to new values. Higher is snappier
custom_listener_target Node3D none Listens from this node instead of the active camera
occluded_lowpass_cutoff_minimum int, Hz 600 The filter cutoff when fully blocked
open_lowpass_cutoff int, Hz 20000 The filter cutoff with a clear line to the listener
update_frequency float, 0.01 to 1 s 0.2 How often the room is re-scanned. Raise it for sounds that don't move
update_only_while_playing bool off Stops scanning while the sound isn't playing, and scans straight away when it starts. Zone and distance signals pause too
audio_bus_prefix String SpatialBus The start of the name of the bus each player makes
effects_enabled bool on Turns spatial effects on and off. This sets global_effects_disabled, so it affects every player

Debug

Property Type Default Description
debug_draw_rays bool off Draws the rays in game. Blue for room rays, green for a clear line, red for blocked or open air
debug_draw_radius bool off Draws the inner (cyan) and outer (orange) spheres in game
debug_draw_playing_state bool off A sphere on the source: green playing, yellow delayed, red stopped
display_debug_info bool off Shows the debug panel while you're in range, playing or not
debug_toggle_effects_key Key F1 Turns effects off and on while the panel shows
debug_toggle_shapes_key Key F2 Turns ray and radius drawing off and on together while the panel shows
debug_toggle_details_key Key F3 Shows or hides the panel details while the panel shows
debug_accent_color Color light blue Colour of the panel's accent bar, level bar and the line to the sound

See Debug tools.

Inherited properties

Property Notes
volume_db Set by the player every frame. Changing it does nothing
max_db The loudest the sound gets. Use this to set its volume
max_distance Godot's hearing range. Set it at least as far as max_raycast_distance
unit_size Not used while enable_volume_attenuation is on
attenuation_model Set to disabled while enable_volume_attenuation is on, and put back when it's turned off
bus The bus the player's own bus sends to. Changing it while the scene runs re-routes the player's bus

Methods

play_with_delay(from_position: float = 0.0) -> void

Plays the sound after distance / speed_of_sound seconds when enable_sound_delay is on, and straight away when it's off. Calling it again before a delayed sound starts cancels the first one. Emits spatial_audio_playback_started when the sound starts, with or without a delay.

play() still works as usual and always plays straight away.

stop() -> void

Stops the sound and emits spatial_audio_playback_stopped. A play_with_delay() that's still waiting is cancelled.

is_delay_pending() -> bool

Whether a play_with_delay() call is still waiting for its sound to arrive.

get_spatial_bus_name() -> String

The name of the audio bus the player made for itself. Empty in the editor and before the scene runs.

var idx := AudioServer.get_bus_index($Radio.get_spatial_bus_name())

static set_global_effects_disabled(disabled: bool) -> void

Turns spatial effects off, or back on, for every SpatialAudioPlayer3D at once.

SpatialAudioPlayer3D.set_global_effects_disabled(true)

Methods for other systems

SpatialReflectionNavigationAgent3D uses these to work with the player. You can call them from your own systems too.

Method Does
set_external_volume_db_offset(offset_db: float) Adds a volume change on top of the player's own
get_external_volume_db_offset() -> float Returns that change
clear_external_volume_db_offset() Resets it to 0
set_external_distance(distance: float) Uses this distance for volume, air absorption, panning and range instead of the straight line. The agent passes the route length
clear_external_distance() Goes back to the straight-line distance
has_external_distance() -> bool Whether a distance is set
get_listener_distance() -> float The distance the player uses: the set one, or the straight line. -1 with no listener
set_external_lowpass(cutoff_hz: float) Adds a lowpass on top of the player's own filters. 0 or 20000 removes it
request_full_update() Runs the full update on the next physics frame instead of waiting for update_frequency
set_external_occlusion_hold(seconds: float) Holds occlusion open for a moment, to smooth a jump in position
clear_external_occlusion_hold() Ends the hold early
is_external_occlusion_held() -> bool Whether a hold is active
set_external_navigation_debug_data(active: bool, info: Dictionary = {}) Shows your data in the debug panel's Route section
clear_external_navigation_debug_data() Removes it

Static variables

Variable Type Description
global_effects_disabled bool When on, every player skips reverb, occlusion and air absorption

Signals

See the Signals reference.