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].
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 General Public License as published by 0025 % the Free Software Foundation; either version 2 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 General Public License for more details. 0032 % 0033 % You can obtain a copy of the GNU General Public License from 0034 % http://www.gnu.org/copyleft/gpl.html or by writing to 0035 % Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA. 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