shithub: opus

ref: 785a2b2e84f955dd3013536b35529bb9fa1afb6b
dir: /dnn/ulaw.py/

View raw version

import numpy as np
import math

def ulaw2lin(u):
    s = np.sign(u)
    u = np.abs(u)
    return s*(np.exp(u/128.*math.log(256))-1)/255


def lin2ulaw(x):
    s = np.sign(x)
    x = np.abs(x)
    u = (s*(128*np.log(1+255*x)/math.log(256)))
    u = np.round(u)
    return u.astype('int16')