AUDIO: Create Mixer::loopChannel()
This commit is contained in:
parent
9c6fa32c82
commit
22775dff7e
3 changed files with 34 additions and 0 deletions
|
@ -126,6 +126,11 @@ public:
|
|||
*/
|
||||
Timestamp getElapsedTime();
|
||||
|
||||
/**
|
||||
* Replaces the channel's stream with a version that loops indefinitely.
|
||||
*/
|
||||
void loop();
|
||||
|
||||
/**
|
||||
* Queries the channel's sound type.
|
||||
*/
|
||||
|
@ -397,6 +402,16 @@ Timestamp MixerImpl::getElapsedTime(SoundHandle handle) {
|
|||
return _channels[index]->getElapsedTime();
|
||||
}
|
||||
|
||||
void MixerImpl::loopChannel(SoundHandle handle) {
|
||||
Common::StackLock lock(_mutex);
|
||||
|
||||
const int index = handle._val % NUM_CHANNELS;
|
||||
if (!_channels[index] || _channels[index]->getHandle()._val != handle._val)
|
||||
return;
|
||||
|
||||
_channels[index]->loop();
|
||||
}
|
||||
|
||||
void MixerImpl::pauseAll(bool paused) {
|
||||
Common::StackLock lock(_mutex);
|
||||
for (int i = 0; i != NUM_CHANNELS; i++) {
|
||||
|
@ -604,6 +619,18 @@ Timestamp Channel::getElapsedTime() {
|
|||
return ts;
|
||||
}
|
||||
|
||||
void Channel::loop() {
|
||||
assert(_stream);
|
||||
|
||||
Audio::RewindableAudioStream *rewindableStream = dynamic_cast<RewindableAudioStream *>(_stream.get());
|
||||
if (rewindableStream) {
|
||||
DisposeAfterUse::Flag dispose = _stream.getDispose();
|
||||
_stream.disownPtr();
|
||||
Audio::LoopingAudioStream *loopingStream = new Audio::LoopingAudioStream(rewindableStream, 0, dispose, false);
|
||||
_stream.reset(loopingStream, DisposeAfterUse::YES);
|
||||
}
|
||||
}
|
||||
|
||||
int Channel::mix(int16 *data, uint len) {
|
||||
assert(_stream);
|
||||
|
||||
|
|
|
@ -265,6 +265,11 @@ public:
|
|||
*/
|
||||
virtual Timestamp getElapsedTime(SoundHandle handle) = 0;
|
||||
|
||||
/**
|
||||
* Replace the channel's stream with a version that loops indefinitely.
|
||||
*/
|
||||
virtual void loopChannel(SoundHandle handle) = 0;
|
||||
|
||||
/**
|
||||
* Check whether any channel of the given sound type is active.
|
||||
*
|
||||
|
|
|
@ -121,6 +121,8 @@ public:
|
|||
virtual uint32 getSoundElapsedTime(SoundHandle handle);
|
||||
virtual Timestamp getElapsedTime(SoundHandle handle);
|
||||
|
||||
virtual void loopChannel(SoundHandle handle);
|
||||
|
||||
virtual bool hasActiveChannelOfType(SoundType type);
|
||||
|
||||
virtual void setVolumeForSoundType(SoundType type, int volume);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue