reckfellENGINE

AudioStreamPlayer2D

A sound source with panning and attenuation in a 2D world.

On this page
class AudioStreamPlayer2DReckfellSharpInherits Entity2D

AudioStreamPlayer2D accounts for a listener in its world and viewport. An explicit AudioListener2D defines the listening point; otherwise it uses the center of the viewport's visible region. The viewport must have 2D listening enabled.

MaxDistance uses 2D world units, usually pixels. Panning also depends on the viewport and scale. Playback startup and spatial updates run during physics steps. Collisions alone do not create acoustic occlusion.

Working example.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Constructors1

AudioStreamPlayer2DConstructor
# AudioStreamPlayer2D
C#
public AudioStreamPlayer2D();

Properties14

AreaMaskProperty
# AreaMask
C#
public uint AreaMask { get; set; }

Determines which Area2D 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.

AttenuationProperty
# Attenuation
C#
public float Attenuation { get; set; }

The volume is attenuated over distance with this as an exponent.

AutoplayProperty
# Autoplay
C#
public bool Autoplay { get; set; }

If true, audio plays when added to scene tree.

BusProperty
# Bus
C#
public StringName Bus { get; set; }

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".

MaxDistanceProperty
# MaxDistance
C#
public float MaxDistance { get; set; }

Maximum distance from which audio is still hearable.

MaxPolyphonyProperty
# MaxPolyphony
C#
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
# PanningStrength
C#
public float PanningStrength { get; set; }

Scales the panning strength for this node by multiplying the base ProjectSettings.audio/general/2d_panning_strength with this factor. Higher values will pan audio from left to right more dramatically than lower values.

PitchScaleProperty
# PitchScale
C#
public float PitchScale { get; set; }

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

PlaybackTypeProperty
# PlaybackType
C#
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
# Playing
C#
public bool Playing { get; set; }

If true, audio is playing or is queued to be played (see AudioStreamPlayer2D.Play).

StreamProperty
# Stream
C#
public AudioStream Stream { get; set; }

The AudioStream object to be played.

StreamPausedProperty
# StreamPaused
C#
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.

VolumeDbProperty
# VolumeDb
C#
public float VolumeDb { get; set; }

Base volume before attenuation, in decibels.

VolumeLinearProperty
# VolumeLinear
C#
public float VolumeLinear { get; set; }

Base volume before attenuation, as a linear value. Note: This member modifies AudioStreamPlayer2D.VolumeDb for convenience. The returned value is equivalent to the result of @GlobalScope.db_to_linear on AudioStreamPlayer2D.VolumeDb. Setting this member is equivalent to setting AudioStreamPlayer2D.VolumeDb to the result of @GlobalScope.linear_to_db on a value.

Methods34

GetAreaMaskuint
# GetAreaMask
C#
public uint GetAreaMask();
Returns uint
GetAttenuationfloat
# GetAttenuation
C#
public float GetAttenuation();
Returns float
GetBusStringName
# GetBus
C#
public StringName GetBus();
Returns StringName
GetMaxDistancefloat
# GetMaxDistance
C#
public float GetMaxDistance();
Returns float
GetMaxPolyphonyint
# GetMaxPolyphony
C#
public int GetMaxPolyphony();
Returns int
GetPanningStrengthfloat
# GetPanningStrength
C#
public float GetPanningStrength();
Returns float
GetPitchScalefloat
# GetPitchScale
C#
public float GetPitchScale();
Returns float
GetPlaybackPositionfloat
# GetPlaybackPosition
C#
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.

Returns float
GetPlaybackTypeAudioServer.PlaybackType
# GetPlaybackType
C#
public AudioServer.PlaybackType GetPlaybackType();
Returns AudioServer.PlaybackType
GetStreamAudioStream
# GetStream
C#
public AudioStream GetStream();
Returns AudioStream
GetStreamPausedbool
# GetStreamPaused
C#
public bool GetStreamPaused();
Returns bool
GetStreamPlaybackAudioStreamPlayback
# GetStreamPlayback
C#
public AudioStreamPlayback GetStreamPlayback();

Returns the AudioStreamPlayback object associated with this AudioStreamPlayer2D.

Returns AudioStreamPlayback
GetVolumeDbfloat
# GetVolumeDb
C#
public float GetVolumeDb();
Returns float
GetVolumeLinearfloat
# GetVolumeLinear
C#
public float GetVolumeLinear();
Returns float
HasStreamPlaybackbool
# HasStreamPlayback
C#
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.

Returns bool
IsAutoplayEnabledbool
# IsAutoplayEnabled
C#
public bool IsAutoplayEnabled();
Returns bool
IsPlayingbool
# IsPlaying
C#
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.

Returns bool
Playvoid
# Play
C#
public void Play(float fromPosition = 0f);

Queues the audio to play on the next physics frame, from the given position from_position, in seconds.

Parameters
NameTypeDefault
fromPositionfloat0f
Seekvoid
# Seek
C#
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.

Parameters
NameTypeDefault
toPositionfloat—
SetAreaMaskvoid
# SetAreaMask
C#
public void SetAreaMask(uint mask);
Parameters
NameTypeDefault
maskuint—
SetAttenuationvoid
# SetAttenuation
C#
public void SetAttenuation(float curve);
Parameters
NameTypeDefault
curvefloat—
SetAutoplayvoid
# SetAutoplay
C#
public void SetAutoplay(bool enable);
Parameters
NameTypeDefault
enablebool—
SetBusvoid
# SetBus
C#
public void SetBus(StringName bus);
Parameters
NameTypeDefault
busStringName—
SetMaxDistancevoid
# SetMaxDistance
C#
public void SetMaxDistance(float pixels);
Parameters
NameTypeDefault
pixelsfloat—
SetMaxPolyphonyvoid
# SetMaxPolyphony
C#
public void SetMaxPolyphony(int maxPolyphony);
Parameters
NameTypeDefault
maxPolyphonyint—
SetPanningStrengthvoid
# SetPanningStrength
C#
public void SetPanningStrength(float panningStrength);
Parameters
NameTypeDefault
panningStrengthfloat—
SetPitchScalevoid
# SetPitchScale
C#
public void SetPitchScale(float pitchScale);
Parameters
NameTypeDefault
pitchScalefloat—
SetPlaybackTypevoid
# SetPlaybackType
C#
public void SetPlaybackType(AudioServer.PlaybackType playbackType);
Parameters
NameTypeDefault
playbackTypeAudioServer.PlaybackType—
SetPlayingvoid
# SetPlaying
C#
public void SetPlaying(bool enable);
Parameters
NameTypeDefault
enablebool—
SetStreamvoid
# SetStream
C#
public void SetStream(AudioStream stream);
Parameters
NameTypeDefault
streamAudioStream—
SetStreamPausedvoid
# SetStreamPaused
C#
public void SetStreamPaused(bool pause);
Parameters
NameTypeDefault
pausebool—
SetVolumeDbvoid
# SetVolumeDb
C#
public void SetVolumeDb(float volumeDb);
Parameters
NameTypeDefault
volumeDbfloat—
SetVolumeLinearvoid
# SetVolumeLinear
C#
public void SetVolumeLinear(float volumeLinear);
Parameters
NameTypeDefault
volumeLinearfloat—
Stopvoid
# Stop
C#
public void Stop();

Stops the audio.

Signals and events1

FinishedEvent
# Finished
C#
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.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.