C# Class Microsoft.Xna.Framework.Audio.SoundEffect

Represents a loaded sound resource.

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().

Inheritance: IDisposable
Datei anzeigen Open project: procfxgen/MGShaderEditor Class Usage Examples

Private Properties

Property Type Description
CreateBuffers void
Dispose void
GetPooledInstance SoundEffectInstance
PlatformInitialize void
PlatformLoadAudioStream void
PlatformLoadAudioStream void
PlatformSetMasterVolume void
SoundEffect System
SoundEffect System

Public Methods

Method Description
CreateInstance ( ) : SoundEffectInstance

Creates a new SoundEffectInstance for this SoundEffect.

Creating a SoundEffectInstance before calling SoundEffectInstance.Play() allows you to access advanced playback features, such as volume, pitch, and 3D positioning.

Dispose ( ) : void

Releases the resources held by this Microsoft.Xna.Framework.Audio.SoundEffect.

FromStream ( Stream s ) : SoundEffect

Creates a SoundEffect object based on the specified data stream.

The Stream object must point to the head of a valid PCM wave file. Also, this wave file must be in the RIFF bitstream format.

GetSampleDuration ( int sizeInBytes, int sampleRate, AudioChannels channels ) : TimeSpan

Gets the TimeSpan representation of a single sample.

GetSampleSizeInBytes ( TimeSpan duration, int sampleRate, AudioChannels channels ) : int

Gets the size of a sample from a TimeSpan.

PlatformInitialize ( byte buffer, int sampleRate, AudioChannels channels ) : void
Play ( ) : bool

Gets an internal SoundEffectInstance and plays it.

Play returns false if more SoundEffectInstances are currently playing then the platform allows.

To loop a sound or apply 3D effects, call SoundEffect.CreateInstance() and SoundEffectInstance.Play() instead.

SoundEffectInstances used by SoundEffect.Play() are pooled internally.

Play ( float volume, float pitch, float pan ) : bool

Gets an internal SoundEffectInstance and plays it with the specified volume, pitch, and panning.

Play returns false if more SoundEffectInstances are currently playing then the platform allows.

To apply looping or simulate 3D audio, call SoundEffect.CreateInstance() and SoundEffectInstance.Play() instead.

SoundEffectInstances used by SoundEffect.Play() are pooled internally.

SoundEffect ( byte buffer, int sampleRate, AudioChannels channels ) : System
SoundEffect ( byte buffer, int offset, int count, int sampleRate, AudioChannels channels, int loopStart, int loopLength ) : System Use SoundEffect.GetSampleDuration() to convert time to samples.

Private Methods

Method Description
CreateBuffers ( WaveFormat format, DataStream dataStream, int loopStart, int loopLength ) : void
Dispose ( bool disposing ) : void

Releases the resources held by this Microsoft.Xna.Framework.Audio.SoundEffect.

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.

GetPooledInstance ( bool forXAct ) : SoundEffectInstance

Returns a sound effect instance from the pool or null if none are available.

PlatformInitialize ( byte buffer, int offset, int count, int sampleRate, AudioChannels channels, int loopStart, int loopLength ) : void
PlatformLoadAudioStream ( Stream s ) : void
PlatformLoadAudioStream ( Stream s ) : void
PlatformSetMasterVolume ( ) : void
SoundEffect ( ) : System
SoundEffect ( string fileName ) : System

Method Details

CreateInstance() public method

Creates a new SoundEffectInstance for this SoundEffect.
Creating a SoundEffectInstance before calling SoundEffectInstance.Play() allows you to access advanced playback features, such as volume, pitch, and 3D positioning.
public CreateInstance ( ) : SoundEffectInstance
return SoundEffectInstance

Dispose() public method

Releases the resources held by this Microsoft.Xna.Framework.Audio.SoundEffect.
public Dispose ( ) : void
return void

FromStream() public static method

Creates a SoundEffect object based on the specified data stream.
The Stream object must point to the head of a valid PCM wave file. Also, this wave file must be in the RIFF bitstream format.
public static FromStream ( Stream s ) : SoundEffect
s Stream Stream object containing PCM wave data.
return SoundEffect

GetSampleDuration() public static method

Gets the TimeSpan representation of a single sample.
public static GetSampleDuration ( int sizeInBytes, int sampleRate, AudioChannels channels ) : TimeSpan
sizeInBytes int Size, in bytes, of audio data.
sampleRate int Sample rate, in Hertz (Hz). Must be between 8000 Hz and 48000 Hz
channels AudioChannels Number of channels in the audio data.
return TimeSpan

GetSampleSizeInBytes() public static method

Gets the size of a sample from a TimeSpan.
public static GetSampleSizeInBytes ( TimeSpan duration, int sampleRate, AudioChannels channels ) : int
duration TimeSpan TimeSpan object that contains the sample duration.
sampleRate int Sample rate, in Hertz (Hz), of audio data. Must be between 8,000 and 48,000 Hz.
channels AudioChannels Number of channels in the audio data.
return int

PlatformInitialize() public method

public PlatformInitialize ( byte buffer, int sampleRate, AudioChannels channels ) : void
buffer byte
sampleRate int
channels AudioChannels
return void

Play() public method

Gets an internal SoundEffectInstance and plays it.

Play returns false if more SoundEffectInstances are currently playing then the platform allows.

To loop a sound or apply 3D effects, call SoundEffect.CreateInstance() and SoundEffectInstance.Play() instead.

SoundEffectInstances used by SoundEffect.Play() are pooled internally.

public Play ( ) : bool
return bool

Play() public method

Gets an internal SoundEffectInstance and plays it with the specified volume, pitch, and panning.

Play returns false if more SoundEffectInstances are currently playing then the platform allows.

To apply looping or simulate 3D audio, call SoundEffect.CreateInstance() and SoundEffectInstance.Play() instead.

SoundEffectInstances used by SoundEffect.Play() are pooled internally.

public Play ( float volume, float pitch, float pan ) : bool
volume float Volume, ranging from 0.0 (silence) to 1.0 (full volume). Volume during playback is scaled by SoundEffect.MasterVolume.
pitch float Pitch adjustment, ranging from -1.0 (down an octave) to 0.0 (no change) to 1.0 (up an octave).
pan float Panning, ranging from -1.0 (left speaker) to 0.0 (centered), 1.0 (right speaker).
return bool

SoundEffect() public method

public SoundEffect ( byte buffer, int sampleRate, AudioChannels channels ) : System
buffer byte Buffer containing PCM wave data.
sampleRate int Sample rate, in Hertz (Hz)
channels AudioChannels Number of channels (mono or stereo).
return System

SoundEffect() public method

Use SoundEffect.GetSampleDuration() to convert time to samples.
public SoundEffect ( byte buffer, int offset, int count, int sampleRate, AudioChannels channels, int loopStart, int loopLength ) : System
buffer byte Buffer containing PCM wave data.
offset int Offset, in bytes, to the starting position of the audio data.
count int Amount, in bytes, of audio data.
sampleRate int Sample rate, in Hertz (Hz)
channels AudioChannels Number of channels (mono or stereo).
loopStart int The position, in samples, where the audio should begin looping.
loopLength int The duration, in samples, that audio should loop over.
return System