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 */ /* Avoid deadlock is sound was too far ahead */
if (_bgSoundStream && !_bgSound.isActive()) if (_bgSoundStream && !_snd->isSoundHandleActive(_bgSound))
return false; return false;
if (checkPaletteSwitch() || (_bgSoundStream == NULL) || if (checkPaletteSwitch() || (_bgSoundStream == NULL) ||

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -152,7 +152,7 @@ Sound::~Sound() {
_soundInitialized = 0; _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; byte flags;
if (!_soundInitialized) { if (!_soundInitialized) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -572,7 +572,7 @@ void Sound::processSfxQueues() {
if (_vm->_imuseDigital) { if (_vm->_imuseDigital) {
finished = !isSoundRunning(kTalkSoundID); finished = !isSoundRunning(kTalkSoundID);
} else { } 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))) { 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; 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 num = 0, i;
int size = 0; int size = 0;
byte *sound; byte *sound;

View File

@ -84,7 +84,7 @@ protected:
int16 _currentCDSound; int16 _currentCDSound;
int16 _currentMusic; int16 _currentMusic;
public: public:
PlayingSoundHandle _talkChannelHandle; // Handle of mixer channel actor is talking on SoundHandle _talkChannelHandle; // Handle of mixer channel actor is talking on
bool _soundsPaused; bool _soundsPaused;
byte _sfxMode; byte _sfxMode;
@ -97,7 +97,7 @@ public:
void processSoundQues(); void processSoundQues();
void setOverrideFreq(int freq); void setOverrideFreq(int freq);
void playSound(int soundID, int heOffset, int heChannel, int heFlags); 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(); void stopTalkSound();
bool isMouthSyncOff(uint pos); bool isMouthSyncOff(uint pos);
int isSoundRunning(int sound) const; int isSoundRunning(int sound) const;

View File

@ -370,7 +370,7 @@ loc_avoid_ks_fe:
// Special case for games using imuse digital.for sound // Special case for games using imuse digital.for sound
} else if ((_gameId == GID_LOOM256) && !ConfMan.getBool("subtitles") && (_sound->pollCD())) { } else if ((_gameId == GID_LOOM256) && !ConfMan.getBool("subtitles") && (_sound->pollCD())) {
// Special case for loomcd, since it only uses CD audio.for sound // 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 // Subtitles are turned off, and there is a voice version
// of this message -> don't print it. // of this message -> don't print it.
} else } 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 base = 0, bool bigendian = false);
BaseSound(SoundMixer *mixer, File *file, uint32 *offsets, bool bigendian = false); BaseSound(SoundMixer *mixer, File *file, uint32 *offsets, bool bigendian = false);
virtual ~BaseSound(); 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 { class WavSound : public BaseSound {
public: public:
WavSound(SoundMixer *mixer, File *file, uint32 base = 0, bool bigendian = false) : BaseSound(mixer, file, base, bigendian) {}; 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) {}; 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 { class VocSound : public BaseSound {
public: public:
VocSound(SoundMixer *mixer, File *file, uint32 base = 0, bool bigendian = false) : BaseSound(mixer, file, base, bigendian) {}; 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 { class RawSound : public BaseSound {
public: public:
RawSound(SoundMixer *mixer, File *file, uint32 base = 0, bool bigendian = false) : BaseSound(mixer, file, base, bigendian) {}; 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) { BaseSound::BaseSound(SoundMixer *mixer, File *file, uint32 base, bool bigendian) {
@ -117,7 +117,7 @@ BaseSound::~BaseSound() {
delete _file; delete _file;
} }
void WavSound::playSound(uint sound, PlayingSoundHandle *handle, byte flags) { void WavSound::playSound(uint sound, SoundHandle *handle, byte flags) {
if (_offsets == NULL) if (_offsets == NULL)
return; return;
@ -132,7 +132,7 @@ void WavSound::playSound(uint sound, PlayingSoundHandle *handle, byte flags) {
_mixer->playInputStream(SoundMixer::kSFXSoundType, handle, stream); _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) if (_offsets == NULL)
return; 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); _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) if (_offsets == NULL)
return; return;
@ -161,10 +161,10 @@ void RawSound::playSound(uint sound, PlayingSoundHandle *handle, byte flags) {
class MP3Sound : public BaseSound { class MP3Sound : public BaseSound {
public: public:
MP3Sound(SoundMixer *mixer, File *file, uint32 base = 0) : BaseSound(mixer, file, base) {}; 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) if (_offsets == NULL)
return; return;
@ -185,10 +185,10 @@ void MP3Sound::playSound(uint sound, PlayingSoundHandle *handle, byte flags)
class VorbisSound : public BaseSound { class VorbisSound : public BaseSound {
public: public:
VorbisSound(SoundMixer *mixer, File *file, uint32 base = 0) : BaseSound(mixer, file, base) {}; 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) if (_offsets == NULL)
return; return;
@ -209,10 +209,10 @@ void VorbisSound::playSound(uint sound, PlayingSoundHandle *handle, byte flags)
class FlacSound : public BaseSound { class FlacSound : public BaseSound {
public: public:
FlacSound(SoundMixer *mixer, File *file, uint32 base = 0) : BaseSound(mixer, file, base) {}; 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) if (_offsets == NULL)
return; return;

View File

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

View File

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

View File

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

View File

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

View File

@ -1031,7 +1031,7 @@ Sound::~Sound(void) {
if (_soundData) free(_soundData); 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; byte flags = 0;
flags |= SoundMixer::FLAG_UNSIGNED|SoundMixer::FLAG_AUTOFREE; flags |= SoundMixer::FLAG_UNSIGNED|SoundMixer::FLAG_AUTOFREE;

View File

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

View File

@ -105,7 +105,7 @@ bool AudioCDManager::isPlaying() const {
void AudioCDManager::updateCD() { void AudioCDManager::updateCD() {
if (_cd.playing) { if (_cd.playing) {
// If the sound handle is 0, then playback stopped. // 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 // 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 // to be repeated, and if that's the case, play it again. Else, stop
// the CD explicitly. // the CD explicitly.

View File

@ -30,7 +30,7 @@
class DigitalTrackInfo { class DigitalTrackInfo {
public: public:
virtual bool error() = 0; 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() { } virtual ~DigitalTrackInfo() { }
}; };
@ -62,7 +62,7 @@ private:
private: private:
/* used for emulated CD music */ /* used for emulated CD music */
struct ExtStatus : Status { struct ExtStatus : Status {
PlayingSoundHandle handle; SoundHandle handle;
}; };
ExtStatus _cd; ExtStatus _cd;

View File

@ -746,7 +746,7 @@ public:
FlacTrackInfo(File *file); FlacTrackInfo(File *file);
~FlacTrackInfo(); ~FlacTrackInfo();
bool error() { return _file == NULL; } 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) FlacTrackInfo::FlacTrackInfo(File *file) : _file(NULL), _firstStream(NULL)
@ -760,7 +760,7 @@ FlacTrackInfo::FlacTrackInfo(File *file) : _file(NULL), _firstStream(NULL)
delete tempStream; 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()) { if (error()) {
debug(1, "FlacTrackInfo::play: invalid state, method should not been called"); debug(1, "FlacTrackInfo::play: invalid state, method should not been called");
} }

View File

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

View File

@ -33,16 +33,16 @@ class Channel;
class File; class File;
class OSystem; class OSystem;
class PlayingSoundHandle { class SoundHandle {
friend class Channel; friend class Channel;
friend class SoundMixer; friend class SoundMixer;
int val; int val;
int getIndex() const { return val - 1; } int getIndex() const { return val - 1; }
void setIndex(int i) { val = i + 1; } void setIndex(int i) { val = i + 1; }
void resetIndex() { val = 0; } void resetIndex() { val = 0; }
public:
PlayingSoundHandle() { resetIndex(); }
bool isActive() const { return val > 0; } bool isActive() const { return val > 0; }
public:
SoundHandle() { resetIndex(); }
}; };
class SoundMixer { class SoundMixer {
@ -136,7 +136,7 @@ public:
* (using the makeLinearInputStream factory function), which is then * (using the makeLinearInputStream factory function), which is then
* passed on to playInputStream. * passed on to playInputStream.
*/ */
void playRaw(PlayingSoundHandle *handle, void playRaw(SoundHandle *handle,
void *sound, uint32 size, uint rate, byte flags, void *sound, uint32 size, uint rate, byte flags,
int id = -1, byte volume = 255, int8 balance = 0, int id = -1, byte volume = 255, int8 balance = 0,
uint32 loopStart = 0, uint32 loopEnd = 0, uint32 loopStart = 0, uint32 loopEnd = 0,
@ -145,7 +145,7 @@ public:
/** /**
* Start playing the given audio input stream. * 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, int id = -1, byte volume = 255, int8 balance = 0,
bool autofreeStream = true, bool permanent = false); bool autofreeStream = true, bool permanent = false);
@ -168,7 +168,7 @@ public:
* *
* @param handle the sound to affect * @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 handle the sound to affect
* @param paused true to pause the sound, false to unpause it * @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); 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). * Check if the mixer is paused (using pauseAll).
* *
@ -221,7 +231,7 @@ public:
* @param handle the sound to affect * @param handle the sound to affect
* @param volume the new channel volume (0 - 255) * @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. * Set the channel balance for the given handle.
@ -230,7 +240,7 @@ public:
* @param balance the new channel balance: * @param balance the new channel balance:
* (-127 ... 0 ... 127) corresponds to (left ... center ... right) * (-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. * 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. * 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. * Check whether any channel of the given sound type is active.
@ -275,7 +285,7 @@ public:
uint getOutputRate() const { return _outputRate; } uint getOutputRate() const { return _outputRate; }
private: 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. * Internal main method -- all the actual mixing work is done from here.

View File

@ -285,7 +285,7 @@ public:
MP3TrackInfo(File *file); MP3TrackInfo(File *file);
~MP3TrackInfo(); ~MP3TrackInfo();
bool error() { return _error_flag; } 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; 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; unsigned int offset;
mad_timer_t durationTime; mad_timer_t durationTime;

View File

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

View File

@ -50,7 +50,7 @@ public:
~VorbisTrackInfo(); ~VorbisTrackInfo();
bool openTrack(); bool openTrack();
bool error() { return _error_flag; } 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 #define VORBIS_TREMOR
#endif #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(); bool err = openTrack();
assert(!err); assert(!err);

View File

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

View File

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

View File

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

View File

@ -42,7 +42,7 @@ namespace Sword1 {
struct QueueElement { struct QueueElement {
uint32 id, delay; uint32 id, delay;
PlayingSoundHandle handle; SoundHandle handle;
}; };
struct RoomVol { struct RoomVol {
@ -101,7 +101,7 @@ private:
uint32 _cowHeaderSize; uint32 _cowHeaderSize;
uint8 _currentCowFile; uint8 _currentCowFile;
CowMode _cowMode; CowMode _cowMode;
PlayingSoundHandle _speechHandle, _fxHandle; SoundHandle _speechHandle, _fxHandle;
Common::RandomSource _rnd; Common::RandomSource _rnd;
QueueElement _fxQueue[MAX_FXQ_LENGTH]; 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) { 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 // This happens if the user quits during the "eye" smacker
if (_vm->_quit) if (_vm->_quit)
@ -205,10 +205,10 @@ int32 MoviePlayer::play(const char *filename, MovieTextObject *text[], int32 lea
playDummy(filename, text, leadOut, leadOutLen); playDummy(filename, text, leadOut, leadOutLen);
#endif #endif
_vm->_mixer->stopHandle(leadInHandle); _snd->stopHandle(leadInHandle);
// Wait for the lead-out to stop, if there is any. // Wait for the lead-out to stop, if there is any.
while (_leadOutHandle.isActive()) { while (_vm->_mixer->isSoundHandleActive(_leadOutHandle)) {
_vm->_screen->updateDisplay(); _vm->_screen->updateDisplay();
_vm->_system->delayMillis(30); _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) { void MoviePlayer::playMPEG(const char *filename, MovieTextObject *text[], byte *leadOut, uint32 leadOutLen) {
uint frameCounter = 0, textCounter = 0; uint frameCounter = 0, textCounter = 0;
PlayingSoundHandle handle; SoundHandle handle;
bool skipCutscene = false, textVisible = false; bool skipCutscene = false, textVisible = false;
uint32 flags = SoundMixer::FLAG_16BITS; uint32 flags = SoundMixer::FLAG_16BITS;
bool startNextText = false; 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); _snd->playRaw(&handle, text[textCounter]->speech, text[textCounter]->speechBufferSize, 22050, flags);
startNextText = false; 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 // If the speech is still playing, redraw the subtitles. At least in
// the English version this is most noticeable in the "carib" cutscene. // the English version this is most noticeable in the "carib" cutscene.
if (textVisible && handle.isActive()) if (textVisible && _snd->isSoundHandleActive(handle))
drawTextObject(anim, text[textCounter]); drawTextObject(anim, text[textCounter]);
if (text) if (text)
@ -354,7 +354,7 @@ void MoviePlayer::playMPEG(const char *filename, MovieTextObject *text[], byte *
if (skipCutscene) if (skipCutscene)
_snd->stopHandle(handle); _snd->stopHandle(handle);
while (handle.isActive()) { while (_snd->isSoundHandleActive(handle)) {
_vm->_screen->updateDisplay(false); _vm->_screen->updateDisplay(false);
_sys->delayMillis(100); _sys->delayMillis(100);
} }
@ -441,7 +441,7 @@ void MoviePlayer::playDummy(const char *filename, MovieTextObject *text[], byte
tmpPal[255 * 4 + 2] = 255; tmpPal[255 * 4 + 2] = 255;
_vm->_screen->setPalette(0, 256, tmpPal, RDPAL_INSTANT); _vm->_screen->setPalette(0, 256, tmpPal, RDPAL_INSTANT);
PlayingSoundHandle handle; SoundHandle handle;
bool skipCutscene = false; 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 // 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. // 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); _vm->_screen->updateDisplay(false);
_sys->delayMillis(100); _sys->delayMillis(100);
} }

View File

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

View File

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

View File

@ -156,7 +156,7 @@ void Sound::processFxQueue() {
break; break;
case FX_SPOT2: case FX_SPOT2:
// Once the FX has finished remove it from the queue. // 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); _vm->_resman->closeResource(_fxQueue[i].resource);
_fxQueue[i].resource = 0; _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); 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) if (_fxMuted)
return RD_OK; return RD_OK;
if (handle->isActive()) if (_vm->_mixer->isSoundHandleActive(*handle))
return RDERR_FXALREADYOPEN; return RDERR_FXALREADYOPEN;
Common::MemoryReadStream stream(data, len); Common::MemoryReadStream stream(data, len);
@ -287,7 +287,6 @@ int32 Sound::stopFx(int32 i) {
if (!_fxQueue[i].resource) if (!_fxQueue[i].resource)
return RDERR_FXNOTOPEN; 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); _vm->_resman->closeResource(_fxQueue[i].resource);

View File

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