2003-10-21 12:29:37 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2003-2006 The ScummVM project
|
2003-10-21 12:29:37 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-10-21 12:29:37 +00:00
|
|
|
*
|
2006-02-11 10:07:12 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2003-10-21 12:29:37 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/stdafx.h"
|
2003-12-01 20:48:41 +00:00
|
|
|
#include "queen/sound.h"
|
2003-12-11 22:16:35 +00:00
|
|
|
|
2003-10-23 06:44:35 +00:00
|
|
|
#include "queen/input.h"
|
2003-12-14 00:33:21 +00:00
|
|
|
#include "queen/music.h"
|
2003-12-11 22:16:35 +00:00
|
|
|
#include "queen/queen.h"
|
2003-10-21 12:29:37 +00:00
|
|
|
#include "queen/resource.h"
|
|
|
|
|
2004-11-27 15:58:18 +00:00
|
|
|
#include "sound/flac.h"
|
|
|
|
#include "sound/mp3.h"
|
|
|
|
#include "sound/vorbis.h"
|
|
|
|
|
2003-10-21 12:29:37 +00:00
|
|
|
#define SB_HEADER_SIZE 110
|
2003-11-07 02:33:20 +00:00
|
|
|
#define STOP_MUSIC -1
|
2003-10-21 12:29:37 +00:00
|
|
|
|
|
|
|
namespace Queen {
|
|
|
|
|
2005-07-30 21:11:48 +00:00
|
|
|
Sound::Sound(Audio::Mixer *mixer, QueenEngine *vm) :
|
2004-02-27 23:54:13 +00:00
|
|
|
_mixer(mixer), _vm(vm), _sfxToggle(true), _speechToggle(true), _musicToggle(true), _lastOverride(0) {
|
2003-10-21 12:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Sound::~Sound() {
|
|
|
|
}
|
|
|
|
|
2005-05-10 23:48:48 +00:00
|
|
|
Sound *Sound::giveSound(Audio::Mixer *mixer, QueenEngine *vm, uint8 compression) {
|
2004-10-01 14:48:49 +00:00
|
|
|
if (!mixer->isReady())
|
|
|
|
return new SilentSound(mixer, vm);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-04-07 08:57:40 +00:00
|
|
|
switch (compression) {
|
|
|
|
case COMPRESSION_NONE:
|
|
|
|
return new SBSound(mixer, vm);
|
|
|
|
break;
|
|
|
|
case COMPRESSION_MP3:
|
|
|
|
#ifndef USE_MAD
|
|
|
|
warning("Using MP3 compressed datafile, but MP3 support not compiled in");
|
|
|
|
return new SilentSound(mixer, vm);
|
|
|
|
#else
|
|
|
|
return new MP3Sound(mixer, vm);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case COMPRESSION_OGG:
|
2005-08-10 12:42:56 +00:00
|
|
|
#ifndef USE_VORBIS
|
2005-04-07 08:57:40 +00:00
|
|
|
warning("Using OGG compressed datafile, but OGG support not compiled in");
|
|
|
|
return new SilentSound(mixer, vm);
|
|
|
|
#else
|
|
|
|
return new OGGSound(mixer, vm);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case COMPRESSION_FLAC:
|
|
|
|
#ifndef USE_FLAC
|
|
|
|
warning("Using FLAC compressed datafile, but FLAC support not compiled in");
|
|
|
|
return new SilentSound(mixer, vm);
|
|
|
|
#else
|
|
|
|
return new FLACSound(mixer, vm);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
warning("Unknown compression type");
|
|
|
|
return new SilentSound(mixer, vm);
|
2003-10-21 12:29:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-25 22:10:23 +00:00
|
|
|
void Sound::waitFinished(bool isSpeech) {
|
|
|
|
if (isSpeech)
|
2005-03-12 18:56:09 +00:00
|
|
|
while (_mixer->isSoundHandleActive(_speechHandle))
|
2004-01-25 22:10:23 +00:00
|
|
|
_vm->input()->delay(10);
|
|
|
|
else
|
2005-03-12 18:56:09 +00:00
|
|
|
while (_mixer->isSoundHandleActive(_sfxHandle))
|
2004-01-25 22:10:23 +00:00
|
|
|
_vm->input()->delay(10);
|
2003-10-21 12:29:37 +00:00
|
|
|
}
|
|
|
|
|
2004-01-25 22:10:23 +00:00
|
|
|
void Sound::playSfx(uint16 sfx, bool isSpeech) {
|
2004-02-21 20:50:56 +00:00
|
|
|
if (isSpeech && !speechOn()) return;
|
2004-12-19 12:19:21 +00:00
|
|
|
else if (!sfxOn()) return;
|
2004-02-21 20:50:56 +00:00
|
|
|
|
2003-12-20 16:54:46 +00:00
|
|
|
if (sfx != 0) {
|
|
|
|
char name[13];
|
2005-11-05 18:12:41 +00:00
|
|
|
#ifndef PALMOS_68K
|
2003-12-20 16:54:46 +00:00
|
|
|
strcpy(name, _sfxName[sfx - 1]);
|
2004-03-17 14:10:51 +00:00
|
|
|
#else
|
|
|
|
strncpy(name, _sfxName + 10 * (sfx - 1), 10); // saved as 8char + /0/0
|
|
|
|
#endif
|
2003-12-20 16:54:46 +00:00
|
|
|
strcat(name, ".SB");
|
2004-01-25 22:10:23 +00:00
|
|
|
waitFinished(isSpeech);
|
2005-11-07 18:34:55 +00:00
|
|
|
if (sfxPlay(name, isSpeech ? &_speechHandle : &_sfxHandle)) {
|
2004-12-19 12:19:21 +00:00
|
|
|
_speechSfxExists = isSpeech;
|
|
|
|
} else {
|
|
|
|
_speechSfxExists = false;
|
|
|
|
}
|
2003-12-20 16:54:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-25 22:10:23 +00:00
|
|
|
void Sound::playSfx(const char *base, bool isSpeech) {
|
2004-02-21 20:50:56 +00:00
|
|
|
if (isSpeech && !speechOn()) return;
|
|
|
|
else if (!sfxOn()) return;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-12-20 16:54:46 +00:00
|
|
|
char name[13];
|
|
|
|
strcpy(name, base);
|
|
|
|
// alter filename to add zeros and append ".SB"
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
if (name[i] == ' ')
|
|
|
|
name[i] = '0';
|
|
|
|
}
|
|
|
|
strcat(name, ".SB");
|
2004-01-25 22:10:23 +00:00
|
|
|
waitFinished(isSpeech);
|
2005-11-07 18:34:55 +00:00
|
|
|
if (sfxPlay(name, isSpeech ? &_speechHandle : &_sfxHandle)) {
|
2004-12-19 12:19:21 +00:00
|
|
|
_speechSfxExists = isSpeech;
|
|
|
|
} else {
|
|
|
|
_speechSfxExists = false;
|
|
|
|
}
|
2003-12-20 16:54:46 +00:00
|
|
|
}
|
|
|
|
|
2003-11-07 02:33:20 +00:00
|
|
|
void Sound::playSong(int16 songNum) {
|
2003-12-28 01:47:37 +00:00
|
|
|
if (songNum <= 0) {
|
2003-12-14 00:33:21 +00:00
|
|
|
_vm->music()->stopSong();
|
|
|
|
return;
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-01-25 05:03:35 +00:00
|
|
|
int16 newTune;
|
|
|
|
if (_vm->resource()->isDemo()) {
|
2004-01-25 16:57:05 +00:00
|
|
|
if (songNum == 17) {
|
|
|
|
_vm->music()->stopSong();
|
|
|
|
return;
|
|
|
|
}
|
2004-01-25 05:03:35 +00:00
|
|
|
newTune = _songDemo[songNum - 1].tuneList[0] - 1;
|
|
|
|
} else {
|
|
|
|
newTune = _song[songNum - 1].tuneList[0] - 1;
|
|
|
|
}
|
2003-11-07 02:33:20 +00:00
|
|
|
|
2004-01-04 03:37:12 +00:00
|
|
|
if (_tune[newTune].sfx[0]) {
|
2003-12-14 03:36:47 +00:00
|
|
|
if (sfxOn())
|
2004-01-25 22:10:23 +00:00
|
|
|
playSfx(_tune[newTune].sfx[0], false);
|
2003-12-14 00:33:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-01-25 05:03:35 +00:00
|
|
|
if (!musicOn())
|
2003-12-14 04:07:22 +00:00
|
|
|
return;
|
|
|
|
|
2004-01-25 05:03:35 +00:00
|
|
|
int override = (_vm->resource()->isDemo()) ? _songDemo[songNum - 1].override : _song[songNum - 1].override;
|
|
|
|
switch (override) {
|
2005-04-07 08:57:40 +00:00
|
|
|
// Override all songs
|
|
|
|
case 1:
|
|
|
|
break;
|
|
|
|
// Alter song settings (such as volume) and exit
|
|
|
|
case 2:
|
|
|
|
_vm->music()->toggleVChange();
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
break;
|
2004-01-04 03:37:12 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-12-28 01:17:29 +00:00
|
|
|
_lastOverride = songNum;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-01-22 23:10:05 +00:00
|
|
|
_vm->music()->queueTuneList(newTune);
|
|
|
|
_vm->music()->playMusic();
|
2003-11-07 02:33:20 +00:00
|
|
|
}
|
|
|
|
|
2004-01-12 13:40:02 +00:00
|
|
|
void Sound::saveState(byte *&ptr) {
|
|
|
|
WRITE_BE_UINT16(ptr, _lastOverride); ptr += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sound::loadState(uint32 ver, byte *&ptr) {
|
2004-03-23 20:34:19 +00:00
|
|
|
_lastOverride = (int16)READ_BE_INT16(ptr); ptr += 2;
|
2004-01-12 13:40:02 +00:00
|
|
|
}
|
|
|
|
|
2005-11-07 18:34:55 +00:00
|
|
|
bool SilentSound::sfxPlay(const char *name, Audio::SoundHandle *soundHandle) {
|
|
|
|
return false;
|
2003-10-21 12:29:37 +00:00
|
|
|
}
|
|
|
|
|
2005-11-07 18:34:55 +00:00
|
|
|
bool SBSound::sfxPlay(const char *name, Audio::SoundHandle *soundHandle) {
|
|
|
|
if (_vm->resource()->fileExists(name)) {
|
|
|
|
uint32 size;
|
|
|
|
uint8 *sound = _vm->resource()->loadFile(name, SB_HEADER_SIZE, &size, true);
|
|
|
|
byte flags = Audio::Mixer::FLAG_UNSIGNED | Audio::Mixer::FLAG_AUTOFREE;
|
|
|
|
_mixer->playRaw(soundHandle, sound, size, 11025, flags);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2003-10-21 12:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_MAD
|
2005-11-07 18:34:55 +00:00
|
|
|
bool MP3Sound::sfxPlay(const char *name, Audio::SoundHandle *soundHandle) {
|
2004-12-19 12:19:21 +00:00
|
|
|
uint32 size;
|
2005-05-10 22:56:25 +00:00
|
|
|
Common::File *f = _vm->resource()->giveCompressedSound(name, &size);
|
2005-11-07 18:34:55 +00:00
|
|
|
if (f) {
|
|
|
|
_mixer->playInputStream(Audio::Mixer::kSFXSoundType, soundHandle, makeMP3Stream(f, size));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2003-10-28 15:26:05 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-08-10 12:42:56 +00:00
|
|
|
#ifdef USE_VORBIS
|
2005-11-07 18:34:55 +00:00
|
|
|
bool OGGSound::sfxPlay(const char *name, Audio::SoundHandle *soundHandle) {
|
2004-12-19 12:19:21 +00:00
|
|
|
uint32 size;
|
2005-07-30 21:11:48 +00:00
|
|
|
Common::File *f = _vm->resource()->giveCompressedSound(name, &size);
|
2005-11-07 18:34:55 +00:00
|
|
|
if (f) {
|
|
|
|
_mixer->playInputStream(Audio::Mixer::kSFXSoundType, soundHandle, makeVorbisStream(f, size));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2003-10-21 12:29:37 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-02-22 14:11:16 +00:00
|
|
|
#ifdef USE_FLAC
|
2005-11-07 18:34:55 +00:00
|
|
|
bool FLACSound::sfxPlay(const char *name, Audio::SoundHandle *soundHandle) {
|
2004-12-19 12:19:21 +00:00
|
|
|
uint32 size;
|
2005-07-30 21:11:48 +00:00
|
|
|
Common::File *f = _vm->resource()->giveCompressedSound(name, &size);
|
2005-11-07 18:34:55 +00:00
|
|
|
if (f) {
|
|
|
|
_mixer->playInputStream(Audio::Mixer::kSFXSoundType, soundHandle, makeFlacStream(f, size));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2004-02-22 14:11:16 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-10-21 12:29:37 +00:00
|
|
|
} //End of namespace Queen
|