diff options
author | Max Horn | 2003-06-22 11:47:03 +0000 |
---|---|---|
committer | Max Horn | 2003-06-22 11:47:03 +0000 |
commit | 4ead10e4d5352e2fd0311ee09a5a99195d5fd97e (patch) | |
tree | 8126babb045a994797cd951ccd326ceaf2b4d7e2 /sound | |
parent | 9d9336492c23a56c5cbb26836f1452838b9a27b7 (diff) | |
download | scummvm-rg350-4ead10e4d5352e2fd0311ee09a5a99195d5fd97e.tar.gz scummvm-rg350-4ead10e4d5352e2fd0311ee09a5a99195d5fd97e.tar.bz2 scummvm-rg350-4ead10e4d5352e2fd0311ee09a5a99195d5fd97e.zip |
Change names of the stream API in the mixer; added endStream method (stop() halts stream immediately; endStream() lets it first finish playing)
svn-id: r8603
Diffstat (limited to 'sound')
-rw-r--r-- | sound/mixer.cpp | 34 | ||||
-rw-r--r-- | sound/mixer.h | 11 |
2 files changed, 36 insertions, 9 deletions
diff --git a/sound/mixer.cpp b/sound/mixer.cpp index bf2fd544b3..9f862ce65c 100644 --- a/sound/mixer.cpp +++ b/sound/mixer.cpp @@ -73,6 +73,7 @@ class ChannelStream : public Channel { uint32 _bufferSize; uint32 _rate; byte _flags; + bool _finished; public: ChannelStream(SoundMixer *mixer, void *sound, uint32 size, uint rate, byte flags, int32 buffer_size); @@ -83,6 +84,7 @@ public: bool isMusicChannel() { return true; } + void finish() { _finished = true; } }; #ifdef USE_MAD @@ -170,18 +172,30 @@ SoundMixer::~SoundMixer() { _syst->delete_mutex(_mutex); } -int SoundMixer::append(int index, void *sound, uint32 size) { +void SoundMixer::appendStream(int index, void *sound, uint32 size) { _syst->lock_mutex(_mutex); - Channel *chan = _channels[index]; + ChannelStream *chan = dynamic_cast<ChannelStream *>(_channels[index]); if (!chan) { - error("Trying to stream to a nonexistant streamer : %d", index); + error("Trying to append to a nonexistant stream %d", index); } else { - dynamic_cast<ChannelStream *>(chan)->append(sound, size); + chan->append(sound, size); + } + + _syst->unlock_mutex(_mutex); +} + +void SoundMixer::endStream(int index) { + _syst->lock_mutex(_mutex); + + ChannelStream *chan = dynamic_cast<ChannelStream *>(_channels[index]); + if (!chan) { + error("Trying to end a nonexistant streamer : %d", index); + } else { + chan->finish(); } _syst->unlock_mutex(_mutex); - return 1; } int SoundMixer::insertChannel(PlayingSoundHandle *handle, Channel *chan) { @@ -209,7 +223,7 @@ int SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, ui return insertChannel(handle, new ChannelRaw(this, sound, size, rate, flags, id)); } -int SoundMixer::playStream(void *sound, uint32 size, uint rate, byte flags, int32 buffer_size) { +int SoundMixer::newStream(void *sound, uint32 size, uint rate, byte flags, int32 buffer_size) { return insertChannel(NULL, new ChannelStream(this, sound, size, rate, flags, buffer_size)); } @@ -717,6 +731,7 @@ ChannelStream::ChannelStream(SoundMixer *mixer, void *sound, uint32 size, uint r _pos = _ptr; _fpPos = 0; _fpSpeed = (1 << 16) * rate / mixer->_outputRate; + _finished = false; // adjust the magnitude to prevent division error while (size & 0xFFFF0000) @@ -757,6 +772,13 @@ void ChannelStream::mix(int16 *data, uint len) { const int16 *vol_tab = _mixer->_volumeTable; if (_pos == _endOfData) { + // Normally, the stream stays around even if all its data is used up. + // This is in case more data is streamed into it. To make the stream + // go away, one can either stop() it (which takes effect immediately, + // ignoring any remaining sound data), or finish() it, which means + // it will finish playing before it terminates itself. + if (_finished) + destroy(); return; } diff --git a/sound/mixer.h b/sound/mixer.h index bced868538..16e94f3326 100644 --- a/sound/mixer.h +++ b/sound/mixer.h @@ -86,7 +86,6 @@ public: FLAG_LOOP = 1 << 5 // loop the audio }; int playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id = -1); - int playStream(void *sound, uint32 size, uint rate, byte flags, int32 buffer_size); #ifdef USE_MAD int playMP3(PlayingSoundHandle *handle, void *sound, uint32 size, byte flags); int playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration); @@ -110,8 +109,14 @@ public: /** stop playing a specific sound */ void stopID(int id); - /** append to existing sound */ - int append(int index, void * sound, uint32 size); + /** Start a new stream. */ + int newStream(void *sound, uint32 size, uint rate, byte flags, int32 buffer_size); + + /** Append to an existing stream. */ + void appendStream(int index, void * sound, uint32 size); + + /** Mark a stream as finished - it will play all its remaining data, then stop. */ + void endStream(int index); /** Check whether any SFX channel is active.*/ bool hasActiveSFXChannel(); |