Mercurial > octave
annotate scripts/audio/playaudio.m @ 12575:d0b799dafede
Grammarcheck files for 3.4.1 release.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Mon, 04 Apr 2011 15:33:46 -0700 |
parents | fd0a3ac60b0e |
children | f754b65f4bc5 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1995-2011 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
2313 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
2303 | 18 |
3332 | 19 ## -*- texinfo -*- |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
20 ## @deftypefn {Function File} {} playaudio (@var{name}, @var{ext}) |
3332 | 21 ## @deftypefnx {Function File} {} playaudio (@var{x}) |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
22 ## Play the audio file @file{@var{name}.@var{ext}} or the audio data |
3332 | 23 ## stored in the vector @var{x}. |
5642 | 24 ## @seealso{lin2mu, mu2lin, loadaudio, saveaudio, setaudio, record} |
3332 | 25 ## @end deftypefn |
2311 | 26 |
2312 | 27 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> |
28 ## Created: 11 April 1994 | |
29 ## Adapted-By: jwe | |
30 | |
1636 | 31 function playaudio (name, ext) |
2325 | 32 |
5443 | 33 if (nargin == 1 && isvector (name) && ! ischar (name)) |
2303 | 34 ## play a vector |
1636 | 35 [nr, nc] = size (name); |
36 if (nc != 1) | |
37 if (nr == 1) | |
3426 | 38 name = name'; |
39 nr = nc; | |
1636 | 40 else |
3426 | 41 error ("playaudio: X must be a vector"); |
1636 | 42 endif |
43 endif | |
44 X = name + 127; | |
2458 | 45 unwind_protect |
46 file = tmpnam (); | |
3167 | 47 num = fopen (file, "wb"); |
2458 | 48 c = fwrite (num, X, "uchar"); |
49 fclose (num); | |
4469 | 50 system (sprintf ("cat \"%s\" > /dev/dsp", file)); |
2458 | 51 unwind_protect_cleanup |
52 unlink (file); | |
53 end_unwind_protect | |
5443 | 54 elseif (nargin >= 1 && ischar (name)) |
2303 | 55 ## play a file |
1636 | 56 if (nargin == 1) |
57 name = [name, ".lin"]; | |
58 elseif (nargin == 2) | |
59 name = [name, ".", ext]; | |
60 else | |
6046 | 61 print_usage (); |
1636 | 62 endif |
63 if (strcmp (ext, "lin") || strcmp (ext, "raw")) | |
4469 | 64 system (sprintf ("cat \"%s\" > /dev/dsp", name)); |
3471 | 65 elseif (strcmp (ext, "mu") || strcmp (ext, "au") |
10549 | 66 || strcmp (ext, "snd") || strcmp (ext, "ul")) |
4469 | 67 system (sprintf ("cat \"%s\" > /dev/audio", name)); |
1636 | 68 else |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
69 error ("playaudio: unsupported extension"); |
1636 | 70 endif |
71 else | |
6046 | 72 print_usage (); |
1636 | 73 endif |
74 | |
75 endfunction |