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 |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, 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}. |
|
25 ## @end deftypefn |
3408
|
26 ## @seealso{lin2mu, mu2lin, loadaudio, saveaudio, setaudio, and record} |
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 |
3456
|
34 usage_msg = "playaudio (name, ext) or playaudio (X)"; |
2325
|
35 |
4030
|
36 if (nargin == 1 && isvector (name) && ! isstr (name)) |
2303
|
37 ## play a vector |
1636
|
38 [nr, nc] = size (name); |
|
39 if (nc != 1) |
|
40 if (nr == 1) |
3426
|
41 name = name'; |
|
42 nr = nc; |
1636
|
43 else |
3426
|
44 error ("playaudio: X must be a vector"); |
1636
|
45 endif |
|
46 endif |
|
47 X = name + 127; |
2458
|
48 unwind_protect |
|
49 file = tmpnam (); |
3167
|
50 num = fopen (file, "wb"); |
2458
|
51 c = fwrite (num, X, "uchar"); |
|
52 fclose (num); |
|
53 system (sprintf ("cat %s > /dev/dsp", file)); |
|
54 unwind_protect_cleanup |
|
55 unlink (file); |
|
56 end_unwind_protect |
1636
|
57 elseif (nargin >= 1 && isstr (name)) |
2303
|
58 ## play a file |
1636
|
59 if (nargin == 1) |
|
60 name = [name, ".lin"]; |
|
61 elseif (nargin == 2) |
|
62 name = [name, ".", ext]; |
|
63 else |
|
64 usage (usage_msg); |
|
65 endif |
|
66 if (strcmp (ext, "lin") || strcmp (ext, "raw")) |
|
67 system (sprintf ("cat %s > /dev/dsp", name)); |
3471
|
68 elseif (strcmp (ext, "mu") || strcmp (ext, "au") |
|
69 || strcmp (ext, "snd") || strcmp (ext, "ul")) |
1636
|
70 system (sprintf ("cat %s > /dev/audio", name)); |
|
71 else |
|
72 error ("playaudio does not support given extension"); |
|
73 endif |
|
74 else |
|
75 usage (usage_msg); |
|
76 endif |
|
77 |
|
78 endfunction |