import torch
import math


def mu_transform(x):
    """ Forward operation of mu-law transform for 16-bit integers. """
    assert x.min() >= -1 and x.max() <= 1
    return torch.sign(x) * torch.log(1 + 32768. * torch.abs(x)) / math.log(1 + 32768.)