2303
|
1 ### Copyright (C) 1996 John W. Eaton |
|
2 ### |
|
3 ### This file is part of Octave. |
|
4 ### |
|
5 ### Octave is free software; you can redistribute it and/or modify it |
|
6 ### under the terms of the GNU General Public License as published by |
|
7 ### the Free Software Foundation; either version 2, or (at your option) |
|
8 ### any later version. |
|
9 ### |
|
10 ### Octave is distributed in the hope that it will be useful, but |
|
11 ### WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ### General Public License for more details. |
|
14 ### |
|
15 ### You should have received a copy of the GNU General Public License |
|
16 ### along with Octave; see the file COPYING. If not, write to the Free |
|
17 ### Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ### 02111-1307, USA. |
|
19 |
1636
|
20 function y = mu2lin (x, bit) |
|
21 |
2303
|
22 ## usage: y = mu2lin (x [, bit]) |
|
23 ## |
|
24 ## If x is a vector of audio data with mu-law encoding, mu2lin (x) |
|
25 ## holds the same data with linear encoding. |
|
26 ## The optional argument bit specifies whether the input data is |
|
27 ## 8 bit (default) or 16 bit. |
1636
|
28 |
2303
|
29 ## Written by AW (Andreas.Weingessel@ci.tuwien.ac.at) on Oct 18, 1994 |
|
30 ## Updated by AW (Andreas.Weingessel@ci.tuwien.ac.at) on Oct 27, 1994 |
|
31 ## Copyright Department of Probability Theory and Statistics TU Wien |
1636
|
32 |
|
33 if (nargin == 1) |
|
34 bit = 8; |
|
35 elseif (nargin == 2) |
|
36 if (bit != 8 && bit != 16) |
|
37 error ("mu2lin: bit must be either 8 or 16"); |
|
38 endif |
|
39 else |
|
40 usage ("y = mu2lin (x [, bit])"); |
|
41 endif |
|
42 |
|
43 if (! is_vector (x)) |
|
44 error ("mu2lin: x must be a vector"); |
|
45 endif |
|
46 |
|
47 exp_lut = [0; 132; 396; 924; 1980; 4092; 8316; 16764]; |
|
48 |
2303
|
49 ## invert x bitwise |
1636
|
50 x = 255 - x; |
|
51 |
2303
|
52 ## determine sign of y |
1636
|
53 sig = (x > 127); |
|
54 |
2303
|
55 ## determine exponent and fraction of y |
1636
|
56 e = fix (x / 16) - 8 .* sig + 1; |
|
57 f = rem (x, 16); |
|
58 |
|
59 sig = 1 - 2 .* sig; |
|
60 y = (pow2 (f, e + 2) + exp_lut (e)) .* sig; |
|
61 |
2303
|
62 ## convert to 8-bit |
1636
|
63 if (bit == 8) |
|
64 ld = max (abs (y)); |
|
65 if (ld < 16384) |
|
66 sc = 64 / ld; |
|
67 else |
|
68 sc = 1 / 256; |
|
69 endif |
|
70 y = fix (y * sc); |
|
71 endif |
|
72 |
|
73 endfunction |