[Scummvm-cvs-logs] CVS: residual/imuse imuse_mcmp_mgr.cpp,NONE,1.1 imuse_mcmp_mgr.h,NONE,1.1 imuse.cpp,1.3,1.4 imuse_sndmgr.cpp,1.1,1.2 imuse_sndmgr.h,1.1,1.2 imuse_track.cpp,1.1,1.2
Pawel Kolodziejski
aquadran at users.sourceforge.net
Tue Dec 28 00:06:01 CET 2004
- Previous message: [Scummvm-cvs-logs] CVS: residual/dists/msvc8 residual.vcproj,1.3,1.4
- Next message: [Scummvm-cvs-logs] CVS: residual Makefile.common,1.8,1.9 actor.cpp,1.31,1.32 actor.h,1.15,1.16 costume.cpp,1.18,1.19 lua.cpp,1.81,1.82 main.cpp,1.36,1.37 resource.cpp,1.15,1.16 resource.h,1.10,1.11 smush.cpp,1.46,1.47 sound.cpp,1.14,NONE sound.h,1.10,NONE
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/scummvm/residual/imuse
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19363/imuse
Modified Files:
imuse.cpp imuse_sndmgr.cpp imuse_sndmgr.h imuse_track.cpp
Added Files:
imuse_mcmp_mgr.cpp imuse_mcmp_mgr.h
Log Message:
- removed/disabled current sound code, will be replaced with imuse
- updated more temporary imuse code
--- NEW FILE: imuse_mcmp_mgr.cpp ---
// Residual - Virtual machine to run LucasArts' 3D adventure games
// Copyright (C) 2003-2004 The ScummVM-Residual Team (www.scummvm.org)
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "../stdafx.h"
#include "../bits.h"
#include "../debug.h"
#include "../timer.h"
#include "../resource.h"
#include "../mixer/mixer.h"
#include "../mixer/audiostream.h"
#include "imuse_mcmp_mgr.h"
#include "imuse_sndmgr.h"
uint16 imuseDestTable[5786];
McmpMgr::McmpMgr() {
_compTable = NULL;
_numCompItems = 0;
_curSample = -1;
_compInput = NULL;
}
McmpMgr::~McmpMgr() {
_numCompItems = 0;
_compTableLoaded = false;
_lastBlock = -1;
_outputSize = 0;
_curSample = -1;
free(_compTable);
_compTable = NULL;
free(_compInput);
_compInput = NULL;
}
bool McmpMgr::openSound(const char *filename, byte *ptr) {
_file = ResourceLoader::instance()->openNewStream(filename);
if (!_file) {
warning("McmpMgr::openFile() Can't open mcmp file: %s", filename);
return false;
}
_outputSize = 0;
_lastBlock = -1;
loadCompTable(ptr);
}
void McmpMgr::loadCompTable(byte *ptr) {
uint32 tag;
int i;
fread(&tag, 1, 4, _file);
tag = MKID_BE32(tag);
if (tag != MKID_BE('MCMP')) {
error("McmpMgr::loadCompTable() Compressed sound %d invalid (%s)", index, tag2str(tag));
}
fread(&_numCompItems, 1, 2, _file);
_numCompItems = MKID_BE16(_numCompItems);
assert(_numCompItems > 0);
int offset = ftell(_file) + (_numCompItems * 9) + 8;
_numCompItems--;
_compTable = (CompTable *)malloc(sizeof(CompTable) * _numCompItems);
int32 header_size;
fseek(_file, 5, SEEK_CUR);
fread(_compTable[i].decompSize, 1, 4, _file);
int32 maxSize = 0;
for (i = 0; i < _numCompItems; i++) {
fread(_compTable[i].codec, 1, 1, _file);
fread(_compTable[i].decompSize, 1, 4, _file);
_compTable[i].decompSize = MKID_BE32(_compTable[i].decompSize);
fread(_compTable[i].compSize, 1, 4, _file);
_compTable[i].compSize = MKID_BE32(_compTable[i].compSize);
_compTable[i].offset = offset;
offset += _compTable[i].compSize;
if (_compTable[i].size > maxSize)
maxSize = _compTable[i].compSize;
}
int16 sizeCodecs;
fread(&sizeCodecs, 1, 2, _file);
sizeCodecs = MKID_BE16(sizeCodecs);
for (i = 0; i < _numCompItems; i++) {
_compTable[i].offset += sizeCodecs;
}
fseek(_file, sizeCodecs, SEEK_CUR);
_compInput = (byte *)malloc(maxSize);
fread(_compInput, 1, _compTable[0].decompSize);
*ptr = _compInput;
}
int32 McmpMgr::decompressSample(int32 offset, int32 size, byte **comp_final) {
int32 i, final_size, output_size;
int skip, first_block, last_block;
if (!_file) {
warning("McmpMgr::decompressSampleByName() File is not open!");
return 0;
}
if (!_compTableLoaded) {
return 0;
}
first_block = offset / 0x2000;
last_block = (offset + size - 1) / 0x2000;
// Clip last_block by the total number of blocks (= "comp items")
if ((last_block >= _numCompItems) && (_numCompItems > 0))
last_block = _numCompItems - 1;
int32 blocks_final_size = 0x2000 * (1 + last_block - first_block);
*comp_final = (byte *)malloc(blocks_final_size);
final_size = 0;
skip = (offset + header_size) % 0x2000;
for (i = first_block; i <= last_block; i++) {
if (_lastBlock != i) {
_file.seek(_compTable[i].offset, SEEK_SET);
_file.read(_compInput, _compTable[i].compSize);
decompressVima(_compInput, (int16 *)_compOutput, _compTable[i].decompSize, imuseDestTable);
_outputSize = _compTable[i].decompSize;
if (_outputSize > 0x2000) {
error("_outputSize: %d", _outputSize);
}
_lastBlock = i;
}
output_size = _outputSize - skip;
if ((output_size + skip) > 0x2000) // workaround
output_size -= (output_size + skip) - 0x2000;
if (output_size > size)
output_size = size;
assert(final_size + output_size <= blocks_final_size);
memcpy(*comp_final + final_size, _compOutput + skip, output_size);
final_size += output_size;
size -= output_size;
assert(size >= 0);
if (size == 0)
break;
skip = 0;
}
return final_size;
}
--- NEW FILE: imuse_mcmp_mgr.h ---
// Residual - Virtual machine to run LucasArts' 3D adventure games
// Copyright (C) 2003-2004 The ScummVM-Residual Team (www.scummvm.org)
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#ifndef MCMP_MGR_H
#define MCMP_MGR_H
#include "../stdafx.h"
#include "../bits.h"
#include "../debug.h"
#include "../timer.h"
#include "../mixer/mixer.h"
#include "../mixer/audiostream.h"
#include "imuse_sndmgr.h"
class McmpMgr {
private:
struct CompTable {
byte codec;
int32 decompSize;
int32 compSize;
int32 offset;
};
CompTable *_compTable;
int16 _numCompItems;
int _curSample;
FILE *_file;
bool _compTableLoaded;
byte _compOutput[0x2000];
byte *_compInput;
int _outputSize;
int _lastBlock;
bool loadCompTable(int32 index);
public:
McmpMgr();
~McmpMgr();
bool openFile(const char *filename);
int32 decompressSampleByName(const char *name, int32 offset, int32 size, byte **comp_final);
int32 decompressSampleByIndex(int32 index, int32 offset, int32 size, byte **comp_final, int header_size);
int32 decompressSampleByCurIndex(int32 offset, int32 size, byte **comp_final, int header_size);
};
#endif
Index: imuse.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/imuse/imuse.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- imuse.cpp 26 Dec 2004 13:43:43 -0000 1.3
+++ imuse.cpp 28 Dec 2004 08:05:18 -0000 1.4
@@ -34,6 +34,9 @@
imuse->callback();
}
+extern void vimaInit(uint16 *destTable);
+extern uint16 imuseDestTable[5786];
+
Imuse::Imuse(int fps) {
_mutex = createMutex();
_pause = false;
@@ -48,6 +51,7 @@
_track[l]->trackId = l;
_track[l]->used = false;
}
+ vimaInit(imuseDestTable);
g_timer->installTimerProc(timerHandler, 1000000 / _callbackFps, this);
}
Index: imuse_sndmgr.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/imuse/imuse_sndmgr.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- imuse_sndmgr.cpp 26 Dec 2004 13:43:43 -0000 1.1
+++ imuse_sndmgr.cpp 28 Dec 2004 08:05:18 -0000 1.2
@@ -19,6 +19,7 @@
#include "../bits.h"
#include "../debug.h"
#include "../timer.h"
+#include "../resource.h"
#include "../mixer/mixer.h"
#include "../mixer/audiostream.h"
@@ -31,8 +32,6 @@
}
_vm = scumm;
_disk = 0;
-// _cacheBundleDir = new BundleDirCache();
-// BundleCodecs::initializeImcTables();
}
ImuseSndMgr::~ImuseSndMgr() {
@@ -69,6 +68,13 @@
}
void ImuseSndMgr::prepareSound(byte *ptr, soundStruct *sound) {
+// numBlocks = READ_BE_UINT16(data + 4);
+// codecsStart = data + 8 + numBlocks * 9;
+// codecsLen = READ_BE_UINT16(codecsStart - 2);
+// headerPos = codecsStart + codecsLen;
+// _numChannels = READ_LE_UINT16(headerPos + 22);
+// dataStart = headerPos + 28 + READ_LE_UINT32(headerPos + 16);
+// dataSize = READ_LE_UINT32(dataStart - 4);
if (READ_UINT32(ptr) == MKID('iMUS')) {
uint32 tag;
int32 size = 0;
@@ -118,7 +124,7 @@
error("ImuseSndMgr::prepareSound(%d/%s) Unknown sfx header '%s'", sound->soundId, sound->name, tag2str(tag));
}
} while (tag != MKID_BE('DATA'));
- sound->offsetData = ptr - s_ptr;
+ sound->ptr = ptr;
} else {
error("ImuseSndMgr::prepareSound(): Unknown sound format");
}
@@ -135,40 +141,40 @@
return NULL;
}
-ImuseSndMgr::soundStruct *ImuseSndMgr::openSound(int32 soundId, const char *soundName, int soundType, int volGroupId, int disk) {
+ImuseSndMgr::soundStruct *ImuseSndMgr::openSound(const char *soundName, int32 soundId, int volGroupId) {
assert(soundId >= 0);
assert(soundType);
+ const char *extension = soundName + std::strlen(soundName) - 3;
+ byte *ptr = NULL;
soundStruct *sound = allocSlot();
if (!sound) {
error("ImuseSndMgr::openSound() can't alloc free sound slot");
}
- const bool header_outside = true;
- bool result = false;
- byte *ptr = NULL;
-
- if (!result) {
- closeSound(sound);
- return NULL;
- }
- if (soundName[0] == 0) {
-// if (sound->bundle->decompressSampleByIndex(soundId, 0, 0x2000, &ptr, 0, header_outside) == 0 || ptr == NULL) {
-// closeSound(sound);
-// return NULL;
-// }
+ if (strcasecmp(extension, "imu") == 0) {
+ Block *b = getFileBlock(soundName);
+ if (b != NULL) {
+ ptr = b->data();
+ delete b;
+ sound->mcmpData = false;
+ } else {
+ closeSound(sound);
+ return NULL;
+ }
+ } else if (strcasecmp(extension, "wav") == 0 || strcasecmp(extension, "imc") == 0) {
+ if (!sound->mcmpMgr->openSound(soundName, &ptr)) {
+ closeSound(sound);
+ return NULL;
+ }
+ sound->mcmpData = true;
} else {
-// if (sound->bundle->decompressSampleByName(soundName, 0, 0x2000, &ptr, header_outside) == 0 || ptr == NULL) {
-// closeSound(sound);
-// return NULL;
-// }
+ error("ImuseSndMgr::openSound() Unrecognized extension for sound file %s\n", soundName);
}
strcpy(sound->name, soundName);
- sound->soundId = soundId;
- sound->type = soundType;
sound->volGroupId = volGroupId;
- sound->disk = _disk;
+ sound->soundId = soundId;
prepareSound(ptr, sound);
return sound;
}
@@ -300,19 +306,20 @@
int32 region_offset = soundHandle->region[region].offset;
int32 region_length = soundHandle->region[region].length;
- int32 offset_data = soundHandle->offsetData;
- int32 start = region_offset - offset_data;
- if (offset + size + offset_data > region_length) {
+ if (offset + size > region_length) {
size = region_length - offset;
soundHandle->endFlag = true;
} else {
soundHandle->endFlag = false;
}
- int header_size = soundHandle->offsetData;
- bool header_outside = true;
-// size = soundHandle->bundle->decompressSampleByCurIndex(start + offset, size, buf, header_size, header_outside);
+ if (sound->mcmpData) {
+ size = soundHandle->mcmpMgr->decompressSample(region_offset + offset, size, buf);
+ } else {
+ *buf = (byte *)malloc(size);
+ memcpy(*buf, soundHandle->resPtr + start + offset, size);
+ }
return size;
}
Index: imuse_sndmgr.h
===================================================================
RCS file: /cvsroot/scummvm/residual/imuse/imuse_sndmgr.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- imuse_sndmgr.h 26 Dec 2004 13:43:43 -0000 1.1
+++ imuse_sndmgr.h 28 Dec 2004 08:05:18 -0000 1.2
@@ -61,12 +61,12 @@
bool endFlag;
bool inUse;
int32 offsetData;
- char name[15];
+ char name[32];
int16 soundId;
- BundleMgr *bundle;
+ McmpMgr *_mcmpMgr;
int type;
int volGroupId;
- int disk;
+ byte *ptr;
};
private:
@@ -76,9 +76,6 @@
bool checkForProperHandle(soundStruct *soundHandle);
soundStruct *allocSlot();
void prepareSound(byte *ptr, soundStruct *sound);
-
- byte _disk;
-
void countElements(byte *ptr, int &numRegions, int &numJumps);
public:
Index: imuse_track.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/imuse/imuse_track.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- imuse_track.cpp 26 Dec 2004 13:43:43 -0000 1.1
+++ imuse_track.cpp 28 Dec 2004 08:05:18 -0000 1.2
@@ -40,7 +40,7 @@
debug(5, "Imuse::startSound(): All slots are full");
for (l = 0; l < MAX_DIGITAL_TRACKS; l++) {
Track *track = _track[l];
- if (track->used && !track->toBeRemoved && (lowest_priority > track->priority) && !track->stream2) {
+ if (track->used && !track->toBeRemoved && lowest_priority > track->priority) {
lowest_priority = track->priority;
trackId = l;
}
- Previous message: [Scummvm-cvs-logs] CVS: residual/dists/msvc8 residual.vcproj,1.3,1.4
- Next message: [Scummvm-cvs-logs] CVS: residual Makefile.common,1.8,1.9 actor.cpp,1.31,1.32 actor.h,1.15,1.16 costume.cpp,1.18,1.19 lua.cpp,1.81,1.82 main.cpp,1.36,1.37 resource.cpp,1.15,1.16 resource.h,1.10,1.11 smush.cpp,1.46,1.47 sound.cpp,1.14,NONE sound.h,1.10,NONE
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Scummvm-git-logs
mailing list