[Scummvm-cvs-logs] CVS: scummvm/scumm/imuse_digi dimuse_bndmgr.cpp,1.23,1.24 dimuse_bndmgr.h,1.10,1.11
Max Horn
fingolfin at users.sourceforge.net
Sat Aug 28 07:07:08 CEST 2004
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/scumm actor.cpp,1.272,1.273 intern.h,2.205,2.206 script_v6he.cpp,2.100,2.101 script_v72he.cpp,2.30,2.31 script_v7he.cpp,2.51,2.52 scumm.cpp,1.158,1.159 scumm.h,1.458,1.459
- Next message: [Scummvm-cvs-logs] CVS: scummvm/scumm/imuse_digi dimuse_sndmgr.cpp,1.51,1.52
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/scummvm/scummvm/scumm/imuse_digi
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10739
Modified Files:
dimuse_bndmgr.cpp dimuse_bndmgr.h
Log Message:
Cleaning up code a bit while trying to understand it...
Index: dimuse_bndmgr.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse_digi/dimuse_bndmgr.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- dimuse_bndmgr.cpp 16 Aug 2004 22:24:24 -0000 1.23
+++ dimuse_bndmgr.cpp 28 Aug 2004 14:06:32 -0000 1.24
@@ -159,11 +159,37 @@
_curSample = -1;
free(_compTable);
_compTable = NULL;
- if (_compInput) {
- free(_compInput);
- _compInput = NULL;
- }
+ free(_compInput);
+ _compInput = NULL;
+ }
+}
+
+bool BundleMgr::loadCompTable(int32 index) {
+ _file.seek(_bundleTable[index].offset, SEEK_SET);
+ uint32 tag = _file.readUint32BE();
+ _numCompItems = _file.readUint32BE();
+ assert(_numCompItems > 0);
+ _file.seek(8, SEEK_CUR);
+
+ if (tag != MKID_BE('COMP')) {
+ warning("BundleMgr::decompressSampleByIndex() Compressed sound %d invalid (%s)", index, tag2str(tag));
+ return false;
}
+
+ _compTable = (CompTable *)malloc(sizeof(CompTable) * _numCompItems);
+ int32 maxSize = 0;
+ for (int i = 0; i < _numCompItems; i++) {
+ _compTable[i].offset = _file.readUint32BE();
+ _compTable[i].size = _file.readUint32BE();
+ _compTable[i].codec = _file.readUint32BE();
+ _file.seek(4, SEEK_CUR);
+ if (_compTable[i].size > maxSize)
+ maxSize = _compTable[i].size;
+ }
+ // CMI hack: one more byte at the end of input buffer
+ _compInput = (byte *)malloc(maxSize + 1);
+
+ return true;
}
int32 BundleMgr::decompressSampleByCurIndex(int32 offset, int32 size, byte **comp_final, int header_size, bool header_outside) {
@@ -171,47 +197,31 @@
}
int32 BundleMgr::decompressSampleByIndex(int32 index, int32 offset, int32 size, byte **comp_final, int header_size, bool header_outside) {
- int32 i, tag, num, final_size, output_size;
+ int32 i, final_size, output_size;
int skip, first_block, last_block;
- if (index != -1)
- _curSample = index;
+ assert(0 <= index && index < _numFiles);
if (_file.isOpen() == false) {
warning("BundleMgr::decompressSampleByIndex() File is not open!");
return 0;
}
- if (!_compTableLoaded) {
- _file.seek(_bundleTable[index].offset, SEEK_SET);
- tag = _file.readUint32BE();
- _numCompItems = num = _file.readUint32BE();
- _file.seek(8, SEEK_CUR);
+ if (_curSample == -1)
+ _curSample = index;
- if (tag != MKID_BE('COMP')) {
- warning("BundleMgr::decompressSampleByIndex() Compressed sound %d invalid (%s)", index, tag2str(tag));
- return 0;
- }
+ assert(_curSample == index);
- _compTable = (CompTable *)malloc(sizeof(CompTable) * num);
- int32 maxSize = 0;
- for (i = 0; i < num; i++) {
- _compTable[i].offset = _file.readUint32BE();
- _compTable[i].size = _file.readUint32BE();
- _compTable[i].codec = _file.readUint32BE();
- _file.seek(4, SEEK_CUR);
- if (_compTable[i].size > maxSize)
- maxSize = _compTable[i].size;
- }
- // CMI hack: one more byte at the end of input buffer
- _compInput = (byte *)malloc(maxSize + 1);
- _compTableLoaded = true;
+ if (!_compTableLoaded) {
+ _compTableLoaded = loadCompTable(index);
+ if (!_compTableLoaded)
+ return 0;
}
-
+
first_block = (offset + header_size) / 0x2000;
- last_block = (offset + size + header_size - 1) / 0x2000;
+ last_block = (offset + header_size + size - 1) / 0x2000;
- // case when (offset + size + header_size - 1) is more one byte after sound resource
+ // Clip last_block by the total number of blocks (= "comp items")
if ((last_block >= _numCompItems) && (_numCompItems > 0))
last_block = _numCompItems - 1;
@@ -219,7 +229,7 @@
*comp_final = (byte *)malloc(blocks_final_size);
final_size = 0;
- skip = offset - (first_block * 0x2000) + header_size;
+ skip = (offset + header_size) % 0x2000;
for (i = first_block; i <= last_block; i++) {
if (_lastBlock != i) {
Index: dimuse_bndmgr.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse_digi/dimuse_bndmgr.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- dimuse_bndmgr.h 27 Jun 2004 22:03:38 -0000 1.10
+++ dimuse_bndmgr.h 28 Aug 2004 14:06:36 -0000 1.11
@@ -72,6 +72,8 @@
byte *_compInput;
int _outputSize;
int _lastBlock;
+
+ bool loadCompTable(int32 index);
public:
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/scumm actor.cpp,1.272,1.273 intern.h,2.205,2.206 script_v6he.cpp,2.100,2.101 script_v72he.cpp,2.30,2.31 script_v7he.cpp,2.51,2.52 scumm.cpp,1.158,1.159 scumm.h,1.458,1.459
- Next message: [Scummvm-cvs-logs] CVS: scummvm/scumm/imuse_digi dimuse_sndmgr.cpp,1.51,1.52
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Scummvm-git-logs
mailing list