Mercurial > octave-nkf
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 |
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 | 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 -*- |
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 | 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 | 27 ## stored in the vector @var{x}. |
5642 | 28 ## @seealso{lin2mu, mu2lin, loadaudio, saveaudio, setaudio, record} |
3332 | 29 ## @end deftypefn |
2311 | 30 |
2312 | 31 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> |
32 ## Created: 11 April 1994 | |
33 ## Adapted-By: jwe | |
34 | |
1636 | 35 function playaudio (name, ext) |
2325 | 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 | 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 | 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 | 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 | 63 unwind_protect_cleanup |
64 unlink (file); | |
65 end_unwind_protect | |
5443 | 66 elseif (nargin >= 1 && ischar (name)) |
2303 | 67 ## play a file |
1636 | 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 | 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 | 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 | 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 | 85 endif |
86 else | |
6046 | 87 print_usage (); |
1636 | 88 endif |
89 | |
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 |