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)

Syntax

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

Parameters

  • buffer
    Buffer that contains the audio data. The audio format must be PCM wave data.
  • offset
    Offset, in bytes, to the starting position of the audio data.
  • count
    Amount, in bytes, of audio data.
  • sampleRate
    Sample rate, in Hertz (Hz), of audio data.
  • channels
    Number of channels (mono or stereo) of audio data.
  • loopStart
    Loop start in samples.
  • loopLength
    Loop length in samples.

Exceptions

Exception type Condition
ArgumentOutOfRangeException

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.
ArgumentException

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.

Remarks

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

See Also

Concepts

Sounds Overview
Audio API Developers Guide

Reference

SoundEffect Class
SoundEffect Members
Microsoft.Xna.Framework.Audio Namespace

Platforms

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