-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsf2filesplitter.cc
552 lines (515 loc) · 18.8 KB
/
sf2filesplitter.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
#include "iffdigest.h"
#include "sf2.h"
#include <iostream>
#include <string.h>
////////////////////////////////////////////////////////////////////////////////
// SF2FileSplitter members
void SF2FileSplitter::clearPresets()
{
presetList.clear();
}
void SF2FileSplitter::addPreset(presetMapIter_t preset)
{
presetList.push_back(preset);
}
char *SF2FileSplitter::createSplit(std::size_t &len)
{
// Clear working variables
pbagIdxForPHDRList.clear();
pbagList.clear();
pmodIdxList.clear();
pgenIdxList.clear();
instIdxList.clear();
instIdxMapper.clear();
ibagIdxForINSTList.clear();
ibagList.clear();
imodIdxList.clear();
igenIdxList.clear();
shdrIdxList.clear();
shdrIdxMapper.clear();
sampleAreas.clear();
sampleCountTotal = 0;
SF2Hydra& hydra = SF2SourceFile->getHydra();
std::cout << "\nCreate soundfont for the following presets:\n";
for(std::list<presetMapIter_t>::iterator presetListIter=presetList.begin();
presetListIter!=presetList.end(); ++presetListIter) {
const sfPresetHeader_t& presetHeader = hydra.getPresetHeader(*presetListIter);
std::string presetName;
sf2NameToStr(presetName, presetHeader.achPresetName);
std::cout << presetName << "\n";
}
std::cout << "\n";
// 1. Collect required hydra chunks and align indexes
prepareSplit();
// 2. Dry run - just calc length / no data write
len = getLenOrWriteData(0, 0);
char *data = new char[len];
memset(data, 0, len);
// 3. Actally write data to buffer
if(!getLenOrWriteData(data, len)) {
// Something went wrong: cleanup
delete[] data;
data = 0;
}
return data;
}
void SF2FileSplitter::addSampleAreaForSHDR(uint32_t shdrIdx)
{
// Maybe this can be enhanced later to avoid redundancies e.g by handling
// overlapping sample areas. Currently a sample area is detected as already
// inserted if it has the same start/end indexes.
SF2Hydra& hydra = SF2SourceFile->getHydra();
// sample area not yet inserted?
bool bInsertNow = false;
const sfSample_t& sample = hydra.getSample(shdrIdx);
std::map<uint32_t, std::map<uint32_t, uint32_t> >::iterator startIter;
startIter = sampleAreas.find(sample.dwStart);
// start found: Check if end not yet inserted
if(startIter != sampleAreas.end()) {
std::map<uint32_t, uint32_t> &endMap = startIter->second;
if(endMap.find(sample.dwEnd) == endMap.end()) {
bInsertNow = true;
}
}
// start not found: insert
else {
bInsertNow = true;
}
if(bInsertNow) {
// keep start/end key with offset to align SHDR created later
sampleAreas[sample.dwStart][sample.dwEnd] = sample.dwStart-sampleCountTotal;
uint32_t sampleCount = sample.dwEnd - sample.dwStart;
sampleCountTotal += (sampleCount + 46);
}
}
void SF2FileSplitter::prepareSplit()
{
SF2Hydra& hydra = SF2SourceFile->getHydra();
// Iterate all presets added..
for(std::list<presetMapIter_t>::iterator presetListIter=presetList.begin();
presetListIter!=presetList.end(); ++presetListIter) {
// Keep new PBAG index for PHDR
pbagIdxForPHDRList.push_back(pbagList.size());
// Get preset info for pbags
const presInfo_t& presInfo = hydra.getPresetInfo(*presetListIter);
uint32_t pbagCount = presInfo.pbagInfoVec.size();
// Loop preset's PBAG-zone
for(uint32_t pbagIDx=0; pbagIDx<pbagCount; pbagIDx++) {
sfPresetBag_t PBAG;
// set new indexes and keep PBAG
PBAG.wModNdx = pmodIdxList.size();
PBAG.wGenNdx = pgenIdxList.size();
pbagList.push_back(PBAG);
const bagInfo_t &pbagInfo = presInfo.pbagInfoVec[pbagIDx];
// Keep PMOD-zone indexes
for(std::list<uint16_t>::const_iterator pmodIter = pbagInfo.modIdxs.begin();
pmodIter!=pbagInfo.modIdxs.end(); ++pmodIter) {
pmodIdxList.push_back(*pmodIter);
}
// Keep PGEN-zone indexes
for(std::list<uint16_t>::const_iterator pgenIter = pbagInfo.genIdxs.begin();
pgenIter!=pbagInfo.genIdxs.end(); ++pgenIter) {
pgenIdxList.push_back(*pgenIter);
}
// Instrument?
if(pbagInfo.instOrSample) {
uint16_t instIdx = pbagInfo.instOrSampleIdx;
// instrument not yet used?
if(instIdxMapper.find(instIdx) == instIdxMapper.end()) {
// Keep instrument indexes old/new
instIdxMapper[instIdx] = instIdxList.size();
instIdxList.push_back(instIdx);
// Keep new IBAG index for INST
ibagIdxForINSTList.push_back(ibagList.size());
// Get instrument info for ibags
const instInfo_t& instInfo = hydra.getInstrumentInfo(instIdx);
uint32_t ibagCount = instInfo.ibagInfoVec.size();
// Loop instruments's IBAG-zone
for(uint32_t ibagIDx=0; ibagIDx<ibagCount; ibagIDx++) {
sfInstBag_t IBAG;
// set new indexes and keep IBAG
IBAG.wInstModNdx = imodIdxList.size();
IBAG.wInstGenNdx = igenIdxList.size();
ibagList.push_back(IBAG);
const bagInfo_t &ibagInfo = instInfo.ibagInfoVec[ibagIDx];
// Keep IMOD-zone indexes
for(std::list<uint16_t>::const_iterator imodIter = ibagInfo.modIdxs.begin();
imodIter!=ibagInfo.modIdxs.end(); ++imodIter) {
imodIdxList.push_back(*imodIter);
}
// Keep IGEN-zone indexes
for(std::list<uint16_t>::const_iterator igenIter = ibagInfo.genIdxs.begin();
igenIter!=ibagInfo.genIdxs.end(); ++igenIter) {
igenIdxList.push_back(*igenIter);
}
// Sample?
if(ibagInfo.instOrSample) {
uint16_t shdrIdx = ibagInfo.instOrSampleIdx;
// sample not yet used?
if(shdrIdxMapper.find(shdrIdx) == shdrIdxMapper.end()) {
// Keep sample header index old/new
shdrIdxMapper[shdrIdx] = shdrIdxList.size();
shdrIdxList.push_back(shdrIdx);
// Keep sample area
addSampleAreaForSHDR(shdrIdx);
// Ignore wSampleLink - in fluid3gm.sf2 Sample 'P200 Piano C10(L)'
// wSampleLink = 0 which links to 'Gun'??. Have no idea what magic
// polyphone uses to display correct link...
// All samples except mono types are linked
/*if(hydra.getSample(shdrIdx).sfSampleType > 1) {
// Add linked samples too
uint16_t shdrIdxLinked = hydra.getSample(shdrIdx).wSampleLink;
if(shdrIdxMapper.find(shdrIdxLinked) == shdrIdxMapper.end()) {
// Keep sample header index old/new
shdrIdxMapper[shdrIdxLinked] = shdrIdxList.size();
shdrIdxList.push_back(shdrIdxLinked);
// Keep sample area
addSampleAreaForSHDR(shdrIdxLinked);
}
}*/
}
}
}
}
}
}
}
}
std::size_t SF2FileSplitter::getLenOrWriteData(char* data, std::size_t maxLen)
{
SF2Hydra& hydra = SF2SourceFile->getHydra();
IFFChunk *infoChunk = SF2SourceFile->getInfo();
SF2Samples &samples = SF2SourceFile->getSamples();
std::size_t len = 0;
std::size_t lenAdd;
// RIFF header
lenAdd = 4;
if(data && maxLen>=len+lenAdd) {
memcpy(data+len, "RIFF", lenAdd);
}
len += lenAdd;
// total len set below
len += lenAdd;
// sfbk id
if(data && maxLen>=len+lenAdd) {
memcpy(data+len, "sfbk", lenAdd);
}
len += lenAdd;
// INFO chunk: 1:1 copy
if(!infoChunk->writeData(len, data, IFF_FMT_RIFF, maxLen)) {
return 0;
}
// Fill sdta/SHDR data (with aligened indexes)
// Note: We deny ROM samples -> smpl is mandatory (sm24 optional)
uint32_t lenSHDR = (shdrIdxList.size()+1/*terminal*/);
sfSample_t* dataSHDR = 0;
int16_t* dataSmpl = 0;
int8_t* dataSm24 = 0;
if(data) {
dataSHDR = new sfSample_t[lenSHDR];
dataSmpl = new int16_t[sampleCountTotal];
memset(dataSmpl, 0, sampleCountTotal*sizeof(int16_t));
if(samples.sm24()) {
dataSm24 = new int8_t[sampleCountTotal];
memset(dataSm24, 0, sampleCountTotal);
}
typedef std::list<uint16_t>::iterator idx16Iterator;
// Loop all SHDRs to be exported
for(idx16Iterator shdrIter=shdrIdxList.begin();
shdrIter!=shdrIdxList.end();
shdrIter++) {
// Get copy of source SHDR
uint16_t sourceSHDRIdx = *shdrIter;
const sfSample_t &sourceSHDREntry = hydra.getSample(sourceSHDRIdx);
// Reference to destination SHDR
assert(shdrIdxMapper.find(sourceSHDRIdx) != shdrIdxMapper.end());
uint16_t destSHDRIdx = shdrIdxMapper[sourceSHDRIdx];
assert(destSHDRIdx < lenSHDR + 1 /*terminal*/);
sfSample_t &destSHDREntry = dataSHDR[destSHDRIdx];
// copy
destSHDREntry = sourceSHDREntry;
// Align sample indexes
uint32_t sampleOffset =
sampleAreas[destSHDREntry.dwStart][destSHDREntry.dwEnd]; // assertion?
destSHDREntry.dwStart -= sampleOffset;
destSHDREntry.dwEnd -= sampleOffset;
destSHDREntry.dwStartloop -= sampleOffset;
destSHDREntry.dwEndloop -= sampleOffset;
// copy samples
memcpy(dataSmpl+destSHDREntry.dwStart,
samples.smpl()->dataPtr() + sourceSHDREntry.dwStart*sizeof(int16_t),
(destSHDREntry.dwEnd - destSHDREntry.dwStart)*sizeof(int16_t));
if(samples.sm24()) {
memcpy(dataSm24+destSHDREntry.dwStart,
samples.sm24()->dataPtr() + sourceSHDREntry.dwStart,
destSHDREntry.dwEnd - destSHDREntry.dwStart);
}
}
// SHDR terminal sample
sfSample_t &destTerminalSHDREntry = dataSHDR[lenSHDR-1];
memcpy(&destTerminalSHDREntry.achSampleName, "EOS", 3);
}
// Setup sdta chunk with smpl/sm24 sub chunks
IFFChunkList sdtaSubChunks;
sdtaSubChunks.push_back(IFFChunk(iff_ckid("smpl"),
(char*)dataSmpl,
sampleCountTotal*2));
if(samples.sm24()) {
sdtaSubChunks.push_back(IFFChunk(iff_ckid("sm24"),
(char*)dataSm24,
sampleCountTotal));
}
// make sdta chunk and write data
IFFChunk sdta(iff_ckid("sdta"), sdtaSubChunks);
if(!sdta.writeData(len, data, IFF_FMT_RIFF, maxLen)) {
return 0;
}
// Create pdta (hydra) chunks
// PHDR data
sfPresetHeader_t *dataPHDR = 0;
uint32_t lenPHDR = (presetList.size()+1/*terminal*/);
if(data) {
dataPHDR = new sfPresetHeader_t[lenPHDR];
assert(presetList.size() == pbagIdxForPHDRList.size());
std::list<presetMapIter_t>::iterator presetListIter;
std::list<uint16_t>::iterator bagIdxIter;
uint16_t headerCount;
for(presetListIter=presetList.begin(), bagIdxIter=pbagIdxForPHDRList.begin(), headerCount=0;
presetListIter!=presetList.end();
presetListIter++, bagIdxIter++, headerCount++) {
const sfPresetHeader_t& presetHeader = hydra.getPresetHeader(*presetListIter);
// copy and align pbag zone pointer
dataPHDR[headerCount] = presetHeader;
dataPHDR[headerCount].wPresetBagNdx = *bagIdxIter;
}
// PHDR terminal sample
sfPresetHeader_t &destTerminalPHDREntry = dataPHDR[lenPHDR-1];
// phdr->pbag
destTerminalPHDREntry.wPresetBagNdx = pbagList.size();
memcpy(&destTerminalPHDREntry.achPresetName, "EOP", 3);
}
// PHDR chunk
IFFChunk PHDR(iff_ckid("phdr"),
(char*)dataPHDR,
lenPHDR * sizeof(sfPresetHeader_t));
// PBAG data
sfPresetBag_t *dataPBAG = 0;
uint32_t lenPBAG = (pbagList.size()+1/*terminal*/);
if(data) {
dataPBAG = new sfPresetBag_t[lenPBAG];
std::list<sfPresetBag_t>::iterator pbagIter;
uint32_t pbagCount;
for(pbagIter=pbagList.begin(), pbagCount=0;
pbagIter!=pbagList.end();
pbagIter++, pbagCount++) {
dataPBAG[pbagCount].wGenNdx = pbagIter->wGenNdx;
dataPBAG[pbagCount].wModNdx = pbagIter->wModNdx;
}
// PBAG terminal: point to terminals
dataPBAG[lenPBAG-1].wGenNdx = pgenIdxList.size();
dataPBAG[lenPBAG-1].wModNdx = pmodIdxList.size();
}
// PBAG chunk
IFFChunk PBAG(iff_ckid("pbag"),
(char*)dataPBAG,
lenPBAG * sizeof(sfPresetBag_t));
// PMOD data
sfModList_t *dataPMOD = 0;
uint32_t lenPMOD = (pmodIdxList.size()+1/*terminal*/);
if(data) {
dataPMOD = new sfModList_t[lenPMOD];
std::list<uint16_t>::iterator pmodIter;
uint32_t pmodCount;
for(pmodIter=pmodIdxList.begin(), pmodCount=0;
pmodIter!=pmodIdxList.end();
pmodIter++, pmodCount++) {
const sfModList_t& sourcePMOD = hydra.getPresetModulator(*pmodIter);
// copy
dataPMOD[pmodCount] = sourcePMOD;
}
// PMOD terminal: all fields 0 -> nothing to do
}
// PMOD chunk
IFFChunk PMOD(iff_ckid("pmod"),
(char*)dataPMOD,
lenPMOD * sizeof(sfModList_t));
// PGEN data
sfGenList_t *dataPGEN = 0;
uint32_t lenPGEN = (pgenIdxList.size()+1/*terminal*/);
if(data) {
dataPGEN = new sfGenList_t[lenPGEN];
std::list<uint16_t>::iterator pgenIter;
uint32_t pgenCount;
for(pgenIter=pgenIdxList.begin(), pgenCount=0;
pgenIter!=pgenIdxList.end();
pgenIter++, pgenCount++) {
const sfGenList_t& sourcePGEN = hydra.getPresetGenerator(*pgenIter);
// copy
dataPGEN[pgenCount] = sourcePGEN;
// instrument?
if(dataPGEN[pgenCount].sfGenOper == (SFGenerator)INSTRUMENT) {
// align instrument index
assert(instIdxMapper.find(sourcePGEN.genAmount) != instIdxMapper.end());
dataPGEN[pgenCount].genAmount = instIdxMapper[sourcePGEN.genAmount];
}
}
// PGEN terminal: all fields 0 -> nothing to do
}
// PGEN chunk
IFFChunk PGEN(iff_ckid("pgen"),
(char*)dataPGEN,
lenPGEN * sizeof(sfGenList_t));
// INST data
sfInst_t *dataINST = 0;
uint32_t lenINST = (instIdxList.size()+1/*terminal*/);
if(data) {
dataINST = new sfInst_t[lenINST];
assert(instIdxList.size() == ibagIdxForINSTList.size());
std::list<uint16_t>::iterator instIter;
std::list<uint16_t>::iterator bagIdxIter;
uint32_t instCount;
for(instIter=instIdxList.begin(), bagIdxIter=ibagIdxForINSTList.begin(), instCount=0;
instIter!=instIdxList.end();
instIter++, bagIdxIter++, instCount++) {
const sfInst_t& sourceINST = hydra.getInstrument(*instIter);
// copy and align ibag zone pointer
dataINST[instCount] = sourceINST;
dataINST[instCount].wInstBagNdx = *bagIdxIter;
}
// INST terminal sample
sfInst_t &destTerminalINSTEntry = dataINST[lenINST-1];
// inst->ibag
destTerminalINSTEntry.wInstBagNdx = ibagList.size();
memcpy(&destTerminalINSTEntry.achInstName, "EOI", 3);
}
// INST chunk
IFFChunk INST(iff_ckid("inst"),
(char*)dataINST,
lenINST * sizeof(sfInst_t));
// IBAG data
sfInstBag_t *dataIBAG = 0;
uint32_t lenIBAG = (ibagList.size()+1/*terminal*/);
if(data) {
dataIBAG = new sfInstBag_t[lenIBAG];
std::list<sfInstBag_t>::iterator ibagIter;
uint32_t ibagCount;
for(ibagIter=ibagList.begin(), ibagCount=0;
ibagIter!=ibagList.end();
ibagIter++, ibagCount++) {
dataIBAG[ibagCount].wInstGenNdx = ibagIter->wInstGenNdx;
dataIBAG[ibagCount].wInstModNdx = ibagIter->wInstModNdx;
}
// IBAG terminal: point to terminals
dataIBAG[lenIBAG-1].wInstGenNdx = igenIdxList.size();
dataIBAG[lenIBAG-1].wInstModNdx = imodIdxList.size();
}
// IBAG chunk
IFFChunk IBAG(iff_ckid("ibag"),
(char*)dataIBAG,
lenIBAG * sizeof(sfInstBag_t));
// IMOD data
sfModList_t *dataIMOD = 0;
uint32_t lenIMOD = (imodIdxList.size()+1/*terminal*/);
if(data) {
dataIMOD = new sfModList_t[lenIMOD];
std::list<uint16_t>::iterator imodIter;
uint32_t imodCount;
for(imodIter=imodIdxList.begin(), imodCount=0;
imodIter!=imodIdxList.end();
imodIter++, imodCount++) {
const sfModList_t& sourceIMOD = hydra.getInstrumentModulator(*imodIter);
// copy
dataIMOD[imodCount] = sourceIMOD;
}
// IMOD terminal: all fields 0 -> nothing to do
}
// IMOD chunk
IFFChunk IMOD(iff_ckid("imod"),
(char*)dataIMOD,
lenIMOD * sizeof(sfModList_t));
// IGEN data
sfGenList_t *dataIGEN = 0;
uint32_t lenIGEN = (igenIdxList.size()+1/*terminal*/);
if(data) {
dataIGEN = new sfGenList_t[lenIGEN];
std::list<uint16_t>::iterator igenIter;
uint32_t igenCount;
for(igenIter=igenIdxList.begin(), igenCount=0;
igenIter!=igenIdxList.end();
igenIter++, igenCount++) {
const sfGenList_t& sourceIGEN = hydra.getInstrumentGenerator(*igenIter);
// copy
dataIGEN[igenCount] = sourceIGEN;
// sample?
if(dataIGEN[igenCount].sfGenOper == (SFGenerator)SAMPLEID) {
// align sample index
assert(shdrIdxMapper.find(sourceIGEN.genAmount) != shdrIdxMapper.end());
dataIGEN[igenCount].genAmount = shdrIdxMapper[sourceIGEN.genAmount];
}
}
// IGEN terminal: all fields 0 -> nothing to do
}
// IGEN chunk
IFFChunk IGEN(iff_ckid("igen"),
(char*)dataIGEN,
lenIGEN * sizeof(sfGenList_t));
// SHDR chunk (data was created with sdta data above)
IFFChunk SHDR(iff_ckid("shdr"),
(char*)dataSHDR,
lenSHDR * sizeof(sfSample_t));
// We have our hydra complete -> create pdta chunk and write data
IFFChunkList pdtaSubChunks;
pdtaSubChunks.push_back(PHDR);
pdtaSubChunks.push_back(PBAG);
pdtaSubChunks.push_back(PMOD);
pdtaSubChunks.push_back(PGEN);
pdtaSubChunks.push_back(INST);
pdtaSubChunks.push_back(IBAG);
pdtaSubChunks.push_back(IMOD);
pdtaSubChunks.push_back(IGEN);
pdtaSubChunks.push_back(SHDR);
// make sdta chunk and write data
IFFChunk pdta(iff_ckid("pdta"), pdtaSubChunks);
if(!pdta.writeData(len, data, IFF_FMT_RIFF, maxLen)) {
return 0;
}
// output what will be written
if(data) {
std::cout << "PHDR:\n";
for(uint16_t phdrEntry = 0; phdrEntry<lenPHDR; phdrEntry++) {
std::string presetName;
sf2NameToStr(presetName, ((sfPresetHeader_t*)PHDR.dataPtr())[phdrEntry].achPresetName);
std::cout << "Preset: " << presetName << "\n";
}
std::cout << "INST:\n";
for(uint16_t instEntry = 0; instEntry<lenINST; instEntry++) {
std::string instName;
sf2NameToStr(instName, ((sfInst_t*)INST.dataPtr())[instEntry].achInstName);
std::cout << "Instrument: " << instName << "\n";
}
std::cout << "SHDR:\n";
for(uint16_t shdrEntry = 0; shdrEntry<lenSHDR; shdrEntry++) {
std::string sampleName;
sf2NameToStr(sampleName, ((sfSample_t*)SHDR.dataPtr())[shdrEntry].achSampleName);
std::cout << "Sample: " << sampleName << "\n";
}
}
// Now that we know total len - write it right after initial 'RIFF'
if(data) {
// RIFF and len itself are not within lenght -> '-8'
uint32_t currLen = u32(len-8, IFF_FMT_RIFF);
memcpy(data+4, &currLen, 4);
}
// Cleanup
for(IFFChunkIterator sdtaSubChunksIter = sdta.ck_begin();
sdtaSubChunksIter != sdta.ck_end();
sdtaSubChunksIter++) {
delete (*sdtaSubChunksIter).dataPtr();
}
for(IFFChunkIterator pdtaSubChunksIter = pdta.ck_begin();
pdtaSubChunksIter != pdta.ck_end();
pdtaSubChunksIter++) {
delete (*pdtaSubChunksIter).dataPtr();
}
return len;
}