PlayingSoundHandle -> SoundHandle; also, turned the handle activity check into a mixer method

svn-id: r17106
This commit is contained in:
Max Horn 2005-03-12 18:56:09 +00:00
parent 8de216f3ae
commit 7cd2cb2b17
41 changed files with 127 additions and 119 deletions

View File

@ -185,7 +185,7 @@ bool BaseAnimationState::decodeFrame() {
*/
/* Avoid deadlock is sound was too far ahead */
if (_bgSoundStream && !_bgSound.isActive())
if (_bgSoundStream && !_snd->isSoundHandleActive(_bgSound))
return false;
if (checkPaletteSwitch() || (_bgSoundStream == NULL) ||

View File

@ -84,7 +84,7 @@ protected:
File *_mpegFile;
PlayingSoundHandle _bgSound;
SoundHandle _bgSound;
AudioStream *_bgSoundStream;
#ifdef BACKEND_8BIT

View File

@ -83,10 +83,10 @@ Sound *Sound::giveSound(SoundMixer *mixer, QueenEngine *vm, uint8 compression) {
void Sound::waitFinished(bool isSpeech) {
if (isSpeech)
while (_speechHandle.isActive())
while (_mixer->isSoundHandleActive(_speechHandle))
_vm->input()->delay(10);
else
while (_sfxHandle.isActive())
while (_mixer->isSoundHandleActive(_sfxHandle))
_vm->input()->delay(10);
}

View File

@ -74,8 +74,8 @@ public:
void musicToggle(bool val) { _musicToggle = val; }
void toggleMusic() { _musicToggle ^= true; }
bool isSpeechActive() const { return _speechHandle.isActive(); }
bool isSfxActive() const { return _sfxHandle.isActive(); }
bool isSpeechActive() const { return _mixer->isSoundHandleActive(_speechHandle); }
bool isSfxActive() const { return _mixer->isSoundHandleActive(_sfxHandle); }
bool speechSfxExists() const { return _speechSfxExists; }
@ -112,8 +112,8 @@ protected:
bool _speechSfxExists;
int16 _lastOverride;
PlayingSoundHandle _sfxHandle;
PlayingSoundHandle _speechHandle;
SoundHandle _sfxHandle;
SoundHandle _speechHandle;
};
class SilentSound : public Sound {

View File

@ -350,7 +350,7 @@ Music::~Music() {
}
bool Music::isPlaying() {
return _musicHandle.isActive() || _player->isPlaying();
return _mixer->isSoundHandleActive(_musicHandle) || _player->isPlaying();
}
// The Wyrmkeep release of Inherit The Earth features external MIDI files, so
@ -409,8 +409,7 @@ int Music::play(uint32 music_rn, uint16 flags) {
_player->stopMusic();
if (_musicHandle.isActive())
_mixer->stopHandle(_musicHandle);
_mixer->stopHandle(_musicHandle);
AudioStream *audioStream = NULL;
MidiParser *parser;

View File

@ -125,7 +125,7 @@ private:
SoundMixer *_mixer;
MusicPlayer *_player;
PlayingSoundHandle _musicHandle;
SoundHandle _musicHandle;
uint32 _trackNumber;
static const MUSIC_MIDITABLE _midiTableITECD[26];

View File

@ -152,7 +152,7 @@ Sound::~Sound() {
_soundInitialized = 0;
}
int Sound::playSoundBuffer(PlayingSoundHandle *handle, SOUNDBUFFER *buf, int volume, bool loop) {
int Sound::playSoundBuffer(SoundHandle *handle, SOUNDBUFFER *buf, int volume, bool loop) {
byte flags;
if (!_soundInitialized) {

View File

@ -64,7 +64,7 @@ public:
private:
int playSoundBuffer(PlayingSoundHandle *handle, SOUNDBUFFER *buf, int volume, bool loop);
int playSoundBuffer(SoundHandle *handle, SOUNDBUFFER *buf, int volume, bool loop);
int _soundInitialized;
int _enabled;
@ -72,8 +72,8 @@ public:
SagaEngine *_vm;
SoundMixer *_mixer;
PlayingSoundHandle _effectHandle;
PlayingSoundHandle _voiceHandle;
SoundHandle _effectHandle;
SoundHandle _voiceHandle;
};

View File

@ -77,7 +77,7 @@ private:
int32 mixerFlags;
ImuseDigiSndMgr::soundStruct *soundHandle;
PlayingSoundHandle handle;
SoundHandle handle;
AppendableAudioStream *stream;
AudioStream *stream2;

View File

@ -279,7 +279,7 @@ int IMuseDigital::getSoundStatus(int sound) const {
for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) {
Track *track = _track[l];
if (track->soundId == sound) {
if ((track->stream2 && track->handle.isActive()) ||
if ((track->stream2 && _vm->_mixer->isSoundHandleActive(track->handle)) ||
(track->stream && track->used && !track->readyToRemove)) {
return 1;
}

View File

@ -69,7 +69,7 @@ void SmushMixer::addChannel(SmushChannel *c) {
}
for (i = 0; i < NUM_CHANNELS; i++) {
if ((_channels[i].chan == NULL || _channels[i].id == -1) && !_channels[i].handle.isActive()) {
if ((_channels[i].chan == NULL || _channels[i].id == -1) && !_mixer->isSoundHandleActive(_channels[i].handle)) {
_channels[i].chan = c;
_channels[i].id = track;
return;
@ -120,7 +120,7 @@ bool SmushMixer::handleFrame() {
}
if (_mixer->isReady()) {
if (!_channels[i].handle.isActive()) {
if (!_mixer->isSoundHandleActive(_channels[i].handle)) {
_channels[i].stream = makeAppendableAudioStream(rate, flags, 500000);
_mixer->playInputStream(SoundMixer::kSFXSoundType, &_channels[i].handle, _channels[i].stream);
}

View File

@ -39,7 +39,7 @@ private:
struct channels {
int id;
SmushChannel *chan;
PlayingSoundHandle handle;
SoundHandle handle;
AppendableAudioStream *stream;
} _channels[NUM_CHANNELS];

View File

@ -507,7 +507,7 @@ void SmushPlayer::handleIACT(Chunk &b) {
}
} while (--count);
if (!_IACTchannel.isActive()) {
if (!_vm->_mixer->isSoundHandleActive(_IACTchannel)) {
_IACTstream = makeAppendableAudioStream(22050, SoundMixer::FLAG_STEREO | SoundMixer::FLAG_16BITS, 400000);
_vm->_mixer->playInputStream(SoundMixer::kSFXSoundType, &_IACTchannel, _IACTstream);
}

View File

@ -56,10 +56,10 @@ private:
bool _skips[37];
int32 _frame;
PlayingSoundHandle _IACTchannel;
SoundHandle _IACTchannel;
AppendableAudioStream *_IACTstream;
PlayingSoundHandle _compressedFileSoundHandle;
SoundHandle _compressedFileSoundHandle;
bool _compressedFileMode;
File _compressedFile;
byte _IACToutput[4096];

View File

@ -572,7 +572,7 @@ void Sound::processSfxQueues() {
if (_vm->_imuseDigital) {
finished = !isSoundRunning(kTalkSoundID);
} else {
finished = !_talkChannelHandle.isActive();
finished = !_vm->_mixer->isSoundHandleActive(_talkChannelHandle);
}
if ((uint) act < 0x80 && ((_vm->_version == 8) || (_vm->_version <= 7 && !_vm->_string[0].no_talk_anim))) {
@ -609,7 +609,7 @@ static int compareMP3OffsetTable(const void *a, const void *b) {
return ((const MP3OffsetTable *)a)->org_offset - ((const MP3OffsetTable *)b)->org_offset;
}
void Sound::startTalkSound(uint32 offset, uint32 b, int mode, PlayingSoundHandle *handle) {
void Sound::startTalkSound(uint32 offset, uint32 b, int mode, SoundHandle *handle) {
int num = 0, i;
int size = 0;
byte *sound;

View File

@ -84,7 +84,7 @@ protected:
int16 _currentCDSound;
int16 _currentMusic;
public:
PlayingSoundHandle _talkChannelHandle; // Handle of mixer channel actor is talking on
SoundHandle _talkChannelHandle; // Handle of mixer channel actor is talking on
bool _soundsPaused;
byte _sfxMode;
@ -97,7 +97,7 @@ public:
void processSoundQues();
void setOverrideFreq(int freq);
void playSound(int soundID, int heOffset, int heChannel, int heFlags);
void startTalkSound(uint32 offset, uint32 b, int mode, PlayingSoundHandle *handle = NULL);
void startTalkSound(uint32 offset, uint32 b, int mode, SoundHandle *handle = NULL);
void stopTalkSound();
bool isMouthSyncOff(uint pos);
int isSoundRunning(int sound) const;

View File

@ -370,7 +370,7 @@ loc_avoid_ks_fe:
// Special case for games using imuse digital.for sound
} else if ((_gameId == GID_LOOM256) && !ConfMan.getBool("subtitles") && (_sound->pollCD())) {
// Special case for loomcd, since it only uses CD audio.for sound
} else if (!ConfMan.getBool("subtitles") && (_haveMsg == 0xFE || _sound->_talkChannelHandle.isActive())) {
} else if (!ConfMan.getBool("subtitles") && (_haveMsg == 0xFE || _mixer->isSoundHandleActive(_sound->_talkChannelHandle))) {
// Subtitles are turned off, and there is a voice version
// of this message -> don't print it.
} else

View File

@ -45,25 +45,25 @@ public:
BaseSound(SoundMixer *mixer, File *file, uint32 base = 0, bool bigendian = false);
BaseSound(SoundMixer *mixer, File *file, uint32 *offsets, bool bigendian = false);
virtual ~BaseSound();
virtual void playSound(uint sound, PlayingSoundHandle *handle, byte flags) = 0;
virtual void playSound(uint sound, SoundHandle *handle, byte flags) = 0;
};
class WavSound : public BaseSound {
public:
WavSound(SoundMixer *mixer, File *file, uint32 base = 0, bool bigendian = false) : BaseSound(mixer, file, base, bigendian) {};
WavSound(SoundMixer *mixer, File *file, uint32 *offsets) : BaseSound(mixer, file, offsets) {};
void playSound(uint sound, PlayingSoundHandle *handle, byte flags);
void playSound(uint sound, SoundHandle *handle, byte flags);
};
class VocSound : public BaseSound {
public:
VocSound(SoundMixer *mixer, File *file, uint32 base = 0, bool bigendian = false) : BaseSound(mixer, file, base, bigendian) {};
void playSound(uint sound, PlayingSoundHandle *handle, byte flags);
void playSound(uint sound, SoundHandle *handle, byte flags);
};
class RawSound : public BaseSound {
public:
RawSound(SoundMixer *mixer, File *file, uint32 base = 0, bool bigendian = false) : BaseSound(mixer, file, base, bigendian) {};
void playSound(uint sound, PlayingSoundHandle *handle, byte flags);
void playSound(uint sound, SoundHandle *handle, byte flags);
};
BaseSound::BaseSound(SoundMixer *mixer, File *file, uint32 base, bool bigendian) {
@ -117,7 +117,7 @@ BaseSound::~BaseSound() {
delete _file;
}
void WavSound::playSound(uint sound, PlayingSoundHandle *handle, byte flags) {
void WavSound::playSound(uint sound, SoundHandle *handle, byte flags) {
if (_offsets == NULL)
return;
@ -132,7 +132,7 @@ void WavSound::playSound(uint sound, PlayingSoundHandle *handle, byte flags) {
_mixer->playInputStream(SoundMixer::kSFXSoundType, handle, stream);
}
void VocSound::playSound(uint sound, PlayingSoundHandle *handle, byte flags) {
void VocSound::playSound(uint sound, SoundHandle *handle, byte flags) {
if (_offsets == NULL)
return;
@ -144,7 +144,7 @@ void VocSound::playSound(uint sound, PlayingSoundHandle *handle, byte flags) {
_mixer->playRaw(handle, buffer, size, samples_per_sec, flags | SoundMixer::FLAG_AUTOFREE);
}
void RawSound::playSound(uint sound, PlayingSoundHandle *handle, byte flags) {
void RawSound::playSound(uint sound, SoundHandle *handle, byte flags) {
if (_offsets == NULL)
return;
@ -161,10 +161,10 @@ void RawSound::playSound(uint sound, PlayingSoundHandle *handle, byte flags) {
class MP3Sound : public BaseSound {
public:
MP3Sound(SoundMixer *mixer, File *file, uint32 base = 0) : BaseSound(mixer, file, base) {};
void playSound(uint sound, PlayingSoundHandle *handle, byte flags);
void playSound(uint sound, SoundHandle *handle, byte flags);
};
void MP3Sound::playSound(uint sound, PlayingSoundHandle *handle, byte flags)
void MP3Sound::playSound(uint sound, SoundHandle *handle, byte flags)
{
if (_offsets == NULL)
return;
@ -185,10 +185,10 @@ void MP3Sound::playSound(uint sound, PlayingSoundHandle *handle, byte flags)
class VorbisSound : public BaseSound {
public:
VorbisSound(SoundMixer *mixer, File *file, uint32 base = 0) : BaseSound(mixer, file, base) {};
void playSound(uint sound, PlayingSoundHandle *handle, byte flags);
void playSound(uint sound, SoundHandle *handle, byte flags);
};
void VorbisSound::playSound(uint sound, PlayingSoundHandle *handle, byte flags)
void VorbisSound::playSound(uint sound, SoundHandle *handle, byte flags)
{
if (_offsets == NULL)
return;
@ -209,10 +209,10 @@ void VorbisSound::playSound(uint sound, PlayingSoundHandle *handle, byte flags)
class FlacSound : public BaseSound {
public:
FlacSound(SoundMixer *mixer, File *file, uint32 base = 0) : BaseSound(mixer, file, base) {};
void playSound(uint sound, PlayingSoundHandle *handle, byte flags);
void playSound(uint sound, SoundHandle *handle, byte flags);
};
void FlacSound::playSound(uint sound, PlayingSoundHandle *handle, byte flags)
void FlacSound::playSound(uint sound, SoundHandle *handle, byte flags)
{
if (_offsets == NULL)
return;

View File

@ -45,9 +45,9 @@ private:
uint16 _last_voice_file;
public:
PlayingSoundHandle _voice_handle;
PlayingSoundHandle _effects_handle;
PlayingSoundHandle _ambient_handle;
SoundHandle _voice_handle;
SoundHandle _effects_handle;
SoundHandle _ambient_handle;
bool _voice_file;
uint _ambient_playing;

View File

@ -1606,7 +1606,7 @@ void SimonEngine::vc_59() {
vc_kill_sprite(file, start);
} while (++start != end);
} else {
if (!_sound->_voice_handle.isActive())
if (!_mixer->isSoundHandleActive(_sound->_voice_handle))
vc_skip_next_instruction();
}
}
@ -1789,7 +1789,7 @@ void SimonEngine::vc_63_palette_thing_2() {
void SimonEngine::vc_64_skip_if_no_speech() {
// Simon2
if (!_sound->_voice_handle.isActive() || (_subtitles && _language != 20))
if (!_mixer->isSoundHandleActive(_sound->_voice_handle) || (_subtitles && _language != 20))
vc_skip_next_instruction();
}

View File

@ -742,7 +742,7 @@ bool Intro::nextPart(uint16 *&data) {
SoundMixer::FLAG_AUTOFREE | SoundMixer::FLAG_UNSIGNED, SOUND_VOICE);
return true;
case WAITVOICE:
while (_voice.isActive())
while (_mixer->isSoundHandleActive(_voice))
if (!escDelay(50))
return false;
return true;

View File

@ -56,7 +56,7 @@ private:
uint8 *_textBuf, *_saveBuf;
uint8 *_bgBuf;
uint32 _bgSize;
PlayingSoundHandle _voice, _bgSfx;
SoundHandle _voice, _bgSfx;
int32 _relDelay;

View File

@ -1031,7 +1031,7 @@ Sound::~Sound(void) {
if (_soundData) free(_soundData);
}
void Sound::playSound(uint32 id, byte *sound, uint32 size, PlayingSoundHandle *handle) {
void Sound::playSound(uint32 id, byte *sound, uint32 size, SoundHandle *handle) {
byte flags = 0;
flags |= SoundMixer::FLAG_UNSIGNED|SoundMixer::FLAG_AUTOFREE;

View File

@ -50,16 +50,16 @@ protected:
public:
SoundMixer *_mixer;
PlayingSoundHandle _voiceHandle;
PlayingSoundHandle _effectHandle;
PlayingSoundHandle _bgSoundHandle;
PlayingSoundHandle _ingameSound0, _ingameSound1, _ingameSpeech;
SoundHandle _voiceHandle;
SoundHandle _effectHandle;
SoundHandle _bgSoundHandle;
SoundHandle _ingameSound0, _ingameSound1, _ingameSpeech;
uint16 _saveSounds[2];
protected:
void playSound(uint32 id, byte *sound, uint32 size, PlayingSoundHandle *handle);
void playSound(uint32 id, byte *sound, uint32 size, SoundHandle *handle);
public:
Sound(SoundMixer *mixer, Disk *pDisk, uint8 pVolume);
@ -69,7 +69,7 @@ public:
void playSound(uint16 sound, uint16 volume, uint8 channel);
void fnStartFx(uint32 sound, uint8 channel);
bool startSpeech(uint16 textNum);
bool speechFinished(void) { return !_ingameSpeech.isActive(); };
bool speechFinished(void) { return !_mixer->isSoundHandleActive(_ingameSpeech); };
void fnPauseFx(void);
void fnUnPauseFx(void);
void fnStopFx(void);

View File

@ -105,7 +105,7 @@ bool AudioCDManager::isPlaying() const {
void AudioCDManager::updateCD() {
if (_cd.playing) {
// If the sound handle is 0, then playback stopped.
if (!_cd.handle.isActive()) {
if (!g_engine->_mixer->isSoundHandleActive(_cd.handle)) {
// If playback just stopped, check if the current track is supposed
// to be repeated, and if that's the case, play it again. Else, stop
// the CD explicitly.

View File

@ -30,7 +30,7 @@
class DigitalTrackInfo {
public:
virtual bool error() = 0;
virtual void play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration) = 0;
virtual void play(SoundMixer *mixer, SoundHandle *handle, int startFrame, int duration) = 0;
virtual ~DigitalTrackInfo() { }
};
@ -62,7 +62,7 @@ private:
private:
/* used for emulated CD music */
struct ExtStatus : Status {
PlayingSoundHandle handle;
SoundHandle handle;
};
ExtStatus _cd;

View File

@ -746,7 +746,7 @@ public:
FlacTrackInfo(File *file);
~FlacTrackInfo();
bool error() { return _file == NULL; }
void play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration);
void play(SoundMixer *mixer, SoundHandle *handle, int startFrame, int duration);
};
FlacTrackInfo::FlacTrackInfo(File *file) : _file(NULL), _firstStream(NULL)
@ -760,7 +760,7 @@ FlacTrackInfo::FlacTrackInfo(File *file) : _file(NULL), _firstStream(NULL)
delete tempStream;
}
void FlacTrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration) {
void FlacTrackInfo::play(SoundMixer *mixer, SoundHandle *handle, int startFrame, int duration) {
if (error()) {
debug(1, "FlacTrackInfo::play: invalid state, method should not been called");
}

View File

@ -47,7 +47,7 @@ public:
const SoundMixer::SoundType _type;
private:
SoundMixer *_mixer;
PlayingSoundHandle *_handle;
SoundHandle *_handle;
bool _autofreeStream;
bool _permanent;
byte _volume;
@ -64,8 +64,8 @@ protected:
public:
Channel(SoundMixer *mixer, PlayingSoundHandle *handle, SoundMixer::SoundType type, int id = -1);
Channel(SoundMixer *mixer, PlayingSoundHandle *handle, SoundMixer::SoundType type, AudioStream *input, bool autofreeStream, bool reverseStereo = false, int id = -1, bool permanent = false);
Channel(SoundMixer *mixer, SoundHandle *handle, SoundMixer::SoundType type, int id = -1);
Channel(SoundMixer *mixer, SoundHandle *handle, SoundMixer::SoundType type, AudioStream *input, bool autofreeStream, bool reverseStereo = false, int id = -1, bool permanent = false);
virtual ~Channel();
void mix(int16 *data, uint len);
@ -148,7 +148,7 @@ void SoundMixer::setupPremix(AudioStream *stream, SoundType type) {
_premixChannel = new Channel(this, 0, type, stream, false);
}
void SoundMixer::insertChannel(PlayingSoundHandle *handle, Channel *chan) {
void SoundMixer::insertChannel(SoundHandle *handle, Channel *chan) {
int index = -1;
for (int i = 0; i != NUM_CHANNELS; i++) {
@ -168,7 +168,7 @@ void SoundMixer::insertChannel(PlayingSoundHandle *handle, Channel *chan) {
handle->setIndex(index);
}
void SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags,
void SoundMixer::playRaw(SoundHandle *handle, void *sound, uint32 size, uint rate, byte flags,
int id, byte volume, int8 balance, uint32 loopStart, uint32 loopEnd, SoundType type) {
Common::StackLock lock(_mutex);
@ -202,7 +202,7 @@ void SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, u
insertChannel(handle, chan);
}
void SoundMixer::playInputStream(SoundType type, PlayingSoundHandle *handle, AudioStream *input,
void SoundMixer::playInputStream(SoundType type, SoundHandle *handle, AudioStream *input,
int id, byte volume, int8 balance, bool autofreeStream, bool permanent) {
Common::StackLock lock(_mutex);
@ -279,7 +279,7 @@ void SoundMixer::stopID(int id) {
}
}
void SoundMixer::stopHandle(PlayingSoundHandle handle) {
void SoundMixer::stopHandle(SoundHandle handle) {
Common::StackLock lock(_mutex);
// Simply ignore stop requests for handles of sounds that already terminated
@ -299,7 +299,7 @@ void SoundMixer::stopHandle(PlayingSoundHandle handle) {
}
}
void SoundMixer::setChannelVolume(PlayingSoundHandle handle, byte volume) {
void SoundMixer::setChannelVolume(SoundHandle handle, byte volume) {
Common::StackLock lock(_mutex);
if (!handle.isActive())
@ -316,7 +316,7 @@ void SoundMixer::setChannelVolume(PlayingSoundHandle handle, byte volume) {
_channels[index]->setVolume(volume);
}
void SoundMixer::setChannelBalance(PlayingSoundHandle handle, int8 balance) {
void SoundMixer::setChannelBalance(SoundHandle handle, int8 balance) {
Common::StackLock lock(_mutex);
if (!handle.isActive())
@ -341,7 +341,7 @@ uint32 SoundMixer::getSoundElapsedTimeOfSoundID(int id) {
return 0;
}
uint32 SoundMixer::getSoundElapsedTime(PlayingSoundHandle handle) {
uint32 SoundMixer::getSoundElapsedTime(SoundHandle handle) {
Common::StackLock lock(_mutex);
if (!handle.isActive())
@ -375,7 +375,7 @@ void SoundMixer::pauseID(int id, bool paused) {
}
}
void SoundMixer::pauseHandle(PlayingSoundHandle handle, bool paused) {
void SoundMixer::pauseHandle(SoundHandle handle, bool paused) {
Common::StackLock lock(_mutex);
// Simply ignore pause/unpause requests for handles of sound that alreayd terminated
@ -436,14 +436,14 @@ int SoundMixer::getVolumeForSoundType(SoundType type) const {
#pragma mark -
Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, SoundMixer::SoundType type, int id)
Channel::Channel(SoundMixer *mixer, SoundHandle *handle, SoundMixer::SoundType type, int id)
: _type(type), _mixer(mixer), _handle(handle), _autofreeStream(true),
_volume(SoundMixer::kMaxChannelVolume), _balance(0), _paused(false), _id(id), _samplesConsumed(0),
_samplesDecoded(0), _mixerTimeStamp(0), _converter(0), _input(0) {
assert(mixer);
}
Channel::Channel(SoundMixer *mixer, PlayingSoundHandle *handle, SoundMixer::SoundType type, AudioStream *input,
Channel::Channel(SoundMixer *mixer, SoundHandle *handle, SoundMixer::SoundType type, AudioStream *input,
bool autofreeStream, bool reverseStereo, int id, bool permanent)
: _type(type), _mixer(mixer), _handle(handle), _autofreeStream(autofreeStream),
_volume(SoundMixer::kMaxChannelVolume), _balance(0), _paused(false), _id(id), _samplesConsumed(0),

View File

@ -33,16 +33,16 @@ class Channel;
class File;
class OSystem;
class PlayingSoundHandle {
class SoundHandle {
friend class Channel;
friend class SoundMixer;
int val;
int getIndex() const { return val - 1; }
void setIndex(int i) { val = i + 1; }
void resetIndex() { val = 0; }
public:
PlayingSoundHandle() { resetIndex(); }
bool isActive() const { return val > 0; }
public:
SoundHandle() { resetIndex(); }
};
class SoundMixer {
@ -136,7 +136,7 @@ public:
* (using the makeLinearInputStream factory function), which is then
* passed on to playInputStream.
*/
void playRaw(PlayingSoundHandle *handle,
void playRaw(SoundHandle *handle,
void *sound, uint32 size, uint rate, byte flags,
int id = -1, byte volume = 255, int8 balance = 0,
uint32 loopStart = 0, uint32 loopEnd = 0,
@ -145,7 +145,7 @@ public:
/**
* Start playing the given audio input stream.
*/
void playInputStream(SoundType type, PlayingSoundHandle *handle, AudioStream *input,
void playInputStream(SoundType type, SoundHandle *handle, AudioStream *input,
int id = -1, byte volume = 255, int8 balance = 0,
bool autofreeStream = true, bool permanent = false);
@ -168,7 +168,7 @@ public:
*
* @param handle the sound to affect
*/
void stopHandle(PlayingSoundHandle handle);
void stopHandle(SoundHandle handle);
@ -194,7 +194,7 @@ public:
* @param handle the sound to affect
* @param paused true to pause the sound, false to unpause it
*/
void pauseHandle(PlayingSoundHandle handle, bool paused);
void pauseHandle(SoundHandle handle, bool paused);
@ -206,6 +206,16 @@ public:
*/
bool isSoundIDActive(int id);
/**
* Check if a sound with the given hANDLE is active.
*
* @param handle the sound to query
* @return true if the sound is active
*/
bool isSoundHandleActive(SoundHandle handle) {
return handle.isActive();
}
/**
* Check if the mixer is paused (using pauseAll).
*
@ -221,7 +231,7 @@ public:
* @param handle the sound to affect
* @param volume the new channel volume (0 - 255)
*/
void setChannelVolume(PlayingSoundHandle handle, byte volume);
void setChannelVolume(SoundHandle handle, byte volume);
/**
* Set the channel balance for the given handle.
@ -230,7 +240,7 @@ public:
* @param balance the new channel balance:
* (-127 ... 0 ... 127) corresponds to (left ... center ... right)
*/
void setChannelBalance(PlayingSoundHandle handle, int8 balance);
void setChannelBalance(SoundHandle handle, int8 balance);
/**
* Get approximation of for how long the Sound ID has been playing.
@ -240,7 +250,7 @@ public:
/**
* Get approximation of for how long the channel has been playing.
*/
uint32 getSoundElapsedTime(PlayingSoundHandle handle);
uint32 getSoundElapsedTime(SoundHandle handle);
/**
* Check whether any channel of the given sound type is active.
@ -275,7 +285,7 @@ public:
uint getOutputRate() const { return _outputRate; }
private:
void insertChannel(PlayingSoundHandle *handle, Channel *chan);
void insertChannel(SoundHandle *handle, Channel *chan);
/**
* Internal main method -- all the actual mixing work is done from here.

View File

@ -285,7 +285,7 @@ public:
MP3TrackInfo(File *file);
~MP3TrackInfo();
bool error() { return _error_flag; }
void play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration);
void play(SoundMixer *mixer, SoundHandle *handle, int startFrame, int duration);
};
@ -360,7 +360,7 @@ error:
delete file;
}
void MP3TrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration) {
void MP3TrackInfo::play(SoundMixer *mixer, SoundHandle *handle, int startFrame, int duration) {
unsigned int offset;
mad_timer_t durationTime;

View File

@ -43,7 +43,7 @@ class MidiChannel_MT32 : public MidiChannel_MPU401 {
class MidiDriver_MT32 : public MidiDriver_Emulated {
private:
PlayingSoundHandle _handle;
SoundHandle _handle;
MidiChannel_MT32 _midiChannels[16];
uint16 _channelMask;
MT32Emu::Synth *_synth;

View File

@ -50,7 +50,7 @@ public:
~VorbisTrackInfo();
bool openTrack();
bool error() { return _error_flag; }
void play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration);
void play(SoundMixer *mixer, SoundHandle *handle, int startFrame, int duration);
};
@ -166,7 +166,7 @@ VorbisTrackInfo::~VorbisTrackInfo() {
#define VORBIS_TREMOR
#endif
void VorbisTrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration) {
void VorbisTrackInfo::play(SoundMixer *mixer, SoundHandle *handle, int startFrame, int duration) {
bool err = openTrack();
assert(!err);

View File

@ -70,7 +70,7 @@ OverlayColor *AnimationState::giveRgbBuffer(void) {
}
bool AnimationState::soundFinished(void) {
return !_bgSound.isActive();
return !_snd->isSoundHandleActive(_bgSound);
}
AudioStream *AnimationState::createAudioStream(const char *name, void *arg) {

View File

@ -112,7 +112,7 @@ void CreditsPlayer::play(void) {
_system->updateScreen();
// everything's initialized, time to render and show the credits.
PlayingSoundHandle bgSound;
SoundHandle bgSound;
_mixer->playInputStream(SoundMixer::kMusicSoundType, &bgSound, bgSoundStream, 0);
int relDelay = 0;

View File

@ -100,7 +100,7 @@ void Sound::engine(void) {
if (_fxQueue[cnt2].delay == 0)
playSample(&_fxQueue[cnt2]);
} else {
if (!_fxQueue[cnt2].handle.isActive()) { // sound finished
if (!_mixer->isSoundHandleActive(_fxQueue[cnt2].handle)) { // sound finished
_resMan->resClose(_fxList[_fxQueue[cnt2].id].sampleId);
if (cnt2 != _endOfQueue-1)
_fxQueue[cnt2] = _fxQueue[_endOfQueue - 1];
@ -130,7 +130,7 @@ bool Sound::amISpeaking(void) {
}
bool Sound::speechFinished(void) {
return !_speechHandle.isActive();
return !_mixer->isSoundHandleActive(_speechHandle);
}
void Sound::newScreen(uint32 screen) {

View File

@ -42,7 +42,7 @@ namespace Sword1 {
struct QueueElement {
uint32 id, delay;
PlayingSoundHandle handle;
SoundHandle handle;
};
struct RoomVol {
@ -101,7 +101,7 @@ private:
uint32 _cowHeaderSize;
uint8 _currentCowFile;
CowMode _cowMode;
PlayingSoundHandle _speechHandle, _fxHandle;
SoundHandle _speechHandle, _fxHandle;
Common::RandomSource _rnd;
QueueElement _fxQueue[MAX_FXQ_LENGTH];

View File

@ -167,7 +167,7 @@ void MoviePlayer::drawTextObject(AnimationState *anim, MovieTextObject *obj) {
*/
int32 MoviePlayer::play(const char *filename, MovieTextObject *text[], int32 leadInRes, int32 leadOutRes) {
PlayingSoundHandle leadInHandle;
SoundHandle leadInHandle;
// This happens if the user quits during the "eye" smacker
if (_vm->_quit)
@ -205,10 +205,10 @@ int32 MoviePlayer::play(const char *filename, MovieTextObject *text[], int32 lea
playDummy(filename, text, leadOut, leadOutLen);
#endif
_vm->_mixer->stopHandle(leadInHandle);
_snd->stopHandle(leadInHandle);
// Wait for the lead-out to stop, if there is any.
while (_leadOutHandle.isActive()) {
while (_vm->_mixer->isSoundHandleActive(_leadOutHandle)) {
_vm->_screen->updateDisplay();
_vm->_system->delayMillis(30);
}
@ -224,7 +224,7 @@ int32 MoviePlayer::play(const char *filename, MovieTextObject *text[], int32 lea
void MoviePlayer::playMPEG(const char *filename, MovieTextObject *text[], byte *leadOut, uint32 leadOutLen) {
uint frameCounter = 0, textCounter = 0;
PlayingSoundHandle handle;
SoundHandle handle;
bool skipCutscene = false, textVisible = false;
uint32 flags = SoundMixer::FLAG_16BITS;
bool startNextText = false;
@ -282,7 +282,7 @@ void MoviePlayer::playMPEG(const char *filename, MovieTextObject *text[], byte *
}
}
if (startNextText && !handle.isActive()) {
if (startNextText && !_snd->isSoundHandleActive(handle)) {
_snd->playRaw(&handle, text[textCounter]->speech, text[textCounter]->speechBufferSize, 22050, flags);
startNextText = false;
}
@ -339,7 +339,7 @@ void MoviePlayer::playMPEG(const char *filename, MovieTextObject *text[], byte *
// If the speech is still playing, redraw the subtitles. At least in
// the English version this is most noticeable in the "carib" cutscene.
if (textVisible && handle.isActive())
if (textVisible && _snd->isSoundHandleActive(handle))
drawTextObject(anim, text[textCounter]);
if (text)
@ -354,7 +354,7 @@ void MoviePlayer::playMPEG(const char *filename, MovieTextObject *text[], byte *
if (skipCutscene)
_snd->stopHandle(handle);
while (handle.isActive()) {
while (_snd->isSoundHandleActive(handle)) {
_vm->_screen->updateDisplay(false);
_sys->delayMillis(100);
}
@ -441,7 +441,7 @@ void MoviePlayer::playDummy(const char *filename, MovieTextObject *text[], byte
tmpPal[255 * 4 + 2] = 255;
_vm->_screen->setPalette(0, 256, tmpPal, RDPAL_INSTANT);
PlayingSoundHandle handle;
SoundHandle handle;
bool skipCutscene = false;
@ -493,7 +493,7 @@ void MoviePlayer::playDummy(const char *filename, MovieTextObject *text[], byte
// don't cut off the speech in mid-sentence, and - even more
// importantly - that we don't free the sound buffer while it's in use.
while (handle.isActive()) {
while (_snd->isSoundHandleActive(handle)) {
_vm->_screen->updateDisplay(false);
_sys->delayMillis(100);
}

View File

@ -77,7 +77,7 @@ private:
byte *_textSurface;
PlayingSoundHandle _leadOutHandle;
SoundHandle _leadOutHandle;
static struct MovieInfo _movies[];

View File

@ -642,7 +642,7 @@ int32 Sound::musicTimeRemaining(void) {
void Sound::muteSpeech(bool mute) {
_speechMuted = mute;
if (_soundHandleSpeech.isActive()) {
if (_vm->_mixer->isSoundHandleActive(_soundHandleSpeech)) {
uint volume = mute ? 0 : SoundMixer::kMaxChannelVolume;
_vm->_mixer->setChannelVolume(_soundHandleSpeech, volume);
@ -672,7 +672,7 @@ void Sound::unpauseSpeech(void) {
*/
int32 Sound::stopSpeech() {
if (_soundHandleSpeech.isActive()) {
if (_vm->_mixer->isSoundHandleActive(_soundHandleSpeech)) {
_vm->_mixer->stopHandle(_soundHandleSpeech);
return RD_OK;
}
@ -685,7 +685,7 @@ int32 Sound::stopSpeech() {
*/
int32 Sound::getSpeechStatus() {
return _soundHandleSpeech.isActive() ? RDSE_SAMPLEPLAYING : RDSE_SAMPLEFINISHED;
return _vm->_mixer->isSoundHandleActive(_soundHandleSpeech) ? RDSE_SAMPLEPLAYING : RDSE_SAMPLEFINISHED;
}
/**
@ -693,7 +693,7 @@ int32 Sound::getSpeechStatus() {
*/
int32 Sound::amISpeaking() {
if (!_speechMuted && !_speechPaused && _soundHandleSpeech.isActive())
if (!_speechMuted && !_speechPaused && _vm->_mixer->isSoundHandleActive(_soundHandleSpeech))
return RDSE_SPEAKING;
return RDSE_QUIET;
@ -818,7 +818,7 @@ int32 Sound::setFxIdVolumePan(int32 i, int vol, int pan) {
_fxQueue[i].pan = (pan * 127) / 16;
}
if (!_fxMuted && _fxQueue[i].handle.isActive()) {
if (!_fxMuted && _vm->_mixer->isSoundHandleActive(_fxQueue[i].handle)) {
_vm->_mixer->setChannelVolume(_fxQueue[i].handle, _fxQueue[i].volume);
if (pan != -1)
_vm->_mixer->setChannelBalance(_fxQueue[i].handle, _fxQueue[i].pan);

View File

@ -156,7 +156,7 @@ void Sound::processFxQueue() {
break;
case FX_SPOT2:
// Once the FX has finished remove it from the queue.
if (!_fxQueue[i].handle.isActive()) {
if (!_vm->_mixer->isSoundHandleActive(_fxQueue[i].handle)) {
_vm->_resman->closeResource(_fxQueue[i].resource);
_fxQueue[i].resource = 0;
}
@ -250,11 +250,11 @@ int32 Sound::playFx(FxQueueEntry *fx) {
return playFx(&fx->handle, fx->data, fx->len, fx->volume, fx->pan, (fx->type == FX_LOOP), SoundMixer::kSFXSoundType);
}
int32 Sound::playFx(PlayingSoundHandle *handle, byte *data, uint32 len, uint8 vol, int8 pan, bool loop, SoundMixer::SoundType soundType) {
int32 Sound::playFx(SoundHandle *handle, byte *data, uint32 len, uint8 vol, int8 pan, bool loop, SoundMixer::SoundType soundType) {
if (_fxMuted)
return RD_OK;
if (handle->isActive())
if (_vm->_mixer->isSoundHandleActive(*handle))
return RDERR_FXALREADYOPEN;
Common::MemoryReadStream stream(data, len);
@ -287,8 +287,7 @@ int32 Sound::stopFx(int32 i) {
if (!_fxQueue[i].resource)
return RDERR_FXNOTOPEN;
if (_fxQueue[i].handle.isActive())
_vm->_mixer->stopHandle(_fxQueue[i].handle);
_vm->_mixer->stopHandle(_fxQueue[i].handle);
_vm->_resman->closeResource(_fxQueue[i].resource);
_fxQueue[i].resource = 0;

View File

@ -172,7 +172,7 @@ private:
Common::Mutex _mutex;
struct FxQueueEntry {
PlayingSoundHandle handle; // sound handle
SoundHandle handle; // sound handle
uint32 resource; // resource id of sample
byte *data; // pointer to WAV data
uint32 len; // WAV data length
@ -198,7 +198,7 @@ private:
int32 _loopingMusicId;
PlayingSoundHandle _soundHandleSpeech;
SoundHandle _soundHandleSpeech;
MusicInputStream *_music[MAXMUS];
//File _musicFile[MAXMUS];
@ -253,7 +253,7 @@ public:
void queueFx(int32 res, int32 type, int32 delay, int32 volume, int32 pan);
int32 playFx(FxQueueEntry *fx);
int32 playFx(PlayingSoundHandle *handle, byte *data, uint32 len, uint8 vol, int8 pan, bool loop, SoundMixer::SoundType soundType);
int32 playFx(SoundHandle *handle, byte *data, uint32 len, uint8 vol, int8 pan, bool loop, SoundMixer::SoundType soundType);
int32 stopFx(int32 i);
int32 setFxIdVolumePan(int32 id, int vol, int pan = 255);