1 ## Copyright (C) 1995-2012 John W. Eaton
3 ## This file is part of Octave.
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
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
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.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} playaudio (@var{name}, @var{ext})
21 ## @deftypefnx {Function File} {} playaudio (@var{x})
22 ## Play the audio file @file{@var{name}.@var{ext}} or the audio data
23 ## stored in the vector @var{x}.
24 ## @seealso{lin2mu, mu2lin, loadaudio, saveaudio, setaudio, record}
27 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at>
28 ## Created: 11 April 1994
31 function playaudio (name, ext)
33 if (nargin < 1 || nargin > 2)
37 if (nargin == 1 && isnumeric (name))
39 if (! isvector (name))
40 error ("playaudio: X must be a vector");
45 fid = fopen (file, "wb");
46 fwrite (fid, X, "uchar");
48 [status, out] = system (sprintf ('cat "%s" > /dev/dsp', file));
50 system (sprintf ("paplay --raw \"%s\"", file))
52 unwind_protect_cleanup
55 elseif (nargin >= 1 && ischar (name))
60 name = [name "." ext];
62 if (any (strcmp (ext, {"lin", "raw"})))
63 [status, out] = system (sprintf ('cat "%s" > /dev/dsp', name));
65 system (sprintf ('paplay --raw "%s"', name))
67 elseif (any (strcmp (ext, {"mu", "au" "snd", "ul"})))
68 [status, out] = system (sprintf ('cat "%s" > /dev/audio', name));
70 system (sprintf ('paplay "%s"', name))
73 error ("playaudio: unsupported extension '%s'", ext);
82 %% Test input validation
84 %!error playaudio (1,2,3)
85 %!error <X must be a vector> playaudio (magic (3))
86 %!error <unsupported extension> playaudio ("file", "abc")
87 %!error playaudio ({"abc"})