tomwalters@0
|
1 % support file for 'aim-mat'
|
tomwalters@0
|
2 %
|
tomwalters@0
|
3 % This external file is included as part of the 'aim-mat' distribution package
|
bleeck@3
|
4 % (c) 2011, University of Southampton
|
bleeck@3
|
5 % Maintained by Stefan Bleeck (bleeck@gmail.com)
|
bleeck@3
|
6 % download of current version is on the soundsoftware site:
|
bleeck@3
|
7 % http://code.soundsoftware.ac.uk/projects/aimmat
|
bleeck@3
|
8 % documentation and everything is on http://www.acousticscale.org
|
bleeck@3
|
9
|
tomwalters@0
|
10
|
tomwalters@0
|
11 function [x,fs]=aiffread(fname)
|
tomwalters@0
|
12
|
tomwalters@0
|
13
|
tomwalters@0
|
14 % function [x,fs]=aiffread(fname)
|
tomwalters@0
|
15 % Read AIFF and AIFF-C file
|
tomwalters@0
|
16 % This is a reduced version and does not fulfill the
|
tomwalters@0
|
17 % AIFF-C standard.
|
tomwalters@0
|
18
|
tomwalters@0
|
19 % Coded by Hideki Kawahara based on "Audio Interchange file format AIFF-C draft"
|
tomwalters@0
|
20 % by Apple Computer inc. 8/26/91
|
tomwalters@0
|
21 % 14/Feb./1998
|
tomwalters@0
|
22 % 17/Feb./1998
|
tomwalters@0
|
23 % 14/Jan./1999 bug fix for Windows
|
tomwalters@0
|
24
|
tomwalters@0
|
25 fid=fopen(fname,'r','ieee-be.l64');
|
tomwalters@0
|
26 id.form=fread(fid,4,'char');
|
tomwalters@0
|
27 id.formcksz=fread(fid,1,'int32');
|
tomwalters@0
|
28 id.formtp=fread(fid,4,'char');
|
tomwalters@0
|
29 x=[];fs=44100;
|
tomwalters@0
|
30 if ~strcmp(char(id.form),['F';'O';'R';'M'])
|
tomwalters@0
|
31 char(id.form)
|
tomwalters@0
|
32 disp('This is not a proper AIFF file.');
|
tomwalters@0
|
33 return;
|
tomwalters@0
|
34 end;
|
tomwalters@0
|
35 if ~strcmp(char(id.formtp),['A';'I';'F';'F']) & ~strcmp(char(id.formtp),['A';'I';'F';'C'])
|
tomwalters@0
|
36 char(id.formtp)
|
tomwalters@0
|
37 disp('This is not a proper AIFF file.');
|
tomwalters@0
|
38 return;
|
tomwalters@0
|
39 end;
|
tomwalters@0
|
40 [id.comm,na]=fread(fid,4,'uchar');
|
tomwalters@0
|
41 while na>3
|
tomwalters@0
|
42 switch(strcat(char(id.comm)'))
|
tomwalters@0
|
43 case 'FVER'
|
tomwalters@0
|
44 id.fsize=fread(fid,1,'int32');
|
tomwalters@0
|
45 id.timesta=fread(fid,1,'uint32');
|
tomwalters@0
|
46 if id.timesta ~= 2726318400
|
tomwalters@0
|
47 disp(['I cannot recognize timestump ' num2str(id.timesta)]);
|
tomwalters@0
|
48 end;
|
tomwalters@0
|
49 [id.comm,na]=fread(fid,4,'uchar');
|
tomwalters@0
|
50 if na==0
|
tomwalters@0
|
51 if isempty(x); disp('End of file reached!');fclose(fid);return;end;
|
tomwalters@0
|
52 end;
|
tomwalters@0
|
53 case 'COMM'
|
tomwalters@0
|
54 id.commsz=fread(fid,1,'int32');
|
tomwalters@0
|
55 id.commnch=fread(fid,1,'int16');
|
tomwalters@0
|
56 id.commdsz=fread(fid,1,'uint32');
|
tomwalters@0
|
57 id.samplesize=fread(fid,1,'int16');
|
tomwalters@0
|
58 id.srex1=fread(fid,1,'uint16');
|
tomwalters@0
|
59 id.srex2=fread(fid,1,'uint64');
|
tomwalters@0
|
60 if strcmp(char(id.formtp),['A';'I';'F';'C'])
|
tomwalters@0
|
61 id.compress=fread(fid,4,'char');
|
tomwalters@0
|
62 if ~strcmp(char(id.compress),['N';'O';'N';'E'])
|
tomwalters@0
|
63 disp('Compression is not supported.');
|
tomwalters@0
|
64 return;
|
tomwalters@0
|
65 end;
|
tomwalters@0
|
66 dummy=fread(fid,id.commsz-22,'char');
|
tomwalters@0
|
67 end;
|
tomwalters@0
|
68 fs=2^(id.srex1-16383)*id.srex2/hex2dec('8000000000000000');
|
tomwalters@0
|
69 [id.comm,na]=fread(fid,4,'uchar');
|
tomwalters@0
|
70 if na==0
|
tomwalters@0
|
71 if isempty(x); disp('End of file reached!');fclose(fid);return;end;
|
tomwalters@0
|
72 end;
|
tomwalters@0
|
73 case 'SSND'
|
tomwalters@0
|
74 id.ckdatasize=fread(fid,1,'uint32');
|
tomwalters@0
|
75 id.offset=fread(fid,1,'int32');
|
tomwalters@0
|
76 id.blksz=fread(fid,1,'int32');
|
tomwalters@0
|
77 switch(id.samplesize)
|
tomwalters@0
|
78 case 8
|
tomwalters@0
|
79 x=fread(fid,id.ckdatasize-8,'int8');
|
tomwalters@0
|
80 x=reshape(x,id.commnch,id.commsz)';
|
tomwalters@0
|
81 case 16
|
tomwalters@0
|
82 x=fread(fid,(id.ckdatasize-8)/2,'int16');
|
tomwalters@0
|
83 x=reshape(x,id.commnch,id.commdsz)';
|
tomwalters@0
|
84 case 24
|
tomwalters@0
|
85 x=fread(fid,(id.ckdatasize-8)/3,'bit24');
|
tomwalters@0
|
86 x=reshape(x,id.commnch,id.commdsz)';
|
tomwalters@0
|
87 end;
|
tomwalters@0
|
88 [id.comm,na]=fread(fid,4,'uchar');
|
tomwalters@0
|
89 if na==0
|
tomwalters@0
|
90 if isempty(x); disp('End of file reached!');fclose(fid);return;end;
|
tomwalters@0
|
91 end;
|
tomwalters@0
|
92 otherwise
|
tomwalters@0
|
93 id.fsize=fread(fid,1,'int32');
|
tomwalters@0
|
94 if feof(fid) | id.fsize > id.formcksz | id.fsize <=0
|
tomwalters@0
|
95 fclose(fid);
|
tomwalters@0
|
96 return;
|
tomwalters@0
|
97 end;
|
tomwalters@0
|
98 id.skip=fread(fid,id.fsize,'char');
|
tomwalters@0
|
99 [id.comm,na]=fread(fid,4,'uchar');
|
tomwalters@0
|
100 if na==0
|
tomwalters@0
|
101 if isempty(x); disp('End of file reached!');fclose(fid);return;end;
|
tomwalters@0
|
102 end;
|
tomwalters@0
|
103 end;
|
tomwalters@0
|
104 end;
|
tomwalters@0
|
105 %id
|
tomwalters@0
|
106 fclose(fid);
|