UnigineScript
The Language
Core Library
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
High-Level Systems
Samples
Usage Examples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
Migration
Migrating to UNIGINE 2.0
C++ API Migration
Migrating from UNIGINE 2.0 to UNIGINE 2.1

AmbientSource Class

This class is used to create an ambient background sound that is non-directional.

Notice
For an ambient source to be played, a player is always required. In case an ambient source needs to be played when neither a world, nor the editor are loaded, a player should be created in the system script unigine.cpp; otherwise, no sound will be heard.

AmbientSource Class

Members


AmbientSource (string name, int stream = 0)

Constructor. Creates a new ambient sound source using a given sound file.

Arguments

  • string name - Path to the sound file.
  • int stream - Positive value to create a streaming source, 0 to create a static source. If the flag is set, the sample will not be fully loaded into memory. Instead, its successive parts will be read one by one into a memory buffer.

float getGain ()

Returns volume of the sound.

Return value

Volume. 0 means muted, 1 means maximum volume.

float getLength ()

Returns the total length of the sound sample.

Return value

Length of the sample in seconds.

int getLoop ()

Returns a value indicating if the sample is looped.

Return value

Positive number if the sample is looped; otherwise, 0.

float getPitch ()

Returns a sound pitch.

Return value

Factor, by which the current pitch will be multiplied.

string getSampleName ()

Returns the name of the sound file.

Return value

Path to the sound file.

int getSourceMask ()

Returns a bit mask that determines to what sound channels the source belongs to. For a sound source to be heard, its mask should match at least with the player's sound mask in at least one bit.

Return value

Integer, each bit of which specifies a sound channel.

float getTime ()

Returns the current time, at which the sample is being played.

Return value

Time in seconds.

int isPlaying ()

Returns a value indicating if the sample is being played.

Return value

1 if the sample is being played; otherwise, 0.

int isStopped ()

Returns a value indicating if playback is stopped.

Return value

1 if the sample is stopped; otherwise, 0.

void play ()

Starts playing the sample.

void setGain (float gain)

Sets volume of the sound.

Arguments

  • float gain - Volume. 0 means muted, 1 means maximum volume.

void setLoop (int mode)

Sets a value indicating if the sample should be looped.

Arguments

  • int mode - Positive number to loop the sample, 0 to play it only once.

void setPitch (float pitch)

Sets a sound pitch.

Arguments

  • float pitch - Factor, by which the current pitch will be multiplied.

void setSampleName (string name)

Reloads the internal sound source.

Arguments

  • string name - Path to the sound file.

void setSourceMask (int mask)

Updates a bit mask that determines to what sound channels the source belongs to. For a sound source to be heard, its mask should match with the player's sound mask in at least one bit.

Arguments

  • int mask - Integer, each bit of which specifies a sound channel.

void setTime (float time)

Sets time, from which the sample should be played.

Arguments

  • float time - Time in seconds.

void stop ()

Stops playback. This function saves the playback position so that playing of the file can be resumed from the same point.
Last update: 2017-07-03