Mercurial > octave
annotate scripts/audio/mu2lin.m @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
1 ## Copyright (C) 1995-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
2 ## |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
5 ## |
2313 | 6 ## |
7 ## This file is part of Octave. | |
8 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
9 ## Octave is free software: you can redistribute it and/or modify it |
2313 | 10 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
11 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
12 ## (at your option) any later version. |
2313 | 13 ## |
14 ## Octave is distributed in the hope that it will be useful, but | |
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## GNU General Public License for more details. |
2313 | 18 ## |
19 ## You should have received a copy of the GNU General Public License | |
7016 | 20 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
21 ## <https://www.gnu.org/licenses/>. |
2303 | 22 |
3332 | 23 ## -*- texinfo -*- |
24575
93714122ed59
doc: Fixes for signal, image, audio, and OOP chapters (bug #52844).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
24 ## @deftypefn {} {@var{y} =} mu2lin (@var{x}, @var{n}) |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
25 ## Convert audio data from mu-law to linear. |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
26 ## |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
27 ## Mu-law values are 8-bit unsigned integers. Linear values use @var{n}-bit |
24575
93714122ed59
doc: Fixes for signal, image, audio, and OOP chapters (bug #52844).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
28 ## signed integers or floating point values in the range -1 @leq{} @var{y} |
93714122ed59
doc: Fixes for signal, image, audio, and OOP chapters (bug #52844).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
29 ## @leq{} 1 if @var{n} is 0. |
12150
605ed5bbb643
mu2lin: make default for N compatible with Matlab
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
30 ## |
605ed5bbb643
mu2lin: make default for N compatible with Matlab
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
31 ## If @var{n} is not specified it defaults to 0. |
19647
0165d9607624
Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
32 ## @seealso{lin2mu} |
3332 | 33 ## @end deftypefn |
2311 | 34 |
3911 | 35 ## Author: Andreas Weingessel <Andreas.Weingessel@ci.tuwien.ac.at> |
2312 | 36 ## Created: 18 October 1994 |
37 ## Adapted-By: jwe | |
38 | |
12150
605ed5bbb643
mu2lin: make default for N compatible with Matlab
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
39 function y = mu2lin (x, n = 0) |
2325 | 40 |
12150
605ed5bbb643
mu2lin: make default for N compatible with Matlab
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
41 if (nargin == 2) |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
42 if (n != 0 && n != 8 && n != 16) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11469
diff
changeset
|
43 error ("mu2lin: N must be either 0, 8, or 16"); |
1636 | 44 endif |
12150
605ed5bbb643
mu2lin: make default for N compatible with Matlab
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
45 elseif (nargin != 1) |
6046 | 46 print_usage (); |
1636 | 47 endif |
48 | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
49 ulaw = [32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956, ... |
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
50 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764, ... |
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
51 15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412, ... |
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
52 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316, ... |
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
53 7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140, ... |
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
54 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092, ... |
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
55 3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004, ... |
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
56 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980, ... |
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
57 1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436, ... |
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
58 1372, 1308, 1244, 1180, 1116, 1052, 988, 924, ... |
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
59 876, 844, 812, 780, 748, 716, 684, 652, ... |
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
60 620, 588, 556, 524, 492, 460, 428, 396, ... |
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
61 372, 356, 340, 324, 308, 292, 276, 260, ... |
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
62 244, 228, 212, 196, 180, 164, 148, 132, ... |
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
63 120, 112, 104, 96, 88, 80, 72, 64, ... |
10549 | 64 56, 48, 40, 32, 24, 16, 8, 0 ]; |
1636 | 65 |
3911 | 66 ulaw = [ -ulaw, ulaw ]; |
67 | |
68 ## Set the shape of y to that of x overwrites the contents of y with | |
69 ## ulaw of x. | |
70 y = x; | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
71 y(:) = ulaw(x + 1); |
1636 | 72 |
3911 | 73 ## Convert to real or 8-bit. |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
74 if (n == 0) |
3911 | 75 ## [ -32768, 32767 ] -> [ -1, 1) |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
76 y /= 32768; |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
77 elseif (n == 8) |
3911 | 78 ld = max (abs (y (:))); |
79 if (ld < 16384 && ld > 0) | |
1636 | 80 sc = 64 / ld; |
81 else | |
82 sc = 1 / 256; | |
83 endif | |
84 y = fix (y * sc); | |
85 endif | |
86 | |
87 endfunction |