import math


def lin2log(val):
    """Convert linear amplitude values to logarithmic.

    Compute amplitude in decibel and map it to the range -1.0 to 1.0.
    (clip amplitudes to range -60dB - 0dB)
    """
    db = (3.0 + math.log10(min(max(abs(val), 0.001), 1.0))) / 3.0
    if val < 0:
        db *= -1
    return db