1636
|
1 function y = lin2mu (x) |
|
2 |
|
3 # usage: y = lin2mu (x) |
|
4 # |
|
5 # x is a vector of an 8- or 16-bit linearly encoded audio sample, |
|
6 # This is transformed into a mu-law encoded vector. |
|
7 |
|
8 # Written by AW (Andreas.Weingessel@ci.tuwien.ac.at) on Oct 17, 1994 |
|
9 # Copyright Department of Probability Theory and Statistics TU Wien |
|
10 |
|
11 if (nargin != 1) |
|
12 usage ("y = lin2mu (x)"); |
|
13 endif |
|
14 |
|
15 if (! is_vector (x)) |
|
16 error ("lin2mu: x must be a vector"); |
|
17 endif |
|
18 |
|
19 # transform 8-bit format to 16-bit |
|
20 if (max (abs (x)) <= 128) |
|
21 x = 256 .* x; |
|
22 endif |
|
23 |
|
24 # determine sign of x, set sign(0) = 1. |
|
25 sig = sign(x) + (x == 0); |
|
26 |
|
27 # take absolute value of x, but force it to be smaller than 32636; |
|
28 # add bias |
|
29 x = min (abs (x), 32635 * ones (size (x))) + 132; |
|
30 |
|
31 # find exponent and fraction of bineary representation |
|
32 [f, e] = log2 (x); |
|
33 |
|
34 y = 64 * sig - 16 * e - fix (32 * f) + 335; |
|
35 |
|
36 endfunction |