Class AudioStreamPlayer3D
- Namespace
- Godot
- Assembly
- GodotSharp.dll
Plays audio with positional sound effects, based on the relative position of the audio listener. Positional effects include distance attenuation, directionality, and the Doppler effect. For greater realism, a low-pass filter is applied to distant sounds. This can be disabled by setting AttenuationFilterCutoffHz to 20500
.
By default, audio is heard from the camera position. This can be changed by adding an AudioListener3D node to the scene and enabling it by calling MakeCurrent() 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 VolumeDb to a very low value like -100
(which isn't audible to human hearing).
public class AudioStreamPlayer3D : Node3D, IDisposable
- Inheritance
-
AudioStreamPlayer3D
- Implements
- Inherited Members
Constructors
AudioStreamPlayer3D()
public AudioStreamPlayer3D()
Properties
AreaMask
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.
public uint AreaMask { get; set; }
Property Value
AttenuationFilterCutoffHz
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.
public float AttenuationFilterCutoffHz { get; set; }
Property Value
AttenuationFilterDb
Amount how much the filter affects the loudness, in decibels.
public float AttenuationFilterDb { get; set; }
Property Value
AttenuationModel
Decides if audio should get quieter with distance linearly, quadratically, logarithmically, or not be affected by distance, effectively disabling attenuation.
public AudioStreamPlayer3D.AttenuationModelEnum AttenuationModel { get; set; }
Property Value
Autoplay
If true, audio plays when the AudioStreamPlayer3D node is added to scene tree.
public bool Autoplay { get; set; }
Property Value
Bus
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"
.
public StringName Bus { get; set; }
Property Value
DopplerTracking
Decides in which step the Doppler effect should be calculated.
public AudioStreamPlayer3D.DopplerTrackingEnum DopplerTracking { get; set; }
Property Value
EmissionAngleDegrees
The angle in which the audio reaches a listener unattenuated.
public float EmissionAngleDegrees { get; set; }
Property Value
EmissionAngleEnabled
If true, the audio should be attenuated according to the direction of the sound.
public bool EmissionAngleEnabled { get; set; }
Property Value
EmissionAngleFilterAttenuationDb
Attenuation factor used if listener is outside of EmissionAngleDegrees and EmissionAngleEnabled is set, in decibels.
public float EmissionAngleFilterAttenuationDb { get; set; }
Property Value
MaxDb
Sets the absolute maximum of the sound level, in decibels.
public float MaxDb { get; set; }
Property Value
MaxDistance
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
. MaxDistance works in tandem with UnitSize. However, unlike UnitSize whose behavior depends on the AttenuationModel, 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.
public float MaxDistance { get; set; }
Property Value
MaxPolyphony
The maximum number of sounds this node can play at the same time. Playing additional sounds after this value is reached will cut off the oldest sounds.
public int MaxPolyphony { get; set; }
Property Value
PanningStrength
Scales the panning strength for this node by multiplying the base ProjectSettings.audio/general/3d_panning_strength
with this factor. Higher values will pan audio from left to right more dramatically than lower values.
public float PanningStrength { get; set; }
Property Value
PitchScale
The pitch and the tempo of the audio, as a multiplier of the audio sample's sample rate.
public float PitchScale { get; set; }
Property Value
PlaybackType
The playback type of the stream player. If set other than to the default value, it will force that playback type.
public AudioServer.PlaybackType PlaybackType { get; set; }
Property Value
Playing
If true, audio is playing or is queued to be played (see Play(float)).
public bool Playing { get; set; }
Property Value
Stream
The AudioStream resource to be played.
public AudioStream Stream { get; set; }
Property Value
StreamPaused
If true, the playback is paused. You can resume it by setting StreamPaused to false.
public bool StreamPaused { get; set; }
Property Value
UnitSize
The factor for the attenuation effect. Higher values make the sound audible over a larger distance.
public float UnitSize { get; set; }
Property Value
VolumeDb
The base sound level before attenuation, in decibels.
public float VolumeDb { get; set; }
Property Value
Methods
GetPlaybackPosition()
Returns the position in the AudioStream.
public float GetPlaybackPosition()
Returns
GetStreamPlayback()
Returns the AudioStreamPlayback object associated with this AudioStreamPlayer3D.
public AudioStreamPlayback GetStreamPlayback()
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
HasStreamPlayback()
Returns whether the AudioStreamPlayer can return the AudioStreamPlayback object or not.
public bool HasStreamPlayback()
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
Play(float)
Queues the audio to play on the next physics frame, from the given position fromPosition
, in seconds.
public void Play(float fromPosition = 0)
Parameters
fromPosition
float
Seek(float)
Sets the position from which audio will be played, in seconds.
public void Seek(float toPosition)
Parameters
toPosition
float
Stop()
Stops the audio.
public void Stop()
Events
Finished
Emitted when the audio stops playing.
public event Action Finished