aboutsummaryrefslogtreecommitdiff
path: root/engines/saga
diff options
context:
space:
mode:
authorTravis Howell2009-08-19 01:22:43 +0000
committerTravis Howell2009-08-19 01:22:43 +0000
commit89d7fea4e619cd44d5ce16eee1e46ad417e26c9c (patch)
treea5df60123d0d6a44d824d21e95df2ef421a4700b /engines/saga
parentdfaa5acbee5766e59b35697ea1b03122aa4ea2aa (diff)
parent2bd1f51d92492fa88ba61dc65f783fc9bbfd852c (diff)
downloadscummvm-rg350-89d7fea4e619cd44d5ce16eee1e46ad417e26c9c.tar.gz
scummvm-rg350-89d7fea4e619cd44d5ce16eee1e46ad417e26c9c.tar.bz2
scummvm-rg350-89d7fea4e619cd44d5ce16eee1e46ad417e26c9c.zip
Merged revisions 43458-43468,43470-43471,43473-43475,43477,43479-43483,43485,43497-43498,43500,43503-43504,43507,43509-43510,43512-43515,43517,43519,43521,43523 via svnmerge from
https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk ........ r43458 | thebluegr | 2009-08-17 15:55:21 +1000 (Mon, 17 Aug 2009) | 8 lines - Simplified some functions to accept only the parts of the EngineState they need as parameters, instead of the whole EngineState - Moved the class table in the Segment manager - it's the only class using it directly - Removed the sci11 flag from save games (we already know this, we don't need to store it) - Moved script_get_segment() and get_class_address() inside the segment manager class - Removed the script_locate_by_segment wrapper - Simplified script_lookup_export() a lot by removing some paranoia checks - Added some WIP code for automatically determining the game id in the fallback detector (still not working) - General cleanup ........ r43459 | lordhoto | 2009-08-17 17:36:08 +1000 (Mon, 17 Aug 2009) | 1 line Fix compilation of the SCI engine. It seems that all of the SCI header files I touched (and probably others I luckily didn't touch) seem to assume that files including them will supply needed types. That looks like a major issue in SCI. Someone with knowledge of the SCI code should look into this and cleanup the includes of *all* SCI headers. ........ r43460 | thebluegr | 2009-08-17 19:19:53 +1000 (Mon, 17 Aug 2009) | 1 line Cleanup ........ r43461 | strangerke | 2009-08-17 19:50:35 +1000 (Mon, 17 Aug 2009) | 1 line Added OPCODEDRAW 0x85, with a specific workaround for Bambou hardcoded paths in scripts ........ r43462 | strangerke | 2009-08-17 19:54:49 +1000 (Mon, 17 Aug 2009) | 1 line Suppress useless parentheses ........ r43463 | lordhoto | 2009-08-17 19:57:09 +1000 (Mon, 17 Aug 2009) | 1 line Formatting. ........ r43464 | strangerke | 2009-08-17 20:05:02 +1000 (Mon, 17 Aug 2009) | 1 line Add back parenthesis (I wasn't aware of this convention, sorry) in saveload, and mimic this code in oPlaytoons_openItk ........ r43465 | lordhoto | 2009-08-17 20:48:03 +1000 (Mon, 17 Aug 2009) | 2 lines - Add note about that modifing the parent stream will mess up SeekableSubReadStream and SeekableSubReadStreamEndian. - Link to SubReadStream documentation from SeekableSubReadStream and SeekableSubReadStreamEndian. ........ r43466 | thebluegr | 2009-08-17 21:06:27 +1000 (Mon, 17 Aug 2009) | 1 line Made sound effect playing code consistent for compressed and uncompressed sounds. MemoryReadStream is used again instead of SeekableSubReadStream, as there will be issues when multiple sound effects or voices are played simultaneously ........ r43467 | thebluegr | 2009-08-17 21:11:38 +1000 (Mon, 17 Aug 2009) | 1 line Ignore speech and sound effect samples with unknown compression, instead of trying to play them as raw sound. Some cleanup ........ r43468 | dreammaster | 2009-08-17 21:36:09 +1000 (Mon, 17 Aug 2009) | 1 line Fix for some more !!HIGH STRINGS!! when talking to the palace guards ........ r43470 | thebluegr | 2009-08-17 21:49:07 +1000 (Mon, 17 Aug 2009) | 1 line Simplified the sound playing code by removing the boolean variables for signed, stereo, endian and sample bit information - now sound flags are used instead. Some cleanup. ........ r43471 | dreammaster | 2009-08-17 21:51:42 +1000 (Mon, 17 Aug 2009) | 1 line Switched event loop while/do to do/while, to ensure event handling occurs even when the game is under heavy load ........ r43473 | lordhoto | 2009-08-17 22:22:15 +1000 (Mon, 17 Aug 2009) | 1 line Cleanup: don't copy the Kyrandia 1 Amiga credits data in a temporary buffer, and thus keeping it twice in memory. ........ r43474 | lordhoto | 2009-08-17 22:22:30 +1000 (Mon, 17 Aug 2009) | 1 line Clear input queue before displaying the credits in Kyrandia 1. ........ r43475 | lordhoto | 2009-08-17 22:47:57 +1000 (Mon, 17 Aug 2009) | 1 line Fix possible out of bounds access in Screen::drawShape. ........ r43477 | joostp | 2009-08-17 22:57:37 +1000 (Mon, 17 Aug 2009) | 2 lines Commit (slightly) modified version of patch #2831248: Allow suspend/resume for PSP ........ r43479 | thebluegr | 2009-08-17 23:16:40 +1000 (Mon, 17 Aug 2009) | 1 line Added looping support to LinearDiskStream, needed by SAGA and perhaps other engines. Note that the loop end parameter is still not implemented ........ r43480 | thebluegr | 2009-08-17 23:25:44 +1000 (Mon, 17 Aug 2009) | 2 lines - Removed the custom DigitalMusicInputStream used in SAGA for the digital music in ITE CD and replaced it with the common LinearDiskStream class - Removed leftover code which plays standalone tracks (it's not used anywhere) ........ r43481 | lordhoto | 2009-08-17 23:49:56 +1000 (Mon, 17 Aug 2009) | 1 line Slight cleanup to makeLinearDiskStream interface. ........ r43482 | waltervn | 2009-08-18 01:49:22 +1000 (Tue, 18 Aug 2009) | 1 line SCI: Add autodetection for DoSound. Cleanup. ........ r43483 | waltervn | 2009-08-18 02:07:47 +1000 (Tue, 18 Aug 2009) | 1 line SCI: Build fix. ........ r43485 | thebluegr | 2009-08-18 04:25:51 +1000 (Tue, 18 Aug 2009) | 1 line Put back the code for playing external digital music, used by the MIDI enhancement project, which was removed in rev. #43480 ........ r43497 | waltervn | 2009-08-18 09:11:25 +1000 (Tue, 18 Aug 2009) | 1 line SCI: Fix kernel table for multilingual SCI01 games. Cleanup. ........ r43498 | joostp | 2009-08-18 09:54:40 +1000 (Tue, 18 Aug 2009) | 2 lines PSP: increase optimization level and change clock rate to 333mhz ........ r43500 | thebluegr | 2009-08-18 16:43:06 +1000 (Tue, 18 Aug 2009) | 1 line Applied agent-q's patch to the SAGA pathfinding code for all platforms - x and y should not ever be greater than 640 and 480 respectively, so it looks safe enough to be applied ........ r43503 | thebluegr | 2009-08-18 19:12:41 +1000 (Tue, 18 Aug 2009) | 1 line Removed the maxMemory parameter of the resource manager and replaced it with a define ........ r43504 | thebluegr | 2009-08-18 20:01:18 +1000 (Tue, 18 Aug 2009) | 2 lines - Added game ID detection to the fallback detector. We still need to map some of Sierra's internal IDs to our own ones - The class table is now created in the segment manager constructor ........ r43507 | dreammaster | 2009-08-18 22:25:04 +1000 (Tue, 18 Aug 2009) | 1 line Bugfix for Castle Skorl problem reported on the list ........ r43509 | thebluegr | 2009-08-18 22:49:34 +1000 (Tue, 18 Aug 2009) | 1 line Mapped some Sierra internal IDs to our own ones, and added a note about a hack currently used in the fallback detector ........ r43510 | thebluegr | 2009-08-19 00:10:31 +1000 (Wed, 19 Aug 2009) | 1 line Started rewriting the SCI engine to use FSNode instead of file names. This is the proper solution for removing the hack in the fallback detector, but it still needs work. Also, reduced the things needed to be initialized a bit, so that the detection is a bit faster ........ r43512 | lordhoto | 2009-08-19 01:31:26 +1000 (Wed, 19 Aug 2009) | 1 line Made AGOS, DRASCULA, GOB, GROOVIE, MADE, SCUMM and TINSEL properly stop CD audio playback on engine quit. (This only problem affected playback from CD, not from ripped audio files) ........ r43513 | lordhoto | 2009-08-19 01:32:26 +1000 (Wed, 19 Aug 2009) | 2 lines - Destory AudioCDManager singleton after user quits a game, this saves a few bytes memory - Added FIXME to audiocd.h, concering why destroying the AudioCDManager can not quit CD playback right now ........ r43514 | joostp | 2009-08-19 01:39:47 +1000 (Wed, 19 Aug 2009) | 2 lines PSP: disable dosbox OPL ........ r43515 | lordhoto | 2009-08-19 01:41:00 +1000 (Wed, 19 Aug 2009) | 1 line Typos. ........ r43517 | joostp | 2009-08-19 03:12:01 +1000 (Wed, 19 Aug 2009) | 2 lines PSP: Make R-trigger act as a context sensitive modifier key, remap ENTER to triangle ........ r43519 | joostp | 2009-08-19 04:06:50 +1000 (Wed, 19 Aug 2009) | 2 lines Implement setCursorPalette(), correct hasFeature() <-> getFeatureState() mixup. ........ r43521 | john_doe | 2009-08-19 05:42:13 +1000 (Wed, 19 Aug 2009) | 2 lines - PMV player: Use frame count from PVM file and fix incorrect "invalid chunk type" warning - Fix sprite drawing glitch with vertically flipped sprites (bug #2825925) ........ r43523 | buddha_ | 2009-08-19 07:37:31 +1000 (Wed, 19 Aug 2009) | 1 line Possible fix for #2828330 (AGI: KQ1: Fast text box). If doesn't break anything else then should go to the branch-1-0-0 too, but haven't had the time to do much testing yet - thus committing to the trunk first. ........ svn-id: r43524
Diffstat (limited to 'engines/saga')
-rw-r--r--engines/saga/actor.h4
-rw-r--r--engines/saga/music.cpp233
-rw-r--r--engines/saga/sndres.cpp59
-rw-r--r--engines/saga/sound.cpp67
-rw-r--r--engines/saga/sound.h6
5 files changed, 89 insertions, 280 deletions
diff --git a/engines/saga/actor.h b/engines/saga/actor.h
index d998c65240..57d06e9e3a 100644
--- a/engines/saga/actor.h
+++ b/engines/saga/actor.h
@@ -183,8 +183,8 @@ enum DragonMoveTypes {
struct PathDirectionData {
int8 direction;
- int x;
- int y;
+ int16 x;
+ int16 y;
};
struct ActorFrameRange {
diff --git a/engines/saga/music.cpp b/engines/saga/music.cpp
index 27566de2c3..8ca946a127 100644
--- a/engines/saga/music.cpp
+++ b/engines/saga/music.cpp
@@ -41,190 +41,6 @@ namespace Saga {
#define BUFFER_SIZE 4096
#define MUSIC_SUNSPOT 26
-class DigitalMusicInputStream : public Audio::AudioStream {
-private:
- Audio::AudioStream *_compressedStream;
- ResourceContext *_context;
- ResourceData * resourceData;
- GameSoundTypes soundType;
- Common::File *_file;
- uint32 _filePos;
- uint32 _startPos;
- uint32 _endPos;
- bool _finished;
- bool _looping;
- int16 _buf[BUFFER_SIZE];
- const int16 *_bufferEnd;
- const int16 *_pos;
- MemoryReadStream *_memoryStream;
- SagaEngine *_vm;
-
- void refill();
- bool eosIntern() const {
- return _pos >= _bufferEnd;
- }
-
-public:
- DigitalMusicInputStream(SagaEngine *vm, ResourceContext *context, uint32 resourceId, bool looping, uint32 loopStart);
- ~DigitalMusicInputStream();
-
- void createCompressedStream();
-
- int readBuffer(int16 *buffer, const int numSamples);
-
- bool endOfData() const { return eosIntern(); }
- bool isStereo() const {
- // The digital music in the ITE Mac demo version is not stereo
- return _vm->getFeatures() & GF_MONO_MUSIC ? false : true;
- }
- int getRate() const { return 11025; }
-};
-
-DigitalMusicInputStream::DigitalMusicInputStream(SagaEngine *vm, ResourceContext *context, uint32 resourceId, bool looping, uint32 loopStart)
- : _vm(vm), _context(context), _finished(false), _looping(looping), _bufferEnd(_buf + BUFFER_SIZE) {
-
- byte compressedHeader[10];
-
- resourceData = context->getResourceData(resourceId);
- _file = context->getFile(resourceData);
-
- _compressedStream = NULL;
-
- if (context->isCompressed) {
- // Read compressed header to determine compression type
- _file->seek((long)resourceData->offset, SEEK_SET);
- _file->read(compressedHeader, 9);
-
- if (compressedHeader[0] == char(0)) {
- soundType = kSoundMP3;
- } else if (compressedHeader[0] == char(1)) {
- soundType = kSoundOGG;
- } else if (compressedHeader[0] == char(2)) {
- soundType = kSoundFLAC;
- }
-
- createCompressedStream();
- }
-
- // Determine the end position
- _filePos = resourceData->offset;
- _endPos = _filePos + resourceData->size;
-
- if (_compressedStream != NULL) {
- _filePos += 9; // skip compressed header
- _endPos -= 9; // decrease size by the size of the compressed header
- }
-
- _startPos = _filePos + loopStart;
- if (_startPos >= _endPos)
- _startPos = _filePos;
-
- // Read in initial data
- refill();
-}
-
-DigitalMusicInputStream::~DigitalMusicInputStream() {
- delete _compressedStream;
-}
-
-void DigitalMusicInputStream::createCompressedStream() {
-#if defined(USE_MAD) || defined(USE_VORBIS) || defined(USE_FLAC)
- uint numLoops = _looping ? 0 : 1;
-#endif
- _memoryStream = _file->readStream(resourceData->size - 9);
-
- switch (soundType) {
-#ifdef USE_MAD
- case kSoundMP3:
- debug(1, "Playing MP3 compressed digital music");
- _compressedStream = Audio::makeMP3Stream(_memoryStream, true, 0, 0, numLoops);
- break;
-#endif
-#ifdef USE_VORBIS
- case kSoundOGG:
- debug(1, "Playing OGG compressed digital music");
- _compressedStream = Audio::makeVorbisStream(_memoryStream, true, 0, 0, numLoops);
- break;
-#endif
-#ifdef USE_FLAC
- case kSoundFLAC:
- debug(1, "Playing FLAC compressed digital music");
- _compressedStream = Audio::makeFlacStream(_memoryStream, true, 0, 0, numLoops);
- break;
-#endif
- default:
- // Unknown compression
- error("Trying to play compressed digital music, but the compression is not known");
- break;
- }
-}
-
-int DigitalMusicInputStream::readBuffer(int16 *buffer, const int numSamples) {
- if (_compressedStream != NULL)
- return _compressedStream->readBuffer(buffer, numSamples);
-
- int samples = 0;
- int len = 0;
-
- while (samples < numSamples && !eosIntern()) {
- len = MIN(numSamples - samples, (int) (_bufferEnd - _pos));
- memcpy(buffer, _pos, len * 2);
- buffer += len;
- _pos += len;
- samples += len;
- if (_pos >= _bufferEnd)
- refill();
- }
- return samples;
-}
-
-void DigitalMusicInputStream::refill() {
- if (_finished)
- return;
-
- uint32 lengthLeft;
- byte *ptr = (byte *) _buf;
-
- _file->seek(_filePos, SEEK_SET);
-
- if (_looping)
- lengthLeft = 2 * BUFFER_SIZE;
- else
- lengthLeft = MIN((uint32) (2 * BUFFER_SIZE), _endPos - _filePos);
-
- while (lengthLeft > 0) {
- uint32 len = _file->read(ptr, MIN(lengthLeft, _endPos - _file->pos()));
-
- if (len & 1)
- len--;
-
-#ifdef SCUMM_BIG_ENDIAN
- if (!_context->isBigEndian) {
-#else
- if (_context->isBigEndian) {
-#endif
- uint16 *ptr16 = (uint16 *)ptr;
- for (uint32 i = 0; i < (len / 2); i++)
- ptr16[i] = SWAP_BYTES_16(ptr16[i]);
- }
-
- lengthLeft -= len;
- ptr += len;
-
- if (lengthLeft > 0)
- _file->seek(_startPos);
- }
-
- _filePos = _file->pos();
- _pos = _buf;
- _bufferEnd = (int16 *)ptr;
-
- if (!_looping && _filePos >= _endPos) {
- _finished = true;
- }
-}
-
-
MusicPlayer::MusicPlayer(MidiDriver *driver) : _parser(0), _driver(driver), _looping(false), _isPlaying(false), _passThrough(false), _isGM(false) {
memset(_channel, 0, sizeof(_channel));
_masterVolume = 0;
@@ -461,9 +277,7 @@ void Music::play(uint32 resourceId, MusicFlags flags) {
sprintf(trackName[1], "track%02d", realTrackNumber);
Audio::AudioStream *stream = 0;
for (int i = 0; i < 2; ++i) {
- // We multiply by 40 / 3 = 1000 / 75 to convert frames to milliseconds
- // FIXME: Do we really want a duration of 10000 frames = 133 seconds, or is that just a random value?
- stream = Audio::AudioStream::openStreamFile(trackName[i], 0, 10000 * 40 / 3, (flags == MUSIC_LOOP) ? 0 : 1);
+ stream = Audio::AudioStream::openStreamFile(trackName[i], 0, 0, (flags == MUSIC_LOOP) ? 0 : 1);
if (stream) {
_mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_musicHandle, stream);
_digitalMusic = true;
@@ -474,15 +288,48 @@ void Music::play(uint32 resourceId, MusicFlags flags) {
if (_vm->getGameId() == GID_ITE) {
if (resourceId >= 9 && resourceId <= 34) {
if (_digitalMusicContext != NULL) {
- //TODO: check resource size
loopStart = 0;
- // fix ITE sunstatm/sunspot score
- if ((_vm->getGameId() == GID_ITE) && (resourceId == MUSIC_SUNSPOT)) {
+ // Fix ITE sunstatm/sunspot score
+ if (resourceId == MUSIC_SUNSPOT)
loopStart = 4 * 18727;
- }
- // digital music
- audioStream = new DigitalMusicInputStream(_vm, _digitalMusicContext, resourceId - 9, flags == MUSIC_LOOP, loopStart);
+ // Digital music
+ ResourceData *resData = _digitalMusicContext->getResourceData(resourceId - 9);
+ Common::File *musicFile = _digitalMusicContext->getFile(resData);
+ int offs = (_digitalMusicContext->isCompressed) ? 9 : 0;
+
+ Common::SeekableSubReadStream *musicStream = new Common::SeekableSubReadStream(musicFile,
+ (uint32)resData->offset + offs, (uint32)resData->offset + resData->size - offs);
+
+ if (!_digitalMusicContext->isCompressed) {
+ byte musicFlags = Audio::Mixer::FLAG_AUTOFREE | Audio::Mixer::FLAG_STEREO |
+ Audio::Mixer::FLAG_16BITS | Audio::Mixer::FLAG_LITTLE_ENDIAN;
+ if (flags == MUSIC_LOOP)
+ musicFlags |= Audio::Mixer::FLAG_LOOP;
+
+ Audio::LinearDiskStreamAudioBlock audioBlocks[1];
+ audioBlocks[0].pos = 0;
+ audioBlocks[0].len = resData->size / 2; // 16-bit sound
+ audioStream = Audio::makeLinearDiskStream(musicStream, audioBlocks, 1, 11025, musicFlags, false, loopStart, 0);
+ } else {
+ // Read compressed header to determine compression type
+ musicFile->seek((uint32)resData->offset, SEEK_SET);
+ byte identifier = musicFile->readByte();
+
+ if (identifier == 0) { // MP3
+#ifdef USE_MAD
+ audioStream = Audio::makeMP3Stream(musicStream, false, 0, 0, (flags == MUSIC_LOOP ? 0 : 1));
+#endif
+ } else if (identifier == 1) { // OGG
+#ifdef USE_VORBIS
+ audioStream = Audio::makeVorbisStream(musicStream, false, 0, 0, (flags == MUSIC_LOOP ? 0 : 1));
+#endif
+ } else if (identifier == 2) { // FLAC
+#ifdef USE_FLAC
+ audioStream = Audio::makeFlacStream(musicStream, false, 0, 0, (flags == MUSIC_LOOP ? 0 : 1));
+#endif
+ }
+ }
}
}
}
diff --git a/engines/saga/sndres.cpp b/engines/saga/sndres.cpp
index b2744482bd..eddd35300e 100644
--- a/engines/saga/sndres.cpp
+++ b/engines/saga/sndres.cpp
@@ -192,7 +192,6 @@ bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buff
GameSoundTypes resourceType = kSoundPCM;
byte *data = 0;
int rate = 0, size = 0;
- byte flags = 0;
Common::File* file;
if (resourceId == (uint32)-1) {
@@ -269,21 +268,17 @@ bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buff
}
- // Default sound type is 16-bit PCM (used in ITE)
- buffer.isBigEndian = context->isBigEndian;
- if ((context->fileType & GAME_VOICEFILE) && (_vm->getFeatures() & GF_LE_VOICES))
- buffer.isBigEndian = false;
+ // Default sound type is 16-bit signed PCM, used in ITE by PCM and VOX files
buffer.isCompressed = context->isCompressed;
buffer.soundType = resourceType;
buffer.originalSize = 0;
- buffer.stereo = false;
- buffer.isSigned = true; // default for PCM and VOX
- buffer.frequency = 22050; // default for PCM and VOX
- buffer.sampleBits = 16; // default for PCM and VOX
+ // Set default flags and frequency for PCM, VOC and VOX files, which got no header
+ buffer.flags = Audio::Mixer::FLAG_16BITS;
+ buffer.frequency = 22050;
if (_vm->getGameId() == GID_ITE) {
if (_vm->getFeatures() & GF_8BIT_UNSIGNED_PCM) { // older ITE demos
- buffer.isSigned = false;
- buffer.sampleBits = 8;
+ buffer.flags |= Audio::Mixer::FLAG_UNSIGNED;
+ buffer.flags &= ~Audio::Mixer::FLAG_16BITS;
} else {
// Voice files in newer ITE demo versions are OKI ADPCM (VOX) encoded
if (!scumm_stricmp(context->fileName, "voicesd.rsc"))
@@ -292,6 +287,12 @@ bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buff
}
buffer.buffer = NULL;
+ // Check for LE sounds
+ if (!context->isBigEndian)
+ buffer.flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN;
+ if ((context->fileType & GAME_VOICEFILE) && (_vm->getFeatures() & GF_LE_VOICES))
+ buffer.flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN;
+
// Older Mac versions of ITE were Macbinary packed
int soundOffset = (context->fileType & GAME_MACBINARY) ? 36 : 0;
@@ -321,25 +322,23 @@ bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buff
case kSoundShorten:
case kSoundVOC:
if (resourceType == kSoundWAV) {
- result = Audio::loadWAVFromStream(readS, size, rate, flags);
+ result = Audio::loadWAVFromStream(readS, size, rate, buffer.flags);
} else if (resourceType == kSoundAIFF) {
- result = Audio::loadAIFFFromStream(readS, size, rate, flags);
+ result = Audio::loadAIFFFromStream(readS, size, rate, buffer.flags);
+#ifdef ENABLE_SAGA2
+ } else if (resourceType == kSoundShorten) {
+ result = Audio::loadShortenFromStream(readS, size, rate, buffer.flags);
+#endif
} else if (resourceType == kSoundVOC) {
data = Audio::loadVOCFromStream(readS, size, rate);
result = (data != 0);
if (onlyHeader)
free(data);
-#ifdef ENABLE_SAGA2
- } else if (resourceType == kSoundShorten) {
- result = Audio::loadShortenFromStream(readS, size, rate, flags);
-#endif
+ buffer.flags |= Audio::Mixer::FLAG_UNSIGNED;
}
if (result) {
buffer.frequency = rate;
- buffer.sampleBits = (flags & Audio::Mixer::FLAG_16BITS) ? 16 : 8;
- buffer.stereo = flags & Audio::Mixer::FLAG_STEREO;
- buffer.isSigned = (resourceType == kSoundVOC) ? false : !(flags & Audio::Mixer::FLAG_UNSIGNED);
buffer.size = size;
if (!onlyHeader && resourceType != kSoundVOC) {
@@ -360,14 +359,20 @@ bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buff
readS.readByte(); // Skip compression identifier byte
buffer.frequency = readS.readUint16LE();
buffer.originalSize = readS.readUint32LE();
- buffer.sampleBits = readS.readByte();
- buffer.stereo = (readS.readByte() == char(0)) ? false : true;
+ if (readS.readByte() == 8) // read sample bits
+ buffer.flags &= ~Audio::Mixer::FLAG_16BITS;
+ if (readS.readByte() != 0) // read stereo flag
+ buffer.flags |= Audio::Mixer::FLAG_STEREO;
buffer.size = soundResourceLength;
buffer.soundType = resourceType;
- buffer.soundFile = context->getFile(resourceData);
buffer.fileOffset = resourceData->offset + 9; // skip compressed sfx header: byte + uint16 + uint32 + byte + byte
+ if (!onlyHeader) {
+ buffer.buffer = (byte *)malloc(buffer.size);
+ readS.read(buffer.buffer, buffer.size);
+ }
+
result = true;
break;
default:
@@ -403,12 +408,12 @@ int SndRes::getVoiceLength(uint32 resourceId) {
msDouble = (double)buffer.size;
else
msDouble = (double)buffer.originalSize;
- if (buffer.sampleBits == 16) {
+
+ if (buffer.flags & Audio::Mixer::FLAG_16BITS)
msDouble /= 2.0;
- }
- if (buffer.stereo) {
+
+ if (buffer.flags & Audio::Mixer::FLAG_STEREO)
msDouble /= 2.0;
- }
msDouble = msDouble / buffer.frequency * 1000.0;
return (int)msDouble;
diff --git a/engines/saga/sound.cpp b/engines/saga/sound.cpp
index fb7acaca8c..14e5492a48 100644
--- a/engines/saga/sound.cpp
+++ b/engines/saga/sound.cpp
@@ -65,84 +65,45 @@ SndHandle *Sound::getHandle() {
void Sound::playSoundBuffer(Audio::SoundHandle *handle, SoundBuffer &buffer, int volume,
sndHandleType handleType, bool loop) {
- byte flags;
- flags = Audio::Mixer::FLAG_AUTOFREE;
+ buffer.flags |= Audio::Mixer::FLAG_AUTOFREE;
if (loop)
- flags |= Audio::Mixer::FLAG_LOOP;
+ buffer.flags |= Audio::Mixer::FLAG_LOOP;
- if (buffer.sampleBits == 16) {
- flags |= Audio::Mixer::FLAG_16BITS;
-
- if (!buffer.isBigEndian)
- flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN;
- }
- if (buffer.stereo)
- flags |= Audio::Mixer::FLAG_STEREO;
- if (!buffer.isSigned)
- flags |= Audio::Mixer::FLAG_UNSIGNED;
+ Audio::Mixer::SoundType soundType = (handleType == kVoiceHandle) ?
+ Audio::Mixer::kSpeechSoundType : Audio::Mixer::kSFXSoundType;
if (!buffer.isCompressed) {
- if (handleType == kVoiceHandle)
- _mixer->playRaw(Audio::Mixer::kSpeechSoundType, handle, buffer.buffer,
- buffer.size, buffer.frequency, flags, -1, volume);
- else
- _mixer->playRaw(Audio::Mixer::kSFXSoundType, handle, buffer.buffer,
- buffer.size, buffer.frequency, flags, -1, volume);
+ _mixer->playRaw(soundType, handle, buffer.buffer,
+ buffer.size, buffer.frequency, buffer.flags, -1, volume);
} else {
- Audio::AudioStream *stream = NULL;
-#if defined(USE_MAD) || defined(USE_VORBIS) || defined(USE_FLAC)
- MemoryReadStream *tmp = NULL;
-#endif
+ Audio::AudioStream *stream = 0;
switch (buffer.soundType) {
#ifdef USE_MAD
case kSoundMP3:
- debug(1, "Playing MP3 compressed sound");
- buffer.soundFile->seek((long)buffer.fileOffset, SEEK_SET);
- tmp = buffer.soundFile->readStream(buffer.size);
- assert(tmp);
- stream = Audio::makeMP3Stream(tmp, true);
+ stream = Audio::makeMP3Stream(new Common::MemoryReadStream(buffer.buffer, buffer.size, true), true);
break;
#endif
#ifdef USE_VORBIS
case kSoundOGG:
- debug(1, "Playing OGG compressed sound");
- buffer.soundFile->seek((long)buffer.fileOffset, SEEK_SET);
- tmp = buffer.soundFile->readStream(buffer.size);
- assert(tmp);
- stream = Audio::makeVorbisStream(tmp, true);
+ stream = Audio::makeVorbisStream(new Common::MemoryReadStream(buffer.buffer, buffer.size, true), true);
break;
#endif
#ifdef USE_FLAC
case kSoundFLAC:
- debug(1, "Playing FLAC compressed sound");
- buffer.soundFile->seek((long)buffer.fileOffset, SEEK_SET);
- tmp = buffer.soundFile->readStream(buffer.size);
- assert(tmp);
- stream = Audio::makeFlacStream(tmp, true);
+ stream = Audio::makeFlacStream(new Common::MemoryReadStream(buffer.buffer, buffer.size, true), true);
break;
#endif
default:
- // No compression, play it as raw sound
- if (handleType == kVoiceHandle)
- _mixer->playRaw(Audio::Mixer::kSpeechSoundType, handle, buffer.buffer,
- buffer.size, buffer.frequency, flags, -1, volume);
- else
- _mixer->playRaw(Audio::Mixer::kSFXSoundType, handle, buffer.buffer,
- buffer.size, buffer.frequency, flags, -1, volume);
+ // Unknown compression, ignore sample
+ warning("Unknown compression, ignoring sound");
break;
}
- if (stream != NULL) {
- if (handleType == kVoiceHandle)
- _mixer->playInputStream(Audio::Mixer::kSpeechSoundType, handle, stream, -1,
- volume, 0, true, false);
- else
- _mixer->playInputStream(Audio::Mixer::kSFXSoundType, handle, stream, -1,
- volume, 0, true, false);
- }
+ if (stream != NULL)
+ _mixer->playInputStream(soundType, handle, stream, -1, volume, 0, true, false);
}
}
diff --git a/engines/saga/sound.h b/engines/saga/sound.h
index b61cbbbe90..0aeb54a55f 100644
--- a/engines/saga/sound.h
+++ b/engines/saga/sound.h
@@ -44,17 +44,13 @@ enum SOUND_FLAGS {
struct SoundBuffer {
uint16 frequency;
- int sampleBits;
- bool stereo;
- bool isSigned;
bool isCompressed;
+ byte flags;
byte *buffer;
size_t size;
size_t originalSize;
- bool isBigEndian;
GameSoundTypes soundType;
- Common::File *soundFile;
size_t fileOffset;
};