Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Audio Mixer audible volume interval question

Discussion in 'Audio & Video' started by IntDev, Nov 5, 2015.

  1. IntDev

    IntDev

    Joined:
    Jan 14, 2013
    Posts:
    152
    We've implemented a slider control (Values ranging from -80 to 0) for our in-game BGM volume, and we're doing it by exposing the attenuation volume parameter of the mixer. Everything seems fine and dandy, but we noticed that most tracks become barely audible at around halfway through the slider, which does seem rather odd. Is this kind of behavior expected? Can anyone shed some light on this matter? Thanks in advance!
     
  2. michaelhartung

    michaelhartung

    Joined:
    Dec 19, 2013
    Posts:
    72
    That's because dB is logarithmic and not linear and therefore perfectly normal [1]. If you want your slider control to "feel linear" you'd have to implement some math that translates say values from 0-100 to corresponding dB values (search for "convert decibel to linear float" or sth. the like).

    Hope that helps.

    https://en.wikipedia.org/wiki/Decibel
     
    IntDev likes this.
  3. IntDev

    IntDev

    Joined:
    Jan 14, 2013
    Posts:
    152
    Just in case someone need, I converted from linear to decibels by using:

    Code (CSharp):
    1. var dB = 20f * Mathf.Log10(linearValue * linearValue); // linearValue ranges 0.0 to 1.0
    2. if (float.IsInfinity(dB))
    3.     dB = -80f;
     
    Last edited: Nov 6, 2015
    The_BenEvans and michaelhartung like this.