Export (0) Print
Expand All

SoundEffect Constructor (Byte[], Int32, Int32, Int32, AudioChannels, Int32, Int32)

Initializes a new instance of SoundEffect with specified parameters such as audio sample rate, channels, looping criteria, and a buffer to hold the audio.

Namespace: Microsoft.Xna.Framework.Audio
Assembly: Microsoft.Xna.Framework (in microsoft.xna.framework.dll)

public SoundEffect (
         byte[] buffer,
         int offset,
         int count,
         int sampleRate,
         AudioChannels channels,
         int loopStart,
         int loopLength


Type: Byte
Buffer that contains the audio data. The audio format must be PCM wave data.
Type: Int32
Offset, in bytes, to the starting position of the audio data.
Type: Int32
Amount, in bytes, of audio data.
Type: Int32
Sample rate, in Hertz (Hz), of audio data.
Type: AudioChannels
Number of channels (mono or stereo) of audio data.
Type: Int32
Loop start in samples.
Type: Int32
Loop length in samples.

Exception typeCondition

The exception thrown when the following arguments are out of range:

  • sampleRate is less than 8,000 Hz or is greater than 48,000 Hz.
  • channels is something other than mono or stereo.

The exception thrown when the following arguments are invalid:

  • buffer is null, has zero length, or does not satisfy alignment requirements.
  • offset is less than zero, is greater than or equal to the size of the buffer, or does not satisfy alignment requirements.
  • The sum of count and offset is greater than the size of the buffer, count is less than or equal to zero, or does not satisfy alignment requirements.
  • loopStart is less than zero, loopLength is less than zero, or loopStart + loopLength is greater than the sample size.

For information regarding audio format using XNA Game Studio see Audio API Developers Guide.

Xbox 360, Windows 7, Windows Vista, Windows XP, Windows Phone

Community Additions

© 2014 Microsoft