AudioStreamPlayer3D
A sound source with direction and attenuation in a 3D world.
AudioStreamPlayer3D calculates sound relative to an active 3D listener. AudioListener3D can separate the listening point from the camera. The viewport must have 3D listening enabled.
The attenuation model and UnitSize determine level changes with distance. A positive MaxDistance additionally limits range. These parameters do not resize objects. Wall occlusion needs separate logic: collisions do not automatically muffle sound. Spatial updates run during physics steps.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
AudioStreamPlayer3DConstructor
public AudioStreamPlayer3D();Properties22
AreaMaskProperty
public uint AreaMask { get; set; }Determines which Area3D 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.
AttenuationFilterCutoffHzProperty
public float AttenuationFilterCutoffHz { get; set; }The cutoff frequency of the attenuation low-pass filter, in Hz. A sound above this frequency is attenuated more than a sound below this frequency. To disable this effect, set this to 20500 as this frequency is above the human hearing limit.
AttenuationFilterDbProperty
public float AttenuationFilterDb { get; set; }Amount how much the filter affects the loudness, in decibels.
AttenuationModelProperty
public AudioStreamPlayer3D.AttenuationModelEnum AttenuationModel { get; set; }Decides if audio should get quieter with distance linearly, quadratically, logarithmically, or not be affected by distance, effectively disabling attenuation.
AutoplayProperty
public bool Autoplay { get; set; }If true, audio plays when the AudioStreamPlayer3D node is added to scene tree.
BusProperty
public StringName Bus { get; set; }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".
DopplerTrackingProperty
public AudioStreamPlayer3D.DopplerTrackingEnum DopplerTracking { get; set; }Decides in which step the Doppler effect should be calculated.
Note: If AudioStreamPlayer3D.DopplerTracking is not AudioStreamPlayer3D.DopplerTrackingEnum.Disabled but the current Camera3D/AudioListener3D has doppler tracking disabled, the Doppler effect will be heard but will not take the movement of the current listener into account. If accurate Doppler effect is desired, doppler tracking should be enabled on both the AudioStreamPlayer3D and the current Camera3D/AudioListener3D.
EmissionAngleDegreesProperty
public float EmissionAngleDegrees { get; set; }The angle in which the audio reaches a listener unattenuated.
EmissionAngleEnabledProperty
public bool EmissionAngleEnabled { get; set; }If true, the audio should be attenuated according to the direction of the sound.
EmissionAngleFilterAttenuationDbProperty
public float EmissionAngleFilterAttenuationDb { get; set; }Attenuation factor used if listener is outside of AudioStreamPlayer3D.EmissionAngleDegrees and AudioStreamPlayer3D.EmissionAngleEnabled is set, in decibels.
MaxDbProperty
public float MaxDb { get; set; }Sets the absolute maximum of the sound level, in decibels.
MaxDistanceProperty
public float MaxDistance { get; set; }The distance past which the sound can no longer be heard at all. Only has an effect if set to a value greater than 0.0. AudioStreamPlayer3D.MaxDistance works in tandem with AudioStreamPlayer3D.UnitSize. However, unlike AudioStreamPlayer3D.UnitSize whose behavior depends on the AudioStreamPlayer3D.AttenuationModel, AudioStreamPlayer3D.MaxDistance always works in a linear fashion. This can be used to prevent the AudioStreamPlayer3D from requiring audio mixing when the listener is far away, which saves CPU resources.
MaxPolyphonyProperty
public int MaxPolyphony { get; set; }Maximum simultaneous voices in this player. A new Play exceeding the limit replaces the oldest voice. Use a positive value; choose 1 for a single controlled music stream.
PanningStrengthProperty
public float PanningStrength { get; set; }Scales the panning strength for this node by multiplying the base ProjectSettings.audio/general/3d_panning_strength by this factor. If the product is 0.0 then stereo panning is disabled and the volume is the same for all channels. If the product is 1.0 then one of the channels will be muted when the sound is located exactly to the left (or right) of the listener.
Two speaker stereo arrangements implement the WebAudio standard for StereoPannerNode Panning where the volume is cosine of half the azimuth angle to the ear.
For other speaker arrangements such as the 5.1 and 7.1 the SPCAP (Speaker-Placement Correction Amplitude) algorithm is implemented.
PitchScaleProperty
public float PitchScale { get; set; }The pitch and the tempo of the audio, as a multiplier of the audio sample's sample rate.
PlaybackTypeProperty
public AudioServer.PlaybackType PlaybackType { get; set; }The playback type of the stream player. If set other than to the default value, it will force that playback type.
PlayingProperty
public bool Playing { get; set; }If true, audio is playing or is queued to be played (see AudioStreamPlayer3D.Play).
StreamProperty
public AudioStream Stream { get; set; }The AudioStream resource to be played.
StreamPausedProperty
public bool StreamPaused { get; set; }Pauses or resumes existing voices. A pending pause is not retained when no voices exist. In Stream mode, pausing makes IsPlaying() false while HasStreamPlayback() remains true.
UnitSizeProperty
public float UnitSize { get; set; }The factor for the attenuation effect. Higher values make the sound audible over a larger distance.
VolumeDbProperty
public float VolumeDb { get; set; }The base sound level before attenuation, in decibels.
VolumeLinearProperty
public float VolumeLinear { get; set; }The base sound level before attenuation, as a linear value.
Note: This member modifies AudioStreamPlayer3D.VolumeDb for convenience. The returned value is equivalent to the result of @GlobalScope.db_to_linear on AudioStreamPlayer3D.VolumeDb. Setting this member is equivalent to setting AudioStreamPlayer3D.VolumeDb to the result of @GlobalScope.linear_to_db on a value.
Methods50
GetAreaMaskuint
public uint GetAreaMask();uintGetAttenuationFilterCutoffHzfloat
public float GetAttenuationFilterCutoffHz();floatGetAttenuationFilterDbfloat
public float GetAttenuationFilterDb();floatGetAttenuationModelAudioStreamPlayer3D.AttenuationModelEnum
public AudioStreamPlayer3D.AttenuationModelEnum GetAttenuationModel();AudioStreamPlayer3D.AttenuationModelEnumGetBusStringName
public StringName GetBus();StringNameGetDopplerTrackingAudioStreamPlayer3D.DopplerTrackingEnum
public AudioStreamPlayer3D.DopplerTrackingEnum GetDopplerTracking();AudioStreamPlayer3D.DopplerTrackingEnumGetEmissionAnglefloat
public float GetEmissionAngle();floatGetEmissionAngleFilterAttenuationDbfloat
public float GetEmissionAngleFilterAttenuationDb();floatGetMaxDbfloat
public float GetMaxDb();floatGetMaxDistancefloat
public float GetMaxDistance();floatGetMaxPolyphonyint
public int GetMaxPolyphony();intGetPanningStrengthfloat
public float GetPanningStrength();floatGetPitchScalefloat
public float GetPitchScale();floatGetPlaybackPositionfloat
public float GetPlaybackPosition();Returns the most recently created voice's position in seconds, not the combined time of all voices. It can advance in steps between mixes. For a single stream at speed 1, time since the last mix can refine an estimate; handle pause, seeking and output latency separately.
floatGetPlaybackTypeAudioServer.PlaybackType
public AudioServer.PlaybackType GetPlaybackType();AudioServer.PlaybackTypeGetStreamAudioStream
public AudioStream GetStream();AudioStreamGetStreamPausedbool
public bool GetStreamPaused();boolGetStreamPlaybackAudioStreamPlayback
public AudioStreamPlayback GetStreamPlayback();Returns the AudioStreamPlayback object associated with this AudioStreamPlayer3D.
AudioStreamPlaybackGetUnitSizefloat
public float GetUnitSize();floatGetVolumeDbfloat
public float GetVolumeDb();floatGetVolumeLinearfloat
public float GetVolumeLinear();floatHasStreamPlaybackbool
public bool HasStreamPlayback();Checks whether the player retains playback objects, including paused ones. This does not prove audible output: mute, distance or pause can produce silence.
boolIsAutoplayEnabledbool
public bool IsAutoplayEnabled();boolIsEmissionAngleEnabledbool
public bool IsEmissionAngleEnabled();boolIsPlayingbool
public bool IsPlaying();In Stream mode, returns true for an actively playing voice. Returns false while paused; use HasStreamPlayback() or StreamPaused to detect retained playback. Do not reject a resume command using this method.
boolPlayvoid
public void Play(float fromPosition = 0f);Queues the audio to play on the next physics frame, from the given position from_position, in seconds.
| Name | Type | Default |
|---|---|---|
fromPosition | float | 0f |
Seekvoid
public void Seek(float toPosition);Restarts the player at a position in seconds only while actively playing. Stops previous voices and starts a new one at the position. In Stream mode it does nothing while paused or stopped. To seek while retaining pause, save the flag, call Stop(), Play(position), then restore StreamPaused.
| Name | Type | Default |
|---|---|---|
toPosition | float | — |
SetAreaMaskvoid
public void SetAreaMask(uint mask);| Name | Type | Default |
|---|---|---|
mask | uint | — |
SetAttenuationFilterCutoffHzvoid
public void SetAttenuationFilterCutoffHz(float degrees);| Name | Type | Default |
|---|---|---|
degrees | float | — |
SetAttenuationFilterDbvoid
public void SetAttenuationFilterDb(float db);| Name | Type | Default |
|---|---|---|
db | float | — |
SetAttenuationModelvoid
public void SetAttenuationModel(AudioStreamPlayer3D.AttenuationModelEnum model);| Name | Type | Default |
|---|---|---|
model | AudioStreamPlayer3D.AttenuationModelEnum | — |
SetAutoplayvoid
public void SetAutoplay(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetBusvoid
public void SetBus(StringName bus);| Name | Type | Default |
|---|---|---|
bus | StringName | — |
SetDopplerTrackingvoid
public void SetDopplerTracking(AudioStreamPlayer3D.DopplerTrackingEnum mode);| Name | Type | Default |
|---|---|---|
mode | AudioStreamPlayer3D.DopplerTrackingEnum | — |
SetEmissionAnglevoid
public void SetEmissionAngle(float degrees);| Name | Type | Default |
|---|---|---|
degrees | float | — |
SetEmissionAngleEnabledvoid
public void SetEmissionAngleEnabled(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
SetEmissionAngleFilterAttenuationDbvoid
public void SetEmissionAngleFilterAttenuationDb(float db);| Name | Type | Default |
|---|---|---|
db | float | — |
SetMaxDbvoid
public void SetMaxDb(float maxDb);| Name | Type | Default |
|---|---|---|
maxDb | float | — |
SetMaxDistancevoid
public void SetMaxDistance(float meters);| Name | Type | Default |
|---|---|---|
meters | float | — |
SetMaxPolyphonyvoid
public void SetMaxPolyphony(int maxPolyphony);| Name | Type | Default |
|---|---|---|
maxPolyphony | int | — |
SetPanningStrengthvoid
public void SetPanningStrength(float panningStrength);| Name | Type | Default |
|---|---|---|
panningStrength | float | — |
SetPitchScalevoid
public void SetPitchScale(float pitchScale);| Name | Type | Default |
|---|---|---|
pitchScale | float | — |
SetPlaybackTypevoid
public void SetPlaybackType(AudioServer.PlaybackType playbackType);| Name | Type | Default |
|---|---|---|
playbackType | AudioServer.PlaybackType | — |
SetPlayingvoid
public void SetPlaying(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetStreamvoid
public void SetStream(AudioStream stream);| Name | Type | Default |
|---|---|---|
stream | AudioStream | — |
SetStreamPausedvoid
public void SetStreamPaused(bool pause);| Name | Type | Default |
|---|---|---|
pause | bool | — |
SetUnitSizevoid
public void SetUnitSize(float unitSize);| Name | Type | Default |
|---|---|---|
unitSize | float | — |
SetVolumeDbvoid
public void SetVolumeDb(float volumeDb);| Name | Type | Default |
|---|---|---|
volumeDb | float | — |
SetVolumeLinearvoid
public void SetVolumeLinear(float volumeLinear);| Name | Type | Default |
|---|---|---|
volumeLinear | float | — |
Stopvoid
public void Stop();Stops the audio.
Signals and events1
FinishedEvent
public event Action Finished;Emitted when an update removes one or more naturally ended voices. Other voices may still be playing. Stop() and voice-limit replacement are not natural completion; looping does not emit this signal each cycle.
AudioStreamPlayer3D.AttenuationModelEnum
| Value | Description |
|---|---|
Disabled = 3 | No attenuation of loudness according to distance. The sound will still be heard positionally, unlike an |
InverseDistance = 0 | Attenuation of loudness according to linear distance. |
InverseSquareDistance = 1 | Attenuation of loudness according to squared distance. |
Logarithmic = 2 | Attenuation of loudness according to logarithmic distance. |
AudioStreamPlayer3D.DopplerTrackingEnum
| Value | Description |
|---|---|
Disabled = 0 | Disables doppler tracking. |
IdleStep = 1 | Executes doppler tracking during process frames (see |
PhysicsStep = 2 | Executes doppler tracking during physics frames (see |