2313
|
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. |
2303
|
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 |
2312
|
25 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> |
|
26 ## Created: 17 October 1994 |
|
27 ## Adapted-By: jwe |
|
28 |
1636
|
29 function y = lin2mu (x) |
2325
|
30 |
1636
|
31 if (nargin != 1) |
|
32 usage ("y = lin2mu (x)"); |
|
33 endif |
|
34 |
|
35 if (! is_vector (x)) |
|
36 error ("lin2mu: x must be a vector"); |
|
37 endif |
2325
|
38 |
2303
|
39 ## transform 8-bit format to 16-bit |
1636
|
40 if (max (abs (x)) <= 128) |
|
41 x = 256 .* x; |
|
42 endif |
|
43 |
2303
|
44 ## determine sign of x, set sign(0) = 1. |
1636
|
45 sig = sign(x) + (x == 0); |
|
46 |
2303
|
47 ## take absolute value of x, but force it to be smaller than 32636; |
2325
|
48 ## add bias |
1636
|
49 x = min (abs (x), 32635 * ones (size (x))) + 132; |
|
50 |
2303
|
51 ## find exponent and fraction of bineary representation |
1636
|
52 [f, e] = log2 (x); |
|
53 |
|
54 y = 64 * sig - 16 * e - fix (32 * f) + 335; |
|
55 |
|
56 endfunction |