SoundEffect Class (Microsoft.Xna.Framework.Audio)

Represents a loaded sound resource.
System.Object
   Microsoft.Xna.Framework.Audio.SoundEffect

Namespace: Microsoft.Xna.Framework.Audio
Assembly: MonoGame.Framework (MonoGame.Framework.dll 3.8.0.1082)
  • C#
  • VB
  • F#
public sealed class SoundEffect : IDisposable

Syntax for VB is not yet implemented.

Syntax for F# is not yet implemented.

The SoundEffect type exposes the following members.

  Platforms Name Description
SoundEffect(Byte[], int, AudioChannels) Create a sound effect. 
SoundEffect(Byte[], int, int, int, AudioChannels, int, int) Create a sound effect. 
Top
  Platforms Name Description
DistanceScale Gets or sets the scale of distance calculations. 
DopplerScale Gets or sets the scale of Doppler calculations applied to sounds. 
Duration Gets the duration of the SoundEffect. 
IsDisposed Indicates whether the object is disposed. 
MasterVolume Gets or sets the master volume scale applied to all SoundEffectInstances. 
Name Gets or sets the asset name of the SoundEffect. 
Speakers  
SpeedOfSound Returns the speed of sound used when calculating the Doppler effect.. 
Top
  Platforms Name Description
CreateInstance Creates a new SoundEffectInstance for this SoundEffect. 
Dispose Releases the resources held by this SoundEffect. (Implements IDisposable.Dispose().)
Finalize Releases unmanaged resources and performs other cleanup operations before the SoundEffect is reclaimed by garbage collection. (Overrides object.Finalize().)
FromFile Creates a new SoundEffect object based on the specified data stream. This internally calls FromStream(Stream)
FromStream Creates a new SoundEffect object based on the specified data stream. 
GetSampleDuration Returns the duration for 16-bit PCM audio. 
GetSampleSizeInBytes Returns the data size in bytes for 16bit PCM audio. 
Initialize Initializes the sound system for SoundEffect support. This method is automatically called when a SoundEffect is loaded, a DynamicSoundEffectInstance is created, or Microphone.All is queried. You can however call this method manually (preferably in, or before the Game constructor) to catch any Exception that may occur during the sound system initialization (and act accordingly). 
Play() Gets an internal SoundEffectInstance and plays it. 
Play(float, float, float) Gets an internal SoundEffectInstance and plays it with the specified volume, pitch, and panning. 
Top
A SoundEffect represents the buffer used to hold audio data and metadata. SoundEffectInstances are used to play from SoundEffects. Multiple SoundEffectInstance objects can be created and played from the same SoundEffect object.The only limit on the number of loaded SoundEffects is restricted by available memory. When a SoundEffect is disposed, all SoundEffectInstances created from it will become invalid.SoundEffect.Play() can be used for 'fire and forget' sounds. If advanced playback controls like volume or pitch is required, use SoundEffect.CreateInstance().
Supported in:

    
 Windows DirectX Desktop
    
 Linux Desktop
    
 Windows OpenGL Desktop
    
 Web