aboutsummaryrefslogtreecommitdiff
path: root/engines/queen/sound.cpp
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/sound.cpp
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/sound.cpp')
-rw-r--r--engines/queen/sound.cpp130
1 files changed, 47 insertions, 83 deletions
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