[Scummvm-cvs-logs] CVS: scummvm/sound audiostream.cpp,1.67,1.68 mixer.cpp,1.170,1.171 mixer.h,1.83,1.84

Max Horn fingolfin at users.sourceforge.net
Sat Nov 27 12:14:06 CET 2004


Update of /cvsroot/scummvm/scummvm/sound
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10249/sound

Modified Files:
	audiostream.cpp mixer.cpp mixer.h 
Log Message:
Removed the (highly SCUMM specific) 'appendable stream' API from SoundMixer; SCUMM now uses the appendable stream directly

Index: audiostream.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.cpp,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -d -r1.67 -r1.68
--- audiostream.cpp	27 Nov 2004 13:54:08 -0000	1.67
+++ audiostream.cpp	27 Nov 2004 17:09:05 -0000	1.68
@@ -186,6 +186,8 @@
 template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
 class AppendableMemoryStream : public AppendableAudioStream {
 protected:
+	OSystem::MutexRef _mutex;
+
 	byte *_bufferStart;
 	byte *_bufferEnd;
 	byte *_pos;
@@ -196,7 +198,7 @@
 	inline bool eosIntern() const { return _end == _pos; };
 public:
 	AppendableMemoryStream(int rate, uint bufferSize);
-	~AppendableMemoryStream()		{ free(_bufferStart); }
+	~AppendableMemoryStream();
 	int readBuffer(int16 *buffer, const int numSamples);
 
 	bool isStereo() const		{ return stereo; }
@@ -222,10 +224,20 @@
 	_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?
@@ -246,6 +258,7 @@
 
 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)

Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.170
retrieving revision 1.171
diff -u -d -r1.170 -r1.171
--- mixer.cpp	27 Nov 2004 16:26:54 -0000	1.170
+++ mixer.cpp	27 Nov 2004 17:09:05 -0000	1.171
@@ -90,14 +90,6 @@
 	uint32 getElapsedTime();
 };
 
-class ChannelStream : public Channel {
-public:
-	ChannelStream(SoundMixer *mixer, PlayingSoundHandle *handle, uint rate, byte flags, uint32 buffer_size);
-	void append(void *sound, uint32 size);
-
-	void finish();
-};
-
 
 #pragma mark -
 #pragma mark --- SoundMixer ---
@@ -155,68 +147,6 @@
 	_premixChannel = new Channel(this, 0, stream, false, false);
 }
 
-void SoundMixer::newStream(PlayingSoundHandle *handle, uint rate, byte flags, uint32 buffer_size, byte volume, int8 balance) {
-	Common::StackLock lock(_mutex);
-
-	Channel *chan = new ChannelStream(this, handle, rate, flags, buffer_size);
-	chan->setVolume(volume);
-	chan->setBalance(balance);
-	insertChannel(handle, chan);
-}
-
-void SoundMixer::appendStream(PlayingSoundHandle handle, void *sound, uint32 size) {
-	Common::StackLock lock(_mutex);
-	
-	if (!handle.isActive())
-		return;
-
-	int index = handle.getIndex();
-
-	if ((index < 0) || (index >= NUM_CHANNELS)) {
-		warning("soundMixer::appendStream has invalid index %d", index);
-		return;
-	}
-
-	ChannelStream *chan;
-#if !defined(_WIN32_WCE) && !defined(__PALM_OS__)
-	chan = dynamic_cast<ChannelStream *>(_channels[index]);
-#else
-	chan = (ChannelStream*)_channels[index];
-#endif
-	if (!chan) {
-		error("Trying to append to nonexistant stream : %d", index);
-	} else {
-		chan->append(sound, size);
-	}
-}
-
-void SoundMixer::endStream(PlayingSoundHandle handle) {
-	Common::StackLock lock(_mutex);
-
-	// Simply ignore stop requests for handles of sounds that already terminated
-	if (!handle.isActive())
-		return;
-
-	int index = handle.getIndex();
-
-	if ((index < 0) || (index >= NUM_CHANNELS)) {
-		warning("soundMixer::endStream has invalid index %d", index);
-		return;
-	}
-
-	ChannelStream *chan;
-#if !defined(_WIN32_WCE) && !defined(__PALM_OS__)
-	chan = dynamic_cast<ChannelStream *>(_channels[index]);
-#else
-	chan = (ChannelStream*)_channels[index];
-#endif
-	if (!chan) {
-		error("Trying to end a nonexistant streamer : %d", index);
-	} else {
-		chan->finish();
-	}
-}
-
 void SoundMixer::insertChannel(PlayingSoundHandle *handle, Channel *chan) {
 
 	int index = -1;
@@ -586,21 +516,3 @@
 	// FIXME: This won't work very well if the sound is paused.
 	return 1000 * seconds + milliseconds + delta;
 }
-
-ChannelStream::ChannelStream(SoundMixer *mixer, PlayingSoundHandle *handle,
-							uint rate, byte flags, uint32 buffer_size)
-	: Channel(mixer, handle, false) {
-	// Create the input stream
-	_input = makeAppendableAudioStream(rate, flags, buffer_size);
-
-	// Get a rate converter instance
-	_converter = makeRateConverter(_input->getRate(), mixer->getOutputRate(), _input->isStereo(), (flags & SoundMixer::FLAG_REVERSE_STEREO) != 0);
-}
-
-void ChannelStream::finish() {
-	((AppendableAudioStream *)_input)->finish();
-}
-
-void ChannelStream::append(void *data, uint32 len) {
-	((AppendableAudioStream *)_input)->append((const byte *)data, len);
-}

Index: mixer.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.h,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -d -r1.83 -r1.84
--- mixer.h	27 Nov 2004 16:26:54 -0000	1.83
+++ mixer.h	27 Nov 2004 17:09:05 -0000	1.84
@@ -135,22 +135,6 @@
 
 
 
-	/** Start a new stream. */
-	void newStream(PlayingSoundHandle *handle, uint rate, byte flags, uint32 buffer_size, byte volume = 255, int8 balance = 0);
-
-	/** Append to an existing stream. */
-	void appendStream(PlayingSoundHandle handle, void *sound, uint32 size);
-
-	/**
-	 * Mark a stream as finished.
-	 * Where stopHandle() would stop the sound immediately, when using this
-	 * method, the stream will first finish playing all its data before it
-	 * finally stops.
-	 */
-	void endStream(PlayingSoundHandle handle);
-
-
-
 	/**
 	 * Stop all currently playing sounds.
 	 */





More information about the Scummvm-git-logs mailing list