2313
|
1 ## Copyright (C) 1996 John W. Eaton |
|
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 |
2325
|
20 ## usage: playaudio (name [, ext]) |
2311
|
21 ## playaudio (X) |
|
22 ## |
|
23 ## `playaudio ("name" [, "ext"])' plays the audio file "name.ext". The |
|
24 ## default value for the "ext" argument, which has to be written |
|
25 ## without the initial ".", is "lin". |
|
26 ## Currently, the following audio formats are suppored: |
|
27 ## *) linear encoding with extension "lin" or "raw", played using |
2325
|
28 ## /dev/dsp |
2311
|
29 ## *) mu-law encoding with extension "mu", "au" or "snd", played |
2325
|
30 ## using /dev/audio |
2311
|
31 ## |
|
32 ## `playaudio (X)' plays the audio data contained in the vector X. |
|
33 |
2312
|
34 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> |
|
35 ## Created: 11 April 1994 |
|
36 ## Adapted-By: jwe |
|
37 |
1636
|
38 function playaudio (name, ext) |
2325
|
39 |
1636
|
40 usage_msg = "playaudio (name [, ext]) or playaudio (X)"; |
2325
|
41 |
|
42 if (nargin == 1 && is_vector (name) && ! isstr (name)) |
2303
|
43 ## play a vector |
1636
|
44 [nr, nc] = size (name); |
|
45 if (nc != 1) |
|
46 if (nr == 1) |
|
47 name = name'; |
|
48 nr = nc; |
|
49 else |
|
50 error ("playaudio: X must be a vector"); |
|
51 endif |
|
52 endif |
|
53 X = name + 127; |
2458
|
54 unwind_protect |
|
55 file = tmpnam (); |
|
56 num = fopen (file, "w"); |
|
57 c = fwrite (num, X, "uchar"); |
|
58 fclose (num); |
|
59 system (sprintf ("cat %s > /dev/dsp", file)); |
|
60 unwind_protect_cleanup |
|
61 unlink (file); |
|
62 end_unwind_protect |
1636
|
63 elseif (nargin >= 1 && isstr (name)) |
2303
|
64 ## play a file |
1636
|
65 if (nargin == 1) |
|
66 name = [name, ".lin"]; |
|
67 elseif (nargin == 2) |
|
68 name = [name, ".", ext]; |
|
69 else |
|
70 usage (usage_msg); |
|
71 endif |
|
72 if (strcmp (ext, "lin") || strcmp (ext, "raw")) |
|
73 system (sprintf ("cat %s > /dev/dsp", name)); |
|
74 elseif (strcmp (ext, "mu") || strcmp (ext, "au") || strcmp (ext, "snd")) |
|
75 system (sprintf ("cat %s > /dev/audio", name)); |
|
76 else |
|
77 error ("playaudio does not support given extension"); |
|
78 endif |
|
79 else |
|
80 usage (usage_msg); |
|
81 endif |
|
82 |
|
83 endfunction |