Last active
February 9, 2018 06:50
-
-
Save TakaakiIchijo/69eefdc44183f4ddea035a7fee8ef0ac to your computer and use it in GitHub Desktop.
UnityのAudioMixerはDecibelでボリュームを設定するので0f~1.0fのLinear値に変換してSetしたりGetしたりする関数
This file contains hidden or 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
public AudioMixer mixer; | |
public void SetLinearVolumeToMixerGroup(string mixerGroupName, float linearVolume) | |
{ | |
float decibel = 20.0f * Mathf.Log10(linearVolume); | |
if (float.IsNegativeInfinity(decibel)) | |
{ | |
decibel = -96f; | |
} | |
mixer.SetFloat(mixerGroupName, decibel); | |
} | |
public float GetLinearVolumeFromMixerGroup(string mixerGroupName) | |
{ | |
float decibel; | |
mixer.GetFloat(mixerGroupName, out decibel); | |
return Mathf.Pow(10f, decibel / 20f); | |
} |
ありがとうございます。無音にしたいときは-96dbを与えるようにしました。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
重箱の隅だけど、量子化ビット数が16bitの時はダイナミックレンジは96dBになるので、無音は-96dB扱いにする事が多いですね。