[Scummvm-cvs-logs] CVS: scummvm/scumm sound.cpp,1.409,1.410 sound.h,1.77,1.78
Max Horn
fingolfin at users.sourceforge.net
Sat Jan 8 19:17:03 CET 2005
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/common file.cpp,1.76,1.77 file.h,1.31,1.32 stream.cpp,1.5,1.6 stream.h,1.11,1.12 system.cpp,1.17,1.18 system.h,1.80,1.81
- Next message: [Scummvm-cvs-logs] CVS: scummvm/scumm/smush smush_mixer.h,1.11,1.12 smush_player.h,1.39,1.40
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/scummvm/scummvm/scumm
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20713/scumm
Modified Files:
sound.cpp sound.h
Log Message:
Moving AppendableAudioStream into SCUMM engine, as it is only used there
Index: sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/sound.cpp,v
retrieving revision 1.409
retrieving revision 1.410
diff -u -d -r1.409 -r1.410
--- sound.cpp 1 Jan 2005 16:09:16 -0000 1.409
+++ sound.cpp 9 Jan 2005 03:15:58 -0000 1.410
@@ -2237,4 +2237,150 @@
}
+#pragma mark -
+#pragma mark --- Appendable audio stream ---
+#pragma mark -
+
+
+/**
+ * Wrapped memory stream.
+ */
+template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
+class AppendableMemoryStream : public AppendableAudioStream {
+protected:
+ OSystem::MutexRef _mutex;
+
+ byte *_bufferStart;
+ byte *_bufferEnd;
+ byte *_pos;
+ byte *_end;
+ bool _finalized;
+ const int _rate;
+
+ inline bool eosIntern() const { return _end == _pos; };
+public:
+ AppendableMemoryStream(int rate, uint bufferSize);
+ ~AppendableMemoryStream();
+ int readBuffer(int16 *buffer, const int numSamples);
+
+ bool isStereo() const { return stereo; }
+ bool endOfStream() const { return _finalized && eosIntern(); }
+ bool endOfData() const { return eosIntern(); }
+
+ int getRate() const { return _rate; }
+
+ void append(const byte *data, uint32 len);
+ void finish() { _finalized = true; }
+};
+
+template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
+AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::AppendableMemoryStream(int rate, uint bufferSize)
+ : _finalized(false), _rate(rate) {
+
+ // Verify the buffer size is sane
+ if (is16Bit && stereo)
+ assert((bufferSize & 3) == 0);
+ else if (is16Bit || stereo)
+ assert((bufferSize & 1) == 0);
+
+ _bufferStart = (byte *)malloc(bufferSize);
+ _pos = _end = _bufferStart;
+ _bufferEnd = _bufferStart + bufferSize;
+
+ _mutex = g_system->createMutex();
+}
+
+template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
+AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::~AppendableMemoryStream() {
+ free(_bufferStart);
+ g_system->deleteMutex(_mutex);
+}
+
+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 = 0;
+ while (samples < numSamples && !eosIntern()) {
+ // Wrap around?
+ if (_pos >= _bufferEnd)
+ _pos = _pos - (_bufferEnd - _bufferStart);
+
+ const byte *endMarker = (_pos > _end) ? _bufferEnd : _end;
+ const int len = MIN(numSamples, samples + (int)(endMarker - _pos) / (is16Bit ? 2 : 1));
+ while (samples < len) {
+ *buffer++ = READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, _pos, isLE);
+ _pos += (is16Bit ? 2 : 1);
+ samples++;
+ }
+ }
+
+ return samples;
+}
+
+template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
+void AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::append(const byte *data, uint32 len) {
+ Common::StackLock lock(_mutex);
+
+ // Verify the buffer size is sane
+ if (is16Bit && stereo)
+ assert((len & 3) == 0);
+ else if (is16Bit || stereo)
+ assert((len & 1) == 0);
+
+ // Verify that the stream has not yet been finalized (by a call to finish())
+ assert(!_finalized);
+
+ if (_end + len > _bufferEnd) {
+ // Wrap-around case
+ uint32 size_to_end_of_buffer = _bufferEnd - _end;
+ len -= size_to_end_of_buffer;
+ if ((_end < _pos) || (_bufferStart + len >= _pos)) {
+ debug(2, "AppendableMemoryStream: buffer overflow (A)");
+ return;
+ }
+ memcpy(_end, data, size_to_end_of_buffer);
+ memcpy(_bufferStart, data + size_to_end_of_buffer, len);
+ _end = _bufferStart + len;
+ } else {
+ if ((_end < _pos) && (_end + len >= _pos)) {
+ debug(2, "AppendableMemoryStream: buffer overflow (B)");
+ return;
+ }
+ memcpy(_end, data, len);
+ _end += len;
+ }
+}
+
+
+#define MAKE_WRAPPED(STEREO, UNSIGNED) \
+ if (is16Bit) { \
+ if (isLE) \
+ return new AppendableMemoryStream<STEREO, true, UNSIGNED, true>(rate, len); \
+ else \
+ return new AppendableMemoryStream<STEREO, true, UNSIGNED, false>(rate, len); \
+ } else \
+ return new AppendableMemoryStream<STEREO, false, UNSIGNED, false>(rate, len)
+
+AppendableAudioStream *makeAppendableAudioStream(int rate, byte _flags, uint32 len) {
+ const bool isStereo = (_flags & SoundMixer::FLAG_STEREO) != 0;
+ const bool is16Bit = (_flags & SoundMixer::FLAG_16BITS) != 0;
+ const bool isUnsigned = (_flags & SoundMixer::FLAG_UNSIGNED) != 0;
+ const bool isLE = (_flags & SoundMixer::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);
+ }
+ }
+}
+
} // End of namespace Scumm
Index: sound.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/sound.h,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -d -r1.77 -r1.78
--- sound.h 1 Jan 2005 16:09:16 -0000 1.77
+++ sound.h 9 Jan 2005 03:15:58 -0000 1.78
@@ -22,6 +22,7 @@
#define SOUND_H
#include "common/scummsys.h"
+#include "sound/audiostream.h"
#include "sound/mixer.h"
class File;
@@ -129,6 +130,19 @@
bool isSoundInQueue(int sound) const;
};
+/**
+ * An audio stream to which additional data can be appended on-the-fly.
+ * Used by SMUSH and iMuseDigital.
+ */
+class AppendableAudioStream : public AudioStream {
+public:
+ virtual void append(const byte *data, uint32 len) = 0;
+ virtual void finish() = 0;
+};
+
+AppendableAudioStream *makeAppendableAudioStream(int rate, byte _flags, uint32 len);
+
+
} // End of namespace Scumm
#endif
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/common file.cpp,1.76,1.77 file.h,1.31,1.32 stream.cpp,1.5,1.6 stream.h,1.11,1.12 system.cpp,1.17,1.18 system.h,1.80,1.81
- Next message: [Scummvm-cvs-logs] CVS: scummvm/scumm/smush smush_mixer.h,1.11,1.12 smush_player.h,1.39,1.40
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Scummvm-git-logs
mailing list