mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-14 05:38:56 +00:00
Improved handling of sound resources
svn-id: r35724
This commit is contained in:
parent
f2b495ba2d
commit
203358bcb7
@ -84,9 +84,6 @@ uint32 SagaEngine::getFeatures() const {
|
||||
if (_gf_wyrmkeep)
|
||||
result |= GF_WYRMKEEP;
|
||||
|
||||
if (_gf_compressed_sounds)
|
||||
result |= GF_COMPRESSED_SOUNDS;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -229,7 +229,7 @@ static const SAGAGameDescription gameDescriptions[] = {
|
||||
Common::ADGF_DEMO
|
||||
},
|
||||
GID_ITE,
|
||||
GF_WYRMKEEP | GF_SCENE_SUBSTITUTES | GF_MONO_MUSIC,
|
||||
GF_WYRMKEEP | GF_SCENE_SUBSTITUTES | GF_MONO_MUSIC | GF_LE_VOICES,
|
||||
ITE_DEFAULT_SCENE,
|
||||
&ITE_Resources,
|
||||
ARRAYSIZE(ITEWINDEMO_GameFonts),
|
||||
@ -256,7 +256,7 @@ static const SAGAGameDescription gameDescriptions[] = {
|
||||
Common::ADGF_DEMO
|
||||
},
|
||||
GID_ITE,
|
||||
GF_WYRMKEEP | GF_NON_INTERACTIVE,
|
||||
GF_WYRMKEEP | GF_NON_INTERACTIVE | GF_LE_VOICES,
|
||||
ITE_DEFAULT_SCENE,
|
||||
&ITE_Resources,
|
||||
ARRAYSIZE(ITEWINDEMO_GameFonts),
|
||||
|
@ -96,12 +96,7 @@ DigitalMusicInputStream::DigitalMusicInputStream(SagaEngine *vm, ResourceContext
|
||||
|
||||
_compressedStream = NULL;
|
||||
|
||||
// FIXME: It is a bad idea to use the File::getName() method to distinguish
|
||||
// files here (note that it is for debugging purposes only, though that was
|
||||
// not correctly documented in the past).
|
||||
// A better way is to keep track of this via some flag, which indicates
|
||||
// whether the music file contains compressed data.
|
||||
if (scumm_stricmp(_file->getName(), "music.cmp") == 0 || scumm_stricmp(_file->getName(), "musicd.cmp") == 0) {
|
||||
if (context->isCompressed) {
|
||||
// Read compressed header to determine compression type
|
||||
_file->seek((long)resourceData->offset, SEEK_SET);
|
||||
_file->read(compressedHeader, 9);
|
||||
|
@ -205,6 +205,8 @@ bool Resource::createContexts() {
|
||||
bool soundFileInArray = false;
|
||||
bool multipleVoices = false;
|
||||
bool censoredVersion = false;
|
||||
bool compressedSounds = false;
|
||||
bool compressedMusic = false;
|
||||
uint16 voiceFileType = GAME_VOICEFILE;
|
||||
bool fileFound = false;
|
||||
int maxFile = 0;
|
||||
@ -284,7 +286,7 @@ bool Resource::createContexts() {
|
||||
_contextsCount++;
|
||||
soundFileIndex = _contextsCount - 1;
|
||||
strcpy(soundFileName, curSoundfiles[i].fileName);
|
||||
_vm->_gf_compressed_sounds = curSoundfiles[i].isCompressed;
|
||||
compressedSounds = curSoundfiles[i].isCompressed;
|
||||
fileFound = true;
|
||||
break;
|
||||
}
|
||||
@ -358,7 +360,7 @@ bool Resource::createContexts() {
|
||||
_contextsCount++;
|
||||
voicesFileIndex = _contextsCount - 1;
|
||||
strcpy(_voicesFileName[0], curSoundfiles[i].fileName);
|
||||
_vm->_gf_compressed_sounds = curSoundfiles[i].isCompressed;
|
||||
compressedSounds = curSoundfiles[i].isCompressed;
|
||||
fileFound = true;
|
||||
|
||||
// Special cases
|
||||
@ -406,11 +408,10 @@ bool Resource::createContexts() {
|
||||
}
|
||||
|
||||
//// Detect and add ITE music files /////////////////////////////////////////
|
||||
// We don't set the compressed flag here
|
||||
SoundFileInfo musicFilesITE[] = {
|
||||
{ "music.rsc", true },
|
||||
{ "music.rsc", false },
|
||||
{ "music.cmp", true },
|
||||
{ "musicd.rsc", true },
|
||||
{ "musicd.rsc", false },
|
||||
{ "musicd.cmp", true },
|
||||
};
|
||||
|
||||
@ -422,6 +423,7 @@ bool Resource::createContexts() {
|
||||
if (Common::File::exists(musicFilesITE[i].fileName)) {
|
||||
_contextsCount++;
|
||||
digitalMusic = true;
|
||||
compressedMusic = musicFilesITE[i].isCompressed;
|
||||
fileFound = true;
|
||||
strcpy(musicFileName, musicFilesITE[i].fileName);
|
||||
break;
|
||||
@ -445,27 +447,32 @@ bool Resource::createContexts() {
|
||||
if (_vm->getGameId() == GID_ITE && digitalMusic && i == _contextsCount - 1) {
|
||||
context->fileName = musicFileName;
|
||||
context->fileType = GAME_MUSICFILE;
|
||||
context->isCompressed = compressedMusic;
|
||||
} else if (!soundFileInArray && i == soundFileIndex) {
|
||||
context->fileName = soundFileName;
|
||||
context->fileType = GAME_SOUNDFILE;
|
||||
context->isCompressed = compressedSounds;
|
||||
} else if (_vm->_voiceFilesExist && i == voicesFileIndex && !(_vm->getGameId() == GID_IHNM && _vm->isMacResources())) {
|
||||
context->fileName = _voicesFileName[0];
|
||||
// can be GAME_VOICEFILE or GAME_SOUNDFILE | GAME_VOICEFILE or GAME_VOICEFILE | GAME_SWAPENDIAN
|
||||
context->fileType = voiceFileType;
|
||||
context->isCompressed = compressedSounds;
|
||||
} else {
|
||||
if (!(_vm->_voiceFilesExist && multipleVoices && (i > voicesFileIndex))) {
|
||||
context->fileName = _vm->getFilesDescriptions()[i].fileName;
|
||||
context->fileType = _vm->getFilesDescriptions()[i].fileType;
|
||||
context->isCompressed = compressedSounds;
|
||||
} else {
|
||||
int token = (censoredVersion && (i - voicesFileIndex >= 4)) ? 1 : 0; // censored versions don't have voice4
|
||||
|
||||
if (_vm->getFeatures() & GF_COMPRESSED_SOUNDS)
|
||||
if (compressedSounds)
|
||||
sprintf(_voicesFileName[i - voicesFileIndex + token], "voices%i.cmp", i - voicesFileIndex + token);
|
||||
else
|
||||
sprintf(_voicesFileName[i - voicesFileIndex + token], "voices%i.res", i - voicesFileIndex + token);
|
||||
|
||||
context->fileName = _voicesFileName[i - voicesFileIndex + token];
|
||||
context->fileType = GAME_VOICEFILE;
|
||||
context->isCompressed = compressedSounds;
|
||||
|
||||
// IHNM has several different voice files, so we need to allow
|
||||
// multiple resource contexts of the same type. We tell them
|
||||
|
@ -71,6 +71,7 @@ struct ResourceContext {
|
||||
Common::File *file;
|
||||
int serial; // IHNM speech files
|
||||
|
||||
bool isCompressed;
|
||||
bool isBigEndian;
|
||||
ResourceData *table;
|
||||
size_t count;
|
||||
|
@ -157,7 +157,6 @@ Common::Error SagaEngine::init() {
|
||||
_readingSpeed = getTalkspeed();
|
||||
_copyProtection = ConfMan.getBool("copy_protection");
|
||||
_gf_wyrmkeep = false;
|
||||
_gf_compressed_sounds = false;
|
||||
_musicWasPlaying = false;
|
||||
|
||||
if (_readingSpeed > 3)
|
||||
|
@ -118,12 +118,12 @@ enum GameFeatures {
|
||||
GF_WYRMKEEP = 1 << 0,
|
||||
GF_ITE_FLOPPY = 1 << 1,
|
||||
GF_SCENE_SUBSTITUTES = 1 << 2,
|
||||
GF_COMPRESSED_SOUNDS = 1 << 3,
|
||||
GF_NON_INTERACTIVE = 1 << 4,
|
||||
GF_OLD_ITE_DOS = 1 << 5,
|
||||
GF_MONO_MUSIC = 1 << 6,
|
||||
GF_EXTRA_ITE_CREDITS = 1 << 7,
|
||||
GF_IHNM_DEMO = 1 << 8
|
||||
GF_NON_INTERACTIVE = 1 << 3,
|
||||
GF_OLD_ITE_DOS = 1 << 4,
|
||||
GF_MONO_MUSIC = 1 << 5,
|
||||
GF_EXTRA_ITE_CREDITS = 1 << 6,
|
||||
GF_IHNM_DEMO = 1 << 7,
|
||||
GF_LE_VOICES = 1 << 8
|
||||
};
|
||||
|
||||
enum VerbTypeIds {
|
||||
@ -495,7 +495,6 @@ public:
|
||||
|
||||
bool _copyProtection;
|
||||
bool _gf_wyrmkeep;
|
||||
bool _gf_compressed_sounds;
|
||||
bool _musicWasPlaying;
|
||||
|
||||
SndRes *_sndRes;
|
||||
|
@ -130,6 +130,8 @@ void SndRes::setVoiceBank(int serial) {
|
||||
_voiceContext->fileType = GAME_VOICEFILE;
|
||||
_voiceContext->count = 0;
|
||||
_voiceContext->serial = 0;
|
||||
_voiceContext->isBigEndian = true;
|
||||
_voiceContext->isCompressed = false;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@ -219,6 +221,7 @@ bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buff
|
||||
|
||||
file->open(soundFileName);
|
||||
soundResourceLength = file->size();
|
||||
context->isBigEndian = true;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
@ -231,7 +234,7 @@ bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buff
|
||||
|
||||
Common::SeekableReadStream& readS = *file;
|
||||
|
||||
if ((context->fileType & GAME_VOICEFILE) != 0) {
|
||||
if (context->fileType & GAME_VOICEFILE) {
|
||||
soundInfo = _vm->getVoiceInfo();
|
||||
} else {
|
||||
soundInfo = _vm->getSfxInfo();
|
||||
@ -265,7 +268,7 @@ bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buff
|
||||
if (_vm->getGameId() == GID_IHNM && (context->fileType & GAME_SOUNDFILE))
|
||||
uncompressedSound = true;
|
||||
|
||||
if ((_vm->getFeatures() & GF_COMPRESSED_SOUNDS) && !uncompressedSound) {
|
||||
if (context->isCompressed && !uncompressedSound) {
|
||||
if (header[0] == char(0)) {
|
||||
resourceType = kSoundMP3;
|
||||
} else if (header[0] == char(1)) {
|
||||
@ -277,7 +280,10 @@ bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buff
|
||||
|
||||
}
|
||||
|
||||
buffer.isBigEndian = _vm->isMacResources();
|
||||
buffer.isBigEndian = context->isBigEndian;
|
||||
if ((context->fileType & GAME_VOICEFILE) && (_vm->getFeatures() & GF_LE_VOICES))
|
||||
buffer.isBigEndian = false;
|
||||
buffer.isCompressed = context->isCompressed;
|
||||
buffer.soundType = resourceType;
|
||||
buffer.originalSize = 0;
|
||||
buffer.stereo = false;
|
||||
@ -398,7 +404,7 @@ int SndRes::getVoiceLength(uint32 resourceId) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(_vm->getFeatures() & GF_COMPRESSED_SOUNDS) || buffer.originalSize == 0)
|
||||
if (!_voiceContext->isCompressed || buffer.originalSize == 0)
|
||||
msDouble = (double)buffer.size;
|
||||
else
|
||||
msDouble = (double)buffer.originalSize;
|
||||
|
@ -83,7 +83,7 @@ void Sound::playSoundBuffer(Audio::SoundHandle *handle, SoundBuffer &buffer, int
|
||||
if (!buffer.isSigned)
|
||||
flags |= Audio::Mixer::FLAG_UNSIGNED;
|
||||
|
||||
if (!(_vm->getFeatures() & GF_COMPRESSED_SOUNDS)) {
|
||||
if (!buffer.isCompressed) {
|
||||
if (handleType == kVoiceHandle)
|
||||
_mixer->playRaw(Audio::Mixer::kSpeechSoundType, handle, buffer.buffer,
|
||||
buffer.size, buffer.frequency, flags, -1, volume);
|
||||
|
@ -47,6 +47,7 @@ struct SoundBuffer {
|
||||
int sampleBits;
|
||||
bool stereo;
|
||||
bool isSigned;
|
||||
bool isCompressed;
|
||||
|
||||
byte *buffer;
|
||||
size_t size;
|
||||
|
Loading…
Reference in New Issue
Block a user