Skip to main content

DecibelUtils

Converts between linear ratios and decibels. A decibel value is a logarithm, so it is a plain number here rather than a [MetricUnit]: decibel gains add where linear ratios multiply, which does not fit MetricUnit's arithmetic.

Amplitude ratios (a signal's level, such as a voltage or a sample value) use 20 × log10; power ratios use 10 × log10. Halving the amplitude is about -6 dB; halving the power is about -3 dB.

DecibelUtils.amplitudeToDecibels(0.5) -- -6.0206
DecibelUtils.decibelsToAmplitude(-6) -- 0.5012
DecibelUtils.powerToDecibels(2) -- 3.0103

Check which kind a property is before converting: a volume that scales a signal is an amplitude ratio.

Functions​

amplitudeToDecibels​

DecibelUtils.amplitudeToDecibels(
ratio: number--

1 is unchanged

) → number

The decibels of an amplitude ratio: 20 × log10(ratio). A ratio of 0 is negative infinity (silence).

decibelsToAmplitude​

DecibelUtils.decibelsToAmplitude(
decibels: number--

0 is unchanged

) → number

The amplitude ratio of a decibel gain: 10 ^ (decibels / 20).

powerToDecibels​

DecibelUtils.powerToDecibels(
ratio: number--

1 is unchanged

) → number

The decibels of a power ratio: 10 × log10(ratio). A ratio of 0 is negative infinity.

decibelsToPower​

DecibelUtils.decibelsToPower(
decibels: number--

0 is unchanged

) → number

The power ratio of a decibel gain: 10 ^ (decibels / 10).

Show raw api
{
    "functions": [
        {
            "name": "amplitudeToDecibels",
            "desc": "The decibels of an amplitude ratio: `20 × log10(ratio)`. A ratio of 0 is negative infinity (silence).",
            "params": [
                {
                    "name": "ratio",
                    "desc": "1 is unchanged",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 28,
                "path": "src/metricutils/src/Shared/Logarithmic/DecibelUtils.lua"
            }
        },
        {
            "name": "decibelsToAmplitude",
            "desc": "The amplitude ratio of a decibel gain: `10 ^ (decibels / 20)`.",
            "params": [
                {
                    "name": "decibels",
                    "desc": "0 is unchanged",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 42,
                "path": "src/metricutils/src/Shared/Logarithmic/DecibelUtils.lua"
            }
        },
        {
            "name": "powerToDecibels",
            "desc": "The decibels of a power ratio: `10 × log10(ratio)`. A ratio of 0 is negative infinity.",
            "params": [
                {
                    "name": "ratio",
                    "desc": "1 is unchanged",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 53,
                "path": "src/metricutils/src/Shared/Logarithmic/DecibelUtils.lua"
            }
        },
        {
            "name": "decibelsToPower",
            "desc": "The power ratio of a decibel gain: `10 ^ (decibels / 10)`.",
            "params": [
                {
                    "name": "decibels",
                    "desc": "0 is unchanged",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 67,
                "path": "src/metricutils/src/Shared/Logarithmic/DecibelUtils.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "DecibelUtils",
    "desc": "Converts between linear ratios and decibels. A decibel value is a logarithm, so it is a plain number here rather\nthan a [MetricUnit]: decibel gains add where linear ratios multiply, which does not fit MetricUnit's arithmetic.\n\nAmplitude ratios (a signal's level, such as a voltage or a sample value) use 20 × log10; power ratios use\n10 × log10. Halving the amplitude is about -6 dB; halving the power is about -3 dB.\n\n```lua\nDecibelUtils.amplitudeToDecibels(0.5) -- -6.0206\nDecibelUtils.decibelsToAmplitude(-6) -- 0.5012\nDecibelUtils.powerToDecibels(2) -- 3.0103\n```\n\nCheck which kind a property is before converting: a volume that scales a signal is an amplitude ratio.",
    "source": {
        "line": 19,
        "path": "src/metricutils/src/Shared/Logarithmic/DecibelUtils.lua"
    }
}