scummvm/queen/sound.cpp

187 lines
4.5 KiB
C++
Raw Normal View History

/* ScummVM - Scumm Interpreter
* Copyright (C) 2003-2004 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
#include "queen/input.h"
#include "queen/music.h"
2003-12-11 22:16:35 +00:00
#include "queen/queen.h"
#include "queen/resource.h"
#define SB_HEADER_SIZE 110
#define STOP_MUSIC -1
namespace Queen {
2003-12-11 22:16:35 +00:00
Sound::Sound(SoundMixer *mixer, QueenEngine *vm) :
_mixer(mixer), _vm(vm), _sfxToggle(true), _speechToggle(true), _musicToggle(true), _lastOverride(0), _currentSong(0) {
}
Sound::~Sound() {
}
2003-12-11 22:16:35 +00:00
Sound *Sound::giveSound(SoundMixer *mixer, QueenEngine *vm, uint8 compression) {
switch(compression) {
case COMPRESSION_NONE:
2003-12-11 22:16:35 +00:00
return new SBSound(mixer, vm);
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);
#else
2003-12-11 22:16:35 +00:00
return new MP3Sound(mixer, vm);
#endif
break;
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);
#else
2003-12-11 22:16:35 +00:00
return new OGGSound(mixer, vm);
#endif
break;
default:
warning("Unknown compression type");
2003-12-11 22:16:35 +00:00
return new SilentSound(mixer, vm);
}
}
void Sound::waitSfxFinished() {
while(_sfxHandle.isActive())
2003-12-11 22:16:35 +00:00
_vm->input()->delay(10);
}
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);
}
void Sound::playSong(int16 songNum) {
if (songNum <= 0) {
_vm->music()->stopSong();
return;
}
int16 newTune = _song[songNum - 1].tuneList[0] - 1;
if (_tune[newTune].sfx[0]) {
if (sfxOn())
playSfx(_tune[newTune].sfx[0]);
return;
}
if (!musicOn() || _vm->resource()->isDemo())
return;
switch (_song[songNum - 1].override) {
// Override all songs
case 1:
break;
// Alter song settings (such as volume) and exit
case 2:
default:
return;
break;
}
_lastOverride = songNum;
switch (_tune[newTune].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;
}
_vm->music()->queueClear();
int i = 0;
while(_tune[newTune].tuneNum[i])
_vm->music()->queueSong(_tune[newTune].tuneNum[i++] - 1);
_vm->music()->playMusic();
}
void Sound::saveState(byte *&ptr) {
WRITE_BE_UINT16(ptr, _lastOverride); ptr += 2;
// XXX lastmerge, lastalter, altmrgpri
}
void Sound::loadState(uint32 ver, byte *&ptr) {
_lastOverride = (int16)READ_BE_UINT16(ptr); ptr += 2;
// XXX lastmerge, lastalter, altmrgpri
}
2003-12-21 00:07:16 +00:00
void SBSound::playSound(byte *sound, uint32 size) {
byte flags = SoundMixer::FLAG_UNSIGNED | SoundMixer::FLAG_AUTOFREE;
2003-12-21 00:07:16 +00:00
_mixer->playRaw(&_sfxHandle, sound, size, 11025, flags);
}
void SBSound::sfxPlay(const char *name) {
waitSfxFinished();
if (_vm->resource()->fileExists(name))
2003-12-11 22:16:35 +00:00
playSound(_vm->resource()->loadFileMalloc(name, SB_HEADER_SIZE), _vm->resource()->fileSize(name) - SB_HEADER_SIZE);
}
#ifdef USE_MAD
void MP3Sound::sfxPlay(const char *name) {
waitSfxFinished();
if (_vm->resource()->fileExists(name))
2003-12-11 22:16:35 +00:00
_mixer->playMP3(&_sfxHandle, _vm->resource()->giveCompressedSound(name), _vm->resource()->fileSize(name));
}
#endif
#ifdef USE_VORBIS
void OGGSound::sfxPlay(const char *name) {
waitSfxFinished();
if (_vm->resource()->fileExists(name))
_mixer->playVorbis(&_sfxHandle, _vm->resource()->giveCompressedSound(name), _vm->resource()->fileSize(name));
}
#endif
} //End of namespace Queen