Share via


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.

Syntax

'Declaration
Public Sub New ( _
         buffer As Byte(), _
         offset As Integer, _
         count As Integer, _
         sampleRate As Integer, _
         channels As AudioChannels, _
         loopStart As Integer, _
         loopLength As Integer _
)
public SoundEffect (
         byte[] buffer,
         int offset,
         int count,
         int sampleRate,
         AudioChannels channels,
         int loopStart,
         int loopLength
)
public:
SoundEffect(
         unsigned char buffer[],
         int offset,
         int count,
         int sampleRate,
         AudioChannels channels,
         int loopStart,
         int loopLength
)

Parameters

  • buffer
    Type: Byte
    Buffer that contains the audio data. The audio format must be PCM wave data.
  • offset
    Type: Int32
    Offset, in bytes, to the starting position of the audio data.
  • count
    Type: Int32
    Amount, in bytes, of audio data.
  • sampleRate
    Type: Int32
    Sample rate, in Hertz (Hz), of audio data.
  • channels
    Type: AudioChannels
    Number of channels (mono or stereo) of audio data.
  • loopStart
    Type: Int32
    Loop start in samples.
  • loopLength
    Type: Int32
    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.

Requirements

Namespace: Microsoft.Xna.Framework.Audio

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

See Also

Concepts

Sounds Overview
Audio API Developers Guide

Reference

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

Platforms

Windows Phone