From 76a339ecd031369c1f4681b5af02a2d0e3b7e37f Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Mon, 17 Aug 2009 13:16:40 +0000 Subject: Added looping support to LinearDiskStream, needed by SAGA and perhaps other engines. Note that the loop end parameter is still not implemented svn-id: r43479 --- sound/audiostream.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'sound') diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp index 57d2e097bf..ce4022bab6 100644 --- a/sound/audiostream.cpp +++ b/sound/audiostream.cpp @@ -211,14 +211,14 @@ protected: int _audioBlockCount; ///< Number of blocks in _audioBlock int _currentBlock; ///< Current audio block number - int _beginLoop; ///< Loop parameter, currently not implemented - int _endLoop; ///< Loop parameter, currently not implemented - + int _beginLoop; ///< Loop start parameter + int _endLoop; ///< Loop end parameter, currently not implemented + bool _loop; ///< Determines if the stream should be looped when it finishes public: - LinearDiskStream(int rate, uint beginLoop, uint endLoop, bool disposeStream, Common::SeekableReadStream *stream, LinearDiskStreamAudioBlock *block, uint numBlocks) + LinearDiskStream(int rate, uint beginLoop, uint endLoop, bool disposeStream, Common::SeekableReadStream *stream, LinearDiskStreamAudioBlock *block, uint numBlocks, bool loop) : _rate(rate), _stream(stream), _beginLoop(beginLoop), _endLoop(endLoop), _disposeAfterUse(disposeStream), - _audioBlockCount(numBlocks) { + _audioBlockCount(numBlocks), _loop(loop) { // Allocate streaming buffer if (is16Bit) { @@ -296,7 +296,6 @@ int LinearDiskStream::readBuffer(int16 *buffe _diskLeft = _audioBlock[_currentBlock].len; } - // Now read more data from disk if there is more to be read if ((_bufferLeft == 0) && (_diskLeft > 0)) { int32 readAmount = MIN(_diskLeft, BUFFER_SIZE); @@ -315,6 +314,14 @@ int LinearDiskStream::readBuffer(int16 *buffe // original position. restoreFilePosition = true; } + + // Looping + if (_diskLeft == 0 && _loop) { + // Reset the stream + _currentBlock = 0; + _filePos = _audioBlock[_currentBlock].pos + _beginLoop; + _diskLeft = _audioBlock[_currentBlock].len; + } } // In case calling code relies on the position of this stream staying @@ -399,11 +406,11 @@ AudioStream *makeLinearInputStream(const byte *ptr, uint32 len, int rate, byte f #define MAKE_LINEAR_DISK(STEREO, UNSIGNED) \ if (is16Bit) { \ if (isLE) \ - return new LinearDiskStream(rate, loopStart, loopEnd, takeOwnership, &stream, block, numBlocks); \ + return new LinearDiskStream(rate, loopStart, loopEnd, takeOwnership, &stream, block, numBlocks, loop); \ else \ - return new LinearDiskStream(rate, loopStart, loopEnd, takeOwnership, &stream, block, numBlocks); \ + return new LinearDiskStream(rate, loopStart, loopEnd, takeOwnership, &stream, block, numBlocks, loop); \ } else \ - return new LinearDiskStream(rate, loopStart, loopEnd, takeOwnership, &stream, block, numBlocks) + return new LinearDiskStream(rate, loopStart, loopEnd, takeOwnership, &stream, block, numBlocks, loop) AudioStream *makeLinearDiskStream(Common::SeekableReadStream& stream, LinearDiskStreamAudioBlock* block, int numBlocks, int rate, byte flags, bool takeOwnership, uint loopStart, uint loopEnd) { @@ -411,7 +418,7 @@ AudioStream *makeLinearDiskStream(Common::SeekableReadStream& stream, LinearDisk const bool is16Bit = (flags & Audio::Mixer::FLAG_16BITS) != 0; const bool isUnsigned = (flags & Audio::Mixer::FLAG_UNSIGNED) != 0; const bool isLE = (flags & Audio::Mixer::FLAG_LITTLE_ENDIAN) != 0; - + const bool loop = (flags & Audio::Mixer::FLAG_LOOP) != 0; if (isStereo) { if (isUnsigned) { -- cgit v1.2.3 From 516dd5c9a4157ab63b20c6e04b698a63dcf8cd65 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 17 Aug 2009 13:49:56 +0000 Subject: Slight cleanup to makeLinearDiskStream interface. svn-id: r43481 --- sound/audiostream.cpp | 8 ++++---- sound/audiostream.h | 2 +- sound/voc.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'sound') diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp index ce4022bab6..783a5733b3 100644 --- a/sound/audiostream.cpp +++ b/sound/audiostream.cpp @@ -406,14 +406,14 @@ AudioStream *makeLinearInputStream(const byte *ptr, uint32 len, int rate, byte f #define MAKE_LINEAR_DISK(STEREO, UNSIGNED) \ if (is16Bit) { \ if (isLE) \ - return new LinearDiskStream(rate, loopStart, loopEnd, takeOwnership, &stream, block, numBlocks, loop); \ + return new LinearDiskStream(rate, loopStart, loopEnd, takeOwnership, stream, block, numBlocks, loop); \ else \ - return new LinearDiskStream(rate, loopStart, loopEnd, takeOwnership, &stream, block, numBlocks, loop); \ + return new LinearDiskStream(rate, loopStart, loopEnd, takeOwnership, stream, block, numBlocks, loop); \ } else \ - return new LinearDiskStream(rate, loopStart, loopEnd, takeOwnership, &stream, block, numBlocks, loop) + return new LinearDiskStream(rate, loopStart, loopEnd, takeOwnership, stream, block, numBlocks, loop) -AudioStream *makeLinearDiskStream(Common::SeekableReadStream& stream, LinearDiskStreamAudioBlock* block, int numBlocks, int rate, byte flags, bool takeOwnership, uint loopStart, uint loopEnd) { +AudioStream *makeLinearDiskStream(Common::SeekableReadStream *stream, LinearDiskStreamAudioBlock *block, int numBlocks, int rate, byte flags, bool takeOwnership, uint loopStart, uint loopEnd) { const bool isStereo = (flags & Audio::Mixer::FLAG_STEREO) != 0; const bool is16Bit = (flags & Audio::Mixer::FLAG_16BITS) != 0; const bool isUnsigned = (flags & Audio::Mixer::FLAG_UNSIGNED) != 0; diff --git a/sound/audiostream.h b/sound/audiostream.h index 99e140608d..09b97374d5 100644 --- a/sound/audiostream.h +++ b/sound/audiostream.h @@ -133,7 +133,7 @@ struct LinearDiskStreamAudioBlock { * start position and length of each block of uncompressed audio in the stream. */ -AudioStream *makeLinearDiskStream(Common::SeekableReadStream& stream, LinearDiskStreamAudioBlock* block, int +AudioStream *makeLinearDiskStream(Common::SeekableReadStream *stream, LinearDiskStreamAudioBlock *block, int numBlocks, int rate, byte flags, bool disposeStream, uint loopStart, uint loopEnd); /** diff --git a/sound/voc.cpp b/sound/voc.cpp index a332477f3c..a5bab0af29 100644 --- a/sound/voc.cpp +++ b/sound/voc.cpp @@ -292,7 +292,7 @@ AudioStream *makeVOCDiskStream(Common::SeekableReadStream &stream, byte flags, b int numBlocks = parseVOCFormat(stream, block, rate, loops, begin_loop, end_loop); - AudioStream* audioStream = makeLinearDiskStream(stream, block, numBlocks, rate, flags, takeOwnership, begin_loop, end_loop); + AudioStream *audioStream = makeLinearDiskStream(&stream, block, numBlocks, rate, flags, takeOwnership, begin_loop, end_loop); delete[] block; -- cgit v1.2.3 From 5c11ec51bc0e246615874876c913371672a725a3 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Tue, 18 Aug 2009 15:32:26 +0000 Subject: - 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 svn-id: r43513 --- sound/audiocd.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'sound') diff --git a/sound/audiocd.h b/sound/audiocd.h index 4c4ff26147..2dc379ca27 100644 --- a/sound/audiocd.h +++ b/sound/audiocd.h @@ -67,6 +67,14 @@ private: friend class Common::Singleton; AudioCDManager(); + // FIXME: It might make sense to stop CD playback, when the AudioCDManager singleton + // is destroyed. Currently we can not do this, since in worst case the OSystem and + // along wiht it the Mixer will be destroyed before the AudioCDManager, thus + // leading to invalid memory access. If we can fix up the code to destroy the + // AudioCDManager before OSystem in *all* cases, that is including calling + // OSystem::quit, we might be able to implement it via a simple "stop()" + // call in a custom destructor of AudioCDManager. + /* used for emulated CD music */ SoundHandle _handle; bool _emulating; -- cgit v1.2.3 From 3ade77dfb06ba0d41f123306fcf529c7007351b9 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Tue, 18 Aug 2009 15:41:00 +0000 Subject: Typos. svn-id: r43515 --- sound/audiocd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/audiocd.h b/sound/audiocd.h index 2dc379ca27..3ef4a1ac09 100644 --- a/sound/audiocd.h +++ b/sound/audiocd.h @@ -69,7 +69,7 @@ private: // FIXME: It might make sense to stop CD playback, when the AudioCDManager singleton // is destroyed. Currently we can not do this, since in worst case the OSystem and - // along wiht it the Mixer will be destroyed before the AudioCDManager, thus + // along with it the Mixer will be destroyed before the AudioCDManager, thus // leading to invalid memory access. If we can fix up the code to destroy the // AudioCDManager before OSystem in *all* cases, that is including calling // OSystem::quit, we might be able to implement it via a simple "stop()" -- cgit v1.2.3 From dd7868acc2512c9761d892e67a4837f4dc38bdc0 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 24 Aug 2009 16:07:46 +0000 Subject: - Change shorten.h guard to match the sjis.h guard. - Also enable shorten code when the build includes support for dynamic engine plugins. svn-id: r43700 --- sound/shorten.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'sound') diff --git a/sound/shorten.h b/sound/shorten.h index c2a40280d3..bc9f229687 100644 --- a/sound/shorten.h +++ b/sound/shorten.h @@ -23,13 +23,15 @@ * */ -// The code in this file is currently only used in SAGA2 (in the -// SAGA engine), so if that engine isn't enabled, we will skip -// compiling it. If you plan to use this code in another engine, -// you will have to add the proper define check here. -// Also please add the define check at the comment after the -// matching #endif further down this file. -#if defined(ENABLE_SAGA2) +// The code in this file is currently only used in SAGA2. +// So when it is disabled, we will skip compiling it. +// We also enable this code for ScummVM builds including support +// for dynamic engine plugins. +// If you plan to use this code in another engine, you will have +// to add the proper define check here. +#if !(defined(ENABLE_SAGA2) || defined(DYNAMIC_MODULES)) + +#else #ifndef SOUND_SHORTEN_H #define SOUND_SHORTEN_H @@ -48,7 +50,7 @@ class AudioStream; * start of the audio data, and size, rate and flags contain information * necessary for playback. */ -extern byte *loadShortenFromStream(Common::ReadStream &stream, int &size, int &rate, byte &flags); +byte *loadShortenFromStream(Common::ReadStream &stream, int &size, int &rate, byte &flags); /** * Try to load a Shorten file from the given stream and create an AudioStream @@ -62,6 +64,5 @@ AudioStream *makeShortenStream(Common::ReadStream &stream); #endif -#endif // defined(ENABLE_SAGA2) - +#endif // engine and dynamic plugins guard -- cgit v1.2.3