2847
|
1 ## Copyright (C) 1996, 1997 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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
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 |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
2303
|
19 |
3332
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} playaudio (@var{name}, @var{ext}) |
|
22 ## @deftypefnx {Function File} {} playaudio (@var{x}) |
|
23 ## Plays the audio file @file{@var{name}.@var{ext}} or the audio data |
|
24 ## stored in the vector @var{x}. |
5642
|
25 ## @seealso{lin2mu, mu2lin, loadaudio, saveaudio, setaudio, record} |
3332
|
26 ## @end deftypefn |
2311
|
27 |
2312
|
28 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> |
|
29 ## Created: 11 April 1994 |
|
30 ## Adapted-By: jwe |
|
31 |
1636
|
32 function playaudio (name, ext) |
2325
|
33 |
5443
|
34 if (nargin == 1 && isvector (name) && ! ischar (name)) |
2303
|
35 ## play a vector |
1636
|
36 [nr, nc] = size (name); |
|
37 if (nc != 1) |
|
38 if (nr == 1) |
3426
|
39 name = name'; |
|
40 nr = nc; |
1636
|
41 else |
3426
|
42 error ("playaudio: X must be a vector"); |
1636
|
43 endif |
|
44 endif |
|
45 X = name + 127; |
2458
|
46 unwind_protect |
|
47 file = tmpnam (); |
3167
|
48 num = fopen (file, "wb"); |
2458
|
49 c = fwrite (num, X, "uchar"); |
|
50 fclose (num); |
4469
|
51 system (sprintf ("cat \"%s\" > /dev/dsp", file)); |
2458
|
52 unwind_protect_cleanup |
|
53 unlink (file); |
|
54 end_unwind_protect |
5443
|
55 elseif (nargin >= 1 && ischar (name)) |
2303
|
56 ## play a file |
1636
|
57 if (nargin == 1) |
|
58 name = [name, ".lin"]; |
|
59 elseif (nargin == 2) |
|
60 name = [name, ".", ext]; |
|
61 else |
6046
|
62 print_usage (); |
1636
|
63 endif |
|
64 if (strcmp (ext, "lin") || strcmp (ext, "raw")) |
4469
|
65 system (sprintf ("cat \"%s\" > /dev/dsp", name)); |
3471
|
66 elseif (strcmp (ext, "mu") || strcmp (ext, "au") |
|
67 || strcmp (ext, "snd") || strcmp (ext, "ul")) |
4469
|
68 system (sprintf ("cat \"%s\" > /dev/audio", name)); |
1636
|
69 else |
|
70 error ("playaudio does not support given extension"); |
|
71 endif |
|
72 else |
6046
|
73 print_usage (); |
1636
|
74 endif |
|
75 |
|
76 endfunction |