This page has been translated automatically.
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
FAQ
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
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-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.Sound Class

Controls the general sound settings, such as volume, speed of sound, the Doppler factor, sound adaptation and sound mixer channels. Settings can be loaded from a *.sound file or changed by the corresponding functions below.

In the *.sound file, the sound settings are stored in the <sound> section, for example:

Source code (XML)
<?xml version="1.0" encoding="utf-8"?>
<settings version="2.5.0.1">
	<sound>
		<scale>1</scale>
		<volume>0.8458</volume>
		<doppler>1</doppler>
		<velocity>340.3</velocity>
		<adaptation>0.01</adaptation>
		<attenuation>3</attenuation>
		<hrtf>0</hrtf>
		<source source="0" limit="2"/>
		<source source="1" limit="4"/>
		<source source="2" limit="4"/>
		<source source="4" volume="0.4"/>
	</sound>
</settings>

Usage Example#

The following example shows how to load sound settings from the *.sound file, change them and then save back to the sound settings file.

AppWorldLogic.cs

Source code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Unigine;

namespace UnigineApp
{
	class AppWorldLogic : WorldLogic
	{
        AmbientSource source;

		public override int init()
		{
           // load sound settings from a file
            Sound.get().loadSettings("sound_settings.sound");

            // create a sound source that plays a sample
            source = new AmbientSource("ambient_source.oga",1);
            source.setLoop(1);
            source.play();

			return 1;
		}

		public override int update()
		{
            // enable/disable sounds in the scene
            if (App.get().clearKeyState('z') == 1) {

	            Sound.get().setEnabled(Convert.ToInt32(!Convert.ToBoolean(Sound.get().isEnabled())));
	            Log.message("The enabled flag is {0}\n", Sound.get().isEnabled());
            }

            // print the current speed of sound
            if (App.get().clearKeyState('c') == 1) {
                Log.message("Sound velocity: {0}\n", Sound.get().getVelocity());
            }

            // make the sound louder
            if (App.get().clearKeyState('n') == 1) {
	            if (Sound.get().getVolume() != 1.0f) Sound.get().setVolume(Sound.get().getVolume() + 0.1f);
                Log.message("The sound is louder {0}\n", Sound.get().getVolume());
            }

            // make the sound quieter
            if (App.get().getKeyState('m') == 1) {
	            if (Sound.get().getVolume() > 0.0f) Sound.get().setVolume(Sound.get().getVolume() - 0.1f);
                Log.message("The sound is quieter {0}\n", Sound.get().getVolume());
            }

			return 1;
		}
		
		public override int shutdown()
		{
            // save the sound settings into the file
	        Sound.get().saveSettings("sound_settings.sound",1);
			source.clear();
			
			return 1;
		}
	}
}

Sound Class

Properties

bool IsSourceOcclusion#

A value indicating if occlusion for sounds is enabled. when enabled, the sound will be occluded when there are other nodes between the listener and the sound source.
set
Enables or disables occlusion for sounds. When enabled, the sound will be occluded when there are other nodes between the listener and the sound source.
set value - 1 to enable occlusion for sounds, 0 to disable it.

int SourceReverbMode#

Current sound reverberation mode.
set
Sets sound reverberation mode.
set value - Reverberation mode. One of the REVERB_* variables. The default value is REVERB_MULTIPLE.

bool IsHRTF#

A value indicating if the binaural hrtf (head related transfer function) sound is enabled. an hrtf provides imitation of the surround sound for the stereo wired headset.
set
Enables or disables the HRTF (Head Related Transfer Function) mode. This mode provides imitation of the surround sound for the stereo wired headset.
set value - 1 to enable binaural sound; 0 to disable it.

int Attenuation#

The current sound attenuation mode.
set
Sets the specified sound attenuation mode. Attenuation is the ability of a sound to lower in volume as the player moves away from it.
set value - One of the ATTENUATION_* variables. The default value is ATTENUATION_LINEAR_CLAMPED.

float Scale#

The current time scale for the sound playing.
set
Set the time scale for the sound playing.
set value - Sound time scale. The provided value is clamped in the range [0; 2].

float Doppler#

The current doppler factor. This parameter allows you to exaggerate or tone-down the Doppler shift effect. The default value is 1.0f.
set
Sets the Doppler factor. This parameter allows you to exaggerate or tone-down the Doppler shift effect. By default, it is set to 1.0f.
set value - Doppler factor.

float Adaptation#

The current time set for sound adaptation, that is used when the sound source becomes occluded or other way round.
set
Sets sound occlusion with the specified adaptation time.
set value - Time for sound adaptation to a filter, used when the sound source becomes occluded or other way round.

float Velocity#

Velocity value the Doppler shift calculation is based upon. By default, it is set to 343.3f. If you have players moving really fast, then you may want to adjust this to stop the Doppler shift from distorting the sound too much.
set
Sets the velocity value the Doppler shift calculation is based upon. By default, it is set to 343.3f. If you have players moving really fast, then you may want to adjust this to stop the Doppler shift from distorting the sound too much.
set value - New velocity value for the Doppler shift calculation to be set.

float Volume#

The current sound volume. the default value is 1.0f.
set
Sets the sound volume. By default, it is set to 1.0f.
set value - Sound volume. 0 means the muted sound, 1 means the maximum volume.

float TotalTime#

The total time of asynchronous loading sounds.

string Data#

User string data associated with the world. this string is written directly into the data tag of the *.world file, into the data child tag of the sound tag, for example:
Source code (XML)
<world version="1.21">
	<sound>
		<data>User data</data>
	</sound>
</world>
set
Sets user data associated with the world. This string is written directly into a *.world file, into the data child tag of the sound tag, for example:
Source code (XML)
<world version="1.21">
	<sound>
		<data>User data</data>
	</sound>
</world>
set value - New user data. Data can contain an XML formatted string

bool IsEnabled#

A value indicating if sounds in the scene are enabled.
set
Enables or disables all sounds in the scene.
set value - 1 to enable all sounds, 0 to disable them.

Members


Sound * get ( ) #

Returns the existing Sound instance.
Source code (C#)
Sound.get().getData();

Return value

The Sound instance.

void SetSourceLimit ( int source, int limit ) #

Limits the number of simultaneously played sound sources per one mixer channel.

Arguments

  • int source - Number of the mixer channel (from 0 to 31).
  • int limit - The maximum number of sound sources that can be played simultaneously.

int GetSourceLimit ( int source ) #

Returns the current number of simultaneously played sound sources per one mixer channel.

Arguments

  • int source - Number of the mixer channel (from 0 to 31).

Return value

The maximum number of sound sources that can be played simultaneously.

void SetSourceVolume ( int source, float volume ) #

Sets the volume of the specified mixer channel.

Arguments

  • int source - Number of the mixer channel (from 0 to 31).
  • float volume - Channel volume. The provided value is clamped within [0;1] range, where 0 means muted sound and 1 is the maximum volume.

float GetSourceVolume ( int source ) #

Returns the current volume of the specified mixer channel.

Arguments

  • int source - Number of the mixer channel (from 0 to 31).

Return value

Volume of the specified mixer channel. The returning value is in range [0;1], where 0 means muted sound and 1 is the maximum volume.

bool LoadSettings ( string name ) #

Loads the sound settings from the given file.

Arguments

  • string name - Path to a sound settings file (*.sound).

Return value

1 if the sound settings are loaded successfully; otherwise, 0.

bool LoadWorld ( Xml xml ) #

Loads a sound state from the Xml. The sound state includes such settings as the volume, velocity, adaptation, Doppler factor, time scale and number of sound sources and their volumes.

Arguments

  • Xml xml - Xml node.

Return value

1 if the sound state is loaded successfully; otherwise, 0.

void RenderWorld ( int force ) #

Forces update of the sound system: all sound settings will be applied at once (such as play, stop events and change of parameters). For example, if you have a sound sample playing and you want to update the time, from which the sample should be played, you can perform as follows:
Source code (C#)
AmbientSource sound = new AmbientSource("ambient_sample.oga");
// ...
// check if the sound sample is playing
if (sound.isPlaying() == 1)
{
	// stop playing the sample
	sound.stop();
	// force updating of the sound thread
	Sound.get().renderWorld(1);
	// update time
	sound.setTime(45.0f);
	// continue playing the sample 
	sound.play();
}
The sound thread is updated at 30 FPS, so the playback won't stop immediately, and, therefore, a new time value won't be set. You need force updating of the sound thread after stopping it.

Arguments

  • int force - 1 to force update of the sound system; otherwise, 0.

bool RestoreState ( Stream stream ) #

Restores a sound state from the stream. The sound state includes such settings as the volume, velocity, adaptation, Doppler factor, time scale and number of sound sources and their volumes.
Warning
This function is deprecated and will be removed in the next release.

Arguments

  • Stream stream - Stream to restore the state from.

Return value

1 if the sound state is restored successfully; otherwise, 0.

bool SaveSettings ( string name, int force = 0 ) #

Saves the current sound settings to the given file.

Arguments

  • string name - Path to a sound settings file (*.sound).
  • int force - Force flag indcating if forced saving of sound settings is enabled.

Return value

1 if the sound settings are saved successfully; otherwise, 0.

bool SaveState ( Stream stream ) #

Saves a sound state into the stream. The sound state includes such settings as the volume, velocity, adaptation, Doppler factor, time scale and number of sound sources and their volumes.
Warning
This function is deprecated and will be removed in the next release.

Arguments

  • Stream stream - Stream to save the state into.

Return value

1 if the sound state is saved successfully; otherwise, 0.

bool SaveWorld ( Xml xml, int force = 0 ) #

Saves a sound state into the given Xml node. The sound state includes such settings as the volume, velocity, adaptation, Doppler factor, time scale and number of sound sources and their volumes.

Arguments

  • Xml xml - Xml node.
  • int force - Force flag indicating if forced saving of the sound state is enabled.

Return value

1 if the sound state is saved successfully; otherwise, 0.
Last update: 2019-11-28
Build: ()