2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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 |
3332
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} lin2mu (@var{x}) |
|
22 ## If the vector @var{x} represents mono audio data in 8- or 16-bit |
|
23 ## linear encoding, @code{lin2mu (@var{x})} is the corresponding mu-law |
|
24 ## encoding. |
|
25 ## @end deftypefn |
3408
|
26 ## @seealso{mu2lin, loadaudio, saveaudio, playaudio, setaudio, and record} |
2311
|
27 |
2312
|
28 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> |
|
29 ## Created: 17 October 1994 |
|
30 ## Adapted-By: jwe |
|
31 |
1636
|
32 function y = lin2mu (x) |
2325
|
33 |
1636
|
34 if (nargin != 1) |
|
35 usage ("y = lin2mu (x)"); |
|
36 endif |
|
37 |
|
38 if (! is_vector (x)) |
|
39 error ("lin2mu: x must be a vector"); |
|
40 endif |
2325
|
41 |
2303
|
42 ## transform 8-bit format to 16-bit |
1636
|
43 if (max (abs (x)) <= 128) |
|
44 x = 256 .* x; |
|
45 endif |
|
46 |
2303
|
47 ## determine sign of x, set sign(0) = 1. |
1636
|
48 sig = sign(x) + (x == 0); |
|
49 |
2303
|
50 ## take absolute value of x, but force it to be smaller than 32636; |
2325
|
51 ## add bias |
1636
|
52 x = min (abs (x), 32635 * ones (size (x))) + 132; |
|
53 |
2303
|
54 ## find exponent and fraction of bineary representation |
1636
|
55 [f, e] = log2 (x); |
|
56 |
|
57 y = 64 * sig - 16 * e - fix (32 * f) + 335; |
|
58 |
|
59 endfunction |