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 |
2311
|
20 ## usage: playaudio (name [, ext]) |
|
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 |
|
28 ## /dev/dsp |
|
29 ## *) mu-law encoding with extension "mu", "au" or "snd", played |
|
30 ## using /dev/audio |
|
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) |
|
39 |
|
40 file = octave_tmp_file_name (); |
|
41 |
|
42 usage_msg = "playaudio (name [, ext]) or playaudio (X)"; |
|
43 |
|
44 if (nargin == 1 && is_vector (name) && ! isstr (name)) |
2303
|
45 ## play a vector |
1636
|
46 [nr, nc] = size (name); |
|
47 if (nc != 1) |
|
48 if (nr == 1) |
|
49 name = name'; |
|
50 nr = nc; |
|
51 else |
|
52 error ("playaudio: X must be a vector"); |
|
53 endif |
|
54 endif |
|
55 X = name + 127; |
|
56 num = fopen (file, "w"); |
|
57 c = fwrite (num, X, "uchar"); |
|
58 fclose (num); |
|
59 system (sprintf ("cat %s > /dev/dsp", file)); |
|
60 unlink (file); |
|
61 elseif (nargin >= 1 && isstr (name)) |
2303
|
62 ## play a file |
1636
|
63 if (nargin == 1) |
|
64 name = [name, ".lin"]; |
|
65 elseif (nargin == 2) |
|
66 name = [name, ".", ext]; |
|
67 else |
|
68 usage (usage_msg); |
|
69 endif |
|
70 if (strcmp (ext, "lin") || strcmp (ext, "raw")) |
|
71 system (sprintf ("cat %s > /dev/dsp", name)); |
|
72 elseif (strcmp (ext, "mu") || strcmp (ext, "au") || strcmp (ext, "snd")) |
|
73 system (sprintf ("cat %s > /dev/audio", name)); |
|
74 else |
|
75 error ("playaudio does not support given extension"); |
|
76 endif |
|
77 else |
|
78 usage (usage_msg); |
|
79 endif |
|
80 |
|
81 endfunction |