This page has been translated automatically.
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
CIGI Client Plugin
Rendering-Related Classes
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Unigine::AmbientSource Class

Header:#include <UnigineSounds.h>

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

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.
Notice

To play a short beep sound repeatedly when a key is held, note that sound events like "play" or "stop" are not updated immediately, sound has its own thread that is updated at 30 FPS. You need to call force sound rendering to stop source first:

Source code (C++)
class MyClass{
	Unigine::AmbientSourcePtr m_beep;
	void MyKeyCallback();
}

...

void MyClass::MyKeyCallback(){
	m_beep->stop();
	m_beep->setTime(0.0f);
	Unigine::Sound()->get()->renderWorld(1);
	m_beep->play();
}

AmbientSource Class

Members


static AmbientSourcePtr create(const char * name, int stream = 0)

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

Arguments

  • const char * 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.

void setGain(float gain)

Sets volume of the sound.

Arguments

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

float getGain()

Returns volume of the sound.

Return value

Volume. 0 means muted, 1 means maximum volume.

void * getInterface()

float getLength()

Returns the total length of the sound sample.

Return value

Length of the sample in seconds.

void setLoop(int loop)

Sets a value indicating if the sample should be looped.

Arguments

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

int getLoop()

Returns a value indicating if the sample is looped.

Return value

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

void setPitch(float pitch)

Sets a sound pitch.

Arguments

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

float getPitch()

Returns a sound pitch.

Return value

Factor, by which the current pitch will be multiplied.

int isPlaying()

Returns a value indicating if the sample is being played.

Return value

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

void setSampleName(const char * name)

Reloads the internal sound source.

Arguments

  • const char * name - Path to the sound file.

const char * getSampleName()

Returns the name of the sound file.

Return value

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.

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.

int isStopped()

Returns a value indicating if playback is stopped.

Return value

1 if the sample is stopped; otherwise, 0.

void setTime(float time)

Sets time, from which the sample should be played.

Arguments

  • float time - Time in seconds.

float getTime()

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

Return value

Time in seconds.

void play()

Starts playing the sample.

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-10-20
Build: ()