50 # include <sys/types.h> 51 # include <sys/stat.h> 58 typedef __int8 int8_t;
59 typedef __int16 int16_t;
60 typedef __int32 int32_t;
61 typedef __int64 int64_t;
62 typedef unsigned __int8 uint8_t;
63 typedef unsigned __int16 uint16_t;
64 typedef unsigned __int32 uint32_t;
65 typedef unsigned __int64 uint64_t;
72 typedef unsigned int uint;
78 # define CHUNK_ID_RIFF 0x52494646 79 # define CHUNK_ID_RIFX 0x52494658 80 # define CHUNK_ID_LIST 0x4C495354 82 # define LIST_TYPE_INFO 0x494E464F 83 # define CHUNK_ID_ICMT 0x49434D54 84 # define CHUNK_ID_ICOP 0x49434F50 85 # define CHUNK_ID_ICRD 0x49435244 86 # define CHUNK_ID_IENG 0x49454E47 87 # define CHUNK_ID_INAM 0x494E414D 88 # define CHUNK_ID_IPRD 0x49505244 89 # define CHUNK_ID_ISFT 0x49534654 91 # define CHUNK_ID_SMPL 0x736D706C 93 #else // little endian 94 # define CHUNK_ID_RIFF 0x46464952 95 # define CHUNK_ID_RIFX 0x58464952 96 # define CHUNK_ID_LIST 0x5453494C 98 # define LIST_TYPE_INFO 0x4F464E49 99 # define CHUNK_ID_ICMT 0x544D4349 100 # define CHUNK_ID_ICOP 0x504F4349 101 # define CHUNK_ID_ICRD 0x44524349 102 # define CHUNK_ID_IENG 0x474E4549 103 # define CHUNK_ID_INAM 0x4D414E49 104 # define CHUNK_ID_IPRD 0x44525049 105 # define CHUNK_ID_ISFT 0x54465349 107 # define CHUNK_ID_SMPL 0x6C706D73 109 #endif // WORDS_BIGENDIAN 111 #define CHUNK_HEADER_SIZE 8 112 #define LIST_HEADER_SIZE 12 113 #define RIFF_HEADER_SIZE 12 142 typedef std::string
String;
208 String GetChunkIDString();
212 unsigned long GetSize()
const {
return CurrentChunkSize; }
217 unsigned long RemainingBytes();
219 unsigned long Read(
void* pData,
unsigned long WordCount,
unsigned long WordSize);
220 unsigned long ReadInt8(int8_t* pData,
unsigned long WordCount = 1);
221 unsigned long ReadUint8(uint8_t* pData,
unsigned long WordCount = 1);
222 unsigned long ReadInt16(int16_t* pData,
unsigned long WordCount = 1);
223 unsigned long ReadUint16(uint16_t* pData,
unsigned long WordCount = 1);
224 unsigned long ReadInt32(int32_t* pData,
unsigned long WordCount = 1);
225 unsigned long ReadUint32(uint32_t* pData,
unsigned long WordCount = 1);
229 uint16_t ReadUint16();
231 uint32_t ReadUint32();
232 void ReadString(String& s,
int size);
233 unsigned long Write(
void* pData,
unsigned long WordCount,
unsigned long WordSize);
234 unsigned long WriteInt8(int8_t* pData,
unsigned long WordCount = 1);
235 unsigned long WriteUint8(uint8_t* pData,
unsigned long WordCount = 1);
236 unsigned long WriteInt16(int16_t* pData,
unsigned long WordCount = 1);
237 unsigned long WriteUint16(uint16_t* pData,
unsigned long WordCount = 1);
238 unsigned long WriteInt32(int32_t* pData,
unsigned long WordCount = 1);
239 unsigned long WriteUint32(uint32_t* pData,
unsigned long WordCount = 1);
240 void* LoadChunkData();
241 void ReleaseChunkData();
242 void Resize(
int iNewSize);
256 Chunk(
File* pFile,
List* pParent, uint32_t uiChunkID, uint uiBodySize);
257 void ReadHeader(
unsigned long fPos);
258 void WriteHeader(
unsigned long fPos);
259 unsigned long ReadSceptical(
void* pData,
unsigned long WordCount,
unsigned long WordSize);
261 uint8_t byteCache = *((uint8_t*) Word);
262 *((uint8_t*) Word) = *((uint8_t*) Word + 1);
263 *((uint8_t*) Word + 1) = byteCache;
266 uint8_t byteCache = *((uint8_t*) Word);
267 *((uint8_t*) Word) = *((uint8_t*) Word + 3);
268 *((uint8_t*) Word + 3) = byteCache;
269 byteCache = *((uint8_t*) Word + 1);
270 *((uint8_t*) Word + 1) = *((uint8_t*) Word + 2);
271 *((uint8_t*) Word + 2) = byteCache;
273 inline void swapBytes(
void* Word,
unsigned long WordSize) {
275 unsigned long lo = 0, hi = WordSize - 1;
276 for (; lo < hi; hi--, lo++) {
277 byteCache = *((uint8_t*) Word + lo);
278 *((uint8_t*) Word + lo) = *((uint8_t*) Word + hi);
279 *((uint8_t*) Word + hi) = byteCache;
284 for (
int i = 0; i < 4; i++) {
285 uint8_t byte = *((uint8_t*)(&word) + i);
291 virtual unsigned long WriteChunk(
unsigned long ulWritePos,
unsigned long ulCurrentDataOffset,
progress_t* pProgress = NULL);
292 virtual void __resetPos();
304 List(
File* pFile,
unsigned long StartPos,
List* Parent);
305 String GetListTypeString();
307 Chunk* GetSubChunk(uint32_t ChunkID);
308 List* GetSubList(uint32_t ListType);
309 Chunk* GetFirstSubChunk();
310 Chunk* GetNextSubChunk();
311 List* GetFirstSubList();
312 List* GetNextSubList();
313 unsigned int CountSubChunks();
314 unsigned int CountSubChunks(uint32_t ChunkID);
315 unsigned int CountSubLists();
316 unsigned int CountSubLists(uint32_t ListType);
317 Chunk* AddSubChunk(uint32_t uiChunkID, uint uiBodySize);
318 List* AddSubList(uint32_t uiListType);
319 void DeleteSubChunk(
Chunk* pSubChunk);
321 void MoveSubChunk(
Chunk* pSrc,
List* pNewParent);
336 void ReadHeader(
unsigned long fPos);
337 void WriteHeader(
unsigned long fPos);
338 void LoadSubChunks(
progress_t* pProgress = NULL);
339 void LoadSubChunksRecursively(
progress_t* pProgress = NULL);
340 virtual unsigned long WriteChunk(
unsigned long ulWritePos,
unsigned long ulCurrentDataOffset,
progress_t* pProgress = NULL);
341 virtual void __resetPos();
342 void DeleteChunkList();
353 File(uint32_t FileType);
354 File(
const String& path);
359 String GetFileName();
360 void SetFileName(
const String& path);
363 virtual void Save(
progress_t* pProgress = NULL);
364 virtual void Save(
const String& path,
progress_t* pProgress = NULL);
382 void LogAsResized(
Chunk* pResizedChunk);
383 void UnlogResized(
Chunk* pResizedChunk);
388 ChunkSet ResizedChunks;
390 void __openExistingFile(
const String& path, uint32_t* FileType = NULL);
391 unsigned long GetFileSize();
392 void ResizeFile(
unsigned long ulNewSize);
394 unsigned long __GetFileSize(
int hFile);
396 unsigned long __GetFileSize(HANDLE hFile);
398 unsigned long __GetFileSize(FILE* hFile);
void swapBytes_16(void *Word)
stream_whence_t
File stream position dependent to these relations.
String libraryName()
Returns the name of this C++ library.
uint32_t GetChunkID()
Chunk ID in unsigned integer representation.
layout_t Layout
An ordinary RIFF file is always set to layout_standard.
void(* callback)(progress_t *)
Callback function pointer which has to be assigned to a function for progress notification.
void swapBytes(void *Word, unsigned long WordSize)
stream_state_t
Current state of the file stream.
String libraryVersion()
Returns version of this C++ library.
int hFileWrite
handle / descriptor for writing to (some) file
Exception(String Message)
stream_mode_t
Whether file stream is open in read or in read/write mode.
std::list< Chunk * > ChunkList
unsigned long GetPos()
Position within the chunk data body.
std::set< Chunk * > ChunkSet
ChunkList::iterator ListIterator
float __range_min
Only for internal usage, do not modify!
layout_t
General chunk structure of a file.
uint32_t GetListType()
Returns unsigned integer representation of the list's ID.
unsigned long GetFilePos()
Current, actual offset in file.
ChunkList::iterator ChunksIterator
File * GetFile()
Returns pointer to the chunk's File object.
void * custom
This pointer can be used for arbitrary data.
Used for indicating the progress of a certain task.
List * GetParent()
Returns pointer to the chunk's parent list chunk.
void swapBytes_32(void *Word)
int hFileRead
handle / descriptor for reading from file
Not a "real" RIFF file: First chunk in file is an ordinary data chunk, not a List chunk...
uint32_t CurrentChunkSize
endian_t
Alignment of data bytes in memory (system dependant).
Standard RIFF file layout: First chunk in file is a List chunk which contains all other chunks and th...
unsigned long ulChunkDataSize
RIFF specific classes and definitions.
unsigned long GetSize() const
Chunk size in bytes (without header, thus the chunk data body)
float factor
Reflects current progress as value between 0.0 and 1.0.
String convertToString(uint32_t word)
float __range_max
Only for internal usage, do not modify!
Will be thrown whenever an error occurs while handling a RIFF file.
unsigned long GetNewSize()
New chunk size if it was modified with Resize().
std::map< uint32_t, RIFF::Chunk * > ChunkMap