1 ## Copyright (C) 1995-2012 John W. Eaton
3 ## This file is part of Octave.
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 3 of the License, or (at
8 ## your option) any later version.
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.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} saveaudio (@var{name}, @var{x}, @var{ext}, @var{bps})
21 ## Save a vector @var{x} of audio data to the file
22 ## @file{@var{name}.@var{ext}}. The optional parameters @var{ext} and
23 ## @var{bps} determine the encoding and the number of bits per sample used
24 ## in the audio file (see @code{loadaudio}); defaults are @file{lin} and
26 ## @seealso{lin2mu, mu2lin, loadaudio, playaudio, setaudio, record}
29 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at>
30 ## Created: 5 September 1994
33 function saveaudio (name, x, ext, bps)
35 if (nargin < 2 || nargin > 4)
45 elseif (bps != 8 && bps != 16)
46 error ("saveaudio: BPS must be either 8 or 16");
55 error ("saveaudio: X must be a vector");
59 num = fopen ([name, ".", ext], "wb");
61 if (strcmp (ext, "lin") || strcmp (ext, "raw"))
64 if (ld > 127) # convert 16 to 8 bit
73 c = fwrite (num, x, "uchar");
75 c = fwrite (num, x, "short");
77 elseif (strcmp (ext, "mu") || strcmp (ext, "au")
78 || strcmp (ext, "snd") || strcmp (ext, "ul"))
80 c = fwrite (num, y, "uchar");
83 error ("saveaudio: unsupported extension");