From 6ad04a4a96b0290125e33535f84a98e4d79dff2c Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Thu, 10 Jun 2010 15:06:25 +0000 Subject: Add support for AIFF sound in SCI32 Mac games and add support for AIFF/WAVE audio36 patches; minor cleanup. svn-id: r49576 --- engines/sci/sound/audio.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'engines/sci/sound/audio.cpp') diff --git a/engines/sci/sound/audio.cpp b/engines/sci/sound/audio.cpp index 7748c0505b..f10cc5ed68 100644 --- a/engines/sci/sound/audio.cpp +++ b/engines/sci/sound/audio.cpp @@ -24,21 +24,22 @@ */ #include "sci/resource.h" -#include "sci/engine/selector.h" #include "sci/engine/kernel.h" +#include "sci/engine/selector.h" #include "sci/engine/seg_manager.h" #include "sci/sound/audio.h" -#include "common/system.h" #include "common/file.h" +#include "common/system.h" -#include "sound/audiostream.h" #include "sound/audiocd.h" -#include "sound/decoders/raw.h" -#include "sound/decoders/wave.h" +#include "sound/audiostream.h" +#include "sound/decoders/aiff.h" #include "sound/decoders/flac.h" #include "sound/decoders/mp3.h" +#include "sound/decoders/raw.h" #include "sound/decoders/vorbis.h" +#include "sound/decoders/wave.h" namespace Sci { @@ -287,6 +288,19 @@ Audio::RewindableAudioStream *AudioPlayer::getAudioStream(uint32 number, uint32 waveStream->seek(0, SEEK_SET); audioStream = Audio::makeWAVStream(waveStream, DisposeAfterUse::YES); + } else if (audioRes->size > 4 && READ_BE_UINT32(audioRes->data) == MKID_BE('FORM')) { + // AIFF detected + Common::MemoryReadStream *waveStream = new Common::MemoryReadStream(audioRes->data, audioRes->size, DisposeAfterUse::NO); + + // Calculate samplelen from AIFF header + int waveSize = 0, waveRate = 0; + byte waveFlags = 0; + Audio::loadAIFFFromStream(*waveStream, waveSize, waveRate, waveFlags); + *sampleLen = (waveFlags & Audio::FLAG_16BITS ? waveSize >> 1 : waveSize) * 60 / waveRate; + + waveStream->seek(0, SEEK_SET); + audioStream = Audio::makeAIFFStream(*waveStream); + delete waveStream; // makeAIFFStream doesn't handle this for us } else if (audioRes->size > 14 && READ_BE_UINT16(audioRes->data) == 1 && READ_BE_UINT16(audioRes->data + 2) == 1 && READ_BE_UINT16(audioRes->data + 4) == 5 && READ_BE_UINT32(audioRes->data + 10) == 0x00018051) { // Mac snd detected -- cgit v1.2.3 From 9f907aac095123ac016a23a559f54ada35af6772 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Thu, 10 Jun 2010 20:26:59 +0000 Subject: kSciAudioWPlay should not actually play the song, but 'pre-load' it. We fake the pre-loading with a flag that will return 0 if the song has been called with kSciAudioWPlay. Fixes the dream sequence sound in MUMG. svn-id: r49583 --- engines/sci/sound/audio.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'engines/sci/sound/audio.cpp') diff --git a/engines/sci/sound/audio.cpp b/engines/sci/sound/audio.cpp index f10cc5ed68..62cfcd9621 100644 --- a/engines/sci/sound/audio.cpp +++ b/engines/sci/sound/audio.cpp @@ -47,6 +47,7 @@ AudioPlayer::AudioPlayer(ResourceManager *resMan) : _resMan(resMan), _audioRate( _syncResource(NULL), _syncOffset(0), _audioCdStart(0) { _mixer = g_system->getMixer(); + _wPlayFlag = false; } AudioPlayer::~AudioPlayer() { @@ -65,6 +66,7 @@ int AudioPlayer::startAudio(uint16 module, uint32 number) { Audio::AudioStream *audioStream = getAudioStream(number, module, &sampleLen); if (audioStream) { + _wPlayFlag = false; _mixer->playStream(Audio::Mixer::kSpeechSoundType, &_audioHandle, audioStream); return sampleLen; } @@ -72,6 +74,18 @@ int AudioPlayer::startAudio(uint16 module, uint32 number) { return 0; } +int AudioPlayer::wPlayAudio(uint16 module, uint32 tuple) { + // Get the audio sample length and set the wPlay flag so we return 0 on position. + // SSCI pre-loads the audio here, but it's much easier for us to just get the + // sample length and return that. wPlayAudio should *not* actually start the sample. + + int sampleLen = 0; + Audio::AudioStream *audioStream = getAudioStream(module, tuple, &sampleLen); + delete audioStream; + _wPlayFlag = true; + return sampleLen; +} + void AudioPlayer::stopAudio() { _mixer->stopHandle(_audioHandle); } @@ -87,6 +101,8 @@ void AudioPlayer::resumeAudio() { int AudioPlayer::getAudioPosition() { if (_mixer->isSoundHandleActive(_audioHandle)) return _mixer->getSoundElapsedTime(_audioHandle) * 6 / 100; // return elapsed time in ticks + else if (_wPlayFlag) + return 0; // Sound has "loaded" so return that it hasn't started else return -1; // Sound finished } -- cgit v1.2.3 From f4739f9f68026d5e3ea3304777260cef3101a031 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sat, 12 Jun 2010 11:41:22 +0000 Subject: Added debug output to kDoAudio and some music commands. Also added a warning when an audio stream can't be created. Finally, the debug level of the MIDI parser debug output has been raised to 4, as it's too verbose svn-id: r49605 --- engines/sci/sound/audio.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'engines/sci/sound/audio.cpp') diff --git a/engines/sci/sound/audio.cpp b/engines/sci/sound/audio.cpp index 62cfcd9621..b0b9a73e00 100644 --- a/engines/sci/sound/audio.cpp +++ b/engines/sci/sound/audio.cpp @@ -69,6 +69,8 @@ int AudioPlayer::startAudio(uint16 module, uint32 number) { _wPlayFlag = false; _mixer->playStream(Audio::Mixer::kSpeechSoundType, &_audioHandle, audioStream); return sampleLen; + } else { + warning("startAudio: unable to create stream for audio number %d, module %d", number, module); } return 0; @@ -81,6 +83,8 @@ int AudioPlayer::wPlayAudio(uint16 module, uint32 tuple) { int sampleLen = 0; Audio::AudioStream *audioStream = getAudioStream(module, tuple, &sampleLen); + if (!audioStream) + warning("wPlayAudio: unable to create stream for audio tuple %d, module %d", tuple, module); delete audioStream; _wPlayFlag = true; return sampleLen; -- cgit v1.2.3 From d570e10b77887fa163f17de512b14fc824f45f33 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 15 Jun 2010 12:33:54 +0000 Subject: Modify makeAIFFStream to match the other sound decoder factories svn-id: r49844 --- engines/sci/sound/audio.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'engines/sci/sound/audio.cpp') diff --git a/engines/sci/sound/audio.cpp b/engines/sci/sound/audio.cpp index b0b9a73e00..8dfbc18976 100644 --- a/engines/sci/sound/audio.cpp +++ b/engines/sci/sound/audio.cpp @@ -260,9 +260,11 @@ Audio::RewindableAudioStream *AudioPlayer::getAudioStream(uint32 number, uint32 // Compressed audio made by our tool byte *compressedData = (byte *)malloc(audioRes->size); assert(compressedData); - // We copy over the compressed data in our own buffer. If we don't do this resourcemanager may free the data - // later. All other compression-types already decompress completely into an additional buffer here. - // MP3/OGG/FLAC decompression works on-the-fly instead. + // We copy over the compressed data in our own buffer. We have to do + // this, because ResourceManager may free the original data late. + // All other compression types already decompress completely into an + // additional buffer here. MP3/OGG/FLAC decompression works on-the-fly + // instead. memcpy(compressedData, audioRes->data, audioRes->size); Common::MemoryReadStream *compressedStream = new Common::MemoryReadStream(compressedData, audioRes->size, DisposeAfterUse::YES); @@ -319,8 +321,7 @@ Audio::RewindableAudioStream *AudioPlayer::getAudioStream(uint32 number, uint32 *sampleLen = (waveFlags & Audio::FLAG_16BITS ? waveSize >> 1 : waveSize) * 60 / waveRate; waveStream->seek(0, SEEK_SET); - audioStream = Audio::makeAIFFStream(*waveStream); - delete waveStream; // makeAIFFStream doesn't handle this for us + audioStream = Audio::makeAIFFStream(waveStream, DisposeAfterUse::YES); } else if (audioRes->size > 14 && READ_BE_UINT16(audioRes->data) == 1 && READ_BE_UINT16(audioRes->data + 2) == 1 && READ_BE_UINT16(audioRes->data + 4) == 5 && READ_BE_UINT32(audioRes->data + 10) == 0x00018051) { // Mac snd detected -- cgit v1.2.3 From f93644325244cc111634e2e8e4f97adb5a3fbe15 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 15 Jun 2010 12:34:33 +0000 Subject: SCI: Saner and simpler conversion from msecs to ticks svn-id: r49846 --- engines/sci/sound/audio.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'engines/sci/sound/audio.cpp') diff --git a/engines/sci/sound/audio.cpp b/engines/sci/sound/audio.cpp index 8dfbc18976..ac3ef54c9a 100644 --- a/engines/sci/sound/audio.cpp +++ b/engines/sci/sound/audio.cpp @@ -353,9 +353,7 @@ Audio::RewindableAudioStream *AudioPlayer::getAudioStream(uint32 number, uint32 } if (audioSeekStream) { - *sampleLen = (audioSeekStream->getLength().msecs() * 10000) / 166666; // we translate msecs to ticks - // Original code - //*sampleLen = (flags & Audio::FLAG_16BITS ? size >> 1 : size) * 60 / _audioRate; + *sampleLen = (audioSeekStream->getLength().msecs() * 60) / 1000; // we translate msecs to ticks audioStream = audioSeekStream; } // We have to make sure that we don't depend on resource manager pointers after this point, because the actual -- cgit v1.2.3 From 0e365131ac58b7504e9e16b08a8b3125b6b37027 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Thu, 17 Jun 2010 12:29:58 +0000 Subject: Fixed wPlayAudio, and added some documentation on the 3 new kDoAudio subops. Digital sounds in Pharkas work again svn-id: r49928 --- engines/sci/sound/audio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/sci/sound/audio.cpp') diff --git a/engines/sci/sound/audio.cpp b/engines/sci/sound/audio.cpp index ac3ef54c9a..0e235ee400 100644 --- a/engines/sci/sound/audio.cpp +++ b/engines/sci/sound/audio.cpp @@ -82,7 +82,7 @@ int AudioPlayer::wPlayAudio(uint16 module, uint32 tuple) { // sample length and return that. wPlayAudio should *not* actually start the sample. int sampleLen = 0; - Audio::AudioStream *audioStream = getAudioStream(module, tuple, &sampleLen); + Audio::AudioStream *audioStream = getAudioStream(tuple, module, &sampleLen); if (!audioStream) warning("wPlayAudio: unable to create stream for audio tuple %d, module %d", tuple, module); delete audioStream; -- cgit v1.2.3 From bb9f556c363718959a43c7a65cec1944b626d358 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Tue, 22 Jun 2010 15:18:55 +0000 Subject: Add support for the QFG3 demo audio map and audio resources. Based on a patch by Walter. svn-id: r50144 --- engines/sci/sound/audio.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'engines/sci/sound/audio.cpp') diff --git a/engines/sci/sound/audio.cpp b/engines/sci/sound/audio.cpp index 0e235ee400..336218eaec 100644 --- a/engines/sci/sound/audio.cpp +++ b/engines/sci/sound/audio.cpp @@ -182,17 +182,28 @@ static void deDPCM8(byte *soundBuf, Common::SeekableReadStream &audioStream, uin // Sierra SOL audio file reader // Check here for more info: http://wiki.multimedia.cx/index.php?title=Sierra_Audio -static bool readSOLHeader(Common::SeekableReadStream *audioStream, int headerSize, uint32 &size, uint16 &audioRate, byte &audioFlags) { - if (headerSize != 11 && headerSize != 12) { +static bool readSOLHeader(Common::SeekableReadStream *audioStream, int headerSize, uint32 &size, uint16 &audioRate, byte &audioFlags, uint32 resSize) { + if (headerSize != 7 && headerSize != 11 && headerSize != 12) { warning("SOL audio header of size %i not supported", headerSize); return false; } - audioStream->readUint32LE(); // skip "SOL" + 0 (4 bytes) + uint32 tag = audioStream->readUint32BE(); + + if (tag != MKID_BE('SOL\0')) { + warning("No 'SOL' FourCC found"); + return false; + } + audioRate = audioStream->readUint16LE(); audioFlags = audioStream->readByte(); - size = audioStream->readUint32LE(); + // For the QFG3 demo format, just use the resource size + // Otherwise, load it from the header + if (headerSize == 7) + size = resSize; + else + size = audioStream->readUint32LE(); return true; } @@ -294,7 +305,7 @@ Audio::RewindableAudioStream *AudioPlayer::getAudioStream(uint32 number, uint32 // SCI1.1 Common::MemoryReadStream headerStream(audioRes->_header, audioRes->_headerSize, DisposeAfterUse::NO); - if (readSOLHeader(&headerStream, audioRes->_headerSize, size, _audioRate, audioFlags)) { + if (readSOLHeader(&headerStream, audioRes->_headerSize, size, _audioRate, audioFlags, audioRes->size)) { Common::MemoryReadStream dataStream(audioRes->data, audioRes->size, DisposeAfterUse::NO); data = readSOLAudio(&dataStream, size, audioFlags, flags); } -- cgit v1.2.3 From b09996cb5cea63482c16faafb55d83bd50c04c90 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 29 Jun 2010 20:50:52 +0000 Subject: SCI: Rewrap yet more comments svn-id: r50505 --- engines/sci/sound/audio.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'engines/sci/sound/audio.cpp') diff --git a/engines/sci/sound/audio.cpp b/engines/sci/sound/audio.cpp index 336218eaec..ed9061ab81 100644 --- a/engines/sci/sound/audio.cpp +++ b/engines/sci/sound/audio.cpp @@ -77,9 +77,10 @@ int AudioPlayer::startAudio(uint16 module, uint32 number) { } int AudioPlayer::wPlayAudio(uint16 module, uint32 tuple) { - // Get the audio sample length and set the wPlay flag so we return 0 on position. - // SSCI pre-loads the audio here, but it's much easier for us to just get the - // sample length and return that. wPlayAudio should *not* actually start the sample. + // Get the audio sample length and set the wPlay flag so we return 0 on + // position. SSCI pre-loads the audio here, but it's much easier for us to + // just get the sample length and return that. wPlayAudio should *not* + // actually start the sample. int sampleLen = 0; Audio::AudioStream *audioStream = getAudioStream(tuple, module, &sampleLen); @@ -272,8 +273,8 @@ Audio::RewindableAudioStream *AudioPlayer::getAudioStream(uint32 number, uint32 byte *compressedData = (byte *)malloc(audioRes->size); assert(compressedData); // We copy over the compressed data in our own buffer. We have to do - // this, because ResourceManager may free the original data late. - // All other compression types already decompress completely into an + // this, because ResourceManager may free the original data late. All + // other compression types already decompress completely into an // additional buffer here. MP3/OGG/FLAC decompression works on-the-fly // instead. memcpy(compressedData, audioRes->data, audioRes->size); @@ -367,8 +368,9 @@ Audio::RewindableAudioStream *AudioPlayer::getAudioStream(uint32 number, uint32 *sampleLen = (audioSeekStream->getLength().msecs() * 60) / 1000; // we translate msecs to ticks audioStream = audioSeekStream; } - // We have to make sure that we don't depend on resource manager pointers after this point, because the actual - // audio resource may get unloaded by resource manager at any time + // We have to make sure that we don't depend on resource manager pointers + // after this point, because the actual audio resource may get unloaded by + // resource manager at any time. if (audioStream) return audioStream; -- cgit v1.2.3 From a1dc56429c3d61afe960924abdc4ee241c4c9fe6 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Thu, 1 Jul 2010 17:42:39 +0000 Subject: SCI: Removed duplicate warning for missing audio samples svn-id: r50560 --- engines/sci/sound/audio.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'engines/sci/sound/audio.cpp') diff --git a/engines/sci/sound/audio.cpp b/engines/sci/sound/audio.cpp index ed9061ab81..2e92754cad 100644 --- a/engines/sci/sound/audio.cpp +++ b/engines/sci/sound/audio.cpp @@ -70,10 +70,11 @@ int AudioPlayer::startAudio(uint16 module, uint32 number) { _mixer->playStream(Audio::Mixer::kSpeechSoundType, &_audioHandle, audioStream); return sampleLen; } else { - warning("startAudio: unable to create stream for audio number %d, module %d", number, module); + // Don't throw a warning in this case. getAudioStream() already has. Some games + // do miss audio entries (perhaps because of a typo, or because they were simply + // forgotten). + return 0; } - - return 0; } int AudioPlayer::wPlayAudio(uint16 module, uint32 tuple) { -- cgit v1.2.3