Mercurial > octave-nkf
annotate scripts/audio/playaudio.m @ 10635:d1978e7364ad
Print name of function in error() string messages.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 16 May 2010 22:26:54 -0700 |
parents | 95c3e38098bf |
children | be55736a0783 |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, |
2 ## 2005, 2006, 2007 John W. Eaton | |
2313 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
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}. | |
5642 | 25 ## @seealso{lin2mu, mu2lin, loadaudio, saveaudio, setaudio, record} |
3332 | 26 ## @end deftypefn |
2311 | 27 |
2312 | 28 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> |
29 ## Created: 11 April 1994 | |
30 ## Adapted-By: jwe | |
31 | |
1636 | 32 function playaudio (name, ext) |
2325 | 33 |
5443 | 34 if (nargin == 1 && isvector (name) && ! ischar (name)) |
2303 | 35 ## play a vector |
1636 | 36 [nr, nc] = size (name); |
37 if (nc != 1) | |
38 if (nr == 1) | |
3426 | 39 name = name'; |
40 nr = nc; | |
1636 | 41 else |
3426 | 42 error ("playaudio: X must be a vector"); |
1636 | 43 endif |
44 endif | |
45 X = name + 127; | |
2458 | 46 unwind_protect |
47 file = tmpnam (); | |
3167 | 48 num = fopen (file, "wb"); |
2458 | 49 c = fwrite (num, X, "uchar"); |
50 fclose (num); | |
4469 | 51 system (sprintf ("cat \"%s\" > /dev/dsp", file)); |
2458 | 52 unwind_protect_cleanup |
53 unlink (file); | |
54 end_unwind_protect | |
5443 | 55 elseif (nargin >= 1 && ischar (name)) |
2303 | 56 ## play a file |
1636 | 57 if (nargin == 1) |
58 name = [name, ".lin"]; | |
59 elseif (nargin == 2) | |
60 name = [name, ".", ext]; | |
61 else | |
6046 | 62 print_usage (); |
1636 | 63 endif |
64 if (strcmp (ext, "lin") || strcmp (ext, "raw")) | |
4469 | 65 system (sprintf ("cat \"%s\" > /dev/dsp", name)); |
3471 | 66 elseif (strcmp (ext, "mu") || strcmp (ext, "au") |
10549 | 67 || strcmp (ext, "snd") || strcmp (ext, "ul")) |
4469 | 68 system (sprintf ("cat \"%s\" > /dev/audio", name)); |
1636 | 69 else |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
70 error ("playaudio: unsupported extension"); |
1636 | 71 endif |
72 else | |
6046 | 73 print_usage (); |
1636 | 74 endif |
75 | |
76 endfunction |