Table of Contents

Class SoundInstance

Namespace
Stride.Audio
Assembly
Stride.Audio.dll

Base class for sound that creates voices

public class SoundInstance : ComponentBase, IDisposable, IComponent, IReferencable, ICollectorHolder, IPositionableSound, IPlayableSound
Inheritance
SoundInstance
Implements
Derived
Inherited Members
Extension Methods

Constructors

SoundInstance(AudioEngine, AudioListener, DynamicSoundSource, int, bool, bool, bool, float, HrtfEnvironment)

Initializes a new instance of the SoundInstance class using a dynamic sound source.

public SoundInstance(AudioEngine engine, AudioListener listener, DynamicSoundSource dynamicSoundSource, int sampleRate, bool mono, bool spatialized = false, bool useHrtf = false, float directionalFactor = 0, HrtfEnvironment environment = HrtfEnvironment.Small)

Parameters

engine AudioEngine

The audio engine that will be used to play this instance

listener AudioListener

The listener of this instance

dynamicSoundSource DynamicSoundSource

The source from where the PCM data will be fetched

sampleRate int

The sample rate of this audio stream

mono bool

Set to true if the souce is mono, false if stereo

spatialized bool

If the SoundInstance will be used for spatialized audio set to true, if not false, if true mono must also be true

useHrtf bool

If the engine should use Hrtf for spatialization

directionalFactor float
environment HrtfEnvironment

Fields

engine

protected AudioEngine engine

Field Value

AudioEngine

isLooping

protected bool isLooping

Field Value

bool

pan

protected float pan

Field Value

float

pitch

protected float pitch

Field Value

float

playState

protected PlayState playState

Field Value

PlayState

sound

protected SoundBase sound

Field Value

SoundBase

soundSource

protected DynamicSoundSource soundSource

Field Value

DynamicSoundSource

spatialized

protected bool spatialized

Field Value

bool

volume

protected float volume

Field Value

float

Properties

DynamicSoundSource

Gets the DynamicSoundSource, might be null if the sound is not using DynamicSoundSource, e.g. not streamed from disk or not using a DynamicSoundSource derived class as backing.

public DynamicSoundSource DynamicSoundSource { get; }

Property Value

DynamicSoundSource

IsLooping

Gets or sets whether the sound is automatically looping from beginning when it reaches the end.

public bool IsLooping { get; set; }

Property Value

bool

Pan

Set the sound balance between left and right speaker.

public float Pan { get; set; }

Property Value

float

Remarks

Panning is ranging from -1.0f (full left) to 1.0f (full right). 0.0f is centered. Values beyond this range are clamped. Panning modifies the total energy of the signal (Pan == -1 => Energy = 1 + 0, Pan == 0 => Energy = 1 + 1, Pan == 0.5 => Energy = 1 + 0.5, ...)

Pitch

Gets or sets the pitch of the sound, might conflict with spatialized sound spatialization.

public float Pitch { get; set; }

Property Value

float

PlayState

Gets the state of the SoundInstance.

public PlayState PlayState { get; }

Property Value

PlayState

Position

Gets the position in time of this playing instance.

public TimeSpan Position { get; }

Property Value

TimeSpan

Volume

The global volume at which the sound is played.

public float Volume { get; set; }

Property Value

float

Remarks

Volume is ranging from 0.0f (silence) to 1.0f (full volume). Values beyond those limits are clamped.

Methods

Apply3D(AudioEmitter)

Applies 3D positioning to the sound. More precisely adjust the channel volumes and pitch of the sound, such that the sound source seems to come from the emitter to the listener/>.

public void Apply3D(AudioEmitter emitter)

Parameters

emitter AudioEmitter

The emitter that correspond to this sound

Remarks

Apply3D(AudioEmitter) can be used only on mono-sounds.

The final resulting pitch depends on the listener and emitter relative velocity. The final resulting channel volumes depend on the listener and emitter relative positions and the value of Volume.

Destroy()

Destroys the instance.

protected override void Destroy()

Pause()

Pause the sounds.

public void Pause()

Remarks

A call to Pause when the sound is already paused or stopped has no effects.

Play()

Play or resume the sound effect instance.

public void Play()

Play(bool)

Play the sound instance.

protected void Play(bool stopSiblingInstances)

Parameters

stopSiblingInstances bool

if true any other istance of the same Sound will be stopped.

PlayExclusive()

Play or resume the sound effect instance, stopping sibling instances.

public void PlayExclusive()

ReadyToPlay()

A task that completes when the sound is ready to play

public Task<bool> ReadyToPlay()

Returns

Task<bool>

Returns a task that will complete when the sound has been buffered and ready to play

SetRange(PlayRange)

Sets the range of the sound to play.

public void SetRange(PlayRange range)

Parameters

range PlayRange

a PlayRange structure that describes the starting offset and ending point of the sound to play in seconds.

Stop()

Stop playing the sound immediately and reset the sound to the beginning of the track.

public void Stop()

Remarks

A call to Stop when the sound is already stopped has no effects.