Mercurial > hg > octave-nkf
annotate scripts/deprecated/saveaudio.m @ 20349:bcf0a288aa6c stable
maint: Merge default to stable in preparation for 4.0.0 release.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 28 Apr 2015 12:12:16 -0400 |
parents | 4197fc428c7d |
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 |
3426 | 19 ## -*- texinfo -*- |
3332 | 20 ## @deftypefn {Function File} {} saveaudio (@var{name}, @var{x}, @var{ext}, @var{bps}) |
19844
0165d9607624
Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
21 ## |
0165d9607624
Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
22 ## @code{saveaudio} is deprecated and will be removed in Octave version 4.4. |
0165d9607624
Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
23 ## Please use @code{audiowrite} in all new code. |
0165d9607624
Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
24 ## |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
25 ## Save a vector @var{x} of audio data to the file |
3332 | 26 ## @file{@var{name}.@var{ext}}. The optional parameters @var{ext} and |
27 ## @var{bps} determine the encoding and the number of bits per sample used | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
28 ## in the audio file (see @code{loadaudio}); defaults are @file{lin} and |
3332 | 29 ## 8, respectively. |
5642 | 30 ## @seealso{lin2mu, mu2lin, loadaudio, playaudio, setaudio, record} |
3332 | 31 ## @end deftypefn |
2311 | 32 |
2312 | 33 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> |
34 ## Created: 5 September 1994 | |
35 ## Adapted-By: jwe | |
36 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
37 function saveaudio (name, x, ext, bps) |
2325 | 38 |
19844
0165d9607624
Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
39 persistent warned = false; |
0165d9607624
Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
40 if (! warned) |
0165d9607624
Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
41 warned = true; |
0165d9607624
Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
42 warning ("Octave:deprecated-function", |
0165d9607624
Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
43 "saveaudio is obsolete and will be removed from a future version of Octave, please use audiowrite instead"); |
0165d9607624
Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
44 endif |
0165d9607624
Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
45 |
1636 | 46 if (nargin < 2 || nargin > 4) |
6046 | 47 print_usage (); |
1636 | 48 endif |
49 | |
50 if (nargin == 2) | |
51 ext = "lin"; | |
52 endif | |
53 | |
54 if (nargin < 4) | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
55 bps = 8; |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
56 elseif (bps != 8 && bps != 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
|
57 error ("saveaudio: BPS must be either 8 or 16"); |
1636 | 58 endif |
59 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
60 [nr, nc] = size (x); |
1636 | 61 if (nc != 1) |
62 if (nr == 1) | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
63 x = x'; |
1636 | 64 nr = nc; |
65 else | |
3458 | 66 error ("saveaudio: X must be a vector"); |
1636 | 67 endif |
68 endif | |
69 | |
3167 | 70 num = fopen ([name, ".", ext], "wb"); |
1636 | 71 |
2325 | 72 if (strcmp (ext, "lin") || strcmp (ext, "raw")) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
73 if (bps == 8) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
74 ld = max (abs (x)); |
1636 | 75 if (ld > 127) # convert 16 to 8 bit |
3426 | 76 if (ld < 16384) |
77 sc = 64 / ld; | |
78 else | |
79 sc = 1 / 256; | |
80 endif | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
81 x = fix (x * sc); |
1636 | 82 endif |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
83 x = x + 127; |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
84 c = fwrite (num, x, "uchar"); |
1636 | 85 else |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
86 c = fwrite (num, x, "short"); |
1636 | 87 endif |
3471 | 88 elseif (strcmp (ext, "mu") || strcmp (ext, "au") |
10549 | 89 || strcmp (ext, "snd") || strcmp (ext, "ul")) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
90 y = lin2mu (x); |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
91 c = fwrite (num, y, "uchar"); |
1636 | 92 else |
93 fclose (num); | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
94 error ("saveaudio: unsupported extension"); |
1636 | 95 endif |
96 | |
97 fclose (num); | |
2325 | 98 |
1636 | 99 endfunction |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
100 |