__version__ = "1.2.0"

import math

P_REF = 20e-6

def spl(pressure):
    return 20 * math.log10(pressure / P_REF)

def speed_of_sound(temp_c):
    return 331.3 * math.sqrt(1 + temp_c / 273.15)

def wavelength(freq, c=343.0):
    return c / freq

def doppler(f0, v_src, v_obs, c=343.0):
    return f0 * (c + v_obs) / (c - v_src)

def combine_levels(levels):
    """Energetic summation of incoherent sources, in dB."""
    return 10 * math.log10(sum(10 ** (L / 10.0) for L in levels))

def a_weighting(freq):
    f2 = freq * freq
    ra = (12194.0 ** 2 * f2 ** 2) / (
        (f2 + 20.6 ** 2)
        * math.sqrt((f2 + 107.7 ** 2) * (f2 + 737.9 ** 2))
        * (f2 + 12194.0 ** 2))
    return 20 * math.log10(ra) + 2.00

def sabine_rt60(volume, total_absorption):
    return 0.161 * volume / total_absorption
