AudioStreamPlayer3D

Inherits: Spatial < Node < Object

Plays 3D 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.

Tutorials

Properties

intarea_mask1
floatattenuation_filter_cutoff_hz5000.0
floatattenuation_filter_db-24.0
AttenuationModelattenuation_model0
boolautoplayfalse
Stringbus“Master”
DopplerTrackingdoppler_tracking0
floatemission_angle_degrees45.0
boolemission_angle_enabledfalse
floatemission_angle_filter_attenuation_db-12.0
floatmax_db3.0
floatmax_distance0.0
OutOfRangeModeout_of_range_mode0
floatpitch_scale1.0
boolplayingfalse
AudioStreamstream 
boolstream_pausedfalse
floatunit_db0.0
floatunit_size1.0

Methods

floatget_playback_position ( )
AudioStreamPlaybackget_stream_playback ( )
voidplay ( float from_position=0.0 )
voidseek ( float to_position )
voidstop ( )

Signals

  • finished ( )

Emitted when the audio stops playing.

Enumerations

enum AttenuationModel:

  • ATTENUATION_INVERSE_DISTANCE = 0 —- Linear dampening of loudness according to distance.
  • ATTENUATION_INVERSE_SQUARE_DISTANCE = 1 —- Squared dampening of loudness according to distance.
  • ATTENUATION_LOGARITHMIC = 2 —- Logarithmic dampening of loudness according to distance.
  • ATTENUATION_DISABLED = 3 —- No dampening of loudness according to distance. The sound will still be heard positionally, unlike an AudioStreamPlayer.

enum 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.
  • 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:

  • DOPPLER_TRACKING_DISABLED = 0 —- Disables doppler tracking.
  • DOPPLER_TRACKING_IDLE_STEP = 1 —- Executes doppler tracking in idle step.
  • DOPPLER_TRACKING_PHYSICS_STEP = 2 —- Executes doppler tracking in physics step.

Property Descriptions

Default1
Setterset_area_mask(value)
Getterget_area_mask()

Areas in which this sound plays.


  • float attenuation_filter_cutoff_hz
Default5000.0
Setterset_attenuation_filter_cutoff_hz(value)
Getterget_attenuation_filter_cutoff_hz()

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
Default-24.0
Setterset_attenuation_filter_db(value)
Getterget_attenuation_filter_db()

Amount how much the filter affects the loudness, in decibels.


Default0
Setterset_attenuation_model(value)
Getterget_attenuation_model()

Decides if audio should get quieter with distance linearly, quadratically, logarithmically, or not be affected by distance, effectively disabling attenuation.


Defaultfalse
Setterset_autoplay(value)
Getteris_autoplay_enabled()

If true, audio plays when the AudioStreamPlayer3D node is added to scene tree.


Default“Master”
Setterset_bus(value)
Getterget_bus()

The bus on which this audio is playing.


Default0
Setterset_doppler_tracking(value)
Getterget_doppler_tracking()

Decides in which step the Doppler effect should be calculated.


  • float emission_angle_degrees
Default45.0
Setterset_emission_angle(value)
Getterget_emission_angle()

The angle in which the audio reaches cameras undampened.


  • bool emission_angle_enabled
Defaultfalse
Setterset_emission_angle_enabled(value)
Getteris_emission_angle_enabled()

If true, the audio should be dampened according to the direction of the sound.


  • float emission_angle_filter_attenuation_db
Default-12.0
Setterset_emission_angle_filter_attenuation_db(value)
Getterget_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.


Default3.0
Setterset_max_db(value)
Getterget_max_db()

Sets the absolute maximum of the soundlevel, in decibels.


Default0.0
Setterset_max_distance(value)
Getterget_max_distance()

Sets the distance from which the out_of_range_mode takes effect. Has no effect if set to 0.


Default0
Setterset_out_of_range_mode(value)
Getterget_out_of_range_mode()

Decides if audio should pause when source is outside of max_distance range.


Default1.0
Setterset_pitch_scale(value)
Getterget_pitch_scale()

The pitch and the tempo of the audio, as a multiplier of the audio sample’s sample rate.


Defaultfalse
Getteris_playing()

If true, audio is playing.


Setterset_stream(value)
Getterget_stream()

The AudioStream resource to be played.


Defaultfalse
Setterset_stream_paused(value)
Getterget_stream_paused()

If true, the playback is paused. You can resume it by setting stream_paused to false.


Default0.0
Setterset_unit_db(value)
Getterget_unit_db()

The base sound level unaffected by dampening, in decibels.


Default1.0
Setterset_unit_size(value)
Getterget_unit_size()

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.


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.