diff options
author | Johannes Schickel | 2010-01-30 15:28:07 +0000 |
---|---|---|
committer | Johannes Schickel | 2010-01-30 15:28:07 +0000 |
commit | 3cc0ef6c1cf5574168456e74736baf8f4e231af6 (patch) | |
tree | a9267881522e6e3704d1d364ce67123d82e4af81 /sound/decoders | |
parent | a505d32eff97e31ac73495e202f9c01f6490dcf8 (diff) | |
download | scummvm-rg350-3cc0ef6c1cf5574168456e74736baf8f4e231af6.tar.gz scummvm-rg350-3cc0ef6c1cf5574168456e74736baf8f4e231af6.tar.bz2 scummvm-rg350-3cc0ef6c1cf5574168456e74736baf8f4e231af6.zip |
Remove RawMemoryStream.
svn-id: r47717
Diffstat (limited to 'sound/decoders')
-rw-r--r-- | sound/decoders/aiff.cpp | 2 | ||||
-rw-r--r-- | sound/decoders/iff_sound.cpp | 2 | ||||
-rw-r--r-- | sound/decoders/raw.cpp | 119 | ||||
-rw-r--r-- | sound/decoders/raw.h | 21 | ||||
-rw-r--r-- | sound/decoders/voc.cpp | 2 | ||||
-rw-r--r-- | sound/decoders/wave.cpp | 2 |
6 files changed, 5 insertions, 143 deletions
diff --git a/sound/decoders/aiff.cpp b/sound/decoders/aiff.cpp index e474e999d0..2f12669072 100644 --- a/sound/decoders/aiff.cpp +++ b/sound/decoders/aiff.cpp @@ -173,7 +173,7 @@ SeekableAudioStream *makeAIFFStream(Common::SeekableReadStream &stream) { stream.read(data, size); // Since we allocated our own buffer for the data, we must specify DisposeAfterUse::YES. - return makeRawMemoryStream(data, size, rate, flags); + return makeRawStream(data, size, rate, flags); } } // End of namespace Audio diff --git a/sound/decoders/iff_sound.cpp b/sound/decoders/iff_sound.cpp index f394b55ef0..b365015a2b 100644 --- a/sound/decoders/iff_sound.cpp +++ b/sound/decoders/iff_sound.cpp @@ -108,7 +108,7 @@ AudioStream *make8SVXStream(Common::ReadStream &input, bool loop) { A8SVXLoader loader; loader.load(input); - SeekableAudioStream *stream = Audio::makeRawMemoryStream((byte *)loader._data, loader._dataSize, loader._header.samplesPerSec, 0); + SeekableAudioStream *stream = Audio::makeRawStream((byte *)loader._data, loader._dataSize, loader._header.samplesPerSec, 0); uint32 loopStart = 0, loopEnd = 0; if (loop) { diff --git a/sound/decoders/raw.cpp b/sound/decoders/raw.cpp index df3d178c7e..e7bbb9b630 100644 --- a/sound/decoders/raw.cpp +++ b/sound/decoders/raw.cpp @@ -42,86 +42,9 @@ namespace Audio { #pragma mark - -#pragma mark --- RawMemoryStream --- -#pragma mark - - -/** - * A simple raw audio stream, purely memory based. It operates on a single - * block of data, which is passed to it upon creation. - * Optionally supports looping the sound. - * - * Design note: This code tries to be as efficient as possible (without - * resorting to assembly, that is). To this end, it is written as a template - * class. This way the compiler can create optimized code for each special - * case. This results in a total of 12 versions of the code being generated. - */ -template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE> -class RawMemoryStream : public SeekableAudioStream { -protected: - const byte *_ptr; - const byte *_end; - const int _rate; - const byte *_origPtr; - const DisposeAfterUse::Flag _disposeAfterUse; - const Timestamp _playtime; - -public: - RawMemoryStream(int rate, const byte *ptr, uint len, DisposeAfterUse::Flag autoFreeMemory) - : _ptr(ptr), _end(ptr+len), _rate(rate), _origPtr(ptr), - _disposeAfterUse(autoFreeMemory), - _playtime(0, len / (is16Bit ? 2 : 1) / (stereo ? 2 : 1), rate) { - } - - virtual ~RawMemoryStream() { - if (_disposeAfterUse == DisposeAfterUse::YES) - free(const_cast<byte *>(_origPtr)); - } - - int readBuffer(int16 *buffer, const int numSamples); - - bool isStereo() const { return stereo; } - bool endOfData() const { return _ptr >= _end; } - - int getRate() const { return _rate; } - bool seek(const Timestamp &where); - Timestamp getLength() const { return _playtime; } -}; - -template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE> -int RawMemoryStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16 *buffer, const int numSamples) { - int samples = numSamples; - while (samples > 0 && _ptr < _end) { - int len = MIN(samples, (int)(_end - _ptr) / (is16Bit ? 2 : 1)); - samples -= len; - do { - *buffer++ = READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, _ptr, isLE); - _ptr += (is16Bit ? 2 : 1); - } while (--len); - } - return numSamples-samples; -} - -template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE> -bool RawMemoryStream<stereo, is16Bit, isUnsigned, isLE>::seek(const Timestamp &where) { - const uint8 *ptr = _origPtr + convertTimeToStreamPos(where, getRate(), isStereo()).totalNumberOfFrames() * (is16Bit ? 2 : 1); - if (ptr > _end) { - _ptr = _end; - return false; - } else if (ptr == _end) { - _ptr = _end; - return true; - } else { - _ptr = ptr; - return true; - } -} - -#pragma mark - #pragma mark --- RawDiskStream --- #pragma mark - - - /** * RawDiskStream. This can stream raw PCM audio data from disk. The * function takes an pointer to an array of RawDiskStreamAudioBlock which defines the @@ -153,7 +76,7 @@ protected: RawStreamBlockList::const_iterator _curBlock; ///< Current audio block number public: RawDiskStream(int rate, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream, const RawStreamBlockList &blocks) - : _rate(rate), _playtime(0, rate), _stream(stream), _disposeAfterUse(disposeStream), _blocks(blocks), _curBlock(blocks.begin()) { + : _rate(rate), _playtime(0, rate), _stream(stream), _disposeAfterUse(disposeStream), _blocks(blocks), _curBlock(_blocks.begin()) { assert(_blocks.size() > 0); @@ -299,46 +222,6 @@ bool RawDiskStream<stereo, is16Bit, isUnsigned, isLE>::seek(const Timestamp &whe * particular case it should actually help it :-) */ -#define MAKE_LINEAR(STEREO, UNSIGNED) \ - if (is16Bit) { \ - if (isLE) \ - return new RawMemoryStream<STEREO, true, UNSIGNED, true>(rate, ptr, len, autoFree); \ - else \ - return new RawMemoryStream<STEREO, true, UNSIGNED, false>(rate, ptr, len, autoFree); \ - } else \ - return new RawMemoryStream<STEREO, false, UNSIGNED, false>(rate, ptr, len, autoFree) - -SeekableAudioStream *makeRawMemoryStream(const byte *ptr, uint32 len, - int rate, byte flags, - DisposeAfterUse::Flag autoFree - ) { - const bool isStereo = (flags & Audio::FLAG_STEREO) != 0; - const bool is16Bit = (flags & Audio::FLAG_16BITS) != 0; - const bool isUnsigned = (flags & Audio::FLAG_UNSIGNED) != 0; - const bool isLE = (flags & Audio::FLAG_LITTLE_ENDIAN) != 0; - - // Verify the buffer sizes are sane - if (is16Bit && isStereo) { - assert((len & 3) == 0); - } else if (is16Bit || isStereo) { - assert((len & 1) == 0); - } - - if (isStereo) { - if (isUnsigned) { - MAKE_LINEAR(true, true); - } else { - MAKE_LINEAR(true, false); - } - } else { - if (isUnsigned) { - MAKE_LINEAR(false, true); - } else { - MAKE_LINEAR(false, false); - } - } -} - #define MAKE_LINEAR_DISK(STEREO, UNSIGNED) \ if (is16Bit) { \ if (isLE) \ diff --git a/sound/decoders/raw.h b/sound/decoders/raw.h index 92add95131..c81884dc00 100644 --- a/sound/decoders/raw.h +++ b/sound/decoders/raw.h @@ -65,27 +65,6 @@ enum RawFlags { /** - * Creates a audio stream, which plays the given raw data. - * - * The data pointer is assumed to have been allocated with malloc(). - * In particular, if autofreeBuffer is set to DisposeAfterUse::YES, - * then this buffer will be deallocated using free(). So do not - * use a buffer allocated with new[]! - * - * @param ptr pointer to a buffer containing audio data - * @param len length of the buffer in bytes - * @param rate sample rate of the data - * @param flags audio format flags combination - * @see RawFlags - * @param autofreeBuffer whether the data buffer should be destroyed after playback - * @return The new SeekableAudioStream (or 0 on failure). - */ -SeekableAudioStream *makeRawMemoryStream(const byte *ptr, uint32 len, - int rate, byte flags, - DisposeAfterUse::Flag autofreeBuffer = DisposeAfterUse::YES - ); - -/** * Struct used to define the audio data to be played by a RawDiskStream. */ struct RawDiskStreamAudioBlock { diff --git a/sound/decoders/voc.cpp b/sound/decoders/voc.cpp index 9cb59db85f..65d594d96f 100644 --- a/sound/decoders/voc.cpp +++ b/sound/decoders/voc.cpp @@ -390,7 +390,7 @@ SeekableAudioStream *makeVOCStream(Common::SeekableReadStream &stream, byte flag if (!data) return 0; - return makeRawMemoryStream(data, size, rate, flags); + return makeRawStream(data, size, rate, flags); #endif } diff --git a/sound/decoders/wave.cpp b/sound/decoders/wave.cpp index 018bd97bce..eeab026ae5 100644 --- a/sound/decoders/wave.cpp +++ b/sound/decoders/wave.cpp @@ -188,7 +188,7 @@ RewindableAudioStream *makeWAVStream(Common::SeekableReadStream *stream, Dispose if (disposeAfterUse == DisposeAfterUse::YES) delete stream; - return makeRawMemoryStream(data, size, rate, flags); + return makeRawStream(data, size, rate, flags); } } // End of namespace Audio |