Table of Contents

Class DynamicSoundEffectInstance

Namespace
Microsoft.Xna.Framework.Audio
Assembly
MonoGame.Framework.dll

A SoundEffectInstance for which the audio buffer is provided by the game at run time.

public sealed class DynamicSoundEffectInstance : SoundEffectInstance, IDisposable
Inheritance
DynamicSoundEffectInstance
Implements
Inherited Members

Constructors

DynamicSoundEffectInstance(int, AudioChannels)

public DynamicSoundEffectInstance(int sampleRate, AudioChannels channels)

Parameters

sampleRate int

Sample rate, in Hertz (Hz).

channels AudioChannels

Number of channels (mono or stereo).

Properties

IsLooped

This value has no effect on DynamicSoundEffectInstance. It may not be set.

public override bool IsLooped { get; set; }

Property Value

bool

PendingBufferCount

Returns the number of audio buffers queued for playback.

public int PendingBufferCount { get; }

Property Value

int

State

Gets the SoundEffectInstance's current playback state.

public override SoundState State { get; }

Property Value

SoundState

Methods

Dispose(bool)

Releases the resources held by this SoundEffectInstance.

protected override void Dispose(bool disposing)

Parameters

disposing bool

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.

GetSampleDuration(int)

Returns the duration of an audio buffer of the specified size, based on the settings of this instance.

public TimeSpan GetSampleDuration(int sizeInBytes)

Parameters

sizeInBytes int

Size of the buffer, in bytes.

Returns

TimeSpan

The playback length of the buffer.

GetSampleSizeInBytes(TimeSpan)

Returns the size, in bytes, of a buffer of the specified duration, based on the settings of this instance.

public int GetSampleSizeInBytes(TimeSpan duration)

Parameters

duration TimeSpan

The playback length of the buffer.

Returns

int

The data size of the buffer, in bytes.

Pause()

Pauses playback of the DynamicSoundEffectInstance.

public override void Pause()

Play()

Plays or resumes the DynamicSoundEffectInstance.

public override void Play()

Resume()

Resumes playback of the DynamicSoundEffectInstance.

public override void Resume()

Stop()

Immediately stops playing the DynamicSoundEffectInstance.

public override void Stop()

Remarks

Calling this also releases all queued buffers.

Stop(bool)

Stops playing the DynamicSoundEffectInstance. If the immediate parameter is false, this call has no effect.

public override void Stop(bool immediate)

Parameters

immediate bool

When set to false, this call has no effect.

Remarks

Calling this also releases all queued buffers.

SubmitBuffer(byte[])

Queues an audio buffer for playback.

public void SubmitBuffer(byte[] buffer)

Parameters

buffer byte[]

The buffer containing PCM audio data.

Remarks

The buffer length must conform to alignment requirements for the audio format.

SubmitBuffer(byte[], int, int)

Queues an audio buffer for playback.

public void SubmitBuffer(byte[] buffer, int offset, int count)

Parameters

buffer byte[]

The buffer containing PCM audio data.

offset int

The starting position of audio data.

count int

The amount of bytes to use.

Remarks

The buffer length must conform to alignment requirements for the audio format.

Events

BufferNeeded

The event that occurs when the number of queued audio buffers is less than or equal to 2.

public event EventHandler<EventArgs> BufferNeeded

Event Type

EventHandler<EventArgs>

Remarks

This event may occur when Play() is called or during playback when a buffer is completed.