2003-10-21 12:29:37 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2003 The ScummVM project
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "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"
|
|
|
|
|
|
|
|
#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 {
|
|
|
|
|
2003-12-11 22:16:35 +00:00
|
|
|
Sound::Sound(SoundMixer *mixer, QueenEngine *vm) :
|
2003-12-24 00:25:18 +00:00
|
|
|
_mixer(mixer), _vm(vm), _sfxToggle(true), _speechToggle(true), _musicToggle(true), _lastOverride(0), _currentSong(0) {
|
2003-10-21 12:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Sound::~Sound() {
|
|
|
|
}
|
|
|
|
|
2003-12-11 22:16:35 +00:00
|
|
|
Sound *Sound::giveSound(SoundMixer *mixer, QueenEngine *vm, uint8 compression) {
|
2003-10-21 12:29:37 +00:00
|
|
|
switch(compression) {
|
|
|
|
case COMPRESSION_NONE:
|
2003-12-11 22:16:35 +00:00
|
|
|
return new SBSound(mixer, vm);
|
2003-10-21 12:29:37 +00:00
|
|
|
break;
|
|
|
|
case COMPRESSION_MP3:
|
|
|
|
#ifndef USE_MAD
|
|
|
|
warning("Using MP3 compressed datafile, but MP3 support not compiled in");
|
2003-12-11 22:16:35 +00:00
|
|
|
return new SilentSound(mixer, vm);
|
2003-10-21 12:29:37 +00:00
|
|
|
#else
|
2003-12-11 22:16:35 +00:00
|
|
|
return new MP3Sound(mixer, vm);
|
2003-10-21 12:29:37 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
break;
|
2003-10-28 15:26:05 +00:00
|
|
|
case COMPRESSION_OGG:
|
|
|
|
#ifndef USE_VORBIS
|
|
|
|
warning("Using OGG compressed datafile, but OGG support not compiled in");
|
2003-12-11 22:16:35 +00:00
|
|
|
return new SilentSound(mixer, vm);
|
2003-10-28 15:26:05 +00:00
|
|
|
#else
|
2003-12-11 22:16:35 +00:00
|
|
|
return new OGGSound(mixer, vm);
|
2003-10-28 15:26:05 +00:00
|
|
|
#endif
|
|
|
|
break;
|
2003-10-21 12:29:37 +00:00
|
|
|
default:
|
|
|
|
warning("Unknown compression type");
|
2003-12-11 22:16:35 +00:00
|
|
|
return new SilentSound(mixer, vm);
|
2003-10-21 12:29:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-07 02:33:20 +00:00
|
|
|
void Sound::waitSfxFinished() {
|
2003-12-24 00:25:18 +00:00
|
|
|
while(_sfxHandle.isActive())
|
2003-12-11 22:16:35 +00:00
|
|
|
_vm->input()->delay(10);
|
2003-10-21 12:29:37 +00:00
|
|
|
}
|
|
|
|
|
2003-12-20 16:54:46 +00:00
|
|
|
void Sound::playSfx(uint16 sfx) {
|
|
|
|
if (sfx != 0) {
|
|
|
|
char name[13];
|
|
|
|
strcpy(name, _sfxName[sfx - 1]);
|
|
|
|
strcat(name, ".SB");
|
|
|
|
sfxPlay(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sound::playSfx(const char *base) {
|
|
|
|
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");
|
|
|
|
sfxPlay(name);
|
|
|
|
}
|
|
|
|
|
2003-11-07 02:33:20 +00:00
|
|
|
void Sound::playSong(int16 songNum) {
|
2003-12-14 00:33:21 +00:00
|
|
|
if (songNum == STOP_MUSIC) {
|
|
|
|
_vm->music()->stopSong();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-11-14 00:45:44 +00:00
|
|
|
int16 newTune = _song[songNum - 1].tuneList[0];
|
2003-11-07 02:33:20 +00:00
|
|
|
|
2003-12-14 03:36:47 +00:00
|
|
|
if (_tune[newTune - 1].sfx[0]) {
|
|
|
|
if (sfxOn())
|
2003-12-20 16:54:46 +00:00
|
|
|
playSfx(_tune[newTune - 1].sfx[0]);
|
2003-12-14 00:33:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-12-14 04:07:22 +00:00
|
|
|
if (!musicOn())
|
|
|
|
return;
|
|
|
|
|
2003-12-28 01:17:29 +00:00
|
|
|
_lastOverride = songNum;
|
2003-12-14 00:33:21 +00:00
|
|
|
|
|
|
|
switch (_tune[newTune - 1].mode) {
|
|
|
|
//Random loop
|
|
|
|
case 0:
|
|
|
|
warning("Music: Random loop not yet supported (doing sequential loop instead)");
|
|
|
|
//Sequential loop
|
|
|
|
case 1:
|
|
|
|
_vm->music()->loop(true);
|
|
|
|
break;
|
|
|
|
//Play once
|
|
|
|
case 2:
|
|
|
|
default:
|
|
|
|
_vm->music()->loop(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-12-28 01:17:29 +00:00
|
|
|
int16 song = _tune[newTune - 1].tuneNum[0] - 1;
|
|
|
|
|
|
|
|
// Work around bug in Roland music, note that these numbers are 'one-off' from
|
|
|
|
// the original code.
|
|
|
|
if (/*isRoland && */ song == 88 || song == 89) {
|
|
|
|
warning("Working around Roland music bug");
|
|
|
|
song = 62;
|
|
|
|
}
|
|
|
|
|
|
|
|
_vm->music()->playSong(song);
|
2003-11-07 02:33:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-21 00:07:16 +00:00
|
|
|
void SBSound::playSound(byte *sound, uint32 size) {
|
2003-12-20 16:54:46 +00:00
|
|
|
byte flags = SoundMixer::FLAG_UNSIGNED | SoundMixer::FLAG_AUTOFREE;
|
2003-12-21 00:07:16 +00:00
|
|
|
_mixer->playRaw(&_sfxHandle, sound, size, 11025, flags);
|
2003-10-21 12:29:37 +00:00
|
|
|
}
|
|
|
|
|
2003-12-20 16:54:46 +00:00
|
|
|
void SBSound::sfxPlay(const char *name) {
|
|
|
|
waitSfxFinished();
|
2003-12-11 22:16:35 +00:00
|
|
|
if (_vm->resource()->exists(name))
|
|
|
|
playSound(_vm->resource()->loadFileMalloc(name, SB_HEADER_SIZE), _vm->resource()->fileSize(name) - SB_HEADER_SIZE);
|
2003-10-21 12:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_MAD
|
2003-12-20 16:54:46 +00:00
|
|
|
void MP3Sound::sfxPlay(const char *name) {
|
2003-11-07 02:33:20 +00:00
|
|
|
waitSfxFinished();
|
2003-12-11 22:16:35 +00:00
|
|
|
if (_vm->resource()->exists(name))
|
|
|
|
_mixer->playMP3(&_sfxHandle, _vm->resource()->giveCompressedSound(name), _vm->resource()->fileSize(name));
|
2003-10-28 15:26:05 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_VORBIS
|
2003-12-20 16:54:46 +00:00
|
|
|
void OGGSound::sfxPlay(const char *name) {
|
|
|
|
waitSfxFinished();
|
2003-12-21 15:47:52 +00:00
|
|
|
if (_vm->resource()->exists(name))
|
|
|
|
_mixer->playVorbis(&_sfxHandle, _vm->resource()->giveCompressedSound(name), _vm->resource()->fileSize(name));
|
2003-10-21 12:29:37 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} //End of namespace Queen
|