Mercurial > hg > octave-nkf
annotate scripts/audio/saveaudio.m @ 13841:0a158dbdb04a
Remove 3 unused warning ids
Removed ids: empty-list-elements, fortran-indexing, complex-cmp-ops.
Renamed ids: string-concat -> mixed-string-concat
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Tue, 08 Nov 2011 09:07:13 -0800 |
parents | d0b799dafede |
children | 72c96de7a403 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1995-2011 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}) |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
21 ## Save a vector @var{x} of audio data to the file |
3332 | 22 ## @file{@var{name}.@var{ext}}. The optional parameters @var{ext} and |
23 ## @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
|
24 ## in the audio file (see @code{loadaudio}); defaults are @file{lin} and |
3332 | 25 ## 8, respectively. |
5642 | 26 ## @seealso{lin2mu, mu2lin, loadaudio, playaudio, setaudio, record} |
3332 | 27 ## @end deftypefn |
2311 | 28 |
2312 | 29 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> |
30 ## Created: 5 September 1994 | |
31 ## Adapted-By: jwe | |
32 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
33 function saveaudio (name, x, ext, bps) |
2325 | 34 |
1636 | 35 if (nargin < 2 || nargin > 4) |
6046 | 36 print_usage (); |
1636 | 37 endif |
38 | |
39 if (nargin == 2) | |
40 ext = "lin"; | |
41 endif | |
42 | |
43 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
|
44 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
|
45 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
|
46 error ("saveaudio: BPS must be either 8 or 16"); |
1636 | 47 endif |
48 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
49 [nr, nc] = size (x); |
1636 | 50 if (nc != 1) |
51 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
|
52 x = x'; |
1636 | 53 nr = nc; |
54 else | |
3458 | 55 error ("saveaudio: X must be a vector"); |
1636 | 56 endif |
57 endif | |
58 | |
3167 | 59 num = fopen ([name, ".", ext], "wb"); |
1636 | 60 |
2325 | 61 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
|
62 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
|
63 ld = max (abs (x)); |
1636 | 64 if (ld > 127) # convert 16 to 8 bit |
3426 | 65 if (ld < 16384) |
66 sc = 64 / ld; | |
67 else | |
68 sc = 1 / 256; | |
69 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
|
70 x = fix (x * sc); |
1636 | 71 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
|
72 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
|
73 c = fwrite (num, x, "uchar"); |
1636 | 74 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
|
75 c = fwrite (num, x, "short"); |
1636 | 76 endif |
3471 | 77 elseif (strcmp (ext, "mu") || strcmp (ext, "au") |
10549 | 78 || 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
|
79 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
|
80 c = fwrite (num, y, "uchar"); |
1636 | 81 else |
82 fclose (num); | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
83 error ("saveaudio: unsupported extension"); |
1636 | 84 endif |
85 | |
86 fclose (num); | |
2325 | 87 |
1636 | 88 endfunction |