diff options
author | Paweł Kołodziejski | 2002-10-15 21:55:04 +0000 |
---|---|---|
committer | Paweł Kołodziejski | 2002-10-15 21:55:04 +0000 |
commit | 09225027f1f8b87360952904b6f55f69976b040a (patch) | |
tree | 4cca795d9594cdfbb3b6d4ba53ed090e6e41fae3 /sound | |
parent | 15ac1c1ee9292073fb8dead67111e31c8f328690 (diff) | |
download | scummvm-rg350-09225027f1f8b87360952904b6f55f69976b040a.tar.gz scummvm-rg350-09225027f1f8b87360952904b6f55f69976b040a.tar.bz2 scummvm-rg350-09225027f1f8b87360952904b6f55f69976b040a.zip |
changes to imuse
svn-id: r5157
Diffstat (limited to 'sound')
-rw-r--r-- | sound/mixer.cpp | 37 | ||||
-rw-r--r-- | sound/mixer.h | 8 |
2 files changed, 25 insertions, 20 deletions
diff --git a/sound/mixer.cpp b/sound/mixer.cpp index e13f6c601b..7edca2a86c 100644 --- a/sound/mixer.cpp +++ b/sound/mixer.cpp @@ -27,6 +27,7 @@ SoundMixer::SoundMixer() { _volumeTable = (int16 *)calloc(256 * sizeof(int16), 1); + _beginSlots = 0; } SoundMixer::~SoundMixer() { @@ -67,7 +68,7 @@ int SoundMixer::append(int index, void * sound, uint32 size, uint rate, byte fla int SoundMixer::insertAt(PlayingSoundHandle * handle, int index, Channel * chan) { if(index == -1) { - for (int i = 0; i != NUM_CHANNELS; i++) + for (int i = _beginSlots; i != NUM_CHANNELS; i++) if (_channels[i] == NULL) { index = i; break; } if(index == -1) { warning("SoundMixer::out of mixer slots"); @@ -85,7 +86,7 @@ int SoundMixer::insertAt(PlayingSoundHandle * handle, int index, Channel * chan) } int SoundMixer::playRaw(PlayingSoundHandle * handle, void * sound, uint32 size, uint rate, byte flags) { - for (int i = 0; i != NUM_CHANNELS; i++) { + for (int i = _beginSlots; i != NUM_CHANNELS; i++) { if (_channels[i] == NULL) { return insertAt(handle, i, new ChannelRaw(this, sound, size, rate, flags, -1)); } @@ -96,7 +97,7 @@ int SoundMixer::playRaw(PlayingSoundHandle * handle, void * sound, uint32 size, } int SoundMixer::playRaw(PlayingSoundHandle * handle, void * sound, uint32 size, uint rate, byte flags, int id) { - for (int i = 0; i != NUM_CHANNELS; i++) { + for (int i = _beginSlots; i != NUM_CHANNELS; i++) { if (_channels[i] == NULL) { return insertAt(handle, i, new ChannelRaw(this, sound, size, rate, flags, id)); } @@ -107,24 +108,21 @@ int SoundMixer::playRaw(PlayingSoundHandle * handle, void * sound, uint32 size, } int SoundMixer::playStream(PlayingSoundHandle * handle, int idx, void * sound, uint32 size, - uint rate, byte flags, int32 timeout) { - return insertAt(handle, idx, new ChannelStream(this, sound, size, rate, flags, timeout)); + uint rate, byte flags, int32 timeout, int32 buffer_size) { + return insertAt(handle, idx, new ChannelStream(this, sound, size, rate, flags, timeout, buffer_size)); } -void SoundMixer::stopChannel(int index) { - if ((index < 0) || (index >= NUM_CHANNELS)) { - warning("soundMixer::stopChannel has invalid index %d", index); +void SoundMixer::beginSlots(int index) { + if ((index < 0) && (index >= NUM_CHANNELS)) { + warning("soundMixer::beginSlots has invalid index %d", index); return; } - - if (_channels[index] != NULL) { - _channels[index]->_toBeDestroyed = true; - } + _beginSlots = index; } #ifdef COMPRESSED_SOUND_FILE int SoundMixer::playMP3(PlayingSoundHandle * handle, void *sound, uint32 size, byte flags) { - for (int i = 0; i != NUM_CHANNELS; i++) { + for (int i = _beginSlots; i != NUM_CHANNELS; i++) { if (_channels[i] == NULL) { return insertAt(handle, i, new ChannelMP3(this, sound, size, flags)); } @@ -135,7 +133,7 @@ int SoundMixer::playMP3(PlayingSoundHandle * handle, void *sound, uint32 size, b } int SoundMixer::playMP3CDTrack(PlayingSoundHandle * handle, File * file, mad_timer_t duration) { /* Stop the previously playing CD track (if any) */ - for (int i = 0; i != NUM_CHANNELS; i++) { + for (int i = _beginSlots; i != NUM_CHANNELS; i++) { if (_channels[i] == NULL) { return insertAt(handle, i, new ChannelMP3CDMusic(this, file, duration)); } @@ -201,6 +199,11 @@ void SoundMixer::stop(PlayingSoundHandle psh) { } void SoundMixer::stop(int index) { + if ((index < 0) || (index >= NUM_CHANNELS)) { + warning("soundMixer::stop has invalid index %d", index); + return; + } + if (_channels[index]) _channels[index]->destroy(); } @@ -210,7 +213,7 @@ void SoundMixer::pause(bool paused) { } bool SoundMixer::hasActiveChannel() { - for (int i = 0; i != NUM_CHANNELS; i++) + for (int i = _beginSlots; i != NUM_CHANNELS; i++) if (_channels[i]) return true; return false; @@ -624,10 +627,10 @@ void SoundMixer::ChannelRaw::realDestroy() { } SoundMixer::ChannelStream::ChannelStream(SoundMixer * mixer, void * sound, uint32 size, uint rate, - byte flags, int32 timeout) { + byte flags, int32 timeout, int32 buffer_size) { _mixer = mixer; _flags = flags; - _bufferSize = 2000000; + _bufferSize = buffer_size; _ptr = (byte *)malloc(_bufferSize); memcpy(_ptr, sound, size); _endOfData = _ptr + size; diff --git a/sound/mixer.h b/sound/mixer.h index e5d7b4aeaa..491ee5fccb 100644 --- a/sound/mixer.h +++ b/sound/mixer.h @@ -85,7 +85,7 @@ private: byte _flags; public: - ChannelStream(SoundMixer * mixer, void * sound, uint32 size, uint rate, byte flags, int32 timout); + ChannelStream(SoundMixer * mixer, void * sound, uint32 size, uint rate, byte flags, int32 timout, int32 buffer_size); void append(void * sound, uint32 size); void mix(int16 * data, uint len); @@ -163,12 +163,15 @@ public: Channel * _channels[NUM_CHANNELS]; PlayingSoundHandle * _handles[NUM_CHANNELS]; + int _beginSlots; + SoundMixer(); ~SoundMixer(); int insertAt(PlayingSoundHandle * handle, int index, Channel * chan); void append(void * data, uint32 len); void unInsert(Channel * chan); + void beginSlots(int index); /* start playing a raw sound */ enum { @@ -183,8 +186,7 @@ public: int playRaw(PlayingSoundHandle * handle, void * sound, uint32 size, uint rate, byte flags); int playRaw(PlayingSoundHandle * handle, void * sound, uint32 size, uint rate, byte flags, int id); int playStream(PlayingSoundHandle * handle, int index, void * sound, uint32 size, uint rate, - byte flags, int32 timeout = 3); - void stopChannel(int index); + byte flags, int32 timeout = 3, int32 buffer_size = 2000000); #ifdef COMPRESSED_SOUND_FILE int playMP3(PlayingSoundHandle * handle, void * sound, uint32 size, byte flags); int playMP3CDTrack(PlayingSoundHandle * handle, File * file, mad_timer_t duration); |