Field Summary |
|
static final int |
E_ENVMODE_GLOBAL Recommended for sounds that are located outside in the wide open. Accepted by setEnvironmentMode. |
static final int |
E_ENVMODE_LOCAL The environment will be computed based on the sound's position. Accepted by setEnvironmentMode. |
static final int |
E_ENVMODE_PLAIN No environmental effect. This is the default. Accepted by setEnvironmentMode. |
static final int |
E_ENVMODE_SAME_AS_LISTENER Same environmental effect as found in the listener's position. |
static final int |
FLAG_MIXDOWN_MONO When this flag is specified, the sound will be reduced to mono if it should be a stereo file. Stereo sounds cannot be spartialized properly using the position and distance parameters, while mono sounds can. |
static final int |
FLAG_MUSIC When this flag is specified, the sound's gain will be controlled by the music volume from the setup instead of the sound volume. |
static final int |
FLAG_SHARED When this flag is specified, the sound will be shared with other instances that use this flags, too. |
Method Summary |
|
double |
getLength() Returns the length of the sound |
static StaticSound |
loadFromFile(String path, int flags) Load a static sound file using a file path and create a handle for playback. |
static StaticSound |
loadFromResource(ResourcePath resourcePath, int flags) Load a static sound file handle using a resource path and create a handle for playback. |
static StaticSound |
loadFromResourceId(String resourceId, int flags) Load a static sound file handle using a resourceId and create a handle for playback. |
void |
play() Plays the sound (single shot) |
void |
playLoop() Plays the sound (looped) |
void |
setAmbientMode(bool enable) Set to true to change from normal mode to ambient mode. |
void |
setDistanceParameters(float referenceDistance, float rolloffFactor) Sets the sound source's distance parameters that will affect the distance attenuation. |
void |
setDopplerMode(bool enable) Enable or disable the doppler effect. |
void |
setEnvironmentMode(int mode) Sets the environment mode for environmental effects. |
void |
setGain(float gain) Sets the sound source's gain. |
void |
setGainFaded(float gain, float fadeTime) Sets the sound source's target gain. Fades over time to the target gain from the current gain. |
void |
setPitch(float pitch) Sets the sound's pitch (frequency) factor |
void |
setPosition(nlvm.math3d.Vector3f p) Sets the sound source's position in world coordinates. |
void |
stop() Stops playing the sound immediately. |
void |
stopFaded(float fadeTime) Fades the sound and stops playing as soon as the volume has reached 0. |
Field Detail |
Method Detail |
public final double getLength()
Returns the length of the sound
Returns:
length of sound in seconds at pitch = 1
Since:
2.5.5.0
public static StaticSound loadFromFile(String path, int flags)
Load a static sound file using a file path and create a handle for playback.
The path should be a constant string expression so that the park package tool can detect used files. If the path is not a constant string expression, the compiler will show a warning and the file will not be detected by the package tool and will therefore not automatically be added to the park package. Will return null if the file could not be loaded. Set flags to 0 if no special features should be used.
Parameters:
path | - | path to file (relative to the classpath) | |
flags | - | bitwise or combination ( | ) of options. Use 0 for default. Valid options are FLAG_SHARED, FLAG_MUSIC, FLAG_MIXDOWN_MONO. |
public static StaticSound loadFromResource(ResourcePath resourcePath, int flags)
Load a static sound file handle using a resource path and create a handle for playback.
The resources can be specified in the script setup and can be obtained from the Script.getResourceForId method. Will return null if the resource path is null or the sound file could not be loaded. Set flags to 0 if no special features should be used.
Parameters:
resourcePath | - | The resource path that can be obtained from Script.getResourcePathForId | |
flags | - | bitwise or combination ( | ) of options. Use 0 for default. Valid options are FLAG_SHARED, FLAG_MUSIC, FLAG_MIXDOWN_MONO. |
Returns:
Handle to sound. Will return null if the resourceId is unknown or the sound file could not be loaded.
public static StaticSound loadFromResourceId(String resourceId, int flags)
Load a static sound file handle using a resourceId and create a handle for playback.
The resourceId has to be specified in the script setup. Will return null if the resourceId is unknown or the sound file could not be loaded. Set flags to 0 if no special features should be used.
Parameters:
resourceId | - | The resource id as specified in the script description (nl2script) file | |
flags | - | bitwise or combination ( | ) of options. Use 0 for default. Valid options are FLAG_SHARED, FLAG_MUSIC, FLAG_MIXDOWN_MONO. |
Returns:
Handle to sound. Will return null if the resourceId is unknown or the sound file could not be loaded.
Note: Deprecated since 2.5.7.0 Use loadFromResource instead because the resourceId might not be found in special listener states
public final void play()
Plays the sound (single shot)
public final void playLoop()
Plays the sound (looped)
public final void setAmbientMode(bool enable)
Set to true to change from normal mode to ambient mode.
Default is false. In ambient mode, the sound will not be affected by the distance parameters. Will be ignored when it is a shared sound (It was loaded using FLAG_SHARED).
public final void setDistanceParameters(float referenceDistance, float rolloffFactor)
Sets the sound source's distance parameters that will affect the distance attenuation.
The Inverse Distance Clamped Distance Attenuation Model is used internally, using the following formula to compute the final gain: distance = max(distance, referenceDistance); FinalGain = gain * referenceDistance / (referenceDistance + rolloffFactor * (distance - referenceDistance)); Default is 1.0f, 1.0f. Distance parameters will be ignored for ambient sounds.
public final void setDopplerMode(bool enable)
Enable or disable the doppler effect.
Default is true for non-ambient sounds. Doppler will be ignored for ambient and shared sounds.
public final void setEnvironmentMode(int mode)
Sets the environment mode for environmental effects.
Parameters:
mode | - | See E_ENVMODE_ constants for acceptable values |
public final void setGain(float gain)
Sets the sound source's gain.
Parameters:
gain | - | 0..1 |
public final void setGainFaded(float gain, float fadeTime)
Sets the sound source's target gain. Fades over time to the target gain from the current gain.
Parameters:
gain | - | 0..1 | |
fadeTime | - | in seconds, must be >= 0 |
public final void setPitch(float pitch)
Sets the sound's pitch (frequency) factor
Setting the pitch has no effect for sounds created with the FLAG_SHARED flag.
Parameters:
pitch | - | frequency factor of playback (1 = original frequency of sound file). Values will be clamped to 0.1f and 10.0f. |
Since:
2.1.0.4
public final void setPosition(nlvm.math3d.Vector3f p)
Sets the sound source's position in world coordinates.
Default is 0,0,0
public final void stop()
Stops playing the sound immediately.
public final void stopFaded(float fadeTime)
Fades the sound and stops playing as soon as the volume has reached 0.
Parameters:
fadeTime | - | in seconds, must be >= 0 |