ScummVM API documentation
rifffile.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21/*
22 * VGMTrans (c) 2002-2019
23 * Licensed under the zlib license,
24 * refer to the included VGMTrans_LICENSE.txt file
25 */
26#ifndef AUDIO_SOUNDFONT_RIFFFILE_H
27#define AUDIO_SOUNDFONT_RIFFFILE_H
28
29#include "common/scummsys.h"
30#include "common/list.h"
31#include "common/str.h"
32#include "common/array.h"
33
35// Chunk - Riff format chunk
37class Chunk {
38public:
39 char _id[4]; // A chunk ID identifies the type of data within the chunk.
40 uint32 _size; // The size of the chunk data in bytes, excluding any pad byte.
41 uint8 *_data; // The actual data not including a possible pad byte to word align
42
43public:
44 Chunk(Common::String theId) : _data(NULL), _size(0) {
45 assert(theId.size() == 4);
46 memcpy(_id, theId.c_str(), 4);
47 }
48
49 virtual ~Chunk() {
50 if (_data != NULL) {
51 delete[] _data;
52 _data = NULL;
53 }
54 }
55
56 void SetData(const void *src, uint32 datasize);
57
58 virtual uint32 GetSize(); // Returns the size of the chunk in bytes, including any pad byte.
59 virtual void Write(uint8 *buffer);
60
61protected:
62 static inline uint32 GetPaddedSize(uint32 originalSize) { return originalSize + (originalSize % 2); }
63};
64
66// ListTypeChunk - Riff chunk type where the first 4 data bytes are a sig
67// and the rest of the data is a collection of child chunks
69class ListTypeChunk : public Chunk {
70public:
71 char _type[4]; // 4 byte sig that begins the data field, "LIST" or "sfbk" for ex
72 Common::List<Chunk *> _childChunks;
73
74public:
75 ListTypeChunk(Common::String theId, Common::String theType) : Chunk(theId) {
76 assert(theType.size() == 4);
77 memcpy(_type, theType.c_str(), 4);
78 }
79
80 virtual ~ListTypeChunk() {
81 _childChunks.erase(_childChunks.begin(), _childChunks.end());
82 }
83
84 Chunk *AddChildChunk(Chunk *ck);
85
86 uint32 GetSize() override; // Returns the size of the chunk in bytes, including any pad byte.
87 void Write(uint8 *buffer) override;
88};
89
91// RIFFChunk
93class RIFFChunk : public ListTypeChunk {
94public:
95 RIFFChunk(Common::String form) : ListTypeChunk("RIFF", form) {}
96};
97
99// LISTChunk
101class LISTChunk : public ListTypeChunk {
102public:
103 LISTChunk(Common::String theType) : ListTypeChunk("LIST", theType) {}
104};
105
107// RiffFile -
109class RiffFile : public RIFFChunk {
110public:
111 RiffFile(const Common::String &file_name, const Common::String &form);
112
113 static void WriteLIST(Common::Array<uint8> &buf, uint32 listName, uint32 listSize) {
114 //TODO
115// PushTypeOnVectBE<uint32>(buf, 0x4C495354); // write "LIST"
116// PushTypeOnVect<uint32>(buf, listSize);
117// PushTypeOnVectBE<uint32>(buf, listName);
118 }
119
120 // Adds a null byte and ensures 16 bit alignment of a text string
121 static void AlignName(Common::String &name) {
122 name += (char) 0x00;
123 if (name.size() % 2) // if the size of the name string is odd
124 name += (char) 0x00; // add another null byte
125 }
126
127protected:
128 Common::String _name;
129};
130
131#endif // AUDIO_SOUNDFONT_RIFFFILE_H
Definition: rifffile.h:37
iterator begin()
Definition: list.h:266
iterator erase(iterator pos)
Definition: list.h:112
iterator end()
Definition: list.h:279
Definition: str.h:59
Definition: rifffile.h:101
Definition: rifffile.h:69
Definition: rifffile.h:93
Definition: rifffile.h:109