Enable asyncio.library.
[AROS-Contrib.git] / FryingPan / DTLib / rAIFFAudio.cpp
blob0c830f3fa0cc3eff74806d8b108b9f6f9f18ba43
1 /*
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
4 *
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.
9 *
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);
39 return pSkel;
42 rAIFFAudio::rAIFFAudio(const char *sName, EDtError &rc)
43 : FileReader(sName, rc)
45 if (rc != DT_OK)
46 return;
48 readHeaders();
49 setBlockSize(2352);
50 setLittleEndian(false);
51 setType(Data_Audio);
54 void rAIFFAudio::readHeaders()
56 unsigned int buff;
57 int c=0;
59 DOS->Seek(getFile(), 0, OFFSET_BEGINNING);
61 if (DOS->Read(getFile(), &buff, 4)!=4)
62 return;
63 buff = L2BE(buff);
64 if (buff != ID_FORM)
65 return;
67 DOS->Seek(getFile(), 4, OFFSET_CURRENT);
68 if (DOS->Read(getFile(), &buff, 4)!=4)
69 return;
70 buff = L2BE(buff);
71 if (buff != ID_AIFF)
72 return;
74 for (c=0; c<2;)
76 if (DOS->Read(getFile(), &buff, 4)!=4)
77 return;
79 if (buff == ID_COMM)
81 c++;
83 else if (buff == ID_SSND)
85 c++;
86 if (DOS->Read(getFile(), &buff, 4)!=4)
87 return;
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)
95 return;
96 buff = L2BE(buff);
97 DOS->Seek(getFile(), buff, OFFSET_CURRENT);
100 return;
103 bool rAIFFAudio::checkFile(const char* sFileName, EDtError &rc)
105 unsigned int buff;
106 int c=0;
107 BPTR fh;
109 rc = DT_UnableToOpenFile;
111 fh = DOS->Open(const_cast<char*>(sFileName), MODE_OLDFILE);
112 if (0 == fh)
113 return false;
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;
122 DOS->Close(fh);
123 return false;
127 * check if we have a FORM header
129 buff = L2BE(buff);
130 if (buff != ID_FORM)
132 rc = DT_InvalidFormat;
133 DOS->Close(fh);
134 return false;
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;
144 DOS->Close(fh);
145 return false;
148 buff = L2BE(buff);
149 if (buff != ID_AIFF)
151 rc = DT_InvalidFormat;
152 DOS->Close(fh);
153 return false;
157 * alright! read what you can.
159 for (c=0;c<2;)
161 if (DOS->Read(fh, &buff, 4)!=4)
163 DOS->Close(fh);
164 return false;
167 buff = L2BE(buff);
169 if (buff == ID_COMM)
171 c++;
173 else if (buff == ID_SSND)
175 c++;
178 if (DOS->Read(fh, &buff, 4)!=4)
180 rc = DT_FileMalformed;
181 DOS->Close(fh);
182 return false;
185 buff = L2BE(buff);
186 DOS->Seek(fh, buff, OFFSET_CURRENT);
189 rc = DT_OK;
190 DOS->Close(fh);
191 return true;
194 const char *rAIFFAudio::static_getName()
196 return "AIFF Audio Track";
199 bool rAIFFAudio::static_isAudio()
201 return true;
204 bool rAIFFAudio::static_isData()
206 return false;
209 bool rAIFFAudio::static_isSession()
211 return false;
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();
229 // vim: ts=3 et