AudioStreamPlayer3D
Plays positional sound in 3D space.
AudioStreamPlayer3D.swift:23class AudioStreamPlayer3D
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.
This object emits the following signals:
Superclasses
class Node3D
Most basic 3D game object, parent of all 3D-related nodes.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
Type members
Instance members
var areaMask: UInt32
Determines which
Area3D
layers affect the sound for reverb and audio bus effects. Areas can be used to redirectAudioStream
s 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.var attenuationFilterCutoffHz: Double
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.var attenuationFilterDb: Double
Amount how much the filter affects the loudness, in decibels.
var attenuationModel: AudioStreamPlayer3D.AttenuationModel
Decides if audio should get quieter with distance linearly, quadratically, logarithmically, or not be affected by distance, effectively disabling attenuation.
var autoplay: Bool
If
true
, audio plays when the AudioStreamPlayer3D node is added to scene tree.var bus: StringName
The bus on which this audio is playing.
var dopplerTracking: AudioStreamPlayer3D.DopplerTracking
Decides in which step the Doppler effect should be calculated.
var emissionAngleDegrees: Double
The angle in which the audio reaches a listener unattenuated.
var emissionAngleEnabled: Bool
If
true
, the audio should be attenuated according to the direction of the sound.var emissionAngleFilterAttenuationDb: Double
Attenuation factor used if listener is outside of
emissionAngleDegrees
andemissionAngleEnabled
is set, in decibels.var finished: SimpleSignal
Emitted when the audio stops playing.
var maxDb: Double
Sets the absolute maximum of the sound level, in decibels.
var maxDistance: Double
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 withunitSize
. However, unlikeunitSize
whose behavior depends on theattenuationModel
,maxDistance
always works in a linear fashion. This can be used to prevent theAudioStreamPlayer3D
from requiring audio mixing when the listener is far away, which saves CPU resources.var maxPolyphony: Int32
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.
var panningStrength: Double
Scales the panning strength for this node by multiplying the base
ProjectSettings/audio/general/3dPanningStrength
with this factor. Higher values will pan audio from left to right more dramatically than lower values.var pitchScale: Double
The pitch and the tempo of the audio, as a multiplier of the audio sample’s sample rate.
var stream: AudioStream?
The
AudioStream
resource to be played.var streamPaused: Bool
If
true
, the playback is paused. You can resume it by settingstreamPaused
tofalse
.var unitSize: Double
The factor for the attenuation effect. Higher values make the sound audible over a larger distance.
var volumeDb: Double
The base sound level before attenuation, in decibels.
func getPlaybackPosition(
) -> Double Returns the position in the
AudioStream
.func getStreamPlayback(
) -> AudioStreamPlayback? Returns the
AudioStreamPlayback
object associated with thisAudioStreamPlayer3D
.func hasStreamPlayback(
) -> Bool Returns whether the
AudioStreamPlayer
can return theAudioStreamPlayback
object or not.func isPlaying(
) -> Bool func play(fromPosition: Double
) Queues the audio to play on the next physics frame, from the given position
fromPosition
, in seconds.func seek(toPosition: Double
) Sets the position from which audio will be played, in seconds.
func stop(
) Stops the audio.