diff options
-rw-r--r-- | engines/groovie/player.h | 2 | ||||
-rw-r--r-- | engines/groovie/roq.cpp | 24 | ||||
-rw-r--r-- | engines/groovie/vdx.cpp | 4 | ||||
-rw-r--r-- | engines/kyra/vqa.cpp | 14 | ||||
-rw-r--r-- | engines/kyra/vqa.h | 4 | ||||
-rw-r--r-- | engines/kyra/wsamovie.h | 6 | ||||
-rw-r--r-- | sound/audiostream.cpp | 165 | ||||
-rw-r--r-- | sound/audiostream.h | 31 |
8 files changed, 26 insertions, 224 deletions
diff --git a/engines/groovie/player.h b/engines/groovie/player.h index 2ef340149a..d54601bc52 100644 --- a/engines/groovie/player.h +++ b/engines/groovie/player.h @@ -52,7 +52,7 @@ protected: OSystem *_syst; Common::SeekableReadStream *_file; uint16 _flags; - Audio::AppendableAudioStream *_audioStream; + Audio::QueuingAudioStream *_audioStream; private: // Synchronization stuff diff --git a/engines/groovie/roq.cpp b/engines/groovie/roq.cpp index 5f16f9c935..11e7fd9aaa 100644 --- a/engines/groovie/roq.cpp +++ b/engines/groovie/roq.cpp @@ -516,11 +516,7 @@ bool ROQPlayer::processBlockSoundMono(ROQBlockHeader &blockHeader) { // Initialize the audio stream if needed if (!_audioStream) { - byte flags = Audio::Mixer::FLAG_16BITS | Audio::Mixer::FLAG_AUTOFREE; -#ifdef SCUMM_LITTLE_ENDIAN - flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN; -#endif - _audioStream = Audio::makeAppendableAudioStream(22050, flags); + _audioStream = Audio::makeQueuingAudioStream(22050, false); Audio::SoundHandle sound_handle; g_system->getMixer()->playInputStream(Audio::Mixer::kPlainSoundType, &sound_handle, _audioStream); } @@ -544,7 +540,11 @@ bool ROQPlayer::processBlockSoundMono(ROQBlockHeader &blockHeader) { } // Queue the read buffer - _audioStream->queueBuffer((byte *)buffer, blockHeader.size * 2); + byte flags = Audio::Mixer::FLAG_16BITS | Audio::Mixer::FLAG_AUTOFREE; +#ifdef SCUMM_LITTLE_ENDIAN + flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN; +#endif + _audioStream->queueBuffer((byte *)buffer, blockHeader.size * 2, flags); return true; } @@ -559,11 +559,7 @@ bool ROQPlayer::processBlockSoundStereo(ROQBlockHeader &blockHeader) { // Initialize the audio stream if needed if (!_audioStream) { - byte flags = Audio::Mixer::FLAG_16BITS | Audio::Mixer::FLAG_AUTOFREE | Audio::Mixer::FLAG_STEREO; -#ifdef SCUMM_LITTLE_ENDIAN - flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN; -#endif - _audioStream = Audio::makeAppendableAudioStream(22050, flags); + _audioStream = Audio::makeQueuingAudioStream(22050, true); Audio::SoundHandle sound_handle; g_system->getMixer()->playInputStream(Audio::Mixer::kPlainSoundType, &sound_handle, _audioStream); } @@ -600,7 +596,11 @@ bool ROQPlayer::processBlockSoundStereo(ROQBlockHeader &blockHeader) { } // Queue the read buffer - _audioStream->queueBuffer((byte *)buffer, blockHeader.size * 2); + byte flags = Audio::Mixer::FLAG_16BITS | Audio::Mixer::FLAG_AUTOFREE | Audio::Mixer::FLAG_STEREO; +#ifdef SCUMM_LITTLE_ENDIAN + flags |= Audio::Mixer::FLAG_LITTLE_ENDIAN; +#endif + _audioStream->queueBuffer((byte *)buffer, blockHeader.size * 2, flags); return true; } diff --git a/engines/groovie/vdx.cpp b/engines/groovie/vdx.cpp index 0c754473fe..e2764defa6 100644 --- a/engines/groovie/vdx.cpp +++ b/engines/groovie/vdx.cpp @@ -498,7 +498,7 @@ void VDXPlayer::decodeBlockDelta(uint32 offset, byte *colours, uint16 imageWidth void VDXPlayer::chunkSound(Common::ReadStream *in) { if (!_audioStream) { - _audioStream = Audio::makeAppendableAudioStream(22050, Audio::Mixer::FLAG_UNSIGNED | Audio::Mixer::FLAG_AUTOFREE); + _audioStream = Audio::makeQueuingAudioStream(22050, false); Audio::SoundHandle sound_handle; g_system->getMixer()->playInputStream(Audio::Mixer::kPlainSoundType, &sound_handle, _audioStream); } @@ -506,7 +506,7 @@ void VDXPlayer::chunkSound(Common::ReadStream *in) { byte *data = new byte[60000]; int chunksize = in->read(data, 60000); if (!Common::isDebugChannelEnabled(kGroovieDebugFast)) { - _audioStream->queueBuffer(data, chunksize); + _audioStream->queueBuffer(data, chunksize, Audio::Mixer::FLAG_UNSIGNED | Audio::Mixer::FLAG_AUTOFREE); } } diff --git a/engines/kyra/vqa.cpp b/engines/kyra/vqa.cpp index 1b9683ed65..fde6e06a96 100644 --- a/engines/kyra/vqa.cpp +++ b/engines/kyra/vqa.cpp @@ -292,7 +292,7 @@ bool VQAMovie::open(const char *filename) { assert(_header.bits == 8); assert(_header.channels == 1); - _stream = Audio::makeAppendableAudioStream(_header.freq, Audio::Mixer::FLAG_UNSIGNED); + _stream = Audio::makeQueuingAudioStream(_header.freq, false); } else { _stream = NULL; } @@ -422,7 +422,7 @@ void VQAMovie::displayFrame(uint frameNum) { inbuf = new byte[size]; _file->read(inbuf, size); assert(_stream); - _stream->queueBuffer(inbuf, size); + _stream->queueBuffer(inbuf, size, Audio::Mixer::FLAG_UNSIGNED); break; case MKID_BE('SND1'): // Compressed sound, almost like AUD @@ -435,12 +435,12 @@ void VQAMovie::displayFrame(uint frameNum) { if (insize == outsize) { assert(_stream); - _stream->queueBuffer(inbuf, insize); + _stream->queueBuffer(inbuf, insize, Audio::Mixer::FLAG_UNSIGNED); } else { outbuf = new byte[outsize]; decodeSND1(inbuf, insize, outbuf, outsize); assert(_stream); - _stream->queueBuffer(outbuf, outsize); + _stream->queueBuffer(outbuf, outsize, Audio::Mixer::FLAG_UNSIGNED); delete[] inbuf; } break; @@ -612,7 +612,7 @@ void VQAMovie::play() { case MKID_BE('SND0'): // Uncompressed sound inbuf = new byte[size]; _file->read(inbuf, size); - _stream->queueBuffer(inbuf, size); + _stream->queueBuffer(inbuf, size, Audio::Mixer::FLAG_UNSIGNED); break; case MKID_BE('SND1'): // Compressed sound @@ -623,11 +623,11 @@ void VQAMovie::play() { _file->read(inbuf, insize); if (insize == outsize) { - _stream->queueBuffer(inbuf, insize); + _stream->queueBuffer(inbuf, insize, Audio::Mixer::FLAG_UNSIGNED); } else { outbuf = new byte[outsize]; decodeSND1(inbuf, insize, outbuf, outsize); - _stream->queueBuffer(outbuf, outsize); + _stream->queueBuffer(outbuf, outsize, Audio::Mixer::FLAG_UNSIGNED); delete[] inbuf; } break; diff --git a/engines/kyra/vqa.h b/engines/kyra/vqa.h index bf3d1fe855..c1448a4865 100644 --- a/engines/kyra/vqa.h +++ b/engines/kyra/vqa.h @@ -33,7 +33,7 @@ class OSystem; namespace Audio { -class AppendableAudioStream; +class QueuingAudioStream; } // End of namespace Audio namespace Common { @@ -127,7 +127,7 @@ protected: byte *_frame; - Audio::AppendableAudioStream *_stream; + Audio::QueuingAudioStream *_stream; Audio::SoundHandle _sound; uint32 readTag(); diff --git a/engines/kyra/wsamovie.h b/engines/kyra/wsamovie.h index c93221d7a0..d2c041742a 100644 --- a/engines/kyra/wsamovie.h +++ b/engines/kyra/wsamovie.h @@ -26,12 +26,8 @@ #ifndef KYRA_WSAMOVIE_H #define KYRA_WSAMOVIE_H -namespace Audio { -class AppendableAudioStream; -class SoundHandle; -} // End of namespace Audio - namespace Kyra { + class KyraEngine_v1; class Screen_v2; class Palette; diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp index 6d7ee24738..72f01b35d1 100644 --- a/sound/audiostream.cpp +++ b/sound/audiostream.cpp @@ -26,7 +26,6 @@ #include "common/debug.h" #include "common/endian.h" #include "common/file.h" -#include "common/list.h" #include "common/queue.h" #include "common/util.h" @@ -604,171 +603,9 @@ SeekableAudioStream *makeLinearDiskStream(Common::SeekableReadStream *stream, Li } -#pragma mark - -#pragma mark --- Appendable audio stream --- -#pragma mark - - -struct Buffer { - byte *start; - byte *end; -}; - -/** - * Wrapped memory stream. - */ -class BaseAppendableMemoryStream : public AppendableAudioStream { -protected: - - /** - * A mutex to avoid access problems (causing e.g. corruption of - * the linked list) in thread aware environments. - */ - Common::Mutex _mutex; - - // List of all queued buffers - Common::List<Buffer> _bufferQueue; - - bool _finalized; - const int _rate; - // Position in the front buffer, if any - byte *_pos; - - inline bool eosIntern() const { return _bufferQueue.empty(); }; -public: - BaseAppendableMemoryStream(int rate); - ~BaseAppendableMemoryStream(); - - bool endOfStream() const { return _finalized && eosIntern(); } - bool endOfData() const { return eosIntern(); } - - int getRate() const { return _rate; } - - void finish() { _finalized = true; } - - void queueBuffer(byte *data, uint32 size); -}; - -/** - * Wrapped memory stream. - */ -template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE> -class AppendableMemoryStream : public BaseAppendableMemoryStream { -public: - AppendableMemoryStream(int rate) : BaseAppendableMemoryStream(rate) {} - - bool isStereo() const { return stereo; } - - int readBuffer(int16 *buffer, const int numSamples); -}; - -BaseAppendableMemoryStream::BaseAppendableMemoryStream(int rate) - : _finalized(false), _rate(rate), _pos(0) { - -} - -BaseAppendableMemoryStream::~BaseAppendableMemoryStream() { - // Clear the queue - Common::List<Buffer>::iterator iter; - for (iter = _bufferQueue.begin(); iter != _bufferQueue.end(); ++iter) - delete[] iter->start; -} - -template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE> -int AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16 *buffer, const int numSamples) { - Common::StackLock lock(_mutex); - int samples = numSamples; - while (samples > 0 && !eosIntern()) { - Buffer buf = *_bufferQueue.begin(); - if (_pos == 0) - _pos = buf.start; - - assert(buf.start <= _pos && _pos <= buf.end); - const int samplesLeftInCurBuffer = buf.end - _pos; - if (samplesLeftInCurBuffer == 0) { - delete[] buf.start; - _bufferQueue.erase(_bufferQueue.begin()); - _pos = 0; - continue; - } - - int len = MIN(samples, samplesLeftInCurBuffer / (is16Bit ? 2 : 1)); - samples -= len; - do { - *buffer++ = READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, _pos, isLE); - _pos += (is16Bit ? 2 : 1); - } while (--len); - } - - return numSamples - samples; -} - -void BaseAppendableMemoryStream::queueBuffer(byte *data, uint32 size) { - Common::StackLock lock(_mutex); - -/* - // Verify the buffer size is sane - if (is16Bit && stereo) { - assert((size & 3) == 0); - } else if (is16Bit || stereo) { - assert((size & 1) == 0); - } -*/ - // Verify that the stream has not yet been finalized (by a call to finish()) - assert(!_finalized); - - // Queue the buffer - Buffer buf = {data, data+size}; - _bufferQueue.push_back(buf); - - -#if 0 - // Output some stats - uint totalSize = 0; - Common::List<Buffer>::iterator iter; - for (iter = _bufferQueue.begin(); iter != _bufferQueue.end(); ++iter) - totalSize += iter->end - iter->start; - printf("AppendableMemoryStream::queueBuffer: added a %d byte buf, a total of %d bytes are queued\n", - size, totalSize); -#endif -} - - -#define MAKE_WRAPPED(STEREO, UNSIGNED) \ - if (is16Bit) { \ - if (isLE) \ - return new AppendableMemoryStream<STEREO, true, UNSIGNED, true>(rate); \ - else \ - return new AppendableMemoryStream<STEREO, true, UNSIGNED, false>(rate); \ - } else \ - return new AppendableMemoryStream<STEREO, false, UNSIGNED, false>(rate) - -AppendableAudioStream *makeAppendableAudioStream(int rate, byte _flags) { - const bool isStereo = (_flags & Mixer::FLAG_STEREO) != 0; - const bool is16Bit = (_flags & Mixer::FLAG_16BITS) != 0; - const bool isUnsigned = (_flags & Mixer::FLAG_UNSIGNED) != 0; - const bool isLE = (_flags & Mixer::FLAG_LITTLE_ENDIAN) != 0; - - if (isStereo) { - if (isUnsigned) { - MAKE_WRAPPED(true, true); - } else { - MAKE_WRAPPED(true, false); - } - } else { - if (isUnsigned) { - MAKE_WRAPPED(false, true); - } else { - MAKE_WRAPPED(false, false); - } - } -} - - - - #pragma mark - -#pragma mark --- Appendable audio stream --- +#pragma mark --- Queueing audio stream --- #pragma mark - diff --git a/sound/audiostream.h b/sound/audiostream.h index 192dc249bf..817cd36f95 100644 --- a/sound/audiostream.h +++ b/sound/audiostream.h @@ -289,37 +289,6 @@ struct LinearDiskStreamAudioBlock { SeekableAudioStream *makeLinearDiskStream(Common::SeekableReadStream *stream, LinearDiskStreamAudioBlock *block, int numBlocks, int rate, byte flags, bool disposeStream, uint loopStart, uint loopEnd); -/** - * An audio stream to which additional data can be appended on-the-fly. - * Used by SMUSH, iMuseDigital, the Kyrandia 3 VQA player, etc. - */ -class AppendableAudioStream : public Audio::AudioStream { -public: - - /** - * Queue another audio data buffer for playback. The stream - * will playback all queued buffers, in the order they were - * queued. After all data contained in them has been played, - * the buffer will be delete[]'d (so make sure to allocate them - * with new[], not with malloc). - */ - virtual void queueBuffer(byte *data, uint32 size) = 0; - - /** - * Mark the stream as finished, that is, signal that no further data - * will be appended to it. Only after this has been done can the - * AppendableAudioStream ever 'end' - */ - virtual void finish() = 0; -}; - -/** - * Factory function for an AppendableAudioStream. The rate and flags - * parameters are analog to those used in makeLinearInputStream. - */ -AppendableAudioStream *makeAppendableAudioStream(int rate, byte flags); - - class QueuingAudioStream : public Audio::AudioStream { public: |