Microsoft.Xna.Framework.Audio
Class SoundEffect

java.lang.Object
  extended by Microsoft.Xna.Framework.Audio.SoundEffect
All Implemented Interfaces:
IDisposable

public final class SoundEffect
extends java.lang.Object
implements IDisposable

Reference page contains links to related code samples.

Author:
Halofreak1990

Constructor Summary
SoundEffect(byte[] buffer, int sampleRate, AudioChannels channels)
          Initializes a new instance of SoundEffect based on an audio buffer, sample rate, and number of audio channels.
SoundEffect(byte[] buffer, int offset, int count, int sampleRate, AudioChannels channels, int loopStart, int loopLength)
          Initializes a new instance of SoundEffect with specified parameters such as audio sample rate, channels, looping criteria, and a buffer to hold the audio.
 
Method Summary
 SoundEffectInstance CreateInstance()
          Creates a new SoundEffectInstance for this SoundEffect.
 void Dispose()
          Releases the resources used by the SoundEffect.
protected  void Dispose(boolean disposing)
           
protected  void finalize()
           
static SoundEffect FromStream(java.io.InputStream stream)
          Creates a SoundEffect object based on the specified data stream.
static SoundEffect FromStream(Stream stream)
          Creates a SoundEffect object based on the specified data stream.
static float getDistanceScale()
          Gets a value that adjusts the effect of distance calculations on the sound (emitter).
static float getDopplerScale()
          Gets a value that adjusts the effect of doppler calculations on the sound (emitter).
 TimeSpan getDuration()
          Gets the duration of the SoundEffect.
static float getMasterVolume()
          Gets the master volume that affects all SoundEffectInstance sounds.
 java.lang.String getName()
          Gets the asset name of the SoundEffect.
static TimeSpan GetSampleDuration(int sizeInBytes, int sampleRate, AudioChannels channels)
          Returns the sample duration based on the specified sample size and sample rate.
static int GetSampleSizeInBytes(TimeSpan duration, int sampleRate, AudioChannels channels)
          Returns the size of the audio sample based on duration, sample rate, and audio channels.
static float getSpeedOfSound()
          Returns the speed of sound. 343.5 meters per second.
 boolean IsDisposed()
          Gets a value that indicates whether the object is disposed.
 boolean Play()
          Plays a sound.
 boolean Play(float volume, float pitch, float pan)
          Plays a sound based on specified volume, pitch, and panning.
static void setDistanceScale(float value)
          Sets a value that adjusts the effect of distance calculations on the sound (emitter).
static void setDopplerScale(float value)
          Sets a value that adjusts the effect of doppler calculations on the sound (emitter).
static void setMasterVolume(float value)
          Sets the master volume that affects all SoundEffectInstance sounds.
 void setName(java.lang.String value)
          Sets the asset name of the SoundEffect to the specified value.
static void setSpeedOfSound(float value)
          Sets the speed of sound.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SoundEffect

public SoundEffect(byte[] buffer,
                   int sampleRate,
                   AudioChannels channels)
Initializes a new instance of SoundEffect based on an audio buffer, sample rate, and number of audio channels. Reference page contains links to related conceptual articles.

Parameters:
buffer - Buffer that contains the audio data. The audio format must be PCM wave data.
sampleRate - Sample rate, in Hertz (Hz), of audio data.
channels - Number of channels (mono or stereo) of audio data.

SoundEffect

public SoundEffect(byte[] buffer,
                   int offset,
                   int count,
                   int sampleRate,
                   AudioChannels channels,
                   int loopStart,
                   int loopLength)
Initializes a new instance of SoundEffect with specified parameters such as audio sample rate, channels, looping criteria, and a buffer to hold the audio. Reference page contains links to related conceptual articles.

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.
Method Detail

getDistanceScale

public static float getDistanceScale()
Gets a value that adjusts the effect of distance calculations on the sound (emitter).


setDistanceScale

public static void setDistanceScale(float value)
Sets a value that adjusts the effect of distance calculations on the sound (emitter).


getDopplerScale

public static float getDopplerScale()
Gets a value that adjusts the effect of doppler calculations on the sound (emitter).


setDopplerScale

public static void setDopplerScale(float value)
Sets a value that adjusts the effect of doppler calculations on the sound (emitter).


getDuration

public TimeSpan getDuration()
Gets the duration of the SoundEffect.


IsDisposed

public boolean IsDisposed()
Gets a value that indicates whether the object is disposed.


getMasterVolume

public static float getMasterVolume()
Gets the master volume that affects all SoundEffectInstance sounds.


setMasterVolume

public static void setMasterVolume(float value)
Sets the master volume that affects all SoundEffectInstance sounds.


getName

public java.lang.String getName()
Gets the asset name of the SoundEffect.


setName

public void setName(java.lang.String value)
Sets the asset name of the SoundEffect to the specified value.


getSpeedOfSound

public static float getSpeedOfSound()
Returns the speed of sound. 343.5 meters per second.


setSpeedOfSound

public static void setSpeedOfSound(float value)
Sets the speed of sound.


CreateInstance

public SoundEffectInstance CreateInstance()
Creates a new SoundEffectInstance for this SoundEffect. Reference page contains links to related code samples.


Dispose

public void Dispose()
Releases the resources used by the SoundEffect.

Specified by:
Dispose in interface IDisposable

Dispose

protected void Dispose(boolean disposing)
Parameters:
disposing -

finalize

protected void finalize()
Overrides:
finalize in class java.lang.Object

FromStream

public static SoundEffect FromStream(Stream stream)
Creates a SoundEffect object based on the specified data stream.

Parameters:
stream - Stream object that contains the data for this SoundEffect object.
Throws:
ArgumentNullException - stream is null.

FromStream

public static SoundEffect FromStream(java.io.InputStream stream)
Creates a SoundEffect object based on the specified data stream.

Parameters:
stream - InputStream object that contains the data for this SoundEffect object.

GetSampleDuration

public static TimeSpan GetSampleDuration(int sizeInBytes,
                                         int sampleRate,
                                         AudioChannels channels)
Returns the sample duration based on the specified sample size and sample rate.

Parameters:
sizeInBytes - Size, in bytes, of audio data.
sampleRate - Sample rate, in Hertz (Hz), of audio content. The sampleRate must be between 8000 Hz and 48000 Hz.
channels - Number of channels in the audio data.

GetSampleSizeInBytes

public static int GetSampleSizeInBytes(TimeSpan duration,
                                       int sampleRate,
                                       AudioChannels channels)
Returns the size of the audio sample based on duration, sample rate, and audio channels.

Parameters:
duration - TimeSpan object that contains the sample duration.
sampleRate - Sample rate, in Hertz (Hz), of audio content. The sampleRate parameter must be between 8,000 Hz and 48,000 Hz.
channels - Number of channels in the audio data.

Play

public boolean Play()
Plays a sound. Reference page contains links to related code samples.

Returns:
True if successful, false otherwise.

Play

public boolean Play(float volume,
                    float pitch,
                    float pan)
Plays a sound based on specified volume, pitch, and panning. Reference page contains links to related code samples.

Parameters:
volume - Volume, ranging from 0.0f (silence) to 1.0f (full volume). 1.0f is full volume relative to SoundEffect.MasterVolume.
pitch - Pitch adjustment, ranging from -1.0f (down one octave) to 1.0f (up one octave). 0.0f is unity (normal) pitch.
pan - Panning, ranging from -1.0f (full left) to 1.0f (full right). 0.0f is centered.
Returns:
True if successful, false otherwise.