1636
|
1 function playaudio (name, ext) |
|
2 |
|
3 # usage: playaudio (name [, ext]) |
|
4 # playaudio (X) |
|
5 # |
|
6 # `playaudio ("name" [, "ext"])' plays the audio file "name.ext". The |
|
7 # default value for the "ext" argument, which has to be written |
|
8 # without the initial ".", is "lin". |
|
9 # Currently, the following audio formats are suppored: |
|
10 # *) linear encoding with extension "lin" or "raw", played using |
|
11 # /dev/dsp |
|
12 # *) mu-law encoding with extension "mu", "au" or "snd", played |
|
13 # using /dev/audio |
|
14 # |
|
15 # `playaudio (X)' plays the audio data contained in the vector X. |
|
16 |
|
17 # Written by AW (Andreas.Weingessel@ci.tuwien.ac.at) on Apr 11, 1994 |
|
18 # Last modified by AW on Nov 7, 1994 |
|
19 # Copyright Dept of Probability Theory and Statistics TU Wien |
|
20 |
|
21 file = octave_tmp_file_name (); |
|
22 |
|
23 usage_msg = "playaudio (name [, ext]) or playaudio (X)"; |
|
24 |
|
25 if (nargin == 1 && is_vector (name) && ! isstr (name)) |
|
26 # play a vector |
|
27 [nr, nc] = size (name); |
|
28 if (nc != 1) |
|
29 if (nr == 1) |
|
30 name = name'; |
|
31 nr = nc; |
|
32 else |
|
33 error ("playaudio: X must be a vector"); |
|
34 endif |
|
35 endif |
|
36 X = name + 127; |
|
37 num = fopen (file, "w"); |
|
38 c = fwrite (num, X, "uchar"); |
|
39 fclose (num); |
|
40 system (sprintf ("cat %s > /dev/dsp", file)); |
|
41 unlink (file); |
|
42 elseif (nargin >= 1 && isstr (name)) |
|
43 # play a file |
|
44 if (nargin == 1) |
|
45 name = [name, ".lin"]; |
|
46 elseif (nargin == 2) |
|
47 name = [name, ".", ext]; |
|
48 else |
|
49 usage (usage_msg); |
|
50 endif |
|
51 if (strcmp (ext, "lin") || strcmp (ext, "raw")) |
|
52 system (sprintf ("cat %s > /dev/dsp", name)); |
|
53 elseif (strcmp (ext, "mu") || strcmp (ext, "au") || strcmp (ext, "snd")) |
|
54 system (sprintf ("cat %s > /dev/audio", name)); |
|
55 else |
|
56 error ("playaudio does not support given extension"); |
|
57 endif |
|
58 else |
|
59 usage (usage_msg); |
|
60 endif |
|
61 |
|
62 endfunction |