spAudio
Loading...
Searching...
No Matches
spWave_Caf.h
1/*
2 * spWave_Caf.h
3 *
4 * **** UNOFFICIAL VERSION, DON'T USE THIS API ****
5 */
6
7#ifndef __SPWAVE_CAF_H
8#define __SPWAVE_CAF_H
9
10#include <sp/spChunk.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16#ifdef SP_SUPPORT_64BIT_INT
17
18#define SP_CAF_MIN_ENTRY_ALLOC_COUNT 4
19
20#define SP_CAF_SUPPORTED_FILE_VERSION 1
21#define SP_CAF_SUPPORTED_FILE_FLAGS 0
22
23#define SP_CAF_INFORMATION_KEY_TITLE "title"
24#define SP_CAF_INFORMATION_KEY_ARTIST "artist"
25#define SP_CAF_INFORMATION_KEY_ALBUM "album"
26#define SP_CAF_INFORMATION_KEY_TRACK "track number"
27#define SP_CAF_INFORMATION_KEY_RELEASE "year"
28#define SP_CAF_INFORMATION_KEY_COMPOSER "composer"
29#define SP_CAF_INFORMATION_KEY_LYRICIST "lyricist"
30#define SP_CAF_INFORMATION_KEY_GENRE "genre"
31#define SP_CAF_INFORMATION_KEY_COMMENT "comments"
32#define SP_CAF_INFORMATION_KEY_COPYRIGHT "copyright"
33#define SP_CAF_INFORMATION_KEY_SOFTWARE "encoding application"
34#define SP_CAF_INFORMATION_KEY_TEMPO "tempo"
35
36#define SP_CAF_INFORMATION_KEY_ALBUM_ARTIST "album artist" /* unofficial */
37#define SP_CAF_INFORMATION_KEY_DISC "disc number" /* unofficial */
38
39enum {
40 SP_CAF_LPCM_FORMAT_FLAG_IS_FLOAT = (1 << 0),
41 SP_CAF_LPCM_FORMAT_FLAG_IS_LITTLE_ENDIAN = (1 << 1),
42};
43#if BYTE_ORDER == BIG_ENDIAN
44#define SP_CAF_LPCM_FORMAT_FLAG_IS_NATIVE_ENDIAN 0
45#else
46#define SP_CAF_LPCM_FORMAT_FLAG_IS_NATIVE_ENDIAN SP_CAF_LPCM_FORMAT_FLAG_IS_LITTLE_ENDIAN
47#endif
48
49enum {
50 SP_CAF_ALAC_FORMAT_FLAG_16BIT_SOURCE_DATA = 1,
51 SP_CAF_ALAC_FORMAT_FLAG_20BIT_SOURCE_DATA = 2,
52 SP_CAF_ALAC_FORMAT_FLAG_24BIT_SOURCE_DATA = 3,
53 SP_CAF_ALAC_FORMAT_FLAG_32BIT_SOURCE_DATA = 4,
54};
55
56typedef struct _spCafChunkHeader {
57 char type[4];
58 spLong64 mChunkSize;
59
60 spLong64 mMarginSize; /* internal */
61} spCafChunkHeader;
62
63typedef struct _spCafChunk {
64 struct _spCafChunk *parent;
65 struct _spCafChunk *child;
66
67 struct _spCafChunk *prev;
68 struct _spCafChunk *next;
69
70 spFileOffset offset;
71
72 spCafChunkHeader header;
73} spCafChunk;
74
75typedef struct _spCafAudioDescChunk {
76 struct _spCafChunk *parent;
77 struct _spCafChunk *child;
78
79 struct _spCafChunk *prev;
80 struct _spCafChunk *next;
81
82 spFileOffset offset;
83
84 spCafChunkHeader header; /* 'desc' */
85
86 double mSampleRate;
87 char mFormatID[4];
88 long mFormatFlags;
89 long mBytesPerPacket;
90 long mFramesPerPacket;
91 long mChannelsPerFrame;
92 long mBitsPerChannel;
93} spCafAudioDescChunk;
94
95typedef struct _spCafAudioDataChunk {
96 struct _spCafChunk *parent;
97 struct _spCafChunk *child;
98
99 struct _spCafChunk *prev;
100 struct _spCafChunk *next;
101
102 spFileOffset offset;
103
104 spCafChunkHeader header; /* 'data' */
105
106 long mEditCount;
107 spLong64 mOffset;
108} spCafAudioDataChunk;
109
110typedef struct _spCafGeneralDataChunk {
111 struct _spCafChunk *parent;
112 struct _spCafChunk *child;
113
114 struct _spCafChunk *prev;
115 struct _spCafChunk *next;
116
117 spFileOffset offset;
118
119 spCafChunkHeader header;
120
121 spBool allocFlag;
122 char *mData;
123} spCafGeneralDataChunk;
124
125typedef struct _spCafChannelDescription {
126 unsigned long mChannelLabel;
127 unsigned long mChannelFlags;
128 float mCoordinates[3];
129} spCafChannelDescription;
130
131typedef struct _spCafChannelLayoutChunk {
132 struct _spCafChunk *parent;
133 struct _spCafChunk *child;
134
135 struct _spCafChunk *prev;
136 struct _spCafChunk *next;
137
138 spFileOffset offset;
139
140 spCafChunkHeader header; /* 'chan' */
141
142 unsigned long mChannelLayoutTag;
143 unsigned long mChannelBitmap;
144 unsigned long mNumberChannelDescriptions;
145 spCafChannelDescription *mChannelDescriptions;
146} spCafChannelLayoutChunk;
147
148typedef struct _spCafPacketTableChunk {
149 struct _spCafChunk *parent;
150 struct _spCafChunk *child;
151
152 struct _spCafChunk *prev;
153 struct _spCafChunk *next;
154
155 spFileOffset offset;
156
157 spCafChunkHeader header; /* 'pakt' */
158
159 spLong64 mNumberPackets;
160 spLong64 mNumberValidFrames;
161 long mPrimingFrames;
162 long mRemainderFrames;
163
164 spLong64 mBufferSize;
165 char *mBuffer;
166
167 spLong64 mTableSize;
168 spLong64 *mTable;
169} spCafPacketTableChunk;
170
171typedef struct _spCafInformation {
172 char *mKey;
173 char *mValue;
174} spCafInformation;
175
176typedef struct _spCafInformationChunk {
177 struct _spCafChunk *parent;
178 struct _spCafChunk *child;
179
180 struct _spCafChunk *prev;
181 struct _spCafChunk *next;
182
183 spFileOffset offset;
184
185 spCafChunkHeader header; /* 'info' */
186
187 long mAllocCount;
188 long mNumEntries;
189 spCafInformation *mInformations;
190} spCafInformationChunk;
191
192typedef struct _spCafHeader {
193 struct _spCafChunk *parent; /* NULL */
194 struct _spCafChunk *child; /* 'desc' */
195
196 struct _spCafChunk *prev; /* NULL */
197 struct _spCafChunk *next; /* NULL */
198
199 spFileOffset offset;
200
201 spCafChunkHeader header; /* 'caff' */
202
203 unsigned short mFileVersion;
204 unsigned short mFileFlags;
205
206 struct _spCafAudioDescChunk *desc;
207 struct _spCafAudioDataChunk *data;
208
209 struct _spCafPacketTableChunk *pakt;
210 struct _spCafGeneralDataChunk *kuki;
211} spCafHeader;
212
213typedef spChunkSize (*spCafChunkUpdateFunc)(spCafChunk *chunk, void *data);
214
215extern spBool spEqCafChunkType(spCafChunk *chunk, const char *type);
216
217extern const char *spGetCafInformationValue(spCafInformationChunk *info, const char *key, long *index);
218extern long spGetCafInformationValueInLocaleCode(spCafInformationChunk *info, const char *key, unsigned char *str_in_locale, long size);
219
220extern spChunkSize spGetCafChunkContentMarginSize(spCafChunk *chunk);
221extern spBool spSetCafChunkContentSize(spCafChunk *chunk, spChunkSize size);
222extern spChunkSize spGetCafChunkSize(spCafChunk *chunk, char *string/* = char string[5] or NULL */);
223extern spChunkSize spGetCafChunkContentSize(spCafChunk *chunk, char *string/* = char string[5] or NULL */);
224
225extern spChunkSize spReadCafHeader(spCafHeader *header, FILE *fp);
226extern spBool spFreeCafHeader(spCafHeader *header);
227
228extern spChunkSize spWriteCafHeader(spCafHeader *header, FILE *fp);
229extern spChunkSize spRewriteCafHeader(spCafHeader *header, long editCount, spLong64 dataSize, FILE *fp);
230
231extern spChunkSize spCopyCafHeader(spCafHeader *dest_header, spCafHeader *src_header);
232
233extern spBool spInitCafHeaderWithCB(spCafHeader *header, unsigned short fileVersion, unsigned short fileFlags,
234 spCafChunkUpdateFunc update_func, void *data);
235extern spBool spInitCafHeader(spCafHeader *header, unsigned short fileVersion, unsigned short fileFlags);
236extern spBool spUpdateCafAudioDescChunk(spCafHeader *header, double sampleRate, const char *formatID,
237 long formatFlags, long bytesPerPacket, long framesPerPacket,
238 long channelsPerFrame, long bitsPerChannel); /* bitsPerChannel: of input data */
239extern spBool spUpdateCafGeneralDataChunk(spCafHeader *header, const char *type, char *data, spLong64 size, spBool copy_flag);
240extern spBool spUpdateCafPacketTableChunkForFixedFrame(spCafHeader *header, long packetMarginSize, spLong64 totalFrames, long *maxPacketSize);
241extern spBool spUpdateCafPacketTableChunkNumberPackets(spCafHeader *header, spLong64 numberPackets, spLong64 totalFrames, spBool *insufficientBuffer);
242
243extern spBool spUpdateCafAudioDataChunk(spCafHeader *header, long editCount, spLong64 dataSize);
244
245extern spCafInformationChunk *spCreateCafInformationChunk(spCafHeader *header, spLong64 sizeWithFree);
246extern spBool spUpdateCafInformationChunk(spCafInformationChunk *info, const char *key, const char *value);
247extern spBool spUpdateCafInformationChunkFromLocaleCode(spCafInformationChunk *info, const char *key, const unsigned char *str_in_locale);
248
249extern spBool spAppendCafInformationChunk(spCafHeader *header, const char *key, const char *value);
250extern spBool spAppendCafInformationChunkFromLocaleCode(spCafHeader *header, const char *key, const unsigned char *str_in_locale);
251
252extern spBool spParseCafSongInfo(spCafHeader *header, spSongInfoV2 *song_info);
253extern spBool spAppendCafSongInfo(spCafHeader *header, spSongInfoV2 *song_info);
254
255extern spCafChunk *spFindCafChunkFromHeader(spCafHeader *header, const char *type);
256
257extern spFileOffset spConvertCafTimeToFileOffset(spCafHeader *header, spLong64 t,
258 long *packet, long *remainder, long *packet_frames);
259extern spLong64 spGetCafTotalDuration(spCafHeader *header);
260extern spLong64 spGetCafPacketSize(spCafHeader *header, long packet);
261extern spBool spSetCafPacketSize(spCafHeader *header, long packet, spLong64 size);
262extern spBool spSetCafFrameLength(spCafHeader *header, long packet, spLong64 length);
263
264#endif
265
266#ifdef __cplusplus
267} /* Close scope of 'extern "C"' declaration */
268#endif
269
270#endif /* __SPWAVE_CAF_H */
int spBool
Definition spWave.h:138