Just a few plots to show the amplitude decay curves from WebAudio, see DistanceModelType.
$d$ .. distance between source and listener
$d_\text{ref}$ .. refDistance
$d_\text{max}$ .. maxDistance
$f$ .. rolloffFactor
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['figure.figsize'] = 12, 4 # inch
plt.rcParams['axes.grid'] = True
d = np.linspace(0, 40, num=200)
def plot_decay(data):
plt.plot(d, data)
plt.ylim(-0.1, 1.1)
linear
¶$d$ is clamped to the interval $[dref, dmax]$.
def linear(d_ref, d_max, f):
return 1 - f * (np.maximum(np.minimum(d, d_max), d_ref) - d_ref) / (d_max - d_ref)
plot_decay(linear(2, 5, 1))
plot_decay(linear(2, 7, 1))
plot_decay(linear(2, 9, 1))
plot_decay(linear(1, 7, 1))
plot_decay(linear(2, 7, 1))
plot_decay(linear(3, 7, 1))
plot_decay(linear(2, 7, 1))
plot_decay(linear(2, 7, 0.5))
plot_decay(linear(2, 7, 0.25))
plot_decay(linear(2, 7, 0))
$d$ is clamped to the interval $[d_\text{ref}, \infty)$.
def inverse(d_ref, f):
return d_ref / (d_ref + f * (np.maximum(d, d_ref) - d_ref))
plot_decay(inverse(1, 1))
plot_decay(inverse(5, 1))
plot_decay(inverse(10, 1))
plot_decay(inverse(5, 1))
plot_decay(inverse(5, 0.5))
plot_decay(inverse(5, 0.25))
plot_decay(inverse(5, 0))
exponential
¶$d$ is clamped to the interval $[d_\text{ref}, \infty)$.
def exponential(d_ref, f):
return (np.maximum(d, d_ref) / d_ref) ** -f
plot_decay(exponential(1, 1))
plot_decay(exponential(5, 1))
plot_decay(exponential(10, 1))
plot_decay(exponential(5, 1))
plot_decay(exponential(5, 0.5))
plot_decay(exponential(5, 0.25))
plot_decay(exponential(5, 0))
inverse
and exponential
¶plot_decay(inverse(1, 0.5))
plot_decay(inverse(5, 0.5))
plot_decay(inverse(10, 0.5))
plot_decay(exponential(1, 0.5))
plot_decay(exponential(5, 0.5))
plot_decay(exponential(10, 0.5))
plot_decay(inverse(1, 0.25))
plot_decay(inverse(5, 0.25))
plot_decay(inverse(10, 0.25))
plot_decay(exponential(1, 0.25))
plot_decay(exponential(5, 0.25))
plot_decay(exponential(10, 0.25))
plot_decay(inverse(5, 0.5))
plot_decay(exponential(5, 0.65))