Search Results for

    Show / Hide Table of Contents

    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
    Type Description
    float

    MaximumLinearVolume

    Declaration
    public const float MaximumLinearVolume = 10
    Field Value
    Type Description
    float

    MaximumPercentageVolume

    Declaration
    public const float MaximumPercentageVolume = 1000
    Field Value
    Type Description
    float

    MaximumSafeDecibelVolume

    Declaration
    public const float MaximumSafeDecibelVolume = 0
    Field Value
    Type Description
    float

    MaximumSafeLinearVolume

    Declaration
    public const float MaximumSafeLinearVolume = 1
    Field Value
    Type Description
    float

    MaximumSafePercentageVolume

    Declaration
    public const float MaximumSafePercentageVolume = 100
    Field Value
    Type Description
    float

    MinimumDecibelVolume

    Declaration
    public const float MinimumDecibelVolume = -80
    Field Value
    Type Description
    float

    MinimumLinearVolume

    Declaration
    public const float MinimumLinearVolume = 0.0001
    Field Value
    Type Description
    float

    MinimumPercentageVolume

    Declaration
    public const float MinimumPercentageVolume = 0
    Field Value
    Type Description
    float

    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
    Type Description
    float

    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
    Type Description
    float

    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
    Type Description
    float

    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
    Type Description
    string

    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
    Type Description
    float

    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
    Type Description
    float

    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
    Type Description
    float

    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
    Type Description
    bool

    SetLinearVolume(AudioMixer, string, float, bool)

    Sets the value of an exposed parameter while automatically converting the linear value to decibel.
    Do NOT call it in Awake() it doesn't work ! (audioMixer.SetFloat() will return true even if the value does not change).
    https://forum.unity.com/threads/audiomixer-setfloat-doesnt-work-on-awake.323880/

    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
    Type Description
    bool
    In This Article
    Back to top Tetra Creations documentation