Skip to content

Instantly share code, notes, and snippets.

@TakaakiIchijo
Last active February 9, 2018 06:50
Show Gist options
  • Save TakaakiIchijo/69eefdc44183f4ddea035a7fee8ef0ac to your computer and use it in GitHub Desktop.
Save TakaakiIchijo/69eefdc44183f4ddea035a7fee8ef0ac to your computer and use it in GitHub Desktop.
UnityのAudioMixerはDecibelでボリュームを設定するので0f~1.0fのLinear値に変換してSetしたりGetしたりする関数
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);
}
@tri-man
Copy link

tri-man commented Jun 16, 2017

重箱の隅だけど、量子化ビット数が16bitの時はダイナミックレンジは96dBになるので、無音は-96dB扱いにする事が多いですね。

@TakaakiIchijo
Copy link
Author

ありがとうございます。無音にしたいときは-96dbを与えるようにしました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment