Last active
August 6, 2021 15:10
-
-
Save made-indrayana/c4155a4b052501edb05479c42c7b477f to your computer and use it in GitHub Desktop.
Small utilities to convert Linear value (0-1) to dB and vice versa - Yes I'm looking at you Unity - as well as FMODs Internal Bus Volume
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// LinearDecibelConverter.cs | |
// Author: Made Indrayana | |
// MIT License | |
// Small utilities to convert Linear value (0-1) to dB and vice versa | |
public class LinearDecibelConverter | |
{ | |
public float LinearToDecibel(float linear) | |
{ | |
float dB; | |
if (linear != 0) | |
dB = 20.0f * Mathf.Log10(linear); | |
else | |
dB = -144.0f; | |
return dB; | |
} | |
public float DecibelToLinear(float dB) | |
{ | |
float linear = Mathf.Pow(10.0f, dB / 20.0f); | |
return linear; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment