2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2005-01-09 16:06:29 +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.
|
2005-01-09 16:06:29 +00:00
|
|
|
*
|
2006-02-09 12:19:53 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2005-01-09 16:06:29 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
#include "common/stdafx.h"
|
2005-09-11 14:35:34 +00:00
|
|
|
#include "common/system.h"
|
2005-06-24 16:01:42 +00:00
|
|
|
#include "kyra/resource.h"
|
2005-08-19 22:12:09 +00:00
|
|
|
#include "kyra/sound.h"
|
2004-11-11 13:37:35 +00:00
|
|
|
|
2006-01-13 23:06:04 +00:00
|
|
|
#include "sound/mixer.h"
|
|
|
|
#include "sound/voc.h"
|
|
|
|
#include "sound/audiostream.h"
|
|
|
|
|
2006-02-10 16:39:56 +00:00
|
|
|
#include "sound/mp3.h"
|
|
|
|
#include "sound/vorbis.h"
|
|
|
|
#include "sound/flac.h"
|
|
|
|
|
2004-11-11 13:37:35 +00:00
|
|
|
namespace Kyra {
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2007-04-01 13:10:50 +00:00
|
|
|
Sound::Sound(KyraEngine *vm, Audio::Mixer *mixer)
|
|
|
|
: _vm(vm), _mixer(mixer), _currentVocFile(0), _vocHandle(), _compressHandle(),
|
2007-03-24 00:04:08 +00:00
|
|
|
_musicEnabled(1), _sfxEnabled(true), _soundFileList(0), _soundFileListSize(0) {
|
2006-02-27 22:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Sound::~Sound() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sound::voicePlay(const char *file) {
|
|
|
|
uint32 fileSize = 0;
|
|
|
|
byte *fileData = 0;
|
|
|
|
bool found = false;
|
|
|
|
char filenamebuffer[25];
|
|
|
|
|
|
|
|
for (int i = 0; _supportedCodes[i].fileext; ++i) {
|
|
|
|
strcpy(filenamebuffer, file);
|
|
|
|
strcat(filenamebuffer, _supportedCodes[i].fileext);
|
|
|
|
|
2006-05-17 18:07:02 +00:00
|
|
|
_compressHandle.close();
|
2007-04-01 13:10:50 +00:00
|
|
|
_vm->resource()->getFileHandle(filenamebuffer, &fileSize, _compressHandle);
|
2007-02-08 08:41:14 +00:00
|
|
|
if (!_compressHandle.isOpen())
|
2006-02-27 22:39:55 +00:00
|
|
|
continue;
|
|
|
|
|
2007-07-15 18:29:05 +00:00
|
|
|
Common::MemoryReadStream *tmp = _compressHandle.readStream(fileSize);
|
|
|
|
assert(tmp);
|
|
|
|
_currentVocFile = _supportedCodes[i].streamFunc(tmp, true, 0, 0, 1);
|
2006-02-27 22:39:55 +00:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
strcpy(filenamebuffer, file);
|
|
|
|
strcat(filenamebuffer, ".VOC");
|
|
|
|
|
2007-04-01 13:10:50 +00:00
|
|
|
fileData = _vm->resource()->fileData(filenamebuffer, &fileSize);
|
2006-02-27 22:39:55 +00:00
|
|
|
if (!fileData)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Common::MemoryReadStream vocStream(fileData, fileSize);
|
2006-04-29 22:33:31 +00:00
|
|
|
_currentVocFile = Audio::makeVOCStream(vocStream);
|
2006-02-27 22:39:55 +00:00
|
|
|
}
|
|
|
|
|
2006-10-29 15:27:03 +00:00
|
|
|
if (_currentVocFile) {
|
|
|
|
_mixer->stopHandle(_vocHandle);
|
2006-02-27 22:39:55 +00:00
|
|
|
_mixer->playInputStream(Audio::Mixer::kSpeechSoundType, &_vocHandle, _currentVocFile);
|
2006-10-29 15:27:03 +00:00
|
|
|
}
|
2006-02-27 22:39:55 +00:00
|
|
|
delete [] fileData;
|
|
|
|
fileSize = 0;
|
|
|
|
}
|
|
|
|
|
2006-05-28 04:46:34 +00:00
|
|
|
void Sound::voiceStop() {
|
2006-05-28 04:53:22 +00:00
|
|
|
if (_mixer->isSoundHandleActive(_vocHandle))
|
|
|
|
_mixer->stopHandle(_vocHandle);
|
2006-05-28 04:46:34 +00:00
|
|
|
}
|
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
bool Sound::voiceIsPlaying() {
|
|
|
|
return _mixer->isSoundHandleActive(_vocHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2007-04-01 13:10:50 +00:00
|
|
|
SoundMidiPC::SoundMidiPC(KyraEngine *vm, Audio::Mixer *mixer, MidiDriver *driver) : Sound(vm, mixer) {
|
2005-08-19 22:12:09 +00:00
|
|
|
_driver = driver;
|
|
|
|
_passThrough = false;
|
2005-09-11 14:35:34 +00:00
|
|
|
_eventFromMusic = false;
|
|
|
|
_fadeMusicOut = _sfxIsPlaying = false;
|
2005-10-12 19:15:32 +00:00
|
|
|
_fadeStartTime = 0;
|
2006-08-01 13:42:33 +00:00
|
|
|
_isPlaying = _nativeMT32 = _useC55 = false;
|
2005-09-11 14:35:34 +00:00
|
|
|
_soundEffect = _parser = 0;
|
|
|
|
_soundEffectSource = _parserSource = 0;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-09-11 14:35:34 +00:00
|
|
|
memset(_channel, 0, sizeof(MidiChannel*) * 32);
|
|
|
|
memset(_channelVolume, 50, sizeof(uint8) * 16);
|
|
|
|
_channelVolume[10] = 100;
|
2007-04-15 16:41:20 +00:00
|
|
|
for (int i = 0; i < 16; ++i)
|
2005-09-11 14:35:34 +00:00
|
|
|
_virChannel[i] = i;
|
2005-08-19 22:12:09 +00:00
|
|
|
_volume = 0;
|
2004-11-11 13:37:35 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
int ret = open();
|
2007-04-15 16:41:20 +00:00
|
|
|
if (ret != MERR_ALREADY_OPEN && ret != 0)
|
2005-08-19 22:12:09 +00:00
|
|
|
error("couldn't open midi driver");
|
|
|
|
}
|
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
SoundMidiPC::~SoundMidiPC() {
|
2006-07-26 22:24:33 +00:00
|
|
|
stopMusic();
|
|
|
|
stopSoundEffect();
|
|
|
|
|
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
2007-01-29 18:15:14 +00:00
|
|
|
_driver->setTimerCallback(0, 0);
|
2005-08-19 22:12:09 +00:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
void SoundMidiPC::setVolume(int volume) {
|
2005-08-19 22:12:09 +00:00
|
|
|
if (volume < 0)
|
|
|
|
volume = 0;
|
|
|
|
else if (volume > 255)
|
|
|
|
volume = 255;
|
|
|
|
|
|
|
|
if (_volume == volume)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_volume = volume;
|
2005-09-11 14:35:34 +00:00
|
|
|
for (int i = 0; i < 32; ++i) {
|
2005-08-19 22:12:09 +00:00
|
|
|
if (_channel[i]) {
|
2005-09-11 14:35:34 +00:00
|
|
|
if (i >= 16) {
|
|
|
|
_channel[i]->volume(_channelVolume[i - 16] * _volume / 255);
|
|
|
|
} else {
|
|
|
|
_channel[i]->volume(_channelVolume[i] * _volume / 255);
|
|
|
|
}
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
2004-11-11 13:37:35 +00:00
|
|
|
}
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
int SoundMidiPC::open() {
|
2005-08-19 22:12:09 +00:00
|
|
|
// Don't ever call open without first setting the output driver!
|
|
|
|
if (!_driver)
|
|
|
|
return 255;
|
|
|
|
|
|
|
|
int ret = _driver->open();
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
_driver->setTimerCallback(this, &onTimer);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
void SoundMidiPC::close() {
|
2005-08-19 22:12:09 +00:00
|
|
|
if (_driver)
|
|
|
|
_driver->close();
|
|
|
|
_driver = 0;
|
|
|
|
}
|
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
void SoundMidiPC::send(uint32 b) {
|
2006-08-03 11:12:05 +00:00
|
|
|
// HACK: For Kyrandia, we make the simplifying assumption that a song
|
|
|
|
// either loops in its entirety, or not at all. So if we see a FOR_LOOP
|
|
|
|
// controller event, we turn on looping even if there isn't any
|
|
|
|
// corresponding NEXT_BREAK event.
|
|
|
|
//
|
|
|
|
// This is a gross over-simplification of how XMIDI handles loops. If
|
|
|
|
// anyone feels like doing a proper implementation, please refer to
|
|
|
|
// the Exult project, and do it in midiparser_xmidi.cpp
|
|
|
|
|
|
|
|
if ((b & 0xFFF0) == 0x74B0) {
|
|
|
|
debugC(9, kDebugLevelMain | kDebugLevelSound, "SoundMidiPC: Looping song");
|
|
|
|
_parser->property(MidiParser::mpAutoLoop, true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
if (_passThrough) {
|
2005-09-11 14:35:34 +00:00
|
|
|
if ((b & 0xFFF0) == 0x007BB0)
|
|
|
|
return;
|
2005-08-19 22:12:09 +00:00
|
|
|
_driver->send(b);
|
|
|
|
return;
|
2004-11-11 13:37:35 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
uint8 channel = (byte)(b & 0x0F);
|
2005-09-11 14:35:34 +00:00
|
|
|
if (((b & 0xFFF0) == 0x6FB0 || (b & 0xFFF0) == 0x6EB0) && channel != 9) {
|
|
|
|
if (_virChannel[channel] == channel) {
|
|
|
|
_virChannel[channel] = channel + 16;
|
|
|
|
if (!_channel[_virChannel[channel]])
|
|
|
|
_channel[_virChannel[channel]] = _driver->allocateChannel();
|
2006-01-12 13:16:42 +00:00
|
|
|
if (_channel[_virChannel[channel]])
|
|
|
|
_channel[_virChannel[channel]]->volume(_channelVolume[channel] * _volume / 255);
|
2005-09-11 14:35:34 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
if ((b & 0xFFF0) == 0x07B0) {
|
|
|
|
// Adjust volume changes by master volume
|
|
|
|
uint8 volume = (uint8)((b >> 16) & 0x7F);
|
|
|
|
_channelVolume[channel] = volume;
|
|
|
|
volume = volume * _volume / 255;
|
|
|
|
b = (b & 0xFF00FFFF) | (volume << 16);
|
2006-08-01 13:42:33 +00:00
|
|
|
} else if ((b & 0xF0) == 0xC0 && !_nativeMT32 && !_useC55) {
|
2005-08-19 22:12:09 +00:00
|
|
|
b = (b & 0xFFFF00FF) | MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8;
|
|
|
|
} else if ((b & 0xFFF0) == 0x007BB0) {
|
|
|
|
//Only respond to All Notes Off if this channel
|
|
|
|
//has currently been allocated
|
2004-11-11 13:37:35 +00:00
|
|
|
if (!_channel[channel])
|
2005-08-19 22:12:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-11-11 13:37:35 +00:00
|
|
|
|
2005-09-11 14:35:34 +00:00
|
|
|
if (!_channel[_virChannel[channel]]) {
|
|
|
|
_channel[_virChannel[channel]] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
|
2006-01-12 13:16:42 +00:00
|
|
|
if (_channel[_virChannel[channel]])
|
|
|
|
_channel[_virChannel[channel]]->volume(_channelVolume[channel] * _volume / 255);
|
2005-09-11 14:35:34 +00:00
|
|
|
}
|
|
|
|
if (_channel[_virChannel[channel]])
|
|
|
|
_channel[_virChannel[channel]]->send(b);
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
void SoundMidiPC::metaEvent(byte type, byte *data, uint16 length) {
|
2005-08-19 22:12:09 +00:00
|
|
|
switch (type) {
|
|
|
|
case 0x2F: // End of Track
|
2005-09-11 14:35:34 +00:00
|
|
|
if (_eventFromMusic) {
|
|
|
|
// remap all channels
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
_virChannel[i] = i;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_sfxIsPlaying = false;
|
|
|
|
}
|
2005-08-19 22:12:09 +00:00
|
|
|
break;
|
|
|
|
default:
|
2005-09-11 14:35:34 +00:00
|
|
|
_driver->metaEvent(type, data, length);
|
2005-08-19 22:12:09 +00:00
|
|
|
break;
|
2004-11-11 13:37:35 +00:00
|
|
|
}
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
2004-11-11 13:37:35 +00:00
|
|
|
|
2007-01-29 18:15:14 +00:00
|
|
|
void SoundMidiPC::loadSoundFile(uint file) {
|
2006-02-27 22:39:55 +00:00
|
|
|
char filename[25];
|
2007-01-29 18:15:14 +00:00
|
|
|
sprintf(filename, "%s.%s", soundFilename(file), _useC55 ? "C55" : "XMI");
|
2006-02-27 22:39:55 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
uint32 size;
|
2007-04-01 13:10:50 +00:00
|
|
|
uint8 *data = (_vm->resource())->fileData(filename, &size);
|
2005-08-19 22:12:09 +00:00
|
|
|
|
|
|
|
if (!data) {
|
2006-02-27 22:39:55 +00:00
|
|
|
warning("couldn't load '%s'", filename);
|
2005-08-19 22:12:09 +00:00
|
|
|
return;
|
2004-11-11 13:37:35 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
playMusic(data, size);
|
2006-03-12 14:22:27 +00:00
|
|
|
loadSoundEffectFile(file);
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
void SoundMidiPC::playMusic(uint8 *data, uint32 size) {
|
2005-09-11 14:35:34 +00:00
|
|
|
stopMusic();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-07-26 22:24:33 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
2005-09-11 14:35:34 +00:00
|
|
|
_parserSource = data;
|
2005-08-19 22:12:09 +00:00
|
|
|
_parser = MidiParser::createParser_XMIDI();
|
|
|
|
assert(_parser);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
if (!_parser->loadMusic(data, size)) {
|
2006-04-04 22:21:10 +00:00
|
|
|
warning("Error reading track");
|
2005-08-19 22:12:09 +00:00
|
|
|
delete _parser;
|
|
|
|
_parser = 0;
|
|
|
|
return;
|
2004-11-11 13:37:35 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
_parser->setMidiDriver(this);
|
|
|
|
_parser->setTimerRate(getBaseTempo());
|
2006-03-28 15:15:36 +00:00
|
|
|
_parser->setTempo(0);
|
2005-09-11 14:35:34 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2007-01-29 18:15:14 +00:00
|
|
|
void SoundMidiPC::loadSoundEffectFile(uint file) {
|
2006-02-27 22:39:55 +00:00
|
|
|
char filename[25];
|
2007-01-29 18:15:14 +00:00
|
|
|
sprintf(filename, "%s.%s", soundFilename(file), _useC55 ? "C55" : "XMI");
|
2006-02-27 22:39:55 +00:00
|
|
|
|
2005-09-11 14:35:34 +00:00
|
|
|
uint32 size;
|
2007-04-01 13:10:50 +00:00
|
|
|
uint8 *data = (_vm->resource())->fileData(filename, &size);
|
2005-09-11 14:35:34 +00:00
|
|
|
|
|
|
|
if (!data) {
|
2006-02-27 22:39:55 +00:00
|
|
|
warning("couldn't load '%s'", filename);
|
2005-09-11 14:35:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
loadSoundEffectFile(data, size);
|
|
|
|
}
|
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
void SoundMidiPC::loadSoundEffectFile(uint8 *data, uint32 size) {
|
2005-09-11 14:35:34 +00:00
|
|
|
stopSoundEffect();
|
|
|
|
|
2006-07-26 22:24:33 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
2005-09-11 14:35:34 +00:00
|
|
|
_soundEffectSource = data;
|
|
|
|
_soundEffect = MidiParser::createParser_XMIDI();
|
|
|
|
assert(_soundEffect);
|
|
|
|
|
|
|
|
if (!_soundEffect->loadMusic(data, size)) {
|
2006-04-04 22:21:10 +00:00
|
|
|
warning("Error reading track");
|
2005-09-11 14:35:34 +00:00
|
|
|
delete _parser;
|
|
|
|
_parser = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_soundEffect->setMidiDriver(this);
|
|
|
|
_soundEffect->setTimerRate(getBaseTempo());
|
2006-03-28 15:15:36 +00:00
|
|
|
_soundEffect->setTempo(0);
|
2005-09-11 14:35:34 +00:00
|
|
|
_soundEffect->property(MidiParser::mpAutoLoop, false);
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
void SoundMidiPC::stopMusic() {
|
2006-07-26 22:24:33 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
_isPlaying = false;
|
|
|
|
if (_parser) {
|
|
|
|
_parser->unloadMusic();
|
|
|
|
delete _parser;
|
2005-09-11 14:35:34 +00:00
|
|
|
_parser = 0;
|
|
|
|
delete [] _parserSource;
|
|
|
|
_parserSource = 0;
|
2006-01-12 15:38:04 +00:00
|
|
|
|
|
|
|
_fadeStartTime = 0;
|
|
|
|
_fadeMusicOut = false;
|
|
|
|
setVolume(255);
|
2005-09-11 14:35:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
void SoundMidiPC::stopSoundEffect() {
|
2006-07-26 22:24:33 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
2005-09-11 14:35:34 +00:00
|
|
|
_sfxIsPlaying = false;
|
|
|
|
if (_soundEffect) {
|
|
|
|
_soundEffect->unloadMusic();
|
|
|
|
delete _soundEffect;
|
|
|
|
_soundEffect = 0;
|
|
|
|
delete [] _soundEffectSource;
|
|
|
|
_soundEffectSource = 0;
|
2004-11-11 13:37:35 +00:00
|
|
|
}
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
2004-11-11 13:37:35 +00:00
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
void SoundMidiPC::onTimer(void *refCon) {
|
|
|
|
SoundMidiPC *music = (SoundMidiPC *)refCon;
|
2006-07-26 22:24:33 +00:00
|
|
|
Common::StackLock lock(music->_mutex);
|
2005-09-11 14:35:34 +00:00
|
|
|
|
|
|
|
// this should be set to the fadeToBlack value
|
2005-12-13 04:11:57 +00:00
|
|
|
static const uint32 musicFadeTime = 2 * 1000;
|
|
|
|
|
2007-04-01 13:10:50 +00:00
|
|
|
if (music->_fadeMusicOut && music->_fadeStartTime + musicFadeTime > music->_vm->_system->getMillis()) {
|
|
|
|
byte volume = (byte)((musicFadeTime - (music->_vm->_system->getMillis() - music->_fadeStartTime)) * 255 / musicFadeTime);
|
2005-09-11 14:35:34 +00:00
|
|
|
music->setVolume(volume);
|
2006-03-12 15:38:59 +00:00
|
|
|
} else if (music->_fadeStartTime) {
|
2005-09-11 14:35:34 +00:00
|
|
|
music->_fadeStartTime = 0;
|
|
|
|
music->_fadeMusicOut = false;
|
2006-01-12 13:16:42 +00:00
|
|
|
music->_isPlaying = false;
|
2006-01-12 15:38:04 +00:00
|
|
|
|
|
|
|
music->_eventFromMusic = true;
|
|
|
|
// from sound/midiparser.cpp
|
|
|
|
for (int i = 0; i < 128; ++i) {
|
|
|
|
for (int j = 0; j < 16; ++j) {
|
|
|
|
music->send(0x80 | j | i << 8);
|
|
|
|
}
|
|
|
|
}
|
2007-04-15 16:41:20 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 16; ++i)
|
2006-01-12 15:38:04 +00:00
|
|
|
music->send(0x007BB0 | i);
|
2005-09-11 14:35:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (music->_isPlaying) {
|
|
|
|
if (music->_parser) {
|
|
|
|
music->_eventFromMusic = true;
|
|
|
|
music->_parser->onTimer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (music->_sfxIsPlaying) {
|
|
|
|
if (music->_soundEffect) {
|
|
|
|
music->_eventFromMusic = false;
|
|
|
|
music->_soundEffect->onTimer();
|
|
|
|
}
|
|
|
|
}
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-03-12 14:22:27 +00:00
|
|
|
void SoundMidiPC::playTrack(uint8 track) {
|
2006-06-02 22:57:02 +00:00
|
|
|
if (_parser && (track != 0 || _nativeMT32) && _musicEnabled) {
|
2005-08-19 22:12:09 +00:00
|
|
|
_isPlaying = true;
|
2006-03-12 15:38:59 +00:00
|
|
|
_fadeMusicOut = false;
|
|
|
|
_fadeStartTime = 0;
|
|
|
|
setVolume(255);
|
2005-08-19 22:12:09 +00:00
|
|
|
_parser->setTrack(track);
|
|
|
|
_parser->jumpToTick(0);
|
2005-09-11 14:35:34 +00:00
|
|
|
_parser->setTempo(1);
|
2006-08-03 11:12:05 +00:00
|
|
|
_parser->property(MidiParser::mpAutoLoop, false);
|
2004-11-11 13:37:35 +00:00
|
|
|
}
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-03-12 15:38:59 +00:00
|
|
|
void SoundMidiPC::haltTrack() {
|
|
|
|
if (_parser) {
|
|
|
|
_isPlaying = false;
|
|
|
|
_fadeMusicOut = false;
|
|
|
|
_fadeStartTime = 0;
|
|
|
|
setVolume(255);
|
|
|
|
_parser->setTrack(0);
|
|
|
|
_parser->jumpToTick(0);
|
2006-03-28 15:15:36 +00:00
|
|
|
_parser->setTempo(0);
|
2006-03-12 15:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
void SoundMidiPC::playSoundEffect(uint8 track) {
|
2006-06-02 22:57:02 +00:00
|
|
|
if (_soundEffect && _sfxEnabled) {
|
2005-09-11 14:35:34 +00:00
|
|
|
_sfxIsPlaying = true;
|
|
|
|
_soundEffect->setTrack(track);
|
|
|
|
_soundEffect->jumpToTick(0);
|
2006-03-28 15:15:36 +00:00
|
|
|
_soundEffect->setTempo(1);
|
2005-09-11 14:35:34 +00:00
|
|
|
_soundEffect->property(MidiParser::mpAutoLoop, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
void SoundMidiPC::beginFadeOut() {
|
2005-09-11 14:35:34 +00:00
|
|
|
_fadeMusicOut = true;
|
2007-04-01 13:10:50 +00:00
|
|
|
_fadeStartTime = _vm->_system->getMillis();
|
2005-09-11 14:35:34 +00:00
|
|
|
}
|
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
#pragma mark -
|
2006-02-09 07:37:19 +00:00
|
|
|
|
2006-05-28 06:07:54 +00:00
|
|
|
bool KyraEngine::speechEnabled() {
|
2006-09-17 20:21:40 +00:00
|
|
|
return _flags.isTalkie && (_configVoice == 1 || _configVoice == 2);
|
2006-05-28 06:07:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool KyraEngine::textEnabled() {
|
2006-09-17 20:21:40 +00:00
|
|
|
return !_flags.isTalkie || (_configVoice == 0 || _configVoice == 2);
|
2006-05-28 06:07:54 +00:00
|
|
|
}
|
|
|
|
|
2006-02-09 07:37:19 +00:00
|
|
|
void KyraEngine::snd_playTheme(int file, int track) {
|
2006-02-27 22:39:55 +00:00
|
|
|
debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine::snd_playTheme(%d)", file);
|
2007-02-03 20:50:26 +00:00
|
|
|
_curSfxFile = _curMusicTheme = file;
|
2007-01-29 18:15:14 +00:00
|
|
|
_sound->loadSoundFile(_curMusicTheme);
|
2006-03-12 14:22:27 +00:00
|
|
|
_sound->playTrack(track);
|
2006-02-09 07:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::snd_playSoundEffect(int track) {
|
2006-02-27 22:39:55 +00:00
|
|
|
debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine::snd_playSoundEffect(%d)", track);
|
2007-03-24 00:04:08 +00:00
|
|
|
if (_flags.platform == Common::kPlatformFMTowns && track == 49) {
|
|
|
|
snd_playWanderScoreViaMap(56, 1);
|
|
|
|
return;
|
2007-01-25 17:47:06 +00:00
|
|
|
}
|
2006-03-14 14:25:13 +00:00
|
|
|
_sound->playSoundEffect(track);
|
2006-02-09 07:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::snd_playWanderScoreViaMap(int command, int restart) {
|
2006-02-27 22:39:55 +00:00
|
|
|
debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine::snd_playWanderScoreViaMap(%d, %d)", command, restart);
|
2006-02-09 07:37:19 +00:00
|
|
|
if (restart)
|
|
|
|
_lastMusicCommand = -1;
|
2007-01-25 17:43:48 +00:00
|
|
|
|
2007-01-29 18:15:14 +00:00
|
|
|
if (_flags.platform == Common::kPlatformFMTowns) {
|
2007-01-25 17:43:48 +00:00
|
|
|
if (command == 1) {
|
|
|
|
_sound->beginFadeOut();
|
|
|
|
} else if (command >= 35 && command <= 38) {
|
|
|
|
snd_playSoundEffect(command-20);
|
|
|
|
} else if (command >= 2) {
|
|
|
|
if (_lastMusicCommand != command) {
|
|
|
|
// the original does -2 here we handle this inside _sound->playTrack()
|
|
|
|
_sound->playTrack(command);
|
|
|
|
}
|
2007-04-15 16:41:20 +00:00
|
|
|
} else {
|
2006-03-09 20:50:19 +00:00
|
|
|
_sound->haltTrack();
|
2007-04-15 16:41:20 +00:00
|
|
|
}
|
2006-02-09 07:37:19 +00:00
|
|
|
} else {
|
2007-01-25 17:43:48 +00:00
|
|
|
static const int8 soundTable[] = {
|
|
|
|
-1, 0, -1, 1, 0, 3, 0, 2,
|
|
|
|
0, 4, 1, 2, 1, 3, 1, 4,
|
|
|
|
1, 92, 1, 6, 1, 7, 2, 2,
|
|
|
|
2, 3, 2, 4, 2, 5, 2, 6,
|
|
|
|
2, 7, 3, 3, 3, 4, 1, 8,
|
|
|
|
1, 9, 4, 2, 4, 3, 4, 4,
|
|
|
|
4, 5, 4, 6, 4, 7, 4, 8,
|
|
|
|
1, 11, 1, 12, 1, 14, 1, 13,
|
|
|
|
4, 9, 5, 12, 6, 2, 6, 6,
|
|
|
|
6, 7, 6, 8, 6, 9, 6, 3,
|
|
|
|
6, 4, 6, 5, 7, 2, 7, 3,
|
|
|
|
7, 4, 7, 5, 7, 6, 7, 7,
|
|
|
|
7, 8, 7, 9, 8, 2, 8, 3,
|
|
|
|
8, 4, 8, 5, 6, 11, 5, 11
|
|
|
|
};
|
|
|
|
//if (!_disableSound) {
|
|
|
|
// XXX
|
|
|
|
//}
|
|
|
|
assert(command*2+1 < ARRAYSIZE(soundTable));
|
|
|
|
if (_curMusicTheme != soundTable[command*2]+1) {
|
2007-04-15 16:41:20 +00:00
|
|
|
if (soundTable[command*2] != -1)
|
2007-01-25 17:43:48 +00:00
|
|
|
snd_playTheme(soundTable[command*2]+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (command != 1) {
|
|
|
|
if (_lastMusicCommand != command) {
|
|
|
|
_sound->haltTrack();
|
|
|
|
_sound->playTrack(soundTable[command*2+1]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_sound->beginFadeOut();
|
|
|
|
}
|
2006-02-09 07:37:19 +00:00
|
|
|
}
|
2007-01-25 17:43:48 +00:00
|
|
|
|
|
|
|
_lastMusicCommand = command;
|
2006-02-09 07:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::snd_playVoiceFile(int id) {
|
2006-02-27 22:39:55 +00:00
|
|
|
debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine::snd_playVoiceFile(%d)", id);
|
2006-02-09 07:37:19 +00:00
|
|
|
char vocFile[9];
|
|
|
|
assert(id >= 0 && id < 9999);
|
2006-02-10 16:39:56 +00:00
|
|
|
sprintf(vocFile, "%03d", id);
|
2006-02-09 07:37:19 +00:00
|
|
|
_sound->voicePlay(vocFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::snd_voiceWaitForFinish(bool ingame) {
|
2006-02-27 22:39:55 +00:00
|
|
|
debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine::snd_voiceWaitForFinish(%d)", ingame);
|
2006-02-09 12:19:53 +00:00
|
|
|
while (_sound->voiceIsPlaying() && !_skipFlag) {
|
2007-04-15 16:41:20 +00:00
|
|
|
if (ingame)
|
2006-02-09 07:37:19 +00:00
|
|
|
delay(10, true);
|
2007-04-15 16:41:20 +00:00
|
|
|
else
|
2006-02-09 07:37:19 +00:00
|
|
|
_system->delayMillis(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-31 18:35:50 +00:00
|
|
|
void KyraEngine::snd_stopVoice() {
|
|
|
|
debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine::snd_stopVoice()");
|
|
|
|
_sound->voiceStop();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KyraEngine::snd_voiceIsPlaying() {
|
|
|
|
debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine::snd_voiceIsPlaying()");
|
|
|
|
return _sound->voiceIsPlaying();
|
|
|
|
}
|
|
|
|
|
2006-02-10 16:39:56 +00:00
|
|
|
// static res
|
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
const Sound::SpeechCodecs Sound::_supportedCodes[] = {
|
2006-02-10 16:39:56 +00:00
|
|
|
#ifdef USE_FLAC
|
2006-04-29 22:33:31 +00:00
|
|
|
{ ".VOF", Audio::makeFlacStream },
|
2006-02-10 16:39:56 +00:00
|
|
|
#endif // USE_FLAC
|
2007-02-24 23:40:28 +00:00
|
|
|
#ifdef USE_VORBIS
|
|
|
|
{ ".VOG", Audio::makeVorbisStream },
|
|
|
|
#endif // USE_VORBIS
|
|
|
|
#ifdef USE_MAD
|
|
|
|
{ ".VO3", Audio::makeMP3Stream },
|
|
|
|
#endif // USE_MAD
|
2006-02-10 16:39:56 +00:00
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
2004-11-11 13:37:35 +00:00
|
|
|
} // end of namespace Kyra
|
2007-04-15 16:41:20 +00:00
|
|
|
|