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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2005-09-11 14:35:34 +00:00
|
|
|
#include "common/system.h"
|
2008-04-07 17:56:04 +00:00
|
|
|
#include "common/config-manager.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
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
Sound::Sound(KyraEngine_v1 *vm, Audio::Mixer *mixer)
|
2008-03-21 16:18:27 +00:00
|
|
|
: _vm(vm), _mixer(mixer), _soundChannels(), _musicEnabled(1),
|
|
|
|
_sfxEnabled(true), _soundDataList(0) {
|
2006-02-27 22:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Sound::~Sound() {
|
|
|
|
}
|
|
|
|
|
2008-03-21 16:18:27 +00:00
|
|
|
bool Sound::voiceFileIsPresent(const char *file) {
|
|
|
|
char filenamebuffer[25];
|
2008-06-03 18:12:21 +00:00
|
|
|
for (int i = 0; _supportedCodecs[i].fileext; ++i) {
|
2008-03-21 16:18:27 +00:00
|
|
|
strcpy(filenamebuffer, file);
|
2008-06-03 18:12:21 +00:00
|
|
|
strcat(filenamebuffer, _supportedCodecs[i].fileext);
|
2008-03-21 16:18:27 +00:00
|
|
|
if (_vm->resource()->getFileSize(filenamebuffer) > 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(filenamebuffer, file);
|
|
|
|
strcat(filenamebuffer, ".VOC");
|
|
|
|
|
|
|
|
if (_vm->resource()->getFileSize(filenamebuffer) > 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-05-24 22:47:08 +00:00
|
|
|
int32 Sound::voicePlay(const char *file, bool isSfx) {
|
2006-02-27 22:39:55 +00:00
|
|
|
char filenamebuffer[25];
|
|
|
|
|
2008-02-17 02:06:04 +00:00
|
|
|
int h = 0;
|
2008-03-21 16:18:27 +00:00
|
|
|
while (_mixer->isSoundHandleActive(_soundChannels[h].channelHandle) && h < kNumChannelHandles)
|
|
|
|
h++;
|
|
|
|
if (h >= kNumChannelHandles)
|
2008-05-24 22:47:08 +00:00
|
|
|
return 0;
|
2008-03-21 16:18:27 +00:00
|
|
|
|
|
|
|
Audio::AudioStream *audioStream = 0;
|
2008-02-17 02:06:04 +00:00
|
|
|
|
2008-06-03 18:12:21 +00:00
|
|
|
for (int i = 0; _supportedCodecs[i].fileext; ++i) {
|
2006-02-27 22:39:55 +00:00
|
|
|
strcpy(filenamebuffer, file);
|
2008-06-03 18:12:21 +00:00
|
|
|
strcat(filenamebuffer, _supportedCodecs[i].fileext);
|
2006-02-27 22:39:55 +00:00
|
|
|
|
2008-02-07 23:13:13 +00:00
|
|
|
Common::SeekableReadStream *stream = _vm->resource()->getFileStream(filenamebuffer);
|
|
|
|
if (!stream)
|
2006-02-27 22:39:55 +00:00
|
|
|
continue;
|
2008-06-03 18:12:21 +00:00
|
|
|
audioStream = _supportedCodecs[i].streamFunc(stream, true, 0, 0, 1);
|
2006-02-27 22:39:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-23 11:35:05 +00:00
|
|
|
if (!audioStream) {
|
2006-02-27 22:39:55 +00:00
|
|
|
strcpy(filenamebuffer, file);
|
|
|
|
strcat(filenamebuffer, ".VOC");
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2008-05-23 11:35:05 +00:00
|
|
|
uint32 fileSize = 0;
|
|
|
|
byte *fileData = _vm->resource()->fileData(filenamebuffer, &fileSize);
|
2006-02-27 22:39:55 +00:00
|
|
|
if (!fileData)
|
2008-05-24 23:05:01 +00:00
|
|
|
return 0;
|
2006-02-27 22:39:55 +00:00
|
|
|
|
|
|
|
Common::MemoryReadStream vocStream(fileData, fileSize);
|
2008-03-21 16:18:27 +00:00
|
|
|
audioStream = Audio::makeVOCStream(vocStream);
|
2008-05-23 11:35:05 +00:00
|
|
|
|
|
|
|
delete[] fileData;
|
|
|
|
fileSize = 0;
|
2006-02-27 22:39:55 +00:00
|
|
|
}
|
|
|
|
|
2008-03-21 16:18:27 +00:00
|
|
|
_soundChannels[h].file = file;
|
|
|
|
_mixer->playInputStream(isSfx ? Audio::Mixer::kSFXSoundType : Audio::Mixer::kSpeechSoundType, &_soundChannels[h].channelHandle, audioStream);
|
2008-02-17 02:06:04 +00:00
|
|
|
|
2008-05-24 22:47:08 +00:00
|
|
|
return audioStream->getTotalPlayTime();
|
2006-02-27 22:39:55 +00:00
|
|
|
}
|
|
|
|
|
2008-03-21 16:18:27 +00:00
|
|
|
void Sound::voiceStop(const char *file) {
|
|
|
|
if (!file) {
|
|
|
|
for (int h = 0; h < kNumChannelHandles; h++) {
|
|
|
|
if (_mixer->isSoundHandleActive(_soundChannels[h].channelHandle))
|
|
|
|
_mixer->stopHandle(_soundChannels[h].channelHandle);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < kNumChannelHandles; ++i) {
|
|
|
|
if (_soundChannels[i].file == file)
|
|
|
|
_mixer->stopHandle(_soundChannels[i].channelHandle);
|
|
|
|
}
|
2008-02-17 02:06:04 +00:00
|
|
|
}
|
2006-05-28 04:46:34 +00:00
|
|
|
}
|
|
|
|
|
2008-03-21 16:18:27 +00:00
|
|
|
bool Sound::voiceIsPlaying(const char *file) {
|
2008-02-17 02:06:04 +00:00
|
|
|
bool res = false;
|
2008-03-21 16:18:27 +00:00
|
|
|
if (!file) {
|
|
|
|
for (int h = 0; h < kNumChannelHandles; h++) {
|
|
|
|
if (_mixer->isSoundHandleActive(_soundChannels[h].channelHandle))
|
|
|
|
res = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < kNumChannelHandles; ++i) {
|
|
|
|
if (_soundChannels[i].file == file)
|
2008-03-22 14:29:30 +00:00
|
|
|
res = _mixer->isSoundHandleActive(_soundChannels[i].channelHandle);
|
2008-03-21 16:18:27 +00:00
|
|
|
}
|
2008-02-17 02:06:04 +00:00
|
|
|
}
|
|
|
|
return res;
|
2006-02-27 22:39:55 +00:00
|
|
|
}
|
|
|
|
|
2008-05-24 22:47:08 +00:00
|
|
|
uint32 Sound::voicePlayedTime(const char *file) {
|
|
|
|
if (!file)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < kNumChannelHandles; ++i) {
|
|
|
|
if (_soundChannels[i].file == file)
|
|
|
|
return _mixer->getSoundElapsedTime(_soundChannels[i].channelHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
SoundMidiPC::SoundMidiPC(KyraEngine_v1 *vm, Audio::Mixer *mixer, MidiDriver *driver) : Sound(vm, mixer) {
|
2005-08-19 22:12:09 +00:00
|
|
|
_driver = driver;
|
|
|
|
_passThrough = false;
|
2008-04-07 17:56:04 +00:00
|
|
|
|
|
|
|
_musicParser = _sfxParser = 0;
|
|
|
|
_isMusicPlaying = _isSfxPlaying = false;
|
2005-09-11 14:35:34 +00:00
|
|
|
_eventFromMusic = false;
|
2008-04-07 17:56:04 +00:00
|
|
|
|
|
|
|
_nativeMT32 = _useC55 = false;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2008-04-10 19:33:06 +00:00
|
|
|
_fadeStartTime = 0;
|
|
|
|
_fadeMusicOut = false;
|
|
|
|
|
2008-04-07 17:56:04 +00:00
|
|
|
memset(_channel, 0, sizeof(_channel));
|
|
|
|
memset(_channelVolume, 50, sizeof(_channelVolume));
|
2005-09-11 14:35:34 +00:00
|
|
|
_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;
|
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)
|
2008-04-07 17:56:04 +00:00
|
|
|
error("Couldn't open midi driver");
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
SoundMidiPC::~SoundMidiPC() {
|
2006-07-26 22:24:33 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
2008-04-07 17:56:04 +00:00
|
|
|
delete _musicParser;
|
|
|
|
delete _sfxParser;
|
|
|
|
|
2007-01-29 18:15:14 +00:00
|
|
|
_driver->setTimerCallback(0, 0);
|
2005-08-19 22:12:09 +00:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
2008-04-07 17:56:04 +00:00
|
|
|
bool SoundMidiPC::init() {
|
|
|
|
_musicParser = MidiParser::createParser_XMIDI();
|
|
|
|
_sfxParser = MidiParser::createParser_XMIDI();
|
|
|
|
|
|
|
|
if (!_musicParser || !_sfxParser)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
_musicParser->setMidiDriver(this);
|
|
|
|
_sfxParser->setMidiDriver(this);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundMidiPC::updateVolumeSettings() {
|
2008-07-24 22:12:48 +00:00
|
|
|
_musicVolume = CLIP(ConfMan.getInt("music_volume"), 0, 255);
|
|
|
|
_sfxVolume = CLIP(ConfMan.getInt("sfx_volume"), 0, 255);
|
2008-04-07 17:56:04 +00:00
|
|
|
|
|
|
|
updateChannelVolume(_musicVolume);
|
|
|
|
}
|
|
|
|
|
2007-12-26 01:09:46 +00:00
|
|
|
void SoundMidiPC::hasNativeMT32(bool nativeMT32) {
|
|
|
|
_nativeMT32 = nativeMT32;
|
|
|
|
|
|
|
|
// C55 appears to be XMIDI for General MIDI instruments
|
|
|
|
if (!_nativeMT32 && _vm->game() == GI_KYRA2)
|
|
|
|
_useC55 = true;
|
|
|
|
else
|
|
|
|
_useC55 = false;
|
|
|
|
}
|
|
|
|
|
2008-04-07 17:56:04 +00:00
|
|
|
void SoundMidiPC::updateChannelVolume(uint8 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]) {
|
2008-04-07 17:56:04 +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() {
|
2008-07-10 11:28:51 +00:00
|
|
|
if (_driver) {
|
2005-08-19 22:12:09 +00:00
|
|
|
_driver->close();
|
2008-07-10 11:28:51 +00:00
|
|
|
delete _driver;
|
|
|
|
}
|
2005-08-19 22:12:09 +00:00
|
|
|
_driver = 0;
|
|
|
|
}
|
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
void SoundMidiPC::send(uint32 b) {
|
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
|
|
|
|
2008-04-10 19:02:17 +00:00
|
|
|
const int volume = /*_eventFromMusic ? */_musicVolume/* : _sfxVolume*/;
|
2008-04-07 17:56:04 +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]])
|
2008-04-07 17:56:04 +00:00
|
|
|
_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
|
2008-04-07 17:56:04 +00:00
|
|
|
uint8 vol = (uint8)((b >> 16) & 0x7F);
|
|
|
|
_channelVolume[channel] = vol;
|
|
|
|
vol = vol * volume / 255;
|
|
|
|
b = (b & 0xFF00FFFF) | (vol << 16);
|
2006-08-01 13:42:33 +00:00
|
|
|
} else if ((b & 0xF0) == 0xC0 && !_nativeMT32 && !_useC55) {
|
2008-04-10 19:02:17 +00:00
|
|
|
b = (b & 0xFFFF00FF) | (MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8);
|
2005-08-19 22:12:09 +00:00
|
|
|
} else if ((b & 0xFFF0) == 0x007BB0) {
|
|
|
|
//Only respond to All Notes Off if this channel
|
|
|
|
//has currently been allocated
|
2008-04-10 20:42:56 +00:00
|
|
|
if (!_channel[/*_virChannel[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]])
|
2008-04-07 17:56:04 +00:00
|
|
|
_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
|
2007-12-24 22:27:30 +00:00
|
|
|
for (int i = 0; i < 16; ++i)
|
2005-09-11 14:35:34 +00:00
|
|
|
_virChannel[i] = i;
|
|
|
|
} else {
|
2008-04-07 17:56:04 +00:00
|
|
|
_isSfxPlaying = false;
|
2005-09-11 14:35:34 +00:00
|
|
|
}
|
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
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
|
2008-04-07 17:56:04 +00:00
|
|
|
struct DeleterArray {
|
|
|
|
void operator ()(byte *ptr) {
|
2008-05-07 14:20:37 +00:00
|
|
|
delete[] ptr;
|
2004-11-11 13:37:35 +00:00
|
|
|
}
|
2008-04-07 17:56:04 +00:00
|
|
|
};
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2008-04-07 17:56:04 +00:00
|
|
|
void SoundMidiPC::loadSoundFile(uint file) {
|
2006-07-26 22:24:33 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
2008-04-07 17:56:04 +00:00
|
|
|
Common::String filename = fileListEntry(file);
|
|
|
|
filename += ".";
|
|
|
|
filename += _useC55 ? "C55" : "XMI";
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2008-04-07 17:56:04 +00:00
|
|
|
if (filename == _currentTrack) {
|
|
|
|
_isMusicPlaying = _isSfxPlaying = false;
|
|
|
|
_fadeStartTime = 0;
|
|
|
|
_fadeMusicOut = false;
|
|
|
|
updateChannelVolume(_musicVolume);
|
|
|
|
_musicParser->setTempo(0);
|
|
|
|
_sfxParser->setTempo(0);
|
|
|
|
_musicParser->property(MidiParser::mpAutoLoop, false);
|
|
|
|
_sfxParser->property(MidiParser::mpAutoLoop, false);
|
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-09-11 14:35:34 +00:00
|
|
|
uint32 size;
|
2008-04-07 17:56:04 +00:00
|
|
|
uint8 *data = (_vm->resource())->fileData(filename.c_str(), &size);
|
2005-09-11 14:35:34 +00:00
|
|
|
|
|
|
|
if (!data) {
|
2008-04-07 17:56:04 +00:00
|
|
|
warning("Couldn't load soundfile '%s'", filename.c_str());
|
2005-09-11 14:35:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-07 17:56:04 +00:00
|
|
|
_currentTrack = filename;
|
2006-07-26 22:24:33 +00:00
|
|
|
|
2008-04-07 17:56:04 +00:00
|
|
|
_musicParser->unloadMusic();
|
2008-04-10 19:15:14 +00:00
|
|
|
_sfxParser->unloadMusic();
|
|
|
|
_midiFile = Common::SharedPtr<byte>(data, DeleterArray());
|
2005-09-11 14:35:34 +00:00
|
|
|
|
2008-04-07 17:56:04 +00:00
|
|
|
_isMusicPlaying = _isSfxPlaying = false;
|
|
|
|
_fadeStartTime = 0;
|
|
|
|
_fadeMusicOut = false;
|
|
|
|
updateChannelVolume(_musicVolume);
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2008-04-07 17:56:04 +00:00
|
|
|
if (_musicParser->loadMusic(_midiFile.get(), size)) {
|
|
|
|
_musicParser->setTimerRate(getBaseTempo());
|
|
|
|
_musicParser->setTempo(0);
|
|
|
|
_musicParser->property(MidiParser::mpAutoLoop, false);
|
|
|
|
} else {
|
|
|
|
warning("Error parsing music track '%s'", filename.c_str());
|
2005-09-11 14:35:34 +00:00
|
|
|
}
|
|
|
|
|
2008-04-07 17:56:04 +00:00
|
|
|
if (_sfxParser->loadMusic(_midiFile.get(), size)) {
|
|
|
|
_sfxParser->setTimerRate(getBaseTempo());
|
|
|
|
_sfxParser->setTempo(0);
|
|
|
|
_sfxParser->property(MidiParser::mpAutoLoop, false);
|
|
|
|
} else {
|
|
|
|
warning("Error parsing sfx track '%s'", filename.c_str());
|
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) {
|
2008-04-07 17:56:04 +00:00
|
|
|
SoundMidiPC *sound = (SoundMidiPC *)refCon;
|
|
|
|
Common::StackLock lock(sound->_mutex);
|
2005-09-11 14:35:34 +00:00
|
|
|
|
|
|
|
// this should be set to the fadeToBlack value
|
2008-04-10 19:33:06 +00:00
|
|
|
static const uint32 musicFadeTime = 1 * 1000;
|
2005-12-13 04:11:57 +00:00
|
|
|
|
2008-04-10 19:33:06 +00:00
|
|
|
if (sound->_fadeMusicOut) {
|
|
|
|
if (sound->_fadeStartTime + musicFadeTime > sound->_vm->_system->getMillis()) {
|
|
|
|
byte volume = (byte)((musicFadeTime - (sound->_vm->_system->getMillis() - sound->_fadeStartTime)) * sound->_musicVolume / musicFadeTime);
|
|
|
|
sound->updateChannelVolume(volume);
|
|
|
|
} else {
|
|
|
|
sound->_fadeStartTime = 0;
|
|
|
|
sound->_fadeMusicOut = false;
|
|
|
|
sound->_isMusicPlaying = false;
|
|
|
|
|
|
|
|
sound->_eventFromMusic = true;
|
|
|
|
// from sound/midiparser.cpp
|
|
|
|
for (int i = 0; i < 128; ++i) {
|
|
|
|
for (int j = 0; j < 16; ++j) {
|
|
|
|
sound->send(0x80 | j | i << 8);
|
|
|
|
}
|
2006-01-12 15:38:04 +00:00
|
|
|
}
|
2007-04-15 16:41:20 +00:00
|
|
|
|
2008-04-10 19:33:06 +00:00
|
|
|
for (int i = 0; i < 16; ++i)
|
|
|
|
sound->send(0x007BB0 | i);
|
|
|
|
}
|
2005-09-11 14:35:34 +00:00
|
|
|
}
|
|
|
|
|
2008-04-07 17:56:04 +00:00
|
|
|
if (sound->_isMusicPlaying) {
|
|
|
|
sound->_eventFromMusic = true;
|
|
|
|
sound->_musicParser->onTimer();
|
2005-09-11 14:35:34 +00:00
|
|
|
}
|
|
|
|
|
2008-04-07 17:56:04 +00:00
|
|
|
if (sound->_isSfxPlaying) {
|
|
|
|
sound->_eventFromMusic = false;
|
|
|
|
sound->_sfxParser->onTimer();
|
2005-09-11 14:35:34 +00:00
|
|
|
}
|
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) {
|
2008-04-07 17:56:04 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
|
|
|
if (_musicParser && (track != 0 || _nativeMT32) && _musicEnabled) {
|
|
|
|
_isMusicPlaying = true;
|
2006-03-12 15:38:59 +00:00
|
|
|
_fadeMusicOut = false;
|
|
|
|
_fadeStartTime = 0;
|
2008-04-07 17:56:04 +00:00
|
|
|
updateChannelVolume(_musicVolume);
|
|
|
|
_musicParser->setTrack(track);
|
|
|
|
_musicParser->jumpToTick(0);
|
|
|
|
_musicParser->setTempo(1);
|
|
|
|
_musicParser->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() {
|
2008-04-07 17:56:04 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
|
|
|
if (_musicParser) {
|
|
|
|
_isMusicPlaying = false;
|
2006-03-12 15:38:59 +00:00
|
|
|
_fadeMusicOut = false;
|
|
|
|
_fadeStartTime = 0;
|
2008-04-07 17:56:04 +00:00
|
|
|
updateChannelVolume(_musicVolume);
|
|
|
|
_musicParser->setTrack(0);
|
|
|
|
_musicParser->jumpToTick(0);
|
|
|
|
_musicParser->setTempo(0);
|
2006-03-12 15:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
void SoundMidiPC::playSoundEffect(uint8 track) {
|
2008-04-10 19:05:05 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
2008-04-07 17:56:04 +00:00
|
|
|
if (_sfxParser && _sfxEnabled) {
|
|
|
|
_isSfxPlaying = true;
|
|
|
|
_sfxParser->setTrack(track);
|
|
|
|
_sfxParser->jumpToTick(0);
|
|
|
|
_sfxParser->setTempo(1);
|
|
|
|
_sfxParser->property(MidiParser::mpAutoLoop, false);
|
2005-09-11 14:35:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-04-07 17:56:04 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
void KyraEngine_v1::snd_playTheme(int file, int track) {
|
|
|
|
debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine_v1::snd_playTheme(%d, %d)", file, track);
|
2008-04-06 14:11:43 +00:00
|
|
|
if (_curMusicTheme == file)
|
|
|
|
return;
|
|
|
|
|
2007-10-10 09:06:15 +00:00
|
|
|
_curSfxFile = _curMusicTheme = file;
|
|
|
|
_sound->loadSoundFile(_curMusicTheme);
|
2008-04-10 15:41:06 +00:00
|
|
|
if (track != -1)
|
|
|
|
_sound->playTrack(track);
|
2007-10-10 09:06:15 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
void KyraEngine_v1::snd_playSoundEffect(int track, int volume) {
|
|
|
|
debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine_v1::snd_playSoundEffect(%d, %d)", track, volume);
|
2007-10-10 09:06:15 +00:00
|
|
|
_sound->playSoundEffect(track);
|
|
|
|
}
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
void KyraEngine_v1::snd_playWanderScoreViaMap(int command, int restart) {
|
|
|
|
debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine_v1::snd_playWanderScoreViaMap(%d, %d)", command, restart);
|
2007-10-10 09:06:15 +00:00
|
|
|
if (restart)
|
|
|
|
_lastMusicCommand = -1;
|
|
|
|
|
|
|
|
// no track mapping given
|
|
|
|
// so don't do anything here
|
|
|
|
if (!_trackMap || !_trackMapSize)
|
|
|
|
return;
|
|
|
|
|
|
|
|
//if (!_disableSound) {
|
|
|
|
// XXX
|
|
|
|
//}
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2008-01-12 08:04:00 +00:00
|
|
|
if (_flags.platform == Common::kPlatformPC) {
|
|
|
|
assert(command*2+1 < _trackMapSize);
|
|
|
|
if (_curMusicTheme != _trackMap[command*2]) {
|
|
|
|
if (_trackMap[command*2] != -1 && _trackMap[command*2] != -2)
|
2008-04-10 15:41:06 +00:00
|
|
|
snd_playTheme(_trackMap[command*2], -1);
|
2008-01-12 08:04:00 +00:00
|
|
|
}
|
2007-10-10 09:06:15 +00:00
|
|
|
|
2008-01-12 08:04:00 +00:00
|
|
|
if (command != 1) {
|
|
|
|
if (_lastMusicCommand != command) {
|
|
|
|
_sound->haltTrack();
|
|
|
|
_sound->playTrack(_trackMap[command*2+1]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_sound->beginFadeOut();
|
|
|
|
}
|
|
|
|
} else if (_flags.platform == Common::kPlatformFMTowns || _flags.platform == Common::kPlatformPC98) {
|
|
|
|
if (command == -1) {
|
2007-10-10 09:06:15 +00:00
|
|
|
_sound->haltTrack();
|
2008-01-12 08:04:00 +00:00
|
|
|
} else {
|
|
|
|
assert(command*2+1 < _trackMapSize);
|
|
|
|
if (_trackMap[command*2] != -2 && command != _lastMusicCommand) {
|
|
|
|
_sound->haltTrack();
|
|
|
|
_sound->playTrack(command);
|
|
|
|
}
|
2007-10-10 09:06:15 +00:00
|
|
|
}
|
2008-01-27 19:47:41 +00:00
|
|
|
}
|
2007-10-10 09:06:15 +00:00
|
|
|
|
|
|
|
_lastMusicCommand = command;
|
|
|
|
}
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
void KyraEngine_v1::snd_stopVoice() {
|
|
|
|
debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine_v1::snd_stopVoice()");
|
2008-05-27 21:04:27 +00:00
|
|
|
if (!_speechFile.empty()) {
|
|
|
|
_sound->voiceStop(_speechFile.c_str());
|
|
|
|
_speechFile.clear();
|
|
|
|
}
|
2007-10-13 06:57:47 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
bool KyraEngine_v1::snd_voiceIsPlaying() {
|
|
|
|
debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine_v1::snd_voiceIsPlaying()");
|
2008-05-27 21:04:27 +00:00
|
|
|
return _speechFile.empty() ? false : _sound->voiceIsPlaying(_speechFile.c_str());
|
2007-10-13 06:57:47 +00:00
|
|
|
}
|
|
|
|
|
2006-02-10 16:39:56 +00:00
|
|
|
// static res
|
|
|
|
|
2008-06-03 18:12:21 +00:00
|
|
|
const Sound::SpeechCodecs Sound::_supportedCodecs[] = {
|
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
|
|
|
|
2008-02-17 02:06:04 +00:00
|
|
|
|