# HG changeset patch # User jwe # Date 1191947865 0 # Node ID cf2f6090147a36bae22132be42f1eff2b4d6e294 # Parent 827be634619e3573addc97e2e658249fa8515f25 [project @ 2007-10-09 16:37:45 by jwe] diff -r 827be634619e -r cf2f6090147a scripts/ChangeLog --- a/scripts/ChangeLog Tue Oct 09 15:55:14 2007 +0000 +++ b/scripts/ChangeLog Tue Oct 09 16:37:45 2007 +0000 @@ -1,3 +1,7 @@ +2007-10-09 John W. Eaton + + * audio/wavwrite.m: Accept arguments in compatible order. + 2007-10-08 David Bateman * general/interp2.m: Relax test for values outside the grid to diff -r 827be634619e -r cf2f6090147a scripts/audio/wavwrite.m --- a/scripts/audio/wavwrite.m Tue Oct 09 15:55:14 2007 +0000 +++ b/scripts/audio/wavwrite.m Tue Oct 09 16:37:45 2007 +0000 @@ -18,30 +18,60 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn {Function File} {} wavwrite (@var{filename}, @var{y}) -## Write @var{y} to the canonical RIFF/WAVE sound file @var{filename}. A sample -## rate of 8000 Hz and 16-bit samples are assumed. Each column of the data -## represents a separate channel. -## -## @deftypefnx {Function File} {} wavwrite (@var{filename}, @var{y}, @var{fs}) -## Set the sample rate to @var{fs} Hz. -## -## @deftypefnx {Function File} {} wavwrite (@var{filename}, @var{y}, @var{fs}, @var{bits}) -## Set the sample rate to @var{fs} Hz and resolution to @var{bits} bits. +## @deftypefn {Function File} {} wavwrite (@var{y}, @var{filename}) +## @deftypefnx {Function File} {} wavwrite (@var{y}, @var{fs}, @var{filename}) +## @deftypefnx {Function File} {} wavwrite (@var{y}, @var{fs}, @var{bits}, @var{filename}) +## Write @var{y} to the canonical RIFF/WAVE sound file @var{filename} +## with sample rate @var{fs} and bits per sample @var{bits}. The +## default sample rate is 8000 Hz with 16-bits per sample. Each column +## of the data represents a separate channel. ## @seealso{wavread} ## @end deftypefn ## Author: Michael Zeising ## Created: 06 December 2005 -function wavwrite (filename, y, samples_per_sec, bits_per_sample) +function wavwrite (y, varargin) BYTEORDER = "ieee-le"; - + + ## For backward compatibility with previous versions of Octave, also + ## accept the inputs + ## + ## wavwrite (filename, y) + ## wavwrite (filename, y, fs) + ## wavwrite (filename, y, fs, bits) + if (nargin < 2 || nargin > 4) print_usage (); endif + ## Defaults. + samples_per_sec = 8000; + bits_per_sample = 16; + + if (ischar (y)) + filename = y; + y = varargin{1}; + if (nargin > 2) + samples_per_sec = varargin{2}; + if (nargin > 3) + bits_per_sample = varargin{3}; + endif + endif + else + filename = varargin{end}; + if (nargin > 2) + samples_per_sec = varargin{1}; + if (nargin > 3) + bits_per_sample = varargin{2}; + endif + endif + endif + + samples_per_sec +bits_per_sample + ## test arguments if (columns (y) < 1) error ("wavwrite: Y must have at least one column"); @@ -50,15 +80,6 @@ error ("wavwrite: Y has more than 32767 columns (too many for a WAV-file)"); endif - ## parse arguments - if (nargin < 3) - samples_per_sec = 8000; - endif - - if (nargin < 4) - bits_per_sample = 16; - endif - ## determine sample format switch (bits_per_sample) case 8