aboutsummaryrefslogtreecommitdiff
path: root/engines/queen
diff options
context:
space:
mode:
authorGregory Montoir2006-11-24 18:37:43 +0000
committerGregory Montoir2006-11-24 18:37:43 +0000
commit28be8164ac396417602594b3362f0b1d04a195a4 (patch)
tree30f6b07354f2832d3d0465d0b6a25f0d5dc5f449 /engines/queen
parentd4f61e6ee91bc705fd781f0b5c2a7f9e55af80e4 (diff)
downloadscummvm-rg350-28be8164ac396417602594b3362f0b1d04a195a4.tar.gz
scummvm-rg350-28be8164ac396417602594b3362f0b1d04a195a4.tar.bz2
scummvm-rg350-28be8164ac396417602594b3362f0b1d04a195a4.zip
simplification, removed some duplicated code
svn-id: r24783
Diffstat (limited to 'engines/queen')
-rw-r--r--engines/queen/cutaway.cpp2
-rw-r--r--engines/queen/graphics.cpp4
-rw-r--r--engines/queen/logic.cpp2
-rw-r--r--engines/queen/sound.cpp130
-rw-r--r--engines/queen/sound.h26
-rw-r--r--engines/queen/talk.cpp7
6 files changed, 72 insertions, 99 deletions
diff --git a/engines/queen/cutaway.cpp b/engines/queen/cutaway.cpp
index acf974fd4e..f6220cf7dd 100644
--- a/engines/queen/cutaway.cpp
+++ b/engines/queen/cutaway.cpp
@@ -1242,7 +1242,7 @@ void Cutaway::handleText(
char voiceFileName[MAX_STRING_SIZE];
findCdCut(_basename, index, voiceFileName);
strcat(voiceFileName, "1");
- _vm->sound()->playSfx(voiceFileName, true);
+ _vm->sound()->playSpeech(voiceFileName);
}
if (OBJECT_TYPE_TEXT_SPEAK == type && _vm->sound()->speechOn() && !_vm->subtitles())
diff --git a/engines/queen/graphics.cpp b/engines/queen/graphics.cpp
index 11ae2d1e27..60be8f86cc 100644
--- a/engines/queen/graphics.cpp
+++ b/engines/queen/graphics.cpp
@@ -380,7 +380,7 @@ void Graphics::sortBobs() {
if (pbs->animating) {
pbs->animOneStep();
if (pbs->frameNum > 500) { // SFX frame
- _vm->sound()->playSfx(_vm->logic()->currentRoomSfx(), false);
+ _vm->sound()->playSfx(_vm->logic()->currentRoomSfx());
pbs->frameNum -= 500;
}
}
@@ -1125,7 +1125,7 @@ void BamScene::playSfx() {
// this problem since its playSfx() function returns immediately
// if a sound is already being played.
if (_lastSoundIndex == 0 || _index - _lastSoundIndex >= SFX_SKIP) {
- _vm->sound()->playSfx(_vm->logic()->currentRoomSfx(), false);
+ _vm->sound()->playSfx(_vm->logic()->currentRoomSfx());
_lastSoundIndex = _index;
}
}
diff --git a/engines/queen/logic.cpp b/engines/queen/logic.cpp
index 150afb5a6b..9973386b65 100644
--- a/engines/queen/logic.cpp
+++ b/engines/queen/logic.cpp
@@ -1760,7 +1760,7 @@ void Logic::asmMakeLightningHitPlane() {
lightningBob->x = 160;
lightningBob->y = 0;
- _vm->sound()->playSfx(currentRoomSfx(), false);
+ _vm->sound()->playSfx(currentRoomSfx());
_vm->bankMan()->unpack(18, lightningBob->frameNum, 15);
_vm->bankMan()->unpack(4, planeBob ->frameNum, 15);
diff --git a/engines/queen/sound.cpp b/engines/queen/sound.cpp
index 5a2e8598df..6cea53f1c1 100644
--- a/engines/queen/sound.cpp
+++ b/engines/queen/sound.cpp
@@ -82,39 +82,27 @@ Sound *Sound::giveSound(Audio::Mixer *mixer, QueenEngine *vm, uint8 compression)
}
void Sound::waitFinished(bool isSpeech) {
- if (isSpeech)
- while (_mixer->isSoundHandleActive(_speechHandle))
- _vm->input()->delay(10);
- else
- while (_mixer->isSoundHandleActive(_sfxHandle))
- _vm->input()->delay(10);
+ while (_mixer->isSoundHandleActive(isSpeech ? _speechHandle : _sfxHandle))
+ _vm->input()->delay(10);
}
-void Sound::playSfx(uint16 sfx, bool isSpeech) {
- if (isSpeech && !speechOn()) return;
- else if (!sfxOn()) return;
-
- if (sfx != 0) {
- char name[13];
+void Sound::playSfx(uint16 sfx) {
+ if (sfxOn() && sfx != 0) {
#ifndef PALMOS_68K
- strcpy(name, _sfxName[sfx - 1]);
+ playSound(_sfxName[sfx - 1], false);
#else
- strncpy(name, _sfxName + 10 * (sfx - 1), 10); // saved as 8char + /0/0
+ playSound(_sfxName + 10 * (sfx - 1), false); // saved as 8char + /0/0
#endif
- strcat(name, ".SB");
- waitFinished(isSpeech);
- if (sfxPlay(name, isSpeech ? &_speechHandle : &_sfxHandle)) {
- _speechSfxExists = isSpeech;
- } else {
- _speechSfxExists = false;
- }
}
}
-void Sound::playSfx(const char *base, bool isSpeech) {
- if (isSpeech && !speechOn()) return;
- else if (!sfxOn()) return;
+void Sound::playSpeech(const char *base) {
+ if (speechOn()) {
+ playSound(base, true);
+ }
+}
+void Sound::playSound(const char *base, bool isSpeech) {
char name[13];
strcpy(name, base);
// alter filename to add zeros and append ".SB"
@@ -124,7 +112,10 @@ void Sound::playSfx(const char *base, bool isSpeech) {
}
strcat(name, ".SB");
waitFinished(isSpeech);
- if (sfxPlay(name, isSpeech ? &_speechHandle : &_sfxHandle)) {
+ uint32 size;
+ Common::File *f = _vm->resource()->giveSound(name, &size);
+ if (f) {
+ playSoundData(f, size, isSpeech ? &_speechHandle : &_sfxHandle);
_speechSfxExists = isSpeech;
} else {
_speechSfxExists = false;
@@ -149,8 +140,7 @@ void Sound::playSong(int16 songNum) {
}
if (_tune[newTune].sfx[0]) {
- if (sfxOn())
- playSfx(_tune[newTune].sfx[0], false);
+ playSfx(_tune[newTune].sfx[0]);
return;
}
@@ -167,7 +157,6 @@ void Sound::playSong(int16 songNum) {
_vm->music()->toggleVChange();
default:
return;
- break;
}
_lastOverride = songNum;
@@ -184,75 +173,50 @@ void Sound::loadState(uint32 ver, byte *&ptr) {
_lastOverride = (int16)READ_BE_INT16(ptr); ptr += 2;
}
-bool SilentSound::sfxPlay(const char *name, Audio::SoundHandle *soundHandle) {
- return false;
+void SilentSound::playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle) {
}
-bool SBSound::sfxPlay(const char *name, Audio::SoundHandle *soundHandle) {
- uint32 size;
- Common::File *f = _vm->resource()->giveSound(name, &size);
- if (f) {
- int headerSize;
- f->seek(2, SEEK_CUR);
- uint16 version = f->readUint16LE();
- switch (version) {
- case 104:
- headerSize = SB_HEADER_SIZE_V104;
- break;
- case 110:
- headerSize = SB_HEADER_SIZE_V110;
- break;
- default:
- warning("Unhandled SB file version %d, defaulting to 104\n", version);
- headerSize = SB_HEADER_SIZE_V104;
- break;
- }
- f->seek(headerSize - 4, SEEK_CUR);
- size -= headerSize;
- uint8 *sound = (uint8 *)malloc(size);
- if (sound) {
- f->read(sound, size);
- byte flags = Audio::Mixer::FLAG_UNSIGNED | Audio::Mixer::FLAG_AUTOFREE;
- _mixer->playRaw(soundHandle, sound, size, 11025, flags);
- return true;
- }
+void SBSound::playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle) {
+ int headerSize;
+ f->seek(2, SEEK_CUR);
+ uint16 version = f->readUint16LE();
+ switch (version) {
+ case 104:
+ headerSize = SB_HEADER_SIZE_V104;
+ break;
+ case 110:
+ headerSize = SB_HEADER_SIZE_V110;
+ break;
+ default:
+ warning("Unhandled SB file version %d, defaulting to 104\n", version);
+ headerSize = SB_HEADER_SIZE_V104;
+ break;
+ }
+ f->seek(headerSize - 4, SEEK_CUR);
+ size -= headerSize;
+ uint8 *sound = (uint8 *)malloc(size);
+ if (sound) {
+ f->read(sound, size);
+ byte flags = Audio::Mixer::FLAG_UNSIGNED | Audio::Mixer::FLAG_AUTOFREE;
+ _mixer->playRaw(soundHandle, sound, size, 11025, flags);
}
- return false;
}
#ifdef USE_MAD
-bool MP3Sound::sfxPlay(const char *name, Audio::SoundHandle *soundHandle) {
- uint32 size;
- Common::File *f = _vm->resource()->giveSound(name, &size);
- if (f) {
- _mixer->playInputStream(Audio::Mixer::kSFXSoundType, soundHandle, Audio::makeMP3Stream(f, size));
- return true;
- }
- return false;
+void MP3Sound::playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle) {
+ _mixer->playInputStream(Audio::Mixer::kSFXSoundType, soundHandle, Audio::makeMP3Stream(f, size));
}
#endif
#ifdef USE_VORBIS
-bool OGGSound::sfxPlay(const char *name, Audio::SoundHandle *soundHandle) {
- uint32 size;
- Common::File *f = _vm->resource()->giveSound(name, &size);
- if (f) {
- _mixer->playInputStream(Audio::Mixer::kSFXSoundType, soundHandle, Audio::makeVorbisStream(f, size));
- return true;
- }
- return false;
+void OGGSound::playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle) {
+ _mixer->playInputStream(Audio::Mixer::kSFXSoundType, soundHandle, Audio::makeVorbisStream(f, size));
}
#endif
#ifdef USE_FLAC
-bool FLACSound::sfxPlay(const char *name, Audio::SoundHandle *soundHandle) {
- uint32 size;
- Common::File *f = _vm->resource()->giveSound(name, &size);
- if (f) {
- _mixer->playInputStream(Audio::Mixer::kSFXSoundType, soundHandle, Audio::makeFlacStream(f, size));
- return true;
- }
- return false;
+void FLACSound::playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle) {
+ _mixer->playInputStream(Audio::Mixer::kSFXSoundType, soundHandle, Audio::makeFlacStream(f, size));
}
#endif
diff --git a/engines/queen/sound.h b/engines/queen/sound.h
index ea6c9f1bb2..354328099d 100644
--- a/engines/queen/sound.h
+++ b/engines/queen/sound.h
@@ -27,6 +27,10 @@
#include "sound/mixer.h"
#include "queen/defs.h"
+namespace Common {
+ class File;
+}
+
namespace Queen {
class Input;
@@ -54,10 +58,9 @@ class Sound {
public:
Sound(Audio::Mixer *mixer, QueenEngine *vm);
virtual ~Sound();
- virtual bool sfxPlay(const char *name, Audio::SoundHandle *soundHandle) = 0;
static Sound *giveSound(Audio::Mixer *mixer, QueenEngine *vm, uint8 compression);
- void playSfx(uint16 sfx, bool isSpeech);
- void playSfx(const char *base, bool isSpeech);
+ void playSfx(uint16 sfx);
+ void playSpeech(const char *base);
void playSong(int16 songNum);
void playLastSong() { playSong(_lastOverride); }
void stopSpeech() { _mixer->stopHandle(_speechHandle); }
@@ -103,6 +106,8 @@ public:
protected:
void waitFinished(bool isSpeech);
+ void playSound(const char *base, bool isSpeech);
+ virtual void playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle) = 0;
Audio::Mixer *_mixer;
QueenEngine *_vm;
@@ -120,20 +125,23 @@ protected:
class SilentSound : public Sound {
public:
SilentSound(Audio::Mixer *mixer, QueenEngine *vm) : Sound(mixer, vm) {};
- bool sfxPlay(const char *name, Audio::SoundHandle *soundHandle);
+protected:
+ void playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle);
};
class SBSound : public Sound {
public:
SBSound(Audio::Mixer *mixer, QueenEngine *vm) : Sound(mixer, vm) {};
- bool sfxPlay(const char *name, Audio::SoundHandle *soundHandle);
+protected:
+ void playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle);
};
#ifdef USE_MAD
class MP3Sound : public Sound {
public:
MP3Sound(Audio::Mixer *mixer, QueenEngine *vm) : Sound(mixer, vm) {};
- bool sfxPlay(const char *name, Audio::SoundHandle *soundHandle);
+protected:
+ void playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle);
};
#endif
@@ -141,7 +149,8 @@ public:
class OGGSound : public Sound {
public:
OGGSound(Audio::Mixer *mixer, QueenEngine *vm) : Sound(mixer, vm) {};
- bool sfxPlay(const char *name, Audio::SoundHandle *soundHandle);
+protected:
+ void playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle);
};
#endif
@@ -149,7 +158,8 @@ public:
class FLACSound : public Sound {
public:
FLACSound(Audio::Mixer *mixer, QueenEngine *vm) : Sound(mixer, vm) {};
- bool sfxPlay(const char *name, Audio::SoundHandle *soundHandle);
+protected:
+ void playSoundData(const char *name, Audio::SoundHandle *soundHandle);
};
#endif // #ifdef USE_FLAC
diff --git a/engines/queen/talk.cpp b/engines/queen/talk.cpp
index bf025523fb..5d1cb6e447 100644
--- a/engines/queen/talk.cpp
+++ b/engines/queen/talk.cpp
@@ -677,7 +677,7 @@ void Talk::stringAnimation(const SpeechParameters *parameters, int startFrame, i
if (frame > 500) {
frame -= 500;
- _vm->sound()->playSfx(_vm->logic()->currentRoomSfx(), false);
+ _vm->sound()->playSfx(_vm->logic()->currentRoomSfx());
}
if (torso) {
@@ -798,9 +798,8 @@ void Talk::speakSegment(
// French talkie version has a useless voice file ; c30e_102 file is the same as c30e_101,
// so there is no need to play it. This voice was used in room 30 (N8) when talking to Klunk.
- if (!(_vm->resource()->getLanguage() == Common::FR_FRA && !strcmp(voiceFileName, "c30e_102"))
- && _vm->sound()->speechOn())
- _vm->sound()->playSfx(voiceFileName, true);
+ if (!(_vm->resource()->getLanguage() == Common::FR_FRA && !strcmp(voiceFileName, "c30e_102")))
+ _vm->sound()->playSpeech(voiceFileName);
int faceDirectionCommand = 0;