2 * FryingPan - Amiga CD/DVD Recording Software (User Interface and supporting Libraries only)
3 * Copyright (C) 2001-2011 Tomasz Wiszkowski Tomasz.Wiszkowski at gmail.com
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation; either version 2.1
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "rAIFFAudio.h"
21 #include <libclass/dos.h>
22 #include <libclass/exec.h>
23 #include <libclass/utility.h>
25 #define MKID(a,b,c,d) (((a&255)<<24)|((b&255)<<16)|((c&255)<<8)|(d&255))
26 #define ID_FORM MKID('F','O','R','M')
27 #define ID_COMM MKID('C','O','M','M')
28 #define ID_AIFF MKID('A','I','F','F')
29 #define ID_SSND MKID('S','S','N','D')
32 IFileReader
*rAIFFAudio::openRead(const char* sFile
, EDtError
&rc
)
34 rAIFFAudio
*pSkel
= 0;
35 if (true == checkFile(sFile
, rc
))
37 pSkel
= new rAIFFAudio(sFile
, rc
);
42 rAIFFAudio::rAIFFAudio(const char *sName
, EDtError
&rc
)
43 : FileReader(sName
, rc
)
50 setLittleEndian(false);
54 void rAIFFAudio::readHeaders()
59 DOS
->Seek(getFile(), 0, OFFSET_BEGINNING
);
61 if (DOS
->Read(getFile(), &buff
, 4)!=4)
67 DOS
->Seek(getFile(), 4, OFFSET_CURRENT
);
68 if (DOS
->Read(getFile(), &buff
, 4)!=4)
76 if (DOS
->Read(getFile(), &buff
, 4)!=4)
83 else if (buff
== ID_SSND
)
86 if (DOS
->Read(getFile(), &buff
, 4)!=4)
88 setDataOffset(DOS
->Seek(getFile(), 0, OFFSET_CURRENT
));
89 setDataSize(L2BE(buff
));
90 DOS
->Seek(getFile(), -4, OFFSET_CURRENT
);
94 if (DOS
->Read(getFile(), &buff
, 4)!=4)
97 DOS
->Seek(getFile(), buff
, OFFSET_CURRENT
);
103 bool rAIFFAudio::checkFile(const char* sFileName
, EDtError
&rc
)
109 rc
= DT_UnableToOpenFile
;
111 fh
= DOS
->Open(const_cast<char*>(sFileName
), MODE_OLDFILE
);
116 * open file at its beginning
118 DOS
->Seek(fh
, 0, OFFSET_BEGINNING
);
119 if (DOS
->Read(fh
, &buff
, 4)!=4)
121 rc
= DT_FileMalformed
;
127 * check if we have a FORM header
132 rc
= DT_InvalidFormat
;
138 * if so - see if it is an AIFF file
140 DOS
->Seek(fh
, 4, OFFSET_CURRENT
);
141 if (DOS
->Read(fh
, &buff
, 4)!=4)
143 rc
= DT_FileMalformed
;
151 rc
= DT_InvalidFormat
;
157 * alright! read what you can.
161 if (DOS
->Read(fh
, &buff
, 4)!=4)
173 else if (buff
== ID_SSND
)
178 if (DOS
->Read(fh
, &buff
, 4)!=4)
180 rc
= DT_FileMalformed
;
186 DOS
->Seek(fh
, buff
, OFFSET_CURRENT
);
194 const char *rAIFFAudio::static_getName()
196 return "AIFF Audio Track";
199 bool rAIFFAudio::static_isAudio()
204 bool rAIFFAudio::static_isData()
209 bool rAIFFAudio::static_isSession()
214 bool rAIFFAudio::isAudio()
216 return static_isAudio();
219 bool rAIFFAudio::isData()
221 return static_isData();
224 const char *rAIFFAudio::getName()
226 return static_getName();