annotate scripts/deprecated/playaudio.m @ 20595:c1a6c31ac29a

eliminate more simple uses of error_state * ov-classdef.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Tue, 06 Oct 2015 00:20:02 -0400
parents 9fc020886ae9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19681
diff changeset
1 ## Copyright (C) 1995-2015 John W. Eaton
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
2 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
3 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
4 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
8 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
9 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
13 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
14 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
17 ## <http://www.gnu.org/licenses/>.
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 1636
diff changeset
18
3332
7c03933635c6 [project @ 1999-11-02 06:57:12 by jwe]
jwe
parents: 3167
diff changeset
19 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
20 ## @deftypefn {Function File} {} playaudio (@var{name}, @var{ext})
3332
7c03933635c6 [project @ 1999-11-02 06:57:12 by jwe]
jwe
parents: 3167
diff changeset
21 ## @deftypefnx {Function File} {} playaudio (@var{x})
19681
0165d9607624 Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents: 19312
diff changeset
22 ##
0165d9607624 Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents: 19312
diff changeset
23 ## @code{playaudio} 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: 19312
diff changeset
24 ## Please use @code{audioplayer} in all new code.
0165d9607624 Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents: 19312
diff changeset
25 ##
12575
d0b799dafede Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
26 ## Play the audio file @file{@var{name}.@var{ext}} or the audio data
3332
7c03933635c6 [project @ 1999-11-02 06:57:12 by jwe]
jwe
parents: 3167
diff changeset
27 ## stored in the vector @var{x}.
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5443
diff changeset
28 ## @seealso{lin2mu, mu2lin, loadaudio, saveaudio, setaudio, record}
3332
7c03933635c6 [project @ 1999-11-02 06:57:12 by jwe]
jwe
parents: 3167
diff changeset
29 ## @end deftypefn
2311
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
30
2312
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
31 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at>
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
32 ## Created: 11 April 1994
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
33 ## Adapted-By: jwe
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
34
1636
21fe2afb3692 [project @ 1995-11-16 19:16:11 by jwe]
jwe
parents:
diff changeset
35 function playaudio (name, ext)
2325
b5568c31ee2c [project @ 1996-07-15 22:20:21 by jwe]
jwe
parents: 2313
diff changeset
36
19681
0165d9607624 Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents: 19312
diff changeset
37 persistent warned = false;
0165d9607624 Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents: 19312
diff changeset
38 if (! warned)
0165d9607624 Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents: 19312
diff changeset
39 warned = true;
0165d9607624 Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents: 19312
diff changeset
40 warning ("Octave:deprecated-function",
0165d9607624 Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents: 19312
diff changeset
41 "playaudio is obsolete and will be removed from a future version of Octave, please use audioplayer instead");
0165d9607624 Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents: 19312
diff changeset
42 endif
0165d9607624 Deprecate audio functions loadaudio, playaudio, saveaudio, and setaudio.
Mike Miller <mtmiller@ieee.org>
parents: 19312
diff changeset
43
13831
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
44 if (nargin < 1 || nargin > 2)
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
45 print_usage ();
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
46 endif
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
47
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
48 if (nargin == 1 && isnumeric (name))
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 1636
diff changeset
49 ## play a vector
13831
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
50 if (! isvector (name))
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
51 error ("playaudio: X must be a vector");
1636
21fe2afb3692 [project @ 1995-11-16 19:16:11 by jwe]
jwe
parents:
diff changeset
52 endif
13831
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
53 X = name(:) + 127;
2458
d07a5d0b57e2 [project @ 1996-11-03 03:25:18 by jwe]
jwe
parents: 2325
diff changeset
54 unwind_protect
19312
6ca096827123 Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents: 17744
diff changeset
55 file = tempname ();
13831
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
56 fid = fopen (file, "wb");
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
57 fwrite (fid, X, "uchar");
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
58 fclose (fid);
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
59 [status, out] = system (sprintf ('cat "%s" > /dev/dsp', file));
12901
f754b65f4bc5 Add a PulseAudio backend to playaudio
Fabian Deutsch <fabian.deutsch@gmx.de>
parents: 12575
diff changeset
60 if (status != 0)
15202
f3b5cadfd6d5 fix missing semicolons in various .m files
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
61 system (sprintf ("paplay --raw \"%s\"", file));
12901
f754b65f4bc5 Add a PulseAudio backend to playaudio
Fabian Deutsch <fabian.deutsch@gmx.de>
parents: 12575
diff changeset
62 endif
2458
d07a5d0b57e2 [project @ 1996-11-03 03:25:18 by jwe]
jwe
parents: 2325
diff changeset
63 unwind_protect_cleanup
d07a5d0b57e2 [project @ 1996-11-03 03:25:18 by jwe]
jwe
parents: 2325
diff changeset
64 unlink (file);
d07a5d0b57e2 [project @ 1996-11-03 03:25:18 by jwe]
jwe
parents: 2325
diff changeset
65 end_unwind_protect
5443
ec8c33dcd1bf [project @ 2005-09-08 01:40:57 by jwe]
jwe
parents: 5307
diff changeset
66 elseif (nargin >= 1 && ischar (name))
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 1636
diff changeset
67 ## play a file
1636
21fe2afb3692 [project @ 1995-11-16 19:16:11 by jwe]
jwe
parents:
diff changeset
68 if (nargin == 1)
13831
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
69 name = [name ".lin"];
1636
21fe2afb3692 [project @ 1995-11-16 19:16:11 by jwe]
jwe
parents:
diff changeset
70 elseif (nargin == 2)
13831
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
71 name = [name "." ext];
1636
21fe2afb3692 [project @ 1995-11-16 19:16:11 by jwe]
jwe
parents:
diff changeset
72 endif
13831
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
73 if (any (strcmp (ext, {"lin", "raw"})))
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
74 [status, out] = system (sprintf ('cat "%s" > /dev/dsp', name));
12901
f754b65f4bc5 Add a PulseAudio backend to playaudio
Fabian Deutsch <fabian.deutsch@gmx.de>
parents: 12575
diff changeset
75 if (status != 0)
15202
f3b5cadfd6d5 fix missing semicolons in various .m files
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
76 system (sprintf ('paplay --raw "%s"', name));
12901
f754b65f4bc5 Add a PulseAudio backend to playaudio
Fabian Deutsch <fabian.deutsch@gmx.de>
parents: 12575
diff changeset
77 endif
13831
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
78 elseif (any (strcmp (ext, {"mu", "au" "snd", "ul"})))
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
79 [status, out] = system (sprintf ('cat "%s" > /dev/audio', name));
12901
f754b65f4bc5 Add a PulseAudio backend to playaudio
Fabian Deutsch <fabian.deutsch@gmx.de>
parents: 12575
diff changeset
80 if (status != 0)
15202
f3b5cadfd6d5 fix missing semicolons in various .m files
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
81 system (sprintf ('paplay "%s"', name));
12901
f754b65f4bc5 Add a PulseAudio backend to playaudio
Fabian Deutsch <fabian.deutsch@gmx.de>
parents: 12575
diff changeset
82 endif
1636
21fe2afb3692 [project @ 1995-11-16 19:16:11 by jwe]
jwe
parents:
diff changeset
83 else
13831
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
84 error ("playaudio: unsupported extension '%s'", ext);
1636
21fe2afb3692 [project @ 1995-11-16 19:16:11 by jwe]
jwe
parents:
diff changeset
85 endif
21fe2afb3692 [project @ 1995-11-16 19:16:11 by jwe]
jwe
parents:
diff changeset
86 else
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5642
diff changeset
87 print_usage ();
1636
21fe2afb3692 [project @ 1995-11-16 19:16:11 by jwe]
jwe
parents:
diff changeset
88 endif
21fe2afb3692 [project @ 1995-11-16 19:16:11 by jwe]
jwe
parents:
diff changeset
89
21fe2afb3692 [project @ 1995-11-16 19:16:11 by jwe]
jwe
parents:
diff changeset
90 endfunction
13831
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
91
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
92
19867
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
93 ## Test input validation
13831
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
94 %!error playaudio ()
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
95 %!error playaudio (1,2,3)
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
96 %!error <X must be a vector> playaudio (magic (3))
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
97 %!error <unsupported extension> playaudio ("file", "abc")
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
98 %!error playaudio ({"abc"})
dc685dd445b4 playaudio.m: Use modern coding standards. Add input validation tests.
Rik <octave@nomad.inbox5.com>
parents: 12901
diff changeset
99