help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

wavwrite


From: John W. Eaton
Subject: wavwrite
Date: Tue, 09 Oct 2007 12:34:03 -0400

On  9-Oct-2007, Schirmacher, Rolf wrote:

| I just found some incompatibility in between octave an matlab for wavwrite.
| 
| Octave wants to get the filename first, Matlab last. So we have 
| wavwrite(filename, signal, fs, bits) in Octave and
| wavwrite(signal, fs, bits, filename) in Matlab.
| 
| Changing it would be straight forward (as far as I see...), but it would
| break existing Octave code :-(

Does the following patch solve the argument ordering problem for you
and still allow the old argument order?

It is generally best to send bug reports to the address@hidden list.

Also, with the Matlab ordering, doesn't it seem odd that the two
required arguments are the first and last instead of just the first
two?  It seems that makes implementing the function unnecessarily
awkward.  I hope that people writing code for Octave don't follow this
style unless they are forced to for some good reason.

| BTW, there are some more differences: 24 bit is currently not supported in
| octave and 32 bit is implemented as 32 bit integer. Matlab has 24 bit
| integer and 32 bit normalised floats. I regard this a minor issue as both
| seems to be correct / legal within the data format and would not really
| break code (except of giving an "unsupported" error for octave 24 bit).

I would consider a patch for these problems.

jwe


scripts/ChangeLog:

2007-10-09  John W. Eaton  <address@hidden>

        * audio/wavwrite.m: Accept arguments in compatible order.


Index: scripts/audio/wavwrite.m
===================================================================
RCS file: /cvs/octave/scripts/audio/wavwrite.m,v
retrieving revision 1.7
diff -u -u -r1.7 wavwrite.m
--- scripts/audio/wavwrite.m    14 Feb 2007 21:22:59 -0000      1.7
+++ scripts/audio/wavwrite.m    9 Oct 2007 16:32:23 -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 <address@hidden>
 ## 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  

reply via email to

[Prev in Thread] Current Thread [Next in Thread]