Mercurial > hg > octave-lyh
annotate scripts/audio/lin2mu.m @ 16618:13728d41fb6a
use functions to handle colors in Windows GUI terminal
* QWinTerminalImpl.cpp (QConsolePrivate::backgroundColor,
QConsolePrivate::foregroundColor, QConsolePrivate::selectionColor,
QConsolePrivate::cursorColor, QConsolePrivate::setBackgroundColor,
QConsolePrivate::setForegroundColor,
QConsolePrivate::setSelectionColor, QConsolePrivate::setCursorColor):
New functions.
(QConsolePrivate::m_backgroundColor,
QConsolePrivate::m_foregroundColor): Delete member variables.
(QConsolePrivate::QConsolePrivate): Call setBackgroundColor and
setForegroundColor to set default colors.
(QWinTerminalImpl::viewPaintEvent): Use functions to access colors.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 May 2013 02:20:01 -0400 |
parents | 5d3a684236b0 |
children | 1c89599167a6 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12150
diff
changeset
|
1 ## Copyright (C) 1995-2012 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}) |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
21 ## Convert audio data from linear to mu-law. Mu-law values use 8-bit |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
22 ## unsigned integers. Linear values use @var{n}-bit signed integers or |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
23 ## floating point values in the range -1 @leq{} @var{x} @leq{} 1 if |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
24 ## @var{n} is 0. |
12150
605ed5bbb643
mu2lin: make default for N compatible with Matlab
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
25 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
26 ## 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
|
27 ## the range of values in @var{x}. |
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
28 ## @seealso{mu2lin, loadaudio, saveaudio} |
3332 | 29 ## @end deftypefn |
5642 | 30 |
2311 | 31 |
3911 | 32 ## Author: Andreas Weingessel <Andreas.Weingessel@ci.tuwien.ac.at> |
2312 | 33 ## Created: 17 October 1994 |
34 ## Adapted-By: jwe | |
35 | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
36 function y = lin2mu (x, n) |
2325 | 37 |
3911 | 38 if (nargin == 1) |
39 range = max (abs (x (:))); | |
40 if (range <= 1) | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
41 n = 0; |
3911 | 42 elseif (range <= 128) |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
43 n = 8; |
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
44 warning ("lin2mu: no precision specified, so using %d", n); |
3911 | 45 else |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
46 n = 16; |
3911 | 47 endif |
48 elseif (nargin == 2) | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
49 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
|
50 error ("lin2mu: N must be either 0, 8 or 16"); |
3911 | 51 endif |
52 else | |
6046 | 53 print_usage (); |
1636 | 54 endif |
2325 | 55 |
3911 | 56 ## 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
|
57 if (n == 0) |
3911 | 58 ## [-1,1] -> [-32768, 32768] |
59 x = 32768 * x; | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
60 elseif (n != 16) |
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
61 x = 2^(16-n) .* x; |
1636 | 62 endif |
63 | |
3911 | 64 ## 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
|
65 sig = sign (x) + (x == 0); |
1636 | 66 |
3911 | 67 ## Take absolute value of x, but force it to be smaller than 32636; |
68 ## add bias. | |
69 x = min (abs (x), 32635) + 132; | |
1636 | 70 |
3911 | 71 ## Find exponent and fraction of bineary representation. |
1636 | 72 [f, e] = log2 (x); |
73 | |
74 y = 64 * sig - 16 * e - fix (32 * f) + 335; | |
75 | |
76 endfunction |