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 |
2311
|
20 ## usage: y = lin2mu (x) |
|
21 ## |
|
22 ## x is a vector of an 8- or 16-bit linearly encoded audio sample, |
|
23 ## This is transformed into a mu-law encoded vector. |
|
24 |
1636
|
25 function y = lin2mu (x) |
|
26 |
2303
|
27 ## Written by AW (Andreas.Weingessel@ci.tuwien.ac.at) on Oct 17, 1994 |
|
28 ## Copyright Department of Probability Theory and Statistics TU Wien |
1636
|
29 |
|
30 if (nargin != 1) |
|
31 usage ("y = lin2mu (x)"); |
|
32 endif |
|
33 |
|
34 if (! is_vector (x)) |
|
35 error ("lin2mu: x must be a vector"); |
|
36 endif |
|
37 |
2303
|
38 ## transform 8-bit format to 16-bit |
1636
|
39 if (max (abs (x)) <= 128) |
|
40 x = 256 .* x; |
|
41 endif |
|
42 |
2303
|
43 ## determine sign of x, set sign(0) = 1. |
1636
|
44 sig = sign(x) + (x == 0); |
|
45 |
2303
|
46 ## take absolute value of x, but force it to be smaller than 32636; |
|
47 ## add bias |
1636
|
48 x = min (abs (x), 32635 * ones (size (x))) + 132; |
|
49 |
2303
|
50 ## find exponent and fraction of bineary representation |
1636
|
51 [f, e] = log2 (x); |
|
52 |
|
53 y = 64 * sig - 16 * e - fix (32 * f) + 335; |
|
54 |
|
55 endfunction |