AudioStreamPlayer3D¶
Inherits: Spatial < Node < Object
Plays positional sound in 3D space.
Description¶
Plays a sound effect with directed sound effects, dampens with distance if needed, generates effect of hearable position in space. For greater realism, a low-pass filter is automatically applied to distant sounds. This can be disabled by setting attenuation_filter_cutoff_hz to 20500
.
By default, audio is heard from the camera position. This can be changed by adding a Listener node to the scene and enabling it by calling Listener.make_current on it.
See also AudioStreamPlayer to play a sound non-positionally.
Note: Hiding an AudioStreamPlayer3D node does not disable its audio output. To temporarily disable an AudioStreamPlayer3D's audio output, set unit_db to a very low value like -100
(which isn't audible to human hearing).
Tutorials¶
Properties¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Methods¶
void |
|
void |
|
void |
stop ( ) |
Signals¶
finished ( )
Emitted when the audio stops playing.
Enumerations¶
enum AttenuationModel:
AttenuationModel ATTENUATION_INVERSE_DISTANCE = 0
Linear dampening of loudness according to distance.
AttenuationModel ATTENUATION_INVERSE_SQUARE_DISTANCE = 1
Squared dampening of loudness according to distance.
AttenuationModel ATTENUATION_LOGARITHMIC = 2
Logarithmic dampening of loudness according to distance.
AttenuationModel ATTENUATION_DISABLED = 3
No dampening of loudness according to distance. The sound will still be heard positionally, unlike an AudioStreamPlayer. ATTENUATION_DISABLED can be combined with a max_distance value greater than 0.0
to achieve linear attenuation clamped to a sphere of a defined size.
enum OutOfRangeMode:
OutOfRangeMode OUT_OF_RANGE_MIX = 0
Mix this audio in, even when it's out of range. This increases CPU usage, but keeps the sound playing at the correct position if the camera leaves and enters the AudioStreamPlayer3D's max_distance radius.
OutOfRangeMode OUT_OF_RANGE_PAUSE = 1
Pause this audio when it gets out of range. This decreases CPU usage, but will cause the sound to restart if the camera leaves and enters the AudioStreamPlayer3D's max_distance radius.
enum DopplerTracking:
DopplerTracking DOPPLER_TRACKING_DISABLED = 0
Disables doppler tracking.
DopplerTracking DOPPLER_TRACKING_IDLE_STEP = 1
Executes doppler tracking in idle step (every rendered frame).
DopplerTracking DOPPLER_TRACKING_PHYSICS_STEP = 2
Executes doppler tracking in physics step (every simulated physics frame).
Property Descriptions¶
int area_mask = 1
Determines which Area layers affect the sound for reverb and audio bus effects. Areas can be used to redirect AudioStreams so that they play in a certain audio bus. An example of how you might use this is making a "water" area so that sounds played in the water are redirected through an audio bus to make them sound like they are being played underwater.
float attenuation_filter_cutoff_hz = 5000.0
Dampens audio using a low-pass filter above this frequency, in Hz. To disable the dampening effect entirely, set this to 20500
as this frequency is above the human hearing limit.
float attenuation_filter_db = -24.0
Amount how much the filter affects the loudness, in decibels.
AttenuationModel attenuation_model = 0
void set_attenuation_model ( AttenuationModel value )
AttenuationModel get_attenuation_model ( )
Decides if audio should get quieter with distance linearly, quadratically, logarithmically, or not be affected by distance, effectively disabling attenuation.
bool autoplay = false
If true
, audio plays when the AudioStreamPlayer3D node is added to scene tree.
String bus = "Master"
The bus on which this audio is playing.
Note: When setting this property, keep in mind that no validation is performed to see if the given name matches an existing bus. This is because audio bus layouts might be loaded after this property is set. If this given name can't be resolved at runtime, it will fall back to "Master"
.
DopplerTracking doppler_tracking = 0
void set_doppler_tracking ( DopplerTracking value )
DopplerTracking get_doppler_tracking ( )
Decides in which step the Doppler effect should be calculated.
Note: Only effective if the current Camera's Camera.doppler_tracking property is set to a value other than Camera.DOPPLER_TRACKING_DISABLED.
float emission_angle_degrees = 45.0
The angle in which the audio reaches cameras undampened.
bool emission_angle_enabled = false
If true
, the audio should be dampened according to the direction of the sound.
float emission_angle_filter_attenuation_db = -12.0
void set_emission_angle_filter_attenuation_db ( float value )
float get_emission_angle_filter_attenuation_db ( )
Dampens audio if camera is outside of emission_angle_degrees and emission_angle_enabled is set by this factor, in decibels.
float max_db = 3.0
Sets the absolute maximum of the soundlevel, in decibels.
float max_distance = 0.0
Sets the distance from which the out_of_range_mode takes effect. Has no effect if set to 0.
OutOfRangeMode out_of_range_mode = 0
void set_out_of_range_mode ( OutOfRangeMode value )
OutOfRangeMode get_out_of_range_mode ( )
Decides if audio should pause when source is outside of max_distance range.
float panning_strength = 1.0
Scales the panning strength for this node by multiplying the base ProjectSettings.audio/3d_panning_strength with this factor. Higher values will pan audio from left to right more dramatically than lower values.
float pitch_scale = 1.0
The pitch and the tempo of the audio, as a multiplier of the audio sample's sample rate.
bool playing = false
bool is_playing ( )
If true
, audio is playing.
AudioStream stream
void set_stream ( AudioStream value )
AudioStream get_stream ( )
The AudioStream resource to be played.
bool stream_paused = false
If true
, the playback is paused. You can resume it by setting stream_paused to false
.
float unit_db = 0.0
The base sound level unaffected by dampening, in decibels.
float unit_size = 1.0
The factor for the attenuation effect. Higher values make the sound audible over a larger distance.
Method Descriptions¶
float get_playback_position ( )
Returns the position in the AudioStream.
AudioStreamPlayback get_stream_playback ( )
Returns the AudioStreamPlayback object associated with this AudioStreamPlayer3D.
void play ( float from_position=0.0 )
Plays the audio from the given position from_position
, in seconds.
void seek ( float to_position )
Sets the position from which audio will be played, in seconds.
void stop ( )
Stops the audio.