diff options
| -rw-r--r-- | scumm/smush/smush_mixer.cpp | 14 | ||||
| -rw-r--r-- | scumm/smush/smush_mixer.h | 2 | ||||
| -rw-r--r-- | scumm/smush/smush_player.cpp | 9 | ||||
| -rw-r--r-- | scumm/smush/smush_player.h | 3 | ||||
| -rw-r--r-- | sound/audiostream.cpp | 15 | ||||
| -rw-r--r-- | sound/mixer.cpp | 88 | ||||
| -rw-r--r-- | sound/mixer.h | 16 | 
7 files changed, 34 insertions, 113 deletions
| diff --git a/scumm/smush/smush_mixer.cpp b/scumm/smush/smush_mixer.cpp index 3c0471e178..f7309cb87e 100644 --- a/scumm/smush/smush_mixer.cpp +++ b/scumm/smush/smush_mixer.cpp @@ -93,7 +93,8 @@ bool SmushMixer::handleFrame() {  				delete _channels[i].chan;  				_channels[i].id = -1;  				_channels[i].chan = NULL; -				_mixer->endStream(_channels[i].handle); +				_channels[i].stream->finish(); +				_channels[i].stream = 0;  			} else {  				int32 rate, vol, pan;  				bool stereo, is_16bit; @@ -119,11 +120,13 @@ bool SmushMixer::handleFrame() {  				}  				if (_mixer->isReady()) { -					if (!_channels[i].handle.isActive()) -						_mixer->newStream(&_channels[i].handle, rate, flags, 500000); +					if (!_channels[i].handle.isActive()) { +						_channels[i].stream = makeAppendableAudioStream(rate, flags, 500000); +						_mixer->playInputStream(&_channels[i].handle, _channels[i].stream, false); +					}  					_mixer->setChannelVolume(_channels[i].handle, vol);  					_mixer->setChannelBalance(_channels[i].handle, pan); -					_mixer->appendStream(_channels[i].handle, data, size); +					_channels[i].stream->append((byte *)data, size);  				}  				free(data);  			} @@ -139,7 +142,8 @@ bool SmushMixer::stop() {  			delete _channels[i].chan;  			_channels[i].id = -1;  			_channels[i].chan = NULL; -			_mixer->endStream(_channels[i].handle); +			_channels[i].stream->finish(); +			_channels[i].stream = 0;  		}  	}  	return true; diff --git a/scumm/smush/smush_mixer.h b/scumm/smush/smush_mixer.h index da6b4be6f7..73f83ae578 100644 --- a/scumm/smush/smush_mixer.h +++ b/scumm/smush/smush_mixer.h @@ -23,6 +23,7 @@  #define SMUSH_MIXER_H  #include "stdafx.h" +#include "sound/audiostream.h"  #include "sound/mixer.h"  namespace Scumm { @@ -40,6 +41,7 @@ private:  		int id;  		SmushChannel *chan;  		PlayingSoundHandle handle; +		AppendableAudioStream *stream;  	} _channels[NUM_CHANNELS];  	int _soundFrequency; diff --git a/scumm/smush/smush_player.cpp b/scumm/smush/smush_player.cpp index 5d6d764bf7..3852ebbb59 100644 --- a/scumm/smush/smush_player.cpp +++ b/scumm/smush/smush_player.cpp @@ -314,6 +314,7 @@ void SmushPlayer::release() {  	_vm->_mixer->stopHandle(_compressedFileSoundHandle);  	_vm->_mixer->stopHandle(_IACTchannel); +	_IACTstream = 0;  	_vm->_fullRedraw = true; @@ -494,9 +495,11 @@ void SmushPlayer::handleIACT(Chunk &b) {  						}  					} while (--count); -					if (!_IACTchannel.isActive()) -						_vm->_mixer->newStream(&_IACTchannel, 22050, SoundMixer::FLAG_STEREO | SoundMixer::FLAG_16BITS, 400000); -					_vm->_mixer->appendStream(_IACTchannel, output_data, 0x1000); +					if (!_IACTchannel.isActive()) { +						_IACTstream = makeAppendableAudioStream(22050, SoundMixer::FLAG_STEREO | SoundMixer::FLAG_16BITS, 400000); +						_vm->_mixer->playInputStream(&_IACTchannel, _IACTstream, false); +					} +					_IACTstream->append(output_data, 0x1000);  					bsize -= len;  					d_src += len; diff --git a/scumm/smush/smush_player.h b/scumm/smush/smush_player.h index b9c0b5c7de..d0ce75da41 100644 --- a/scumm/smush/smush_player.h +++ b/scumm/smush/smush_player.h @@ -26,6 +26,7 @@  #include "scumm/smush/chunk.h"  #include "scumm/smush/codec37.h"  #include "scumm/smush/codec47.h" +#include "sound/audiostream.h"  #include "sound/mixer.h"  namespace Scumm { @@ -57,6 +58,8 @@ private:  	int32 _frame;  	PlayingSoundHandle _IACTchannel; +	AppendableAudioStream *_IACTstream; +  	PlayingSoundHandle _compressedFileSoundHandle;  	bool _compressedFileMode;  	File _compressedFile; diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp index 81c051221f..348b4084f7 100644 --- a/sound/audiostream.cpp +++ b/sound/audiostream.cpp @@ -186,6 +186,8 @@ int LinearMemoryStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16 *buf  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 @@ protected:  	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 @@ AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::AppendableMemoryStrea  	_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 @@ int AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16  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) diff --git a/sound/mixer.cpp b/sound/mixer.cpp index cc6164ab0a..64c748adcb 100644 --- a/sound/mixer.cpp +++ b/sound/mixer.cpp @@ -90,14 +90,6 @@ public:  	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 @@ void SoundMixer::setupPremix(AudioStream *stream) {  	_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 @@ uint32 Channel::getElapsedTime() {  	// 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); -} diff --git a/sound/mixer.h b/sound/mixer.h index 4f89d20666..b51f4976b1 100644 --- a/sound/mixer.h +++ b/sound/mixer.h @@ -135,22 +135,6 @@ public: -	/** 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.  	 */ | 
