Last active
October 14, 2016 15:52
-
-
Save luke161/0979c5fcb518a741abe022711b19c2d2 to your computer and use it in GitHub Desktop.
Util class for converting between a linear volume (0..1) and decibel volume in Unity.
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
/** | |
* VolumeUtils.cs | |
* Author: Luke Holland (http://lukeholland.me/) | |
*/ | |
using UnityEngine; | |
public static class VolumeUtils | |
{ | |
public static float ConvertLinearToDB(float linear) | |
{ | |
return linear<=0 ? -144.0f : 20f * Mathf.Log10(linear); | |
} | |
public static float ConvertDBToLinear(float dB) | |
{ | |
return Mathf.Clamp01( Mathf.Pow(10.0f, dB/20.0f) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment