Class AudioMixerExtensions
Contain several methods for easily converting the volume value in decibels to a linear or percentage value.
Exposed volume parameters of an AudioMixer are in decibels, but when the volume is controlled
using a slider from the user interface, the linear value must be converted.
The convertion is done automatically when SetLinearVolume() is called.
Inheritance
object
AudioMixerExtensions
Namespace: TetraCreations.Core
Assembly: cs.temp.dll.dll
Syntax
public static class AudioMixerExtensions
Fields
MaximumDecibelVolume
Declaration
public const float MaximumDecibelVolume = 20
Field Value
MaximumLinearVolume
Declaration
public const float MaximumLinearVolume = 10
Field Value
MaximumPercentageVolume
Declaration
public const float MaximumPercentageVolume = 1000
Field Value
MaximumSafeDecibelVolume
Declaration
public const float MaximumSafeDecibelVolume = 0
Field Value
MaximumSafeLinearVolume
Declaration
public const float MaximumSafeLinearVolume = 1
Field Value
MaximumSafePercentageVolume
Declaration
public const float MaximumSafePercentageVolume = 100
Field Value
MinimumDecibelVolume
Declaration
public const float MinimumDecibelVolume = -80
Field Value
MinimumLinearVolume
Declaration
public const float MinimumLinearVolume = 0.0001
Field Value
MinimumPercentageVolume
Declaration
public const float MinimumPercentageVolume = 0
Field Value
Methods
ClampDecibelVolume(float, float, float)
Clamp the decibel volume from -80f to 0f.
Declaration
public static float ClampDecibelVolume(float dB, float min = -80, float max = 0)
Parameters
Type |
Name |
Description |
float |
dB |
|
float |
min |
|
float |
max |
|
Returns
ClampLinearVolume(float, float, float)
Clamp the linear volume from 0.0001f to 1f.
Declaration
public static float ClampLinearVolume(float linear, float min = 0.0001, float max = 1)
Parameters
Type |
Name |
Description |
float |
linear |
|
float |
min |
|
float |
max |
|
Returns
ClampPercentageVolume(float, float, float)
Clamp the volume as percentage from 0% to 100%.
Declaration
public static float ClampPercentageVolume(float percentage, float min = 0, float max = 100)
Parameters
Type |
Name |
Description |
float |
percentage |
|
float |
min |
|
float |
max |
|
Returns
DecibelToString(float)
Returns the decibel value as a string using the format : "+0.## dbB"
Declaration
public static string DecibelToString(float dB)
Parameters
Type |
Name |
Description |
float |
dB |
Value in decibel
|
Returns
GetAudioMixerGroup(AudioMixer, string, string)
Returns an AudioMixerGroup if it's name contains the word passed as parameter.
For example GetAudioMixerGroup("MusicVolumeParam") will find the group called "Music".
Declaration
public static AudioMixerGroup GetAudioMixerGroup(this AudioMixer audioMixer, string name, string mainGroupName = "Master")
Parameters
Type |
Name |
Description |
AudioMixer |
audioMixer |
|
string |
name |
The group name we are looking for.
|
string |
mainGroupName |
The main group to search in, by default it's the "Master" group.
|
Returns
Type |
Description |
AudioMixerGroup |
|
GetDecibelValueFromLinear(float, bool)
Returns the decibel value from a linear value.
Declaration
public static float GetDecibelValueFromLinear(float linearVolume, bool clamp = true)
Parameters
Type |
Name |
Description |
float |
linearVolume |
Volume as linear
|
bool |
clamp |
Will prevent the value to exceed : -80f and 0f
|
Returns
GetLinearValueFromDecibel(float, bool)
Returns the linear value from a decibel value.
Declaration
public static float GetLinearValueFromDecibel(float decibel, bool clamp = true)
Parameters
Type |
Name |
Description |
float |
decibel |
Volume in decibel
|
bool |
clamp |
Prevent the returned value to exceed : 0.0001f to 1f
|
Returns
GetLinearValueFromPercentage(float, bool)
Returns the linear value from a percentage value.
Declaration
public static float GetLinearValueFromPercentage(float percentage, bool clamp = true)
Parameters
Type |
Name |
Description |
float |
percentage |
Volume as a percentage
|
bool |
clamp |
Prevent the returned value to exceed : 0.0001f to 1f
|
Returns
GetLinearVolume(AudioMixer, string, out float, bool)
Returns the linear value of an exposed parameter by it's name from an AudioMixer.
We assume the parameter is a Volume.
Declaration
public static bool GetLinearVolume(this AudioMixer audioMixer, string parameterName, out float linearValue, bool clamp = true)
Parameters
Type |
Name |
Description |
AudioMixer |
audioMixer |
|
string |
parameterName |
Name of the exposed parameter
|
float |
linearValue |
The current linear value of the volume
|
bool |
clamp |
If true the returned value cannot exceed 0f and 1f
|
Returns
SetLinearVolume(AudioMixer, string, float, bool)
Declaration
public static bool SetLinearVolume(this AudioMixer audioMixer, string parameterName, float value, bool clamp = true)
Parameters
Type |
Name |
Description |
AudioMixer |
audioMixer |
|
string |
parameterName |
The name of the volume exposed parameter
|
float |
value |
The linear value
|
bool |
clamp |
|
Returns