[Scummvm-cvs-logs] CVS: residual/mixer audiostream.cpp,1.3,1.4 audiostream.h,1.3,1.4 mixer.cpp,1.4,1.5
Pawel Kolodziejski
aquadran at users.sourceforge.net
Fri Dec 10 12:34:09 CET 2004
- Previous message: [Scummvm-cvs-logs] CVS: residual main.cpp,1.33,1.34 stdafx.h,1.4,1.5 timer.cpp,1.9,1.10
- Next message: [Scummvm-cvs-logs] CVS: residual/mixer mixer.cpp,1.5,1.6 mixer.h,1.4,1.5
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/scummvm/residual/mixer
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1746/mixer
Modified Files:
audiostream.cpp audiostream.h mixer.cpp
Log Message:
rename create/delete_mutex to proper naming,
synced audiostream with main tree
Index: audiostream.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/mixer/audiostream.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- audiostream.cpp 24 Feb 2004 08:20:45 -0000 1.3
+++ audiostream.cpp 10 Dec 2004 20:33:31 -0000 1.4
@@ -20,11 +20,6 @@
#include "mixer.h"
#include "audiostream.h"
-// This used to be an inline template function, but
-// buggy template function handling in MSVC6 forced
-// us to go with the macro approach. So far this is
-// the only template function that MSVC6 seemed to
-// compile incorrectly. Knock on wood.
#define READSAMPLE(is16Bit, isUnsigned, ptr) \
((is16Bit ? READ_BE_UINT16(ptr) : (*ptr << 8)) ^ (isUnsigned ? 0x8000 : 0))
@@ -66,16 +61,6 @@
}
int readBuffer(int16 *buffer, const int numSamples);
- int16 read() {
- //assert(_ptr < _end);
- int16 val = READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, _ptr, isLE);
- _ptr += (is16Bit ? 2 : 1);
- if (_loopPtr && eosIntern()) {
- _ptr = _loopPtr;
- _end = _loopEnd;
- }
- return val;
- }
bool isStereo() const { return stereo; }
bool endOfData() const { return eosIntern(); }
@@ -104,9 +89,11 @@
/**
* Wrapped memory stream.
*/
-template<bool stereo, bool is16Bit, bool isUnsigned>
+template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
class AppendableMemoryStream : public AppendableAudioStream {
protected:
+ MutexRef _mutex;
+
byte *_bufferStart;
byte *_bufferEnd;
byte *_pos;
@@ -117,10 +104,9 @@
inline bool eosIntern() const { return _end == _pos; };
public:
AppendableMemoryStream(int rate, uint bufferSize);
- ~AppendableMemoryStream() { free(_bufferStart); }
+ ~AppendableMemoryStream();
int readBuffer(int16 *buffer, const int numSamples);
- int16 read();
bool isStereo() const { return stereo; }
bool endOfStream() const { return _finalized && eosIntern(); }
bool endOfData() const { return eosIntern(); }
@@ -131,10 +117,9 @@
void finish() { _finalized = true; }
};
-
-template<bool stereo, bool is16Bit, bool isUnsigned>
-AppendableMemoryStream<stereo, is16Bit, isUnsigned>::AppendableMemoryStream(int rate, uint bufferSize)
- : _finalized(false), _rate(rate) {
+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)
@@ -145,24 +130,20 @@
_bufferStart = (byte *)malloc(bufferSize);
_pos = _end = _bufferStart;
_bufferEnd = _bufferStart + bufferSize;
-}
-
-template<bool stereo, bool is16Bit, bool isUnsigned>
-inline int16 AppendableMemoryStream<stereo, is16Bit, isUnsigned>::read() {
- assert(!eosIntern());
- // Wrap around?
- if (_pos >= _bufferEnd)
- _pos = _pos - (_bufferEnd - _bufferStart);
-
- int16 val = READSAMPLE(is16Bit, isUnsigned, _pos);
- _pos += (is16Bit ? 2 : 1);
+ _mutex = createMutex();
+}
- return val;
+template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
+AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::~AppendableMemoryStream() {
+ free(_bufferStart);
+ deleteMutex(_mutex);
}
-template<bool stereo, bool is16Bit, bool isUnsigned>
-int AppendableMemoryStream<stereo, is16Bit, isUnsigned>::readBuffer(int16 *buffer, const int numSamples) {
+template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
+int AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16 *buffer, const int numSamples) {
+ StackLock lock(_mutex);
+
int samples = 0;
while (samples < numSamples && !eosIntern()) {
// Wrap around?
@@ -172,16 +153,18 @@
const byte *endMarker = (_pos > _end) ? _bufferEnd : _end;
const int len = MIN(numSamples, samples + (int)(endMarker - _pos) / (is16Bit ? 2 : 1));
while (samples < len) {
- *buffer++ = READSAMPLE(is16Bit, isUnsigned, _pos);
+ *buffer++ = READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, _pos, isLE);
_pos += (is16Bit ? 2 : 1);
samples++;
}
}
+
return samples;
}
-template<bool stereo, bool is16Bit, bool isUnsigned>
-void AppendableMemoryStream<stereo, is16Bit, isUnsigned>::append(const byte *data, uint32 len) {
+template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
+void AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::append(const byte *data, uint32 len) {
+ StackLock lock(_mutex);
// Verify the buffer size is sane
if (is16Bit && stereo)
@@ -213,39 +196,6 @@
}
}
-
-#if 0
-// Work in progress!!! Not yet usable/finished/working/anything :-)
-
-class ProcInputStream : public AudioStream {
-public:
- typedef void InputProc (void *refCon, int16 *data, uint len);
-
-private:
- const int _rate;
- const bool _isStereo;
- InputProc *_proc;
- void *_refCon;
-
-public:
- ProcInputStream(int rate, bool stereo, InputProc *proc, void *refCon)
- : _rate(rate), _isStereo(stereo), _proc(proc), _refCon(refCon) { }
- int readBuffer(int16 *buffer, const int numSamples) {
- (_proc)(_refCon, buffer, numSamples);
- return numSamples;
- }
- int16 read() {
- int16 sample;
- (_proc)(_refCon, &sample, 1);
- return sample;
- }
- bool isStereo() const { return _isStereo; }
- bool endOfData() const { return false; }
-
- int getRate() const { return _rate; }
-};
-#endif
-
#define MAKE_LINEAR(STEREO, UNSIGNED) \
if (is16Bit) { \
if (isLE) \
@@ -278,15 +228,19 @@
}
#define MAKE_WRAPPED(STEREO, UNSIGNED) \
- if (is16Bit) \
- return new AppendableMemoryStream<STEREO, true, UNSIGNED>(rate, len); \
- else \
- return new AppendableMemoryStream<STEREO, false, UNSIGNED>(rate, len)
+ 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) {
Index: audiostream.h
===================================================================
RCS file: /cvsroot/scummvm/residual/mixer/audiostream.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- audiostream.h 24 Feb 2004 08:20:45 -0000 1.3
+++ audiostream.h 10 Dec 2004 20:33:31 -0000 1.4
@@ -21,6 +21,7 @@
#include "../stdafx.h"
#include "../bits.h"
+
/**
* Generic input stream for the resampling code.
*/
@@ -39,11 +40,6 @@
*/
virtual int readBuffer(int16 *buffer, const int numSamples) = 0;
- /**
- * Read a single (16 bit signed) sample from the stream.
- */
-// virtual int16 read() = 0;
-
/** Is this a stereo stream? */
virtual bool isStereo() const = 0;
@@ -68,19 +64,6 @@
/** Sample rate of the stream. */
virtual int getRate() const = 0;
-
- /**
- * This function returns the number of samples that were delivered to
- * the mixer which is a rough estimate of how moch time of the stream
- * has been played.
- * The exact value is not available as it needs information from the
- * audio device on how many samples have been already played
- * As our buffer is relatively short the estimate is exact enough
- * The return -1 is kind of a hack as this function is only required
- * for the video audio sync in the bs2 cutscenes I am to lazy to
- * implement it for all subclasses
- */
- virtual int getSamplesPlayed() const { return -1; }
};
class AppendableAudioStream : public AudioStream {
@@ -100,7 +83,6 @@
_len -= samples;
return samples;
}
- int16 read() { assert(_len > 0); _len--; return 0; }
bool isStereo() const { return false; }
bool eos() const { return _len <= 0; }
Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/mixer/mixer.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- mixer.cpp 24 Feb 2004 08:20:45 -0000 1.4
+++ mixer.cpp 10 Dec 2004 20:33:31 -0000 1.5
@@ -83,7 +83,7 @@
};
SoundMixer::SoundMixer() {
- _mutex = create_mutex();
+ _mutex = createMutex();
_premixParam = NULL;
_premixProc = NULL;
_outputRate = 22050;
@@ -99,7 +99,7 @@
SoundMixer::~SoundMixer() {
SDL_CloseAudio();
stopAll();
- delete_mutex(_mutex);
+ deleteMutex(_mutex);
}
bool SoundMixer::setSoundProc(SoundProc proc, void *param) {
- Previous message: [Scummvm-cvs-logs] CVS: residual main.cpp,1.33,1.34 stdafx.h,1.4,1.5 timer.cpp,1.9,1.10
- Next message: [Scummvm-cvs-logs] CVS: residual/mixer mixer.cpp,1.5,1.6 mixer.h,1.4,1.5
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Scummvm-git-logs
mailing list