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}. |
|
25 ## @end deftypefn |
5053
|
26 ## |
3408
|
27 ## @seealso{lin2mu, mu2lin, loadaudio, saveaudio, setaudio, and record} |
2311
|
28 |
2312
|
29 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> |
|
30 ## Created: 11 April 1994 |
|
31 ## Adapted-By: jwe |
|
32 |
1636
|
33 function playaudio (name, ext) |
2325
|
34 |
3456
|
35 usage_msg = "playaudio (name, ext) or playaudio (X)"; |
2325
|
36 |
4030
|
37 if (nargin == 1 && isvector (name) && ! isstr (name)) |
2303
|
38 ## play a vector |
1636
|
39 [nr, nc] = size (name); |
|
40 if (nc != 1) |
|
41 if (nr == 1) |
3426
|
42 name = name'; |
|
43 nr = nc; |
1636
|
44 else |
3426
|
45 error ("playaudio: X must be a vector"); |
1636
|
46 endif |
|
47 endif |
|
48 X = name + 127; |
2458
|
49 unwind_protect |
|
50 file = tmpnam (); |
3167
|
51 num = fopen (file, "wb"); |
2458
|
52 c = fwrite (num, X, "uchar"); |
|
53 fclose (num); |
4469
|
54 system (sprintf ("cat \"%s\" > /dev/dsp", file)); |
2458
|
55 unwind_protect_cleanup |
|
56 unlink (file); |
|
57 end_unwind_protect |
1636
|
58 elseif (nargin >= 1 && isstr (name)) |
2303
|
59 ## play a file |
1636
|
60 if (nargin == 1) |
|
61 name = [name, ".lin"]; |
|
62 elseif (nargin == 2) |
|
63 name = [name, ".", ext]; |
|
64 else |
|
65 usage (usage_msg); |
|
66 endif |
|
67 if (strcmp (ext, "lin") || strcmp (ext, "raw")) |
4469
|
68 system (sprintf ("cat \"%s\" > /dev/dsp", name)); |
3471
|
69 elseif (strcmp (ext, "mu") || strcmp (ext, "au") |
|
70 || strcmp (ext, "snd") || strcmp (ext, "ul")) |
4469
|
71 system (sprintf ("cat \"%s\" > /dev/audio", name)); |
1636
|
72 else |
|
73 error ("playaudio does not support given extension"); |
|
74 endif |
|
75 else |
|
76 usage (usage_msg); |
|
77 endif |
|
78 |
|
79 endfunction |