mirror of
https://github.com/xiph/opus.git
synced 2025-05-31 23:57:42 +00:00
mu-law code cleanup
This commit is contained in:
parent
08211c279f
commit
aba9af8bde
3 changed files with 25 additions and 23 deletions
|
@ -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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue