How can I calculate an audio volume in a human like perception?

107 Views Asked by At

Let's say I have a value v, such that $x \in [0, 1]$, and v represents digital audio volume. knowing that human perception of loudness is logarithmic, how can I find a function $f(v) = v'$ to interpolate, such that $v'$ respect that rule?

I've tried linear interpolation but the loudness doesn't change much when $v \in (0.5, 1]$.

1

There are 1 best solutions below

0
On BEST ANSWER

Considering that human perception of loudness is exponential (measured using power, intensity and represented as decibels), therefore it's not linear, we need to find a function in a format $f(v) = ae^{bx}$ that tights $0$ at lower bounds and $1$ at upper bounds, so we can interpolate using $v$.

Now, let's find $a$ and $b$ that constraints that bound. Looking for points $(0, 0)$ and $(1, 1)$ in the function $f$ graph we can find valid unknowns to interpolate volume in a non-linear fashion:

$(1, 1): f(v) = ae^{bx} \therefore 1 = ae^{b\cdot1} \therefore a = \frac{1}{e^b}$ (1)

$(0, 0):$ Impossible, because logarithmic curves $g$ (like the one who's describes human loudness perception) never touches y axis when $g(v) \lt 1$, like the following:

Any log curve

So, we need another initial point to interpolate. Looking for the conversion formula between volume and decibels, we have:

$dB = 20 \log v \therefore v = 10^{\frac{dB}{20}}$

And a valid initial point could be $(0, 10^{-\frac{dB}{20}}) \therefore a = 10^{-\frac{dB}{20}}$. (2)

Now, to find a valid $b$ we can apply cross-multiplication rule using (1) and (2):

$10^{-\frac{dB}{20}} = \frac{1}{e^b} \therefore b = \ln 10^\frac{dB}{20}$

Finally, our final formula is:

$f(v) = \frac{1}{10^\frac{dB}{20}} \cdot e^{\ln(10\frac{dB}{20})\cdot v}$

You can try some values for dB that fits your constraints. $dB = 40$ works very well, because $f(0) \approx 0$ and $f(1) \approx 1$. For $dB \lt 30$ you can feel considerable loudness at $f(0)$ and when $dB \gt 50$, $v \le 0.5$ tends to silence during almost all interval.

You can simulate the formula here.