Mercurial > hg > octave-nkf
annotate scripts/audio/lin2mu.m @ 20830:b65888ec820e draft default tip gccjit
dmalcom gcc jit import
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Fri, 27 Feb 2015 16:59:36 +0100 |
parents | 7503499a252b |
children |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19844
diff
changeset
|
1 ## Copyright (C) 1995-2015 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
2313 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
2303 | 18 |
3332 | 19 ## -*- texinfo -*- |
12150
605ed5bbb643
mu2lin: make default for N compatible with Matlab
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
20 ## @deftypefn {Function File} {} lin2mu (@var{x}, @var{n}) |
20368
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
21 ## Convert audio data from linear to mu-law. |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
22 ## |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
23 ## Mu-law values use 8-bit unsigned integers. Linear values use @var{n}-bit |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
24 ## signed integers or floating point values in the range -1 @leq{} @var{x} |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
25 ## @leq{} 1 if @var{n} is 0. |
12150
605ed5bbb643
mu2lin: make default for N compatible with Matlab
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
26 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
27 ## If @var{n} is not specified it defaults to 0, 8, or 16 depending on |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
28 ## the range of values in @var{x}. |
19844
0165d9607624
Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
29 ## @seealso{mu2lin} |
3332 | 30 ## @end deftypefn |
5642 | 31 |
2311 | 32 |
3911 | 33 ## Author: Andreas Weingessel <Andreas.Weingessel@ci.tuwien.ac.at> |
2312 | 34 ## Created: 17 October 1994 |
35 ## Adapted-By: jwe | |
36 | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
37 function y = lin2mu (x, n) |
2325 | 38 |
3911 | 39 if (nargin == 1) |
40 range = max (abs (x (:))); | |
41 if (range <= 1) | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
42 n = 0; |
3911 | 43 elseif (range <= 128) |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
44 n = 8; |
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
45 warning ("lin2mu: no precision specified, so using %d", n); |
3911 | 46 else |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
47 n = 16; |
3911 | 48 endif |
49 elseif (nargin == 2) | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
50 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:
10793
diff
changeset
|
51 error ("lin2mu: N must be either 0, 8 or 16"); |
3911 | 52 endif |
53 else | |
6046 | 54 print_usage (); |
1636 | 55 endif |
2325 | 56 |
3911 | 57 ## Transform real and n-bit format to 16-bit. |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
58 if (n == 0) |
3911 | 59 ## [-1,1] -> [-32768, 32768] |
60 x = 32768 * x; | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
61 elseif (n != 16) |
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
62 x = 2^(16-n) .* x; |
1636 | 63 endif |
64 | |
3911 | 65 ## Determine sign of x, set sign(0) = 1. |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
66 sig = sign (x) + (x == 0); |
1636 | 67 |
3911 | 68 ## Take absolute value of x, but force it to be smaller than 32636; |
69 ## add bias. | |
70 x = min (abs (x), 32635) + 132; | |
1636 | 71 |
3911 | 72 ## Find exponent and fraction of bineary representation. |
1636 | 73 [f, e] = log2 (x); |
74 | |
75 y = 64 * sig - 16 * e - fix (32 * f) + 335; | |
76 | |
77 endfunction | |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
78 |