# wavwrite

## PURPOSE

WAVREAD Legacy MATLAB function to write .WAV file (Y,Fs,N,FILENAME)

## SYNOPSIS

function wavwrite(y,fs,n,fn)

## DESCRIPTION

    WAVREAD  Legacy MATLAB function to write .WAV file (Y,Fs,N,FILENAME)
     wavwrite writes data to 8-, 16-, 24-, and 32-bit .wav files.

     Usage:
     wavwrite(y,'filename')        writes the data stored in the variable y to a WAVE file called filename.
                                   The data has a sample rate of 8000 Hz and is assumed to be 16-bit.
                                   Each column of the data represents a separate channel.
                                   Therefore, stereo data should be specified as a matrix with two columns.
                                   Amplitude values outside the range [-1,+1] are clipped prior to writing.
     wavwrite(y,Fs,'filename')     writes the data stored in the variable y to a WAVE file called filename.
                                   The data has a sample rate of Fs Hz and is assumed to be 16-bit.
                                   Amplitude values outside the range [-1,+1] are clipped prior to writing.
     wavwrite(y,Fs,N,'filename')   writes the data stored in the variable y to a WAVE file called filename.
                                   The data has a sample rate of Fs Hz and is N-bit, where N is 8, 16, 24, or 32.
                                   For N < 32, amplitude values outside the range [-1,+1] are clipped.
     Note:    8-, 16-, and 24-bit files are type 1 integer pulse code modulation (PCM). 32-bit files are written as type 3 normalized floating point.

## CROSS-REFERENCE INFORMATION

This function calls:

- v_writewav V_WRITEWAV Creates .WAV format sound files FIDX=(D,FS,FILENAME,MODE,NSKIP,MASK,MAD)

This function is called by:

## SOURCE CODE

    0001 function wavwrite(y,fs,n,fn)
    0002 %WAVREAD  Legacy MATLAB function to write .WAV file (Y,Fs,N,FILENAME)
    0003 % wavwrite writes data to 8-, 16-, 24-, and 32-bit .wav files.
    0004 %
    0005 % Usage:
    0006 % wavwrite(y,'filename')        writes the data stored in the variable y to a WAVE file called filename.
    0007 %                               The data has a sample rate of 8000 Hz and is assumed to be 16-bit.
    0008 %                               Each column of the data represents a separate channel.
    0009 %                               Therefore, stereo data should be specified as a matrix with two columns.
    0010 %                               Amplitude values outside the range [-1,+1] are clipped prior to writing.
    0011 % wavwrite(y,Fs,'filename')     writes the data stored in the variable y to a WAVE file called filename.
    0012 %                               The data has a sample rate of Fs Hz and is assumed to be 16-bit.
    0013 %                               Amplitude values outside the range [-1,+1] are clipped prior to writing.
    0014 % wavwrite(y,Fs,N,'filename')   writes the data stored in the variable y to a WAVE file called filename.
    0015 %                               The data has a sample rate of Fs Hz and is N-bit, where N is 8, 16, 24, or 32.
    0016 %                               For N < 32, amplitude values outside the range [-1,+1] are clipped.
    0017 % Note:    8-, 16-, and 24-bit files are type 1 integer pulse code modulation (PCM). 32-bit files are written as type 3 normalized floating point.
    0018
    0019 %       Copyright (C) Mike Brookes 2018
    0020 %      Version: $Id: wavwrite.m 10865 2018-09-21 17:22:45Z dmb $
    0021 %
    0022 %   VOICEBOX is a MATLAB toolbox for speech processing.
    0023 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
    0024 %
    0025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0026 %   This program is free software; you can redistribute it and/or modify
    0027 %   it under the terms of the GNU Lesser General Public License as published by
    0028 %   the Free Software Foundation; either version 3 of the License, or
    0029 %   (at your option) any later version.
    0030 %
    0031 %   This program is distributed in the hope that it will be useful,
    0032 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
    0033 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0034 %   GNU Lesser General Public License for more details.
    0035 %
    0036 %   You can obtain a copy of the GNU Lesser General Public License from
    0037 %   https://www.gnu.org/licenses/ .
    0038 %
    0039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0040 if nargin<3
    0041     v_writewav(y,8000,fs,'p'); % default is 8kHz, 16 bit
    0042 elseif nargin<4
    0043     v_writewav(y,fs,n,'p'); % default is 16 bit
    0044 else
    0045     switch n
    0046         case 8
    0047             v_writewav(y,fs,fn,'8p'); % write 8 bit fixed-point data
    0048         case 16
    0049             v_writewav(y,fs,fn,'p'); % default is 16 bit
    0050         case 24
    0051             v_writewav(y,fs,fn,'24p'); % write 24 bit fixed-point data
    0052         case 32
    0053             v_writewav(y,fs,fn,'v'); % write 32 bit floating-point data
    0054         otherwise
    0055             error('invalid precision: %d',n);
    0056     end
    0057 end