Back to monogame.net
Show / Hide Table of Contents

Class SoundEffectInstance

Represents a single instance of a playing, paused, or stopped sound.

Inheritance
Object
SoundEffectInstance
DynamicSoundEffectInstance
Implements
IDisposable
Namespace: Microsoft.Xna.Framework.Audio
Assembly: MonoGame.Framework.dll
Syntax
public class SoundEffectInstance : IDisposable
Remarks

SoundEffectInstances are created through SoundEffect.CreateInstance() and used internally by SoundEffect.Play()

Properties

IsDisposed

Indicates whether the object is disposed.

Declaration
public bool IsDisposed { get; }
Property Value
Type Description
Boolean

IsLooped

Enables or Disables whether the SoundEffectInstance should repeat after playback.

Declaration
public virtual bool IsLooped { get; set; }
Property Value
Type Description
Boolean
Remarks

This value has no effect on an already playing sound.

Pan

Gets or sets the pan, or speaker balance..

Declaration
public float Pan { get; set; }
Property Value
Type Description
Single

Pan value ranging from -1.0 (left speaker) to 0.0 (centered), 1.0 (right speaker). Values outside of this range will throw an exception.

Pitch

Gets or sets the pitch adjustment.

Declaration
public float Pitch { get; set; }
Property Value
Type Description
Single

Pitch adjustment, ranging from -1.0 (down an octave) to 0.0 (no change) to 1.0 (up an octave). Values outside of this range will throw an Exception.

State

Gets the SoundEffectInstance's current playback state.

Declaration
public virtual SoundState State { get; }
Property Value
Type Description
SoundState

Volume

Gets or sets the volume of the SoundEffectInstance.

Declaration
public float Volume { get; set; }
Property Value
Type Description
Single

Volume, ranging from 0.0 (silence) to 1.0 (full volume). Volume during playback is scaled by SoundEffect.MasterVolume.

Remarks

This is the volume relative to SoundEffect.MasterVolume. Before playback, this Volume property is multiplied by SoundEffect.MasterVolume when determining the final mix volume.

Methods

Apply3D(AudioListener, AudioEmitter)

Applies 3D positioning to the SoundEffectInstance using a single listener.

Declaration
public void Apply3D(AudioListener listener, AudioEmitter emitter)
Parameters
Type Name Description
AudioListener listener

Data about the listener.

AudioEmitter emitter

Data about the source of emission.

Apply3D(AudioListener[], AudioEmitter)

Applies 3D positioning to the SoundEffectInstance using multiple listeners.

Declaration
public void Apply3D(AudioListener[] listeners, AudioEmitter emitter)
Parameters
Type Name Description
AudioListener[] listeners

Data about each listener.

AudioEmitter emitter

Data about the source of emission.

Dispose()

Releases the resources held by this SoundEffectInstance.

Declaration
public void Dispose()

Dispose(Boolean)

Releases the resources held by this SoundEffectInstance.

Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
Boolean disposing

If set to true, Dispose was called explicitly.

Remarks

If the disposing parameter is true, the Dispose method was called explicitly. This means that managed objects referenced by this instance should be disposed or released as required. If the disposing parameter is false, Dispose was called by the finalizer and no managed objects should be touched because we do not know if they are still valid or not at that time. Unmanaged resources should always be released.

Finalize()

Releases unmanaged resources and performs other cleanup operations before the SoundEffectInstance is reclaimed by garbage collection.

Declaration
protected void Finalize()

Pause()

Pauses playback of a SoundEffectInstance.

Declaration
public virtual void Pause()
Remarks

Paused instances can be resumed with SoundEffectInstance.Play() or SoundEffectInstance.Resume().

Play()

Plays or resumes a SoundEffectInstance.

Declaration
public virtual void Play()
Remarks

Throws an exception if more sounds are playing than the platform allows.

Resume()

Resumes playback for a SoundEffectInstance.

Declaration
public virtual void Resume()
Remarks

Only has effect on a SoundEffectInstance in a paused state.

Stop()

Immediately stops playing a SoundEffectInstance.

Declaration
public virtual void Stop()

Stop(Boolean)

Stops playing a SoundEffectInstance, either immediately or as authored.

Declaration
public virtual void Stop(bool immediate)
Parameters
Type Name Description
Boolean immediate

Determined whether the sound stops immediately, or after playing its release phase and/or transitions.

Remarks

Stopping a sound with the immediate argument set to false will allow it to play any release phases, such as fade, before coming to a stop.

Implements

IDisposable
In This Article
Back to top

© 2012 Microsoft Corporation. All rights reserved.

© The MonoGame Team.