public final class SoundEffect extends java.lang.Object implements IDisposable
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
public SoundEffect(byte[] buffer, int sampleRate, AudioChannels channels)
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.public SoundEffect(byte[] buffer, int offset, int count, int sampleRate, AudioChannels channels, int loopStart, int loopLength)
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.public static float getDistanceScale()
public static void setDistanceScale(float value)
public static float getDopplerScale()
public static void setDopplerScale(float value)
public TimeSpan getDuration()
public boolean IsDisposed()
public static float getMasterVolume()
public static void setMasterVolume(float value)
public java.lang.String getName()
public void setName(java.lang.String value)
public static float getSpeedOfSound()
public static void setSpeedOfSound(float value)
public SoundEffectInstance CreateInstance()
public void Dispose()
Dispose
in interface IDisposable
protected void Dispose(boolean disposing)
disposing
- protected void finalize()
finalize
in class java.lang.Object
public static SoundEffect FromStream(Stream stream)
stream
- Stream object that contains the data for this SoundEffect object.ArgumentNullException
- stream is null.public static SoundEffect FromStream(java.io.InputStream stream)
stream
- InputStream object that contains the data for this SoundEffect object.public static TimeSpan GetSampleDuration(int sizeInBytes, int sampleRate, AudioChannels channels)
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.public static int GetSampleSizeInBytes(TimeSpan duration, int sampleRate, AudioChannels channels)
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.public boolean Play()
public boolean Play(float volume, float pitch, float pan)
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.