1
## Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2004, 2005, 2006,
4
## This file is part of Octave.
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
8
## the Free Software Foundation; either version 3 of the License, or (at
9
## your option) any later version.
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.
16
## You should have received a copy of the GNU General Public License
17
## along with Octave; see the file COPYING. If not, see
18
## <http://www.gnu.org/licenses/>.
21
## @deftypefn {Function File} {} saveaudio (@var{name}, @var{x}, @var{ext}, @var{bps})
22
## Saves a vector @var{x} of audio data to the file
23
## @file{@var{name}.@var{ext}}. The optional parameters @var{ext} and
24
## @var{bps} determine the encoding and the number of bits per sample used
25
## in the audio file (see @code{loadaudio}); defaults are @file{lin} and
27
## @seealso{lin2mu, mu2lin, loadaudio, playaudio, setaudio, record}
30
## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at>
31
## Created: 5 September 1994
34
function saveaudio (name, X, ext, bit)
36
if (nargin < 2 || nargin > 4)
46
elseif (bit != 8 && bit != 16)
47
error ("saveaudio: bit must be either 8 or 16");
56
error ("saveaudio: X must be a vector");
60
num = fopen ([name, ".", ext], "wb");
62
if (strcmp (ext, "lin") || strcmp (ext, "raw"))
65
if (ld > 127) # convert 16 to 8 bit
74
c = fwrite (num, X, "uchar");
76
c = fwrite (num, X, "short");
78
elseif (strcmp (ext, "mu") || strcmp (ext, "au")
79
|| strcmp (ext, "snd") || strcmp (ext, "ul"))
81
c = fwrite (num, Y, "uchar");
84
error ("saveaudio does not support given extension");