c@0
|
1 function [y,fs,bits] = wavread(filename,arg)
|
c@0
|
2 %WAVREAD Read an audio file
|
c@0
|
3 %
|
c@0
|
4 % WAVREAD is a wrapper function for audioread, using the same function
|
c@0
|
5 % name and input arguments as the deprecated MATLAB WAVREAD function. It
|
c@0
|
6 % is provided in order to improve the compatibility of legacy code.
|
c@0
|
7 %
|
c@0
|
8 % Y = WAVREAD(FILENAME) loads an audio file specified by the string
|
c@0
|
9 % FILENAME, returning the sampled data in Y. Audio channels are returned
|
c@0
|
10 % in the columns of Y.
|
c@0
|
11 %
|
c@0
|
12 % [Y,FS,BITS] = WAVREAD(FILENAME) returns the sample rate (FF) in Hertz
|
c@0
|
13 % and the number of bits per sample (BITS) used to encode the data in the
|
c@0
|
14 % file.
|
c@0
|
15 %
|
c@0
|
16 % ... = WAVREAD(FILENAME,N) returns only the first N samples from each
|
c@0
|
17 % channel in the file.
|
c@0
|
18 %
|
c@0
|
19 % ... = WAVREAD(FILENAME,[N1 N2]) returns only samples N1 through N2 from
|
c@0
|
20 % each channel in the file.
|
c@0
|
21 %
|
c@0
|
22 % SIZ = WAVREAD(FILENAME,'SIZE') returns the size of the audio data
|
c@0
|
23 % contained in the file in place of the actual audio data, returning the
|
c@0
|
24 % vector SIZ = [NumSamples NumChannels].
|
c@0
|
25 %
|
c@0
|
26 % See also AUDIOREAD.
|
c@0
|
27
|
c@0
|
28 % Copyright 2016 University of Surrey.
|
c@0
|
29
|
c@0
|
30 % basic info
|
c@0
|
31 info = audioinfo(filename);
|
c@0
|
32 bits = info.BitsPerSample;
|
c@0
|
33
|
c@0
|
34 if nargin>1
|
c@0
|
35 if ischar(arg)
|
c@0
|
36 % return size
|
c@0
|
37 if strcmpi(arg,'size')
|
c@0
|
38 y = [info.TotalSamples info.NumChannels];
|
c@0
|
39 else
|
c@0
|
40 error('Unknown argument ''%s'' specified',arg)
|
c@0
|
41 end
|
c@0
|
42 else
|
c@0
|
43 % return some samples
|
c@0
|
44 assert(isnumeric(arg) && numel(arg)<=2,'The second argument must be a one- or two-element numeric array.')
|
c@0
|
45 [y,fs] = audioread(filename,arg);
|
c@0
|
46 end
|
c@0
|
47 else
|
c@0
|
48 % return all samples
|
c@0
|
49 [y,fs] = audioread(filename);
|
c@0
|
50 end
|
c@0
|
51
|
c@0
|
52 end
|