mu-law code cleanup

This commit is contained in:
Jean-Marc Valin 2018-10-09 02:39:12 -04:00
parent 08211c279f
commit aba9af8bde
3 changed files with 25 additions and 23 deletions

View file

@ -2,15 +2,18 @@
import numpy as np
import math
scale = 255.0/32768.0
scale_1 = 32768.0/255.0
def ulaw2lin(u):
u = u - 128
s = np.sign(u)
u = np.abs(u)
return s*(np.exp(u/128.*math.log(256))-1)/255
return s*scale_1*(np.exp(u/128.*math.log(256))-1)
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)
u = (s*(128*np.log(1+scale*x)/math.log(256)))
u = np.clip(128 + np.round(u), 0, 255)
return u.astype('int16')