Modified WaveWrite for Matlab.


The Matlab wavwrite function writes a Microsoft *.wav audio file, but cannot add in the various descriptive fields (e.g. author, title) which are supported by wav editors such as CoolEdit. The modified syntax is


where factstring is added to the file as a wav fact, displaystring is added as a title, and listarray is a cell array of any other standard wav fields, including:

['icmt','Date Species Loc'] a comment
['inam','Bruce Land'] author's name
['icrd',datestr(datenum(now))] the date
['ignr','EOD file'] 
['imed','dat tape'] the medium
['isft','matlab',version] software used
['isrf','record #01'] ;
['bozo','any 4-character tag will work'] you can define your own tags, but editors may not read them.

The program RIFFview was essential in debugging the code.

The program

Here is the modified help file for the enhanced wavwrite function. The full code is not given because it would violate Matlab copyright. If you are licensed for Matlab, I will send you a copy of the code.

function MYwavwrite(y,Fs,nbits,wavefile,comStr,wavlist,dispname)
%WAVWRITE Write Microsoft WAVE (".wav") sound file.
%   writes data Y to a Windows WAVE
%   file specified by the file name WAVEFILE, with a sample rate
%   of FS Hz and with NBITS number of bits.  NBITS must be 8 or 16.
%   Stereo data should be specified as a matrix with two columns.
%   Amplitude values outside the range [-1,+1] are clipped.
%   The comStr STRING value is appended the the WAV file as a FACT chunk.
%   If omitted, comStr defaults to a couple of spaces.
%   The wavlist specifies a series of fields to store. Wavlist must be a cell
%   array, with each cell containing a four-character ID, followed by a string.
%   Microsoft and others define a standard set of IDs. 
%   e.g.
%   wavlist{1} = ['inam','Bruce Land'] ;
%   wavlist{2} = ['icrd',datestr(datenum(now))] ;
%   If wavlist is omitted, 
%   then one entry is added: a standard 'icmt' with value 'No info stored'.
%   The dispname specifies a standard WAV display title in the file. If
%   dispname is omitted, then the string 'No Title' is stored.
%   If you use ANY of the optional chunks (FACT,LIST,DISP) , then you MUST
%   specify all parameters preceeding the chunk input parameters.
%   WAVWRITE(Y,FS,WAVEFILE) assumes NBITS=16 bits.
%   WAVWRITE(Y,WAVEFILE) assumes NBITS=16 bits and FS=8000 Hz.
%   See also WAVREAD, AUWRITE.
% The following is a program to test the options 
% %test modified wavewrite
% clear all
% %read a small wav file
% [y,Fs,nbits] = wavread('c:\windows\media\ding.wav');
% %file name to write new wav file
% wavefile = 'c:\my documents\junk.wav';
% %String to write as a FACT chunk
% comStr = 'Testing the fact chunk!';
% %cell array to pass into MYwavwrite as a LIST chunk
% wavlist{1} = ['icmt','Date Species Loc'] ; 
% wavlist{2} = ['inam','Bruce Land'] ;
% wavlist{3} = ['icrd',datestr(datenum(now))] ;
% wavlist{4} = ['ignr','EOD file'] ;
% wavlist{5} = ['imed','dat tape'];
% wavlist{6} = ['isft','matlab',version];
% wavlist{7} = ['itch','digitizer'] ;
% wavlist{8} = ['isrf','record #01'] ;
% wavlist{9} = ['bozo','any 4-character tag will work'];
% %specify a display title
% dispTitle = 'EOD file';
% %build the new wav file
% MYwavwrite2(y,Fs,nbits,wavefile,comStr, wavlist, dispTitle);
% %now read it again to check
% [y,Fs,nbits,opts] = wavread(wavefile);
% opts
% opts.disp

%   Copyright 1984-2000 The MathWorks, Inc. 
%   $Revision: 5.10 $  $Date: 2000/06/01 17:29:55 $

%   D. Orofino, 11/95
%Modified by Bruce Land, 
%Cornell University June 2003
%To include optional chunks: list-info, disp, fact

Copyright Dec 2003 - Cornell University