# wavread

## PURPOSE

WAVREAD Legacy MATLAB function to read .WAV file [Y,FS,BITS]=(FILENAME,NMAX)

## SYNOPSIS

function [y,fs,bits]=wavread(fn,n)

## DESCRIPTION

    WAVREAD  Legacy MATLAB function to read .WAV file [Y,FS,BITS]=(FILENAME,NMAX)
     wavread supports multichannel data, with up to 32 bits per sample, and supports reading 24- and 32-bit .wav files.

     Usage:
     y = wavread('filename')               loads a WAVE file specified by the string filename, returning
                                           the sampled data in y. The .wav extension is appended if no
                                           extension is given. Amplitude values are in the range [-1,+1].
     [y,Fs,bits] = wavread('filename')     returns the sample rate (Fs) in Hertz and the number of bits
                                           per sample (bits) used to encode the data in the file.
     [...] = wavread('filename',N)         returns only the first N samples from each channel in the file.
     [...] = wavread('filename',[N1 N2])   returns only samples N1 through N2 from each channel in the file.
     siz = wavread('filename','size')      returns the size of the audio data contained in the file in place
                                           of the actual audio data, returning the vector siz = [samples channels].

## CROSS-REFERENCE INFORMATION

This function calls:

- v_readwav V_READWAV Read a .WAV format sound file [Y,FS,WMODE,FIDX]=(FILENAME,MODE,NMAX,NSKIP)

This function is called by:

## SOURCE CODE

    0001 function [y,fs,bits]=wavread(fn,n)
    0002 %WAVREAD  Legacy MATLAB function to read .WAV file [Y,FS,BITS]=(FILENAME,NMAX)
    0003 % wavread supports multichannel data, with up to 32 bits per sample, and supports reading 24- and 32-bit .wav files.
    0004 %
    0005 % Usage:
    0006 % y = wavread('filename')               loads a WAVE file specified by the string filename, returning
    0007 %                                       the sampled data in y. The .wav extension is appended if no
    0008 %                                       extension is given. Amplitude values are in the range [-1,+1].
    0009 % [y,Fs,bits] = wavread('filename')     returns the sample rate (Fs) in Hertz and the number of bits
    0010 %                                       per sample (bits) used to encode the data in the file.
    0011 % [...] = wavread('filename',N)         returns only the first N samples from each channel in the file.
    0012 % [...] = wavread('filename',[N1 N2])   returns only samples N1 through N2 from each channel in the file.
    0013 % siz = wavread('filename','size')      returns the size of the audio data contained in the file in place
    0014 %                                       of the actual audio data, returning the vector siz = [samples channels].
    0015
    0016 %       Copyright (C) Mike Brookes 2018
    0017 %      Version: $Id: wavread.m 10865 2018-09-21 17:22:45Z dmb $
    0018 %
    0019 %   VOICEBOX is a MATLAB toolbox for speech processing.
    0020 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
    0021 %
    0022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0023 %   This program is free software; you can redistribute it and/or modify
    0024 %   it under the terms of the GNU Lesser General Public License as published by
    0025 %   the Free Software Foundation; either version 3 of the License, or
    0026 %   (at your option) any later version.
    0027 %
    0028 %   This program is distributed in the hope that it will be useful,
    0029 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
    0030 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0031 %   GNU Lesser General Public License for more details.
    0032 %
    0033 %   You can obtain a copy of the GNU Lesser General Public License from
    0034 %   https://www.gnu.org/licenses/ .
    0035 %
    0036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0037 if nargin<2
    0038     [y,fs,wm,fx]=v_readwav(fn);
    0039 elseif ischar(n)
    0040     if strcmp(n,'size')
    0041         [y,fs,wm,fx]=v_readwav(fn,'',0);
    0042         y=fx(4:5); % number of samples and channels
    0043     else
    0044         error('%s is invalid option',n);
    0045     end
    0046 elseif length(n)<2
    0047     [y,fs,wm,fx]=v_readwav(fn,'',n);
    0048 else
    0049     [y,fs,wm,fx]=v_readwav(fn,'',n(2)-n(1)+1,n(1)-1);
    0050 end
    0051 bits=fx(7); % bits precision