1636
|
1 function y = mu2lin (x, bit) |
|
2 |
|
3 # usage: y = mu2lin (x [, bit]) |
|
4 # |
|
5 # If x is a vector of audio data with mu-law encoding, mu2lin (x) |
|
6 # holds the same data with linear encoding. |
|
7 # The optional argument bit specifies whether the input data is |
|
8 # 8 bit (default) or 16 bit. |
|
9 |
|
10 # Written by AW (Andreas.Weingessel@ci.tuwien.ac.at) on Oct 18, 1994 |
|
11 # Updated by AW (Andreas.Weingessel@ci.tuwien.ac.at) on Oct 27, 1994 |
|
12 # Copyright Department of Probability Theory and Statistics TU Wien |
|
13 |
|
14 if (nargin == 1) |
|
15 bit = 8; |
|
16 elseif (nargin == 2) |
|
17 if (bit != 8 && bit != 16) |
|
18 error ("mu2lin: bit must be either 8 or 16"); |
|
19 endif |
|
20 else |
|
21 usage ("y = mu2lin (x [, bit])"); |
|
22 endif |
|
23 |
|
24 if (! is_vector (x)) |
|
25 error ("mu2lin: x must be a vector"); |
|
26 endif |
|
27 |
|
28 exp_lut = [0; 132; 396; 924; 1980; 4092; 8316; 16764]; |
|
29 |
|
30 # invert x bitwise |
|
31 x = 255 - x; |
|
32 |
|
33 # determine sign of y |
|
34 sig = (x > 127); |
|
35 |
|
36 # determine exponent and fraction of y |
|
37 e = fix (x / 16) - 8 .* sig + 1; |
|
38 f = rem (x, 16); |
|
39 |
|
40 sig = 1 - 2 .* sig; |
|
41 y = (pow2 (f, e + 2) + exp_lut (e)) .* sig; |
|
42 |
|
43 # convert to 8-bit |
|
44 if (bit == 8) |
|
45 ld = max (abs (y)); |
|
46 if (ld < 16384) |
|
47 sc = 64 / ld; |
|
48 else |
|
49 sc = 1 / 256; |
|
50 endif |
|
51 y = fix (y * sc); |
|
52 endif |
|
53 |
|
54 endfunction |