2012-09-08 21:43:33 +10: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.
|
|
|
|
*
|
|
|
|
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-12-02 17:16:00 +11:00
|
|
|
#include "audio/decoders/adpcm_intern.h"
|
2012-09-08 21:43:33 +10:00
|
|
|
#include "common/system.h"
|
2012-11-11 15:21:30 +11:00
|
|
|
#include "common/config-manager.h"
|
2012-11-10 23:32:06 +11:00
|
|
|
#include "common/file.h"
|
2012-09-15 13:23:46 +10:00
|
|
|
#include "common/textconsole.h"
|
2012-09-08 21:43:33 +10:00
|
|
|
#include "hopkins/sound.h"
|
2012-11-10 23:32:06 +11:00
|
|
|
#include "hopkins/globals.h"
|
|
|
|
#include "hopkins/hopkins.h"
|
2012-12-25 23:53:45 +01:00
|
|
|
#include "audio/audiostream.h"
|
|
|
|
#include "audio/mods/protracker.h"
|
2012-09-08 21:43:33 +10:00
|
|
|
|
2012-12-02 17:16:00 +11:00
|
|
|
namespace Audio {
|
|
|
|
|
|
|
|
class APC_ADPCMStream : public Audio::DVI_ADPCMStream {
|
|
|
|
public:
|
|
|
|
APC_ADPCMStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse, int rate, int channels) : DVI_ADPCMStream(stream, disposeAfterUse, stream->size(), rate, channels, 0) {
|
|
|
|
stream->seek(-12, SEEK_CUR);
|
|
|
|
_status.ima_ch[0].last = _startValue[0] = stream->readUint32LE();
|
|
|
|
_status.ima_ch[1].last = _startValue[1] = stream->readUint32LE();
|
|
|
|
stream->seek(4, SEEK_CUR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
DVI_ADPCMStream::reset();
|
|
|
|
_status.ima_ch[0].last = _startValue[0];
|
|
|
|
_status.ima_ch[1].last = _startValue[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int16 _startValue[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
Audio::RewindableAudioStream *makeAPCStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse) {
|
|
|
|
if (stream->readUint32BE() != MKTAG('C', 'R', 'Y', 'O'))
|
|
|
|
return 0;
|
|
|
|
if (stream->readUint32BE() != MKTAG('_', 'A', 'P', 'C'))
|
|
|
|
return 0;
|
|
|
|
stream->readUint32BE(); // version
|
|
|
|
stream->readUint32LE(); // out size
|
|
|
|
uint32 rate = stream->readUint32LE();
|
|
|
|
stream->skip(8); // initial values, will be handled by the class
|
|
|
|
bool stereo = stream->readUint32LE() != 0;
|
|
|
|
|
|
|
|
return new APC_ADPCMStream(stream, disposeAfterUse, rate, stereo ? 2 : 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
2012-09-08 21:43:33 +10:00
|
|
|
namespace Hopkins {
|
|
|
|
|
2012-10-23 20:49:22 +11:00
|
|
|
SoundManager::SoundManager() {
|
2012-10-25 08:08:00 +11:00
|
|
|
SPECIAL_SOUND = 0;
|
2012-12-27 19:08:10 +01:00
|
|
|
_soundVolume = 0;
|
|
|
|
_voiceVolume = 0;
|
|
|
|
_musicVolume = 0;
|
2012-12-25 22:48:11 +01:00
|
|
|
_soundOffFl = true;
|
2012-12-27 19:08:10 +01:00
|
|
|
_musicOffFl = true;
|
2012-12-24 11:36:53 +01:00
|
|
|
_voiceOffFl = true;
|
|
|
|
_textOffFl = false;
|
2012-12-25 22:48:11 +01:00
|
|
|
_soundFl = false;
|
2012-11-10 23:32:06 +11:00
|
|
|
VBL_MERDE = false;
|
2012-11-11 15:21:30 +11:00
|
|
|
SOUND_NUM = 0;
|
2012-11-11 18:58:45 +11:00
|
|
|
old_music = 0;
|
|
|
|
MOD_FLAG = false;
|
|
|
|
|
2012-11-10 23:32:06 +11:00
|
|
|
for (int i = 0; i < VOICE_COUNT; ++i)
|
|
|
|
Common::fill((byte *)&Voice[i], (byte *)&Voice[i] + sizeof(VoiceItem), 0);
|
|
|
|
for (int i = 0; i < SWAV_COUNT; ++i)
|
|
|
|
Common::fill((byte *)&Swav[i], (byte *)&Swav[i] + sizeof(SwavItem), 0);
|
2012-11-11 18:58:45 +11:00
|
|
|
for (int i = 0; i < MWAV_COUNT; ++i)
|
|
|
|
Common::fill((byte *)&Mwav[i], (byte *)&Mwav[i] + sizeof(MwavItem), 0);
|
2012-11-11 15:21:30 +11:00
|
|
|
for (int i = 0; i < SOUND_COUNT; ++i)
|
|
|
|
Common::fill((byte *)&SOUND[i], (byte *)&SOUND[i] + sizeof(SoundItem), 0);
|
2012-11-11 18:58:45 +11:00
|
|
|
Common::fill((byte *)&Music, (byte *)&Music + sizeof(MusicItem), 0);
|
2012-10-23 20:49:22 +11:00
|
|
|
}
|
|
|
|
|
2012-12-08 22:44:00 +11:00
|
|
|
SoundManager::~SoundManager() {
|
2012-12-25 22:48:11 +01:00
|
|
|
stopMusic();
|
|
|
|
delMusic();
|
2012-12-25 23:53:45 +01:00
|
|
|
_vm->_mixer->stopHandle(_modHandle);
|
2012-12-08 22:44:00 +11:00
|
|
|
MOD_FLAG = false;
|
|
|
|
}
|
|
|
|
|
2012-09-15 10:27:15 +10:00
|
|
|
void SoundManager::setParent(HopkinsEngine *vm) {
|
|
|
|
_vm = vm;
|
2012-09-15 13:23:46 +10:00
|
|
|
SPECIAL_SOUND = 0;
|
2012-09-15 10:27:15 +10:00
|
|
|
}
|
|
|
|
|
2012-09-08 21:43:33 +10:00
|
|
|
void SoundManager::WSOUND_INIT() {
|
2012-09-15 13:23:46 +10:00
|
|
|
warning("TODO: WSOUND_INIT");
|
2012-09-08 21:43:33 +10:00
|
|
|
}
|
|
|
|
|
2012-09-15 10:27:15 +10:00
|
|
|
void SoundManager::VERIF_SOUND() {
|
2012-12-25 22:48:11 +01:00
|
|
|
if (!_soundOffFl && _soundFl) {
|
2012-11-11 15:21:30 +11:00
|
|
|
if (!VOICE_STAT(1)) {
|
2012-12-26 00:31:42 +01:00
|
|
|
stopVoice(1);
|
2012-11-11 15:21:30 +11:00
|
|
|
DEL_NWAV(SOUND_NUM);
|
|
|
|
}
|
|
|
|
}
|
2012-09-15 10:27:15 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
void SoundManager::LOAD_ANM_SOUND() {
|
2012-12-08 20:19:14 +01:00
|
|
|
switch (SPECIAL_SOUND) {
|
|
|
|
case 2:
|
2012-12-24 01:43:37 +01:00
|
|
|
loadSample(5, "mitra1.wav");
|
|
|
|
loadSample(1, "tir2.wav");
|
|
|
|
loadSample(2, "sound6.wav");
|
|
|
|
loadSample(3, "sound5.WAV");
|
|
|
|
loadSample(4, "sound4.WAV");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
LOAD_WAV("CRIE.WAV", 1);
|
|
|
|
break;
|
|
|
|
case 14:
|
|
|
|
LOAD_WAV("SOUND14.WAV", 1);
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
LOAD_WAV("SOUND16.WAV", 1);
|
|
|
|
break;
|
|
|
|
case 198:
|
|
|
|
LOAD_WAV("SOUND3.WAV", 1);
|
|
|
|
break;
|
|
|
|
case 199:
|
|
|
|
LOAD_WAV("SOUND22.WAV", 1);
|
|
|
|
break;
|
|
|
|
case 200:
|
2012-12-23 19:08:23 +01:00
|
|
|
mixVoice(682, 1);
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 208:
|
|
|
|
LOAD_WAV("SOUND77.WAV", 1);
|
|
|
|
break;
|
|
|
|
case 210:
|
|
|
|
LOAD_WAV("SOUND78.WAV", 1);
|
|
|
|
break;
|
|
|
|
case 211:
|
|
|
|
LOAD_WAV("SOUND78.WAV", 1);
|
|
|
|
break;
|
|
|
|
case 229:
|
2012-11-11 15:21:30 +11:00
|
|
|
LOAD_WAV("SOUND80.WAV", 1);
|
|
|
|
LOAD_WAV("SOUND82.WAV", 2);
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
2012-11-11 15:21:30 +11:00
|
|
|
}
|
2012-09-30 21:02:39 +10:00
|
|
|
}
|
|
|
|
|
2012-12-09 22:35:59 +01:00
|
|
|
void SoundManager::playAnim_SOUND(int soundNumber) {
|
2012-12-31 00:18:08 +01:00
|
|
|
if (!_vm->_globals._censorshipFl && SPECIAL_SOUND == 2) {
|
2012-12-08 20:02:33 +01:00
|
|
|
switch (soundNumber) {
|
|
|
|
case 20:
|
2012-11-10 23:32:06 +11:00
|
|
|
PLAY_SAMPLE2(5);
|
2012-12-08 20:02:33 +01:00
|
|
|
break;
|
|
|
|
case 57:
|
|
|
|
case 63:
|
|
|
|
case 69:
|
2012-11-10 23:32:06 +11:00
|
|
|
PLAY_SAMPLE2(1);
|
2012-12-08 20:02:33 +01:00
|
|
|
break;
|
|
|
|
case 75:
|
2012-11-10 23:32:06 +11:00
|
|
|
PLAY_SAMPLE2(2);
|
2012-12-08 20:02:33 +01:00
|
|
|
break;
|
|
|
|
case 109:
|
2012-11-10 23:32:06 +11:00
|
|
|
PLAY_SAMPLE2(3);
|
2012-12-08 20:02:33 +01:00
|
|
|
break;
|
|
|
|
case 122:
|
2012-11-10 23:32:06 +11:00
|
|
|
PLAY_SAMPLE2(4);
|
2012-12-08 20:02:33 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (SPECIAL_SOUND == 1 && soundNumber == 17)
|
2012-12-25 22:48:11 +01:00
|
|
|
playSound("SOUND42.WAV");
|
2012-12-08 20:02:33 +01:00
|
|
|
else if (SPECIAL_SOUND == 5 && soundNumber == 19)
|
2012-12-25 22:48:11 +01:00
|
|
|
playWav(1);
|
2012-12-08 20:02:33 +01:00
|
|
|
else if (SPECIAL_SOUND == 14 && soundNumber == 625)
|
2012-12-25 22:48:11 +01:00
|
|
|
playWav(1);
|
2012-12-08 20:02:33 +01:00
|
|
|
else if (SPECIAL_SOUND == 16 && soundNumber == 25)
|
2012-12-25 22:48:11 +01:00
|
|
|
playWav(1);
|
2012-12-08 20:02:33 +01:00
|
|
|
else if (SPECIAL_SOUND == 17) {
|
|
|
|
if (soundNumber == 6)
|
|
|
|
PLAY_SAMPLE2(1);
|
|
|
|
else if (soundNumber == 14)
|
|
|
|
PLAY_SAMPLE2(2);
|
|
|
|
else if (soundNumber == 67)
|
|
|
|
PLAY_SAMPLE2(3);
|
|
|
|
} else if (SPECIAL_SOUND == 198 && soundNumber == 15)
|
2012-12-25 22:48:11 +01:00
|
|
|
playWav(1);
|
2012-12-08 20:02:33 +01:00
|
|
|
else if (SPECIAL_SOUND == 199 && soundNumber == 72)
|
2012-12-25 22:48:11 +01:00
|
|
|
playWav(1);
|
2012-12-08 20:02:33 +01:00
|
|
|
else if (SPECIAL_SOUND == 208 && soundNumber == 40)
|
2012-12-25 22:48:11 +01:00
|
|
|
playWav(1);
|
2012-12-08 20:02:33 +01:00
|
|
|
else if (SPECIAL_SOUND == 210 && soundNumber == 2)
|
2012-12-25 22:48:11 +01:00
|
|
|
playWav(1);
|
2012-12-08 20:02:33 +01:00
|
|
|
else if (SPECIAL_SOUND == 211 && soundNumber == 22)
|
2012-12-25 22:48:11 +01:00
|
|
|
playWav(1);
|
2012-12-08 20:02:33 +01:00
|
|
|
else if (SPECIAL_SOUND == 229) {
|
2012-11-10 23:32:06 +11:00
|
|
|
if (soundNumber == 15)
|
2012-12-25 22:48:11 +01:00
|
|
|
playWav(1);
|
2012-12-08 20:02:33 +01:00
|
|
|
else if (soundNumber == 91)
|
2012-12-25 22:48:11 +01:00
|
|
|
playWav(2);
|
2012-11-10 23:32:06 +11:00
|
|
|
}
|
2012-09-15 13:23:46 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
void SoundManager::WSOUND(int soundNumber) {
|
2012-12-26 07:55:56 +01:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS) {
|
|
|
|
if (soundNumber > 27)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-06 07:49:55 +01:00
|
|
|
if (old_music != soundNumber || !MOD_FLAG) {
|
2012-12-25 22:48:11 +01:00
|
|
|
if (MOD_FLAG)
|
2012-11-11 18:58:45 +11:00
|
|
|
WSOUND_OFF();
|
2012-12-08 20:19:14 +01:00
|
|
|
|
|
|
|
switch (soundNumber) {
|
|
|
|
case 1:
|
2012-12-25 23:53:45 +01:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS)
|
|
|
|
PLAY_MOD("appart");
|
|
|
|
else
|
|
|
|
PLAY_MOD("appar");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2012-11-11 18:58:45 +11:00
|
|
|
PLAY_MOD("ville");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
2012-11-11 18:58:45 +11:00
|
|
|
PLAY_MOD("Rock");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
2012-12-25 23:53:45 +01:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS)
|
|
|
|
PLAY_MOD("police");
|
|
|
|
else
|
|
|
|
PLAY_MOD("polic");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 5:
|
2012-11-11 18:58:45 +11:00
|
|
|
PLAY_MOD("deep");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 6:
|
2012-12-25 23:53:45 +01:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS)
|
|
|
|
PLAY_MOD("purgat");
|
|
|
|
else
|
|
|
|
PLAY_MOD("purga");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 7:
|
2012-12-25 23:53:45 +01:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS)
|
|
|
|
PLAY_MOD("riviere");
|
|
|
|
else
|
|
|
|
PLAY_MOD("rivie");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 8:
|
2012-12-25 23:53:45 +01:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS)
|
|
|
|
PLAY_MOD("SUSPENS");
|
|
|
|
else
|
|
|
|
PLAY_MOD("SUSPE");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 9:
|
2012-11-11 18:58:45 +11:00
|
|
|
PLAY_MOD("labo");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 10:
|
2012-12-25 23:53:45 +01:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS)
|
|
|
|
PLAY_MOD("cadavre");
|
|
|
|
else
|
|
|
|
PLAY_MOD("cadav");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 11:
|
2012-12-25 23:53:45 +01:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS)
|
|
|
|
PLAY_MOD("cabane");
|
|
|
|
else
|
|
|
|
PLAY_MOD("caban");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 12:
|
2012-12-25 23:53:45 +01:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS)
|
|
|
|
PLAY_MOD("purgat2");
|
|
|
|
else
|
|
|
|
PLAY_MOD("purg2");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 13:
|
2012-11-11 18:58:45 +11:00
|
|
|
PLAY_MOD("foret");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 14:
|
2012-11-11 18:58:45 +11:00
|
|
|
PLAY_MOD("ile");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 15:
|
2012-11-11 18:58:45 +11:00
|
|
|
PLAY_MOD("ile2");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 16:
|
2012-12-25 23:53:45 +01:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS)
|
|
|
|
PLAY_MOD("hopkins");
|
|
|
|
else
|
|
|
|
PLAY_MOD("hopki");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 17:
|
2012-11-11 18:58:45 +11:00
|
|
|
PLAY_MOD("peur");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 18:
|
2012-12-25 23:53:45 +01:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS)
|
|
|
|
PLAY_MOD("URAVOLGA");
|
|
|
|
else
|
|
|
|
PLAY_MOD("peur");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 19:
|
2012-11-11 18:58:45 +11:00
|
|
|
PLAY_MOD("BASE");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 20:
|
2012-12-25 23:53:45 +01:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS)
|
|
|
|
PLAY_MOD("cadavre2");
|
|
|
|
else
|
|
|
|
PLAY_MOD("cada2");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 21:
|
2012-11-11 18:58:45 +11:00
|
|
|
PLAY_MOD("usine");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 22:
|
2012-11-11 18:58:45 +11:00
|
|
|
PLAY_MOD("chien");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 23:
|
2012-11-11 18:58:45 +11:00
|
|
|
PLAY_MOD("coeur");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 24:
|
2012-11-11 18:58:45 +11:00
|
|
|
PLAY_MOD("stand");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 25:
|
2012-11-11 18:58:45 +11:00
|
|
|
PLAY_MOD("ocean");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 26:
|
2012-11-11 18:58:45 +11:00
|
|
|
PLAY_MOD("base3");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 27:
|
2012-11-11 18:58:45 +11:00
|
|
|
PLAY_MOD("gloop");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 28:
|
2012-11-11 18:58:45 +11:00
|
|
|
PLAY_MOD("cant");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 29:
|
2012-11-11 18:58:45 +11:00
|
|
|
PLAY_MOD("feel");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 30:
|
2012-11-11 18:58:45 +11:00
|
|
|
PLAY_MOD("lost");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
case 31:
|
2012-11-11 18:58:45 +11:00
|
|
|
PLAY_MOD("tobac");
|
2012-12-08 20:19:14 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-11-11 18:58:45 +11:00
|
|
|
old_music = soundNumber;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundManager::WSOUND_OFF() {
|
2012-12-26 00:31:42 +01:00
|
|
|
stopVoice(0);
|
|
|
|
stopVoice(1);
|
|
|
|
stopVoice(2);
|
2012-12-25 22:48:11 +01:00
|
|
|
if (_vm->_soundManager._soundFl)
|
2012-12-06 07:49:55 +01:00
|
|
|
DEL_NWAV(SOUND_NUM);
|
2012-11-11 18:58:45 +11:00
|
|
|
|
2012-12-06 07:49:55 +01:00
|
|
|
for (int i = 1; i <= 48; ++i)
|
|
|
|
DEL_SAMPLE_SDL(i);
|
2012-12-14 01:49:22 +01:00
|
|
|
|
2012-12-06 07:49:55 +01:00
|
|
|
if (MOD_FLAG) {
|
2012-12-25 22:48:11 +01:00
|
|
|
stopMusic();
|
|
|
|
delMusic();
|
2012-12-06 07:49:55 +01:00
|
|
|
MOD_FLAG = false;
|
2012-11-11 18:58:45 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundManager::PLAY_MOD(const Common::String &file) {
|
2012-12-27 19:08:10 +01:00
|
|
|
if (_musicOffFl)
|
2012-12-25 22:48:11 +01:00
|
|
|
return;
|
|
|
|
_vm->_fileManager.constructFilename(_vm->_globals.HOPMUSIC, file);
|
|
|
|
if (MOD_FLAG) {
|
|
|
|
stopMusic();
|
|
|
|
delMusic();
|
|
|
|
MOD_FLAG = false;
|
2012-11-11 18:58:45 +11:00
|
|
|
}
|
2012-12-25 22:48:11 +01:00
|
|
|
|
2012-12-28 08:26:27 +01:00
|
|
|
loadMusic(_vm->_globals._curFilename);
|
2012-12-25 22:48:11 +01:00
|
|
|
playMusic();
|
|
|
|
MOD_FLAG = true;
|
2012-11-11 18:58:45 +11:00
|
|
|
}
|
|
|
|
|
2012-12-25 22:48:11 +01:00
|
|
|
void SoundManager::loadMusic(const Common::String &file) {
|
2012-11-11 18:58:45 +11:00
|
|
|
if (Music._active)
|
2012-12-25 22:48:11 +01:00
|
|
|
delMusic();
|
2012-11-11 18:58:45 +11:00
|
|
|
|
|
|
|
Common::File f;
|
2012-12-25 23:53:45 +01:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS) {
|
|
|
|
Common::String filename = Common::String::format("%s.MOD", file.c_str());
|
|
|
|
|
|
|
|
if (!f.open(filename))
|
|
|
|
error("Error opening file %s", filename.c_str());
|
|
|
|
|
|
|
|
Audio::AudioStream *modStream = Audio::makeProtrackerStream(&f);
|
|
|
|
_vm->_mixer->playStream(Audio::Mixer::kMusicSoundType, &_modHandle, modStream);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Common::String filename = Common::String::format("%s.TWA", file.c_str());
|
|
|
|
|
|
|
|
if (!f.open(filename))
|
|
|
|
error("Error opening file %s", filename.c_str());
|
|
|
|
|
|
|
|
char s[8];
|
|
|
|
int destIndex = 0;
|
|
|
|
int mwavIndex;
|
|
|
|
|
|
|
|
bool breakFlag = false;
|
|
|
|
do {
|
|
|
|
f.read(&s[0], 3);
|
|
|
|
|
|
|
|
if (s[0] == 'x') {
|
|
|
|
// End of list reached
|
|
|
|
Music._mwavIndexes[destIndex] = -1;
|
|
|
|
breakFlag = true;
|
|
|
|
} else {
|
|
|
|
// Convert two digits to a number
|
|
|
|
s[2] = '\0';
|
|
|
|
mwavIndex = atol(&s[0]);
|
|
|
|
|
|
|
|
filename = Common::String::format("%s_%s.%s", file.c_str(), &s[0],
|
|
|
|
(_vm->getPlatform() == Common::kPlatformWindows) ? "APC" : "WAV");
|
|
|
|
LOAD_MSAMPLE(mwavIndex, filename);
|
|
|
|
|
|
|
|
assert(destIndex < MUSIC_WAVE_COUNT);
|
|
|
|
Music._mwavIndexes[destIndex++] = mwavIndex;
|
|
|
|
}
|
|
|
|
} while (!breakFlag);
|
|
|
|
f.close();
|
|
|
|
}
|
2012-11-11 18:58:45 +11:00
|
|
|
|
|
|
|
Music._active = true;
|
|
|
|
Music._isPlaying = false;
|
|
|
|
Music._currentIndex = -1;
|
|
|
|
}
|
|
|
|
|
2012-12-25 22:48:11 +01:00
|
|
|
void SoundManager::playMusic() {
|
2012-11-11 18:58:45 +11:00
|
|
|
if (Music._active)
|
|
|
|
Music._isPlaying = true;
|
|
|
|
}
|
|
|
|
|
2012-12-25 22:48:11 +01:00
|
|
|
void SoundManager::stopMusic() {
|
2012-11-11 18:58:45 +11:00
|
|
|
if (Music._active)
|
|
|
|
Music._isPlaying = false;
|
2012-12-27 18:41:20 +01:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS)
|
|
|
|
_vm->_mixer->stopHandle(_modHandle);
|
|
|
|
|
2012-11-11 18:58:45 +11:00
|
|
|
}
|
|
|
|
|
2012-12-25 22:48:11 +01:00
|
|
|
void SoundManager::delMusic() {
|
2012-11-11 18:58:45 +11:00
|
|
|
if (Music._active) {
|
|
|
|
for (int i = 0; i < 50; ++i) {
|
|
|
|
DEL_MSAMPLE(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Music._active = false;
|
|
|
|
Music._isPlaying = false;
|
|
|
|
Music._string = " ";
|
|
|
|
Music._currentIndex = -1;
|
|
|
|
}
|
|
|
|
|
2012-11-12 20:09:29 +11:00
|
|
|
void SoundManager::checkSounds() {
|
|
|
|
checkMusic();
|
|
|
|
checkVoices();
|
|
|
|
}
|
|
|
|
|
2012-11-11 18:58:45 +11:00
|
|
|
void SoundManager::checkMusic() {
|
2012-12-26 00:31:42 +01:00
|
|
|
// OS2 and BeOS versions use MOD files.
|
2012-12-25 23:53:45 +01:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS)
|
|
|
|
return;
|
|
|
|
|
2012-11-11 18:58:45 +11:00
|
|
|
if (Music._active && Music._isPlaying) {
|
|
|
|
int mwavIndex = Music._mwavIndexes[Music._currentIndex];
|
|
|
|
if (mwavIndex == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (Music._currentIndex >= 0 && Music._currentIndex < MWAV_COUNT) {
|
|
|
|
if (mwavIndex != -1 && !Mwav[mwavIndex]._audioStream->endOfStream())
|
|
|
|
// Currently playing wav has not finished, so exit
|
|
|
|
return;
|
|
|
|
|
|
|
|
_vm->_mixer->stopHandle(Mwav[mwavIndex]._soundHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Time to move to the next index
|
|
|
|
if (++Music._currentIndex >= MWAV_COUNT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mwavIndex = Music._mwavIndexes[Music._currentIndex];
|
2012-11-11 19:28:28 +11:00
|
|
|
if (mwavIndex == -1) {
|
|
|
|
Music._currentIndex = 0;
|
|
|
|
mwavIndex = Music._mwavIndexes[Music._currentIndex];
|
2012-12-14 01:49:22 +01:00
|
|
|
}
|
2012-11-11 18:58:45 +11:00
|
|
|
|
2012-12-27 19:08:10 +01:00
|
|
|
int volume = _musicVolume * 255 / 16;
|
2012-11-11 19:28:28 +11:00
|
|
|
|
|
|
|
Mwav[mwavIndex]._audioStream->rewind();
|
2012-12-14 01:49:22 +01:00
|
|
|
_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &Mwav[mwavIndex]._soundHandle,
|
2012-11-11 19:28:28 +11:00
|
|
|
Mwav[mwavIndex]._audioStream, -1, volume, 0, DisposeAfterUse::NO);
|
2012-11-11 18:58:45 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-12 20:09:29 +11:00
|
|
|
void SoundManager::checkVoices() {
|
|
|
|
// Check the status of each voice.
|
|
|
|
bool hasActiveVoice = false;
|
|
|
|
for (int i = 0; i < VOICE_COUNT; ++i) {
|
|
|
|
VOICE_STAT(i);
|
|
|
|
hasActiveVoice |= Voice[i]._status != 0;
|
|
|
|
}
|
|
|
|
|
2012-12-25 22:48:11 +01:00
|
|
|
if (!hasActiveVoice && _soundFl) {
|
|
|
|
_soundFl = false;
|
2012-11-12 20:09:29 +11:00
|
|
|
SOUND_NUM = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-11 18:58:45 +11:00
|
|
|
void SoundManager::LOAD_MSAMPLE(int mwavIndex, const Common::String &file) {
|
|
|
|
if (!Mwav[mwavIndex]._active) {
|
|
|
|
Common::File f;
|
2012-12-03 07:48:37 +01:00
|
|
|
if (!f.open(file)) {
|
|
|
|
// Fallback from WAV to APC...
|
|
|
|
if (!f.open(setExtension(file, ".APC")))
|
|
|
|
error("Could not open %s for reading", file.c_str());
|
|
|
|
}
|
2012-11-11 18:58:45 +11:00
|
|
|
|
2012-12-02 17:16:00 +11:00
|
|
|
Mwav[mwavIndex]._audioStream = makeSoundStream(f.readStream(f.size()));
|
2012-11-11 18:58:45 +11:00
|
|
|
Mwav[mwavIndex]._active = true;
|
|
|
|
|
|
|
|
f.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundManager::DEL_MSAMPLE(int mwavIndex) {
|
|
|
|
if (Mwav[mwavIndex]._active) {
|
|
|
|
Mwav[mwavIndex]._active = false;
|
|
|
|
_vm->_mixer->stopHandle(Mwav[mwavIndex]._soundHandle);
|
|
|
|
|
|
|
|
delete Mwav[mwavIndex]._audioStream;
|
|
|
|
Mwav[mwavIndex]._audioStream = NULL;
|
2012-11-11 15:21:30 +11:00
|
|
|
}
|
2012-09-15 13:23:46 +10:00
|
|
|
}
|
2012-09-15 10:27:15 +10:00
|
|
|
|
2012-12-23 19:08:23 +01:00
|
|
|
bool SoundManager::mixVoice(int voiceId, int voiceMode) {
|
2012-12-14 01:49:22 +01:00
|
|
|
int fileNumber;
|
|
|
|
int oldMusicVol;
|
|
|
|
bool breakFlag;
|
2012-11-10 23:32:06 +11:00
|
|
|
Common::String prefix;
|
|
|
|
Common::String filename;
|
|
|
|
Common::File f;
|
2012-11-11 15:21:30 +11:00
|
|
|
size_t catPos, catLen;
|
2012-11-10 23:32:06 +11:00
|
|
|
|
|
|
|
fileNumber = voiceId;
|
2012-12-24 11:36:53 +01:00
|
|
|
if (_voiceOffFl)
|
2012-11-10 23:32:06 +11:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if ((unsigned int)(voiceMode - 1) <= 1
|
|
|
|
&& (voiceId == 4
|
|
|
|
|| voiceId == 16
|
|
|
|
|| voiceId == 121
|
|
|
|
|| voiceId == 142
|
|
|
|
|| voiceId == 182
|
|
|
|
|| voiceId == 191
|
|
|
|
|| voiceId == 212
|
|
|
|
|| voiceId == 225
|
|
|
|
|| voiceId == 239
|
|
|
|
|| voiceId == 245
|
|
|
|
|| voiceId == 297
|
|
|
|
|| voiceId == 308
|
|
|
|
|| voiceId == 333
|
|
|
|
|| voiceId == 348
|
|
|
|
|| voiceId == 352
|
|
|
|
|| voiceId == 358
|
|
|
|
|| voiceId == 364
|
|
|
|
|| voiceId == 371
|
|
|
|
|| voiceId == 394
|
|
|
|
|| voiceId == 414
|
|
|
|
|| voiceId == 429
|
|
|
|
|| voiceId == 442
|
|
|
|
|| voiceId == 446
|
|
|
|
|| voiceId == 461
|
|
|
|
|| voiceId == 468
|
|
|
|
|| voiceId == 476
|
|
|
|
|| voiceId == 484
|
|
|
|
|| voiceId == 491
|
|
|
|
|| voiceId == 497
|
|
|
|
|| voiceId == 501
|
|
|
|
|| voiceId == 511
|
|
|
|
|| voiceId == 520
|
|
|
|
|| voiceId == 536
|
|
|
|
|| voiceId == 554
|
|
|
|
|| voiceId == 566
|
|
|
|
|| voiceId == 573
|
|
|
|
|| voiceId == 632
|
|
|
|
|| voiceId == 645))
|
|
|
|
fileNumber = 684;
|
2012-12-14 01:49:22 +01:00
|
|
|
|
2012-11-10 23:32:06 +11:00
|
|
|
if ((unsigned int)(voiceMode - 1) <= 1) {
|
|
|
|
prefix = "DF";
|
|
|
|
}
|
|
|
|
if (voiceMode == 3) {
|
|
|
|
prefix = "IF";
|
|
|
|
}
|
|
|
|
if (voiceMode == 4) {
|
|
|
|
prefix = "TF";
|
|
|
|
}
|
|
|
|
if (voiceMode == 5) {
|
|
|
|
prefix = "OF";
|
|
|
|
}
|
|
|
|
|
2012-12-06 08:12:00 +01:00
|
|
|
filename = Common::String::format("%s%d", prefix.c_str(), fileNumber);
|
2012-12-14 01:49:22 +01:00
|
|
|
|
2012-12-09 20:22:12 +01:00
|
|
|
if (!_vm->_fileManager.searchCat(filename + ".WAV", 9)) {
|
2012-12-26 00:31:42 +01:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS)
|
|
|
|
_vm->_fileManager.constructFilename(_vm->_globals.HOPVOICE, "ENG_VOI.RES");
|
|
|
|
// Win95 and Linux versions uses another set of names
|
|
|
|
else if (_vm->_globals._language == LANG_FR)
|
2012-12-09 20:22:12 +01:00
|
|
|
_vm->_fileManager.constructFilename(_vm->_globals.HOPVOICE, "RES_VFR.RES");
|
2012-12-24 11:36:53 +01:00
|
|
|
else if (_vm->_globals._language == LANG_EN)
|
2012-12-09 20:22:12 +01:00
|
|
|
_vm->_fileManager.constructFilename(_vm->_globals.HOPVOICE, "RES_VAN.RES");
|
2012-12-24 11:36:53 +01:00
|
|
|
else if (_vm->_globals._language == LANG_SP)
|
2012-12-09 20:22:12 +01:00
|
|
|
_vm->_fileManager.constructFilename(_vm->_globals.HOPVOICE, "RES_VES.RES");
|
2012-11-10 23:32:06 +11:00
|
|
|
|
2012-12-19 08:00:22 +01:00
|
|
|
catPos = _vm->_globals._catalogPos;
|
|
|
|
catLen = _vm->_globals._catalogSize;
|
2012-12-09 20:22:12 +01:00
|
|
|
} else if (!_vm->_fileManager.searchCat(filename + ".APC", 9)) {
|
2012-12-26 00:31:42 +01:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS)
|
|
|
|
_vm->_fileManager.constructFilename(_vm->_globals.HOPVOICE, "ENG_VOI.RES");
|
|
|
|
// Win95 and Linux versions uses another set of names
|
|
|
|
else if (_vm->_globals._language == LANG_FR)
|
2012-12-09 20:22:12 +01:00
|
|
|
_vm->_fileManager.constructFilename(_vm->_globals.HOPVOICE, "RES_VFR.RES");
|
2012-12-24 11:36:53 +01:00
|
|
|
else if (_vm->_globals._language == LANG_EN)
|
2012-12-09 20:22:12 +01:00
|
|
|
_vm->_fileManager.constructFilename(_vm->_globals.HOPVOICE, "RES_VAN.RES");
|
2012-12-24 11:36:53 +01:00
|
|
|
else if (_vm->_globals._language == LANG_SP)
|
2012-12-09 20:22:12 +01:00
|
|
|
_vm->_fileManager.constructFilename(_vm->_globals.HOPVOICE, "RES_VES.RES");
|
2012-12-06 08:12:00 +01:00
|
|
|
|
2012-12-19 08:00:22 +01:00
|
|
|
catPos = _vm->_globals._catalogPos;
|
|
|
|
catLen = _vm->_globals._catalogSize;
|
2012-12-14 01:49:22 +01:00
|
|
|
} else {
|
2012-12-09 20:22:12 +01:00
|
|
|
_vm->_fileManager.constructFilename(_vm->_globals.HOPVOICE, filename + ".WAV");
|
2012-12-28 08:26:27 +01:00
|
|
|
if (!f.exists(_vm->_globals._curFilename)) {
|
2012-12-09 20:22:12 +01:00
|
|
|
_vm->_fileManager.constructFilename(_vm->_globals.HOPVOICE, filename + ".APC");
|
2012-12-28 08:26:27 +01:00
|
|
|
if (!f.exists(_vm->_globals._curFilename))
|
2012-12-06 08:12:00 +01:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-10 23:32:06 +11:00
|
|
|
|
|
|
|
catPos = 0;
|
2012-11-11 15:21:30 +11:00
|
|
|
catLen = 0;
|
2012-11-10 23:32:06 +11:00
|
|
|
}
|
|
|
|
|
2012-11-11 15:21:30 +11:00
|
|
|
SDL_LVOICE(catPos, catLen);
|
2012-12-27 19:08:10 +01:00
|
|
|
oldMusicVol = _musicVolume;
|
|
|
|
if (!_musicOffFl && _musicVolume > 2)
|
|
|
|
_musicVolume = (signed int)((long double)_musicVolume - (long double)_musicVolume / 100.0 * 45.0);
|
2012-11-10 23:32:06 +11:00
|
|
|
|
|
|
|
PLAY_VOICE_SDL();
|
|
|
|
|
2012-11-11 15:21:30 +11:00
|
|
|
// Loop for playing voice
|
2012-11-10 23:32:06 +11:00
|
|
|
breakFlag = 0;
|
|
|
|
do {
|
|
|
|
if (SPECIAL_SOUND != 4 && !VBL_MERDE)
|
|
|
|
_vm->_eventsManager.VBL();
|
2012-12-11 01:53:50 +01:00
|
|
|
if (_vm->_eventsManager.getMouseButton())
|
2012-11-10 23:32:06 +11:00
|
|
|
break;
|
2012-12-11 08:31:07 +01:00
|
|
|
_vm->_eventsManager.refreshEvents();
|
2012-12-11 01:53:50 +01:00
|
|
|
if (_vm->_eventsManager._escKeyFl)
|
2012-11-10 23:32:06 +11:00
|
|
|
break;
|
|
|
|
if (!VOICE_STAT(2))
|
|
|
|
breakFlag = true;
|
|
|
|
} while (!_vm->shouldQuit() && !breakFlag);
|
|
|
|
|
|
|
|
|
2012-12-26 00:31:42 +01:00
|
|
|
stopVoice(2);
|
2012-11-10 23:32:06 +11:00
|
|
|
DEL_SAMPLE_SDL(20);
|
2012-12-27 19:08:10 +01:00
|
|
|
_musicVolume = oldMusicVol;
|
2012-12-11 01:53:50 +01:00
|
|
|
_vm->_eventsManager._escKeyFl = false;
|
2012-11-10 23:32:06 +11:00
|
|
|
VBL_MERDE = 0;
|
|
|
|
return true;
|
2012-09-15 10:27:15 +10:00
|
|
|
}
|
|
|
|
|
2012-11-11 15:21:30 +11:00
|
|
|
void SoundManager::DEL_SAMPLE(int soundIndex) {
|
2012-12-06 07:49:55 +01:00
|
|
|
if (VOICE_STAT(1) == 1)
|
2012-12-26 00:31:42 +01:00
|
|
|
stopVoice(1);
|
2012-12-06 07:49:55 +01:00
|
|
|
if (VOICE_STAT(2) == 2)
|
2012-12-26 00:31:42 +01:00
|
|
|
stopVoice(2);
|
2012-12-06 07:49:55 +01:00
|
|
|
if (VOICE_STAT(3) == 3)
|
2012-12-26 00:31:42 +01:00
|
|
|
stopVoice(3);
|
2012-12-06 07:49:55 +01:00
|
|
|
DEL_SAMPLE_SDL(soundIndex);
|
|
|
|
SOUND[soundIndex]._active = false;
|
2012-09-17 16:53:21 +10:00
|
|
|
}
|
|
|
|
|
2012-12-25 22:48:11 +01:00
|
|
|
void SoundManager::playSound(const Common::String &file) {
|
|
|
|
if (!_soundOffFl) {
|
|
|
|
if (_soundFl)
|
2012-11-11 15:21:30 +11:00
|
|
|
DEL_NWAV(SOUND_NUM);
|
|
|
|
LOAD_NWAV(file, 1);
|
|
|
|
PLAY_NWAV(1);
|
|
|
|
}
|
2012-09-23 10:59:52 +10:00
|
|
|
}
|
|
|
|
|
2012-09-30 21:02:39 +10:00
|
|
|
void SoundManager::PLAY_SOUND2(const Common::String &file) {
|
2012-12-25 22:48:11 +01:00
|
|
|
if (!_soundOffFl) {
|
2012-12-06 07:49:55 +01:00
|
|
|
LOAD_NWAV(file, 1);
|
|
|
|
PLAY_NWAV(1);
|
2012-11-11 15:21:30 +11:00
|
|
|
}
|
2012-09-30 21:02:39 +10:00
|
|
|
}
|
|
|
|
|
2012-09-23 10:59:52 +10:00
|
|
|
void SoundManager::MODSetSampleVolume() {
|
2012-11-11 18:58:45 +11:00
|
|
|
// No implementatoin needed
|
2012-09-23 10:59:52 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
void SoundManager::MODSetVoiceVolume() {
|
2012-11-11 18:58:45 +11:00
|
|
|
// No implementatoin needed
|
2012-09-23 10:59:52 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
void SoundManager::MODSetMusicVolume(int volume) {
|
2012-11-11 18:58:45 +11:00
|
|
|
// No implementatoin needed
|
2012-09-23 10:59:52 +10:00
|
|
|
}
|
|
|
|
|
2012-12-24 01:43:37 +01:00
|
|
|
void SoundManager::loadSample(int wavIndex, const Common::String &file) {
|
2012-12-09 20:22:12 +01:00
|
|
|
_vm->_fileManager.constructFilename(_vm->_globals.HOPSOUND, file);
|
2012-12-28 08:26:27 +01:00
|
|
|
LOAD_SAMPLE2_SDL(wavIndex, _vm->_globals._curFilename, 0);
|
2012-12-06 07:49:55 +01:00
|
|
|
SOUND[wavIndex]._active = true;
|
2012-09-30 21:02:39 +10:00
|
|
|
}
|
|
|
|
|
2012-11-17 20:49:07 +11:00
|
|
|
void SoundManager::PLAY_SAMPLE(int wavIndex, int voiceMode) {
|
2012-12-25 22:48:11 +01:00
|
|
|
if (!_soundOffFl && SOUND[wavIndex]._active) {
|
|
|
|
if (_soundFl)
|
2012-11-17 20:49:07 +11:00
|
|
|
DEL_NWAV(SOUND_NUM);
|
|
|
|
if (voiceMode == 5) {
|
|
|
|
if (VOICE_STAT(1) == 1)
|
2012-12-26 00:31:42 +01:00
|
|
|
stopVoice(1);
|
2012-11-17 20:49:07 +11:00
|
|
|
PLAY_SAMPLE_SDL(1, wavIndex);
|
|
|
|
}
|
|
|
|
if (voiceMode == 6) {
|
|
|
|
if (VOICE_STAT(2) == 1)
|
2012-12-26 00:31:42 +01:00
|
|
|
stopVoice(1);
|
2012-11-17 20:49:07 +11:00
|
|
|
PLAY_SAMPLE_SDL(2, wavIndex);
|
|
|
|
}
|
|
|
|
if (voiceMode == 7) {
|
|
|
|
if (VOICE_STAT(3) == 1)
|
2012-12-26 00:31:42 +01:00
|
|
|
stopVoice(1);
|
2012-11-17 20:49:07 +11:00
|
|
|
PLAY_SAMPLE_SDL(3, wavIndex);
|
|
|
|
}
|
|
|
|
if (voiceMode == 8) {
|
|
|
|
if (VOICE_STAT(1) == 1)
|
2012-12-26 00:31:42 +01:00
|
|
|
stopVoice(1);
|
2012-11-17 20:49:07 +11:00
|
|
|
PLAY_SAMPLE_SDL(1, wavIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-30 21:02:39 +10:00
|
|
|
void SoundManager::PLAY_SAMPLE2(int idx) {
|
2012-12-25 22:48:11 +01:00
|
|
|
if (!_soundOffFl && SOUND[idx]._active) {
|
|
|
|
if (_soundFl)
|
2012-11-11 15:21:30 +11:00
|
|
|
DEL_NWAV(SOUND_NUM);
|
|
|
|
if (VOICE_STAT(1) == 1)
|
2012-12-26 00:31:42 +01:00
|
|
|
stopVoice(1);
|
2012-11-11 15:21:30 +11:00
|
|
|
PLAY_SAMPLE_SDL(1, idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundManager::LOAD_WAV(const Common::String &file, int wavIndex) {
|
2012-12-06 07:49:55 +01:00
|
|
|
LOAD_NWAV(file, wavIndex);
|
2012-09-30 21:02:39 +10:00
|
|
|
}
|
|
|
|
|
2012-12-25 22:48:11 +01:00
|
|
|
void SoundManager::playWav(int wavIndex) {
|
2012-12-06 07:49:55 +01:00
|
|
|
PLAY_NWAV(wavIndex);
|
2012-09-30 21:02:39 +10:00
|
|
|
}
|
2012-09-23 10:59:52 +10:00
|
|
|
|
2012-11-11 15:21:30 +11:00
|
|
|
int SoundManager::VOICE_STAT(int voiceIndex) {
|
2012-11-11 18:58:45 +11:00
|
|
|
if (Voice[voiceIndex]._status) {
|
2012-11-12 20:09:29 +11:00
|
|
|
int wavIndex = Voice[voiceIndex]._wavIndex;
|
2012-11-18 10:31:58 +11:00
|
|
|
if (Swav[wavIndex]._audioStream != NULL && Swav[wavIndex]._audioStream->endOfStream())
|
2012-12-26 00:31:42 +01:00
|
|
|
stopVoice(voiceIndex);
|
2012-11-11 15:21:30 +11:00
|
|
|
}
|
|
|
|
|
2012-11-11 18:58:45 +11:00
|
|
|
return Voice[voiceIndex]._status;
|
2012-11-10 23:32:06 +11:00
|
|
|
}
|
|
|
|
|
2012-12-26 00:31:42 +01:00
|
|
|
void SoundManager::stopVoice(int voiceIndex) {
|
2012-11-11 18:58:45 +11:00
|
|
|
if (Voice[voiceIndex]._status) {
|
|
|
|
Voice[voiceIndex]._status = 0;
|
2012-11-24 00:16:44 +01:00
|
|
|
int wavIndex = Voice[voiceIndex]._wavIndex;
|
2012-11-11 18:58:45 +11:00
|
|
|
if (Swav[wavIndex]._active) {
|
2012-11-11 19:54:48 +11:00
|
|
|
if (Swav[wavIndex].freeSample)
|
2012-11-10 23:32:06 +11:00
|
|
|
DEL_SAMPLE_SDL(wavIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Voice[voiceIndex].fieldC = 0;
|
2012-11-11 18:58:45 +11:00
|
|
|
Voice[voiceIndex]._status = 0;
|
2012-11-10 23:32:06 +11:00
|
|
|
Voice[voiceIndex].field14 = 0;
|
|
|
|
}
|
|
|
|
|
2012-11-11 15:21:30 +11:00
|
|
|
void SoundManager::SDL_LVOICE(size_t filePosition, size_t entryLength) {
|
2012-12-28 08:26:27 +01:00
|
|
|
if (!SDL_LoadVoice(_vm->_globals._curFilename, filePosition, entryLength, Swav[20]))
|
|
|
|
error("Couldn't load the sample %s", _vm->_globals._curFilename.c_str());
|
2012-11-10 23:32:06 +11:00
|
|
|
|
2012-11-11 18:58:45 +11:00
|
|
|
Swav[20]._active = true;
|
2012-11-10 23:32:06 +11:00
|
|
|
}
|
2012-12-14 01:49:22 +01:00
|
|
|
|
2012-11-10 23:32:06 +11:00
|
|
|
void SoundManager::PLAY_VOICE_SDL() {
|
2012-11-11 18:58:45 +11:00
|
|
|
if (!Swav[20]._active)
|
2012-11-10 23:32:06 +11:00
|
|
|
error("Bad handle");
|
|
|
|
|
2012-11-11 18:58:45 +11:00
|
|
|
if (!Voice[2]._status) {
|
|
|
|
int wavIndex = Voice[2]._wavIndex;
|
2012-11-11 19:54:48 +11:00
|
|
|
if (Swav[wavIndex]._active && Swav[wavIndex].freeSample)
|
2012-11-10 23:32:06 +11:00
|
|
|
DEL_SAMPLE_SDL(wavIndex);
|
|
|
|
}
|
|
|
|
|
2012-11-11 15:21:30 +11:00
|
|
|
PLAY_SAMPLE_SDL(2, 20);
|
2012-11-10 23:32:06 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SoundManager::DEL_SAMPLE_SDL(int wavIndex) {
|
2012-11-11 18:58:45 +11:00
|
|
|
if (Swav[wavIndex]._active) {
|
2012-11-11 15:21:30 +11:00
|
|
|
_vm->_mixer->stopHandle(Swav[wavIndex]._soundHandle);
|
2012-11-11 18:58:45 +11:00
|
|
|
delete Swav[wavIndex]._audioStream;
|
2012-11-18 10:31:58 +11:00
|
|
|
Swav[wavIndex]._audioStream = NULL;
|
|
|
|
Swav[wavIndex]._active = false;
|
|
|
|
|
2012-11-10 23:32:06 +11:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-11 15:21:30 +11:00
|
|
|
bool SoundManager::SDL_LoadVoice(const Common::String &filename, size_t fileOffset, size_t entryLength, SwavItem &item) {
|
2012-11-10 23:32:06 +11:00
|
|
|
Common::File f;
|
2012-12-03 07:48:37 +01:00
|
|
|
if (!f.open(filename)) {
|
|
|
|
// Fallback from WAV to APC...
|
|
|
|
if (!f.open(setExtension(filename, ".APC")))
|
|
|
|
error("Could not open %s for reading", filename.c_str());
|
|
|
|
}
|
2012-11-10 23:32:06 +11:00
|
|
|
|
|
|
|
f.seek(fileOffset);
|
2012-12-02 17:16:00 +11:00
|
|
|
item._audioStream = makeSoundStream(f.readStream((entryLength == 0) ? f.size() : entryLength));
|
2012-11-10 23:32:06 +11:00
|
|
|
f.close();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-11 19:54:48 +11:00
|
|
|
void SoundManager::LOAD_SAMPLE2_SDL(int wavIndex, const Common::String &filename, bool freeSample) {
|
2012-11-11 18:58:45 +11:00
|
|
|
if (Swav[wavIndex]._active)
|
2012-11-11 15:21:30 +11:00
|
|
|
DEL_SAMPLE_SDL(wavIndex);
|
|
|
|
|
|
|
|
SDL_LoadVoice(filename, 0, 0, Swav[wavIndex]);
|
2012-11-11 18:58:45 +11:00
|
|
|
Swav[wavIndex]._active = true;
|
2012-11-11 19:54:48 +11:00
|
|
|
Swav[wavIndex].freeSample = freeSample;
|
2012-11-11 15:21:30 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
void SoundManager::LOAD_NWAV(const Common::String &file, int wavIndex) {
|
2012-12-09 20:22:12 +01:00
|
|
|
_vm->_fileManager.constructFilename(_vm->_globals.HOPSOUND, file);
|
2012-12-28 08:26:27 +01:00
|
|
|
LOAD_SAMPLE2_SDL(wavIndex, _vm->_globals._curFilename, 1);
|
2012-11-11 15:21:30 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
void SoundManager::PLAY_NWAV(int wavIndex) {
|
2012-12-25 22:48:11 +01:00
|
|
|
if (!_soundFl && !_soundOffFl) {
|
|
|
|
_soundFl = true;
|
2012-11-11 15:21:30 +11:00
|
|
|
SOUND_NUM = wavIndex;
|
|
|
|
PLAY_SAMPLE_SDL(1, wavIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundManager::DEL_NWAV(int wavIndex) {
|
2012-12-06 07:49:55 +01:00
|
|
|
if (DEL_SAMPLE_SDL(wavIndex)) {
|
|
|
|
if (VOICE_STAT(1) == 1)
|
2012-12-26 00:31:42 +01:00
|
|
|
stopVoice(1);
|
2012-11-11 15:21:30 +11:00
|
|
|
|
2012-12-06 07:49:55 +01:00
|
|
|
SOUND_NUM = 0;
|
2012-12-25 22:48:11 +01:00
|
|
|
_soundFl = false;
|
2012-11-11 15:21:30 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundManager::PLAY_SAMPLE_SDL(int voiceIndex, int wavIndex) {
|
2012-11-11 18:58:45 +11:00
|
|
|
if (!Swav[wavIndex]._active)
|
2012-11-11 15:21:30 +11:00
|
|
|
warning("Bad handle");
|
|
|
|
|
2012-11-11 19:54:48 +11:00
|
|
|
if (Voice[voiceIndex]._status == 1 && Swav[wavIndex]._active && Swav[wavIndex].freeSample)
|
2012-11-11 15:21:30 +11:00
|
|
|
DEL_SAMPLE_SDL(wavIndex);
|
|
|
|
|
|
|
|
Voice[voiceIndex].fieldC = 0;
|
2012-11-11 18:58:45 +11:00
|
|
|
Voice[voiceIndex]._status = 1;
|
2012-11-11 15:21:30 +11:00
|
|
|
Voice[voiceIndex].field14 = 4;
|
2012-11-12 20:09:29 +11:00
|
|
|
Voice[voiceIndex]._wavIndex = wavIndex;
|
2012-12-14 01:49:22 +01:00
|
|
|
|
2012-12-27 19:08:10 +01:00
|
|
|
int volume = (voiceIndex == 2) ? _voiceVolume * 255 / 16 : _soundVolume * 255 / 16;
|
2012-11-11 15:21:30 +11:00
|
|
|
|
|
|
|
// Start the voice playing
|
2012-12-09 20:38:28 +11:00
|
|
|
Swav[wavIndex]._audioStream->rewind();
|
2012-12-14 01:49:22 +01:00
|
|
|
_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &Swav[wavIndex]._soundHandle,
|
2012-11-11 18:58:45 +11:00
|
|
|
Swav[wavIndex]._audioStream, -1, volume, 0, DisposeAfterUse::NO);
|
2012-11-11 15:21:30 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
void SoundManager::syncSoundSettings() {
|
|
|
|
bool muteAll = false;
|
|
|
|
if (ConfMan.hasKey("mute"))
|
|
|
|
muteAll = ConfMan.getBool("mute");
|
|
|
|
|
|
|
|
// Update the mute settings
|
2012-12-27 19:08:10 +01:00
|
|
|
_musicOffFl = muteAll || (ConfMan.hasKey("music_mute") && ConfMan.getBool("music_mute"));
|
2012-12-25 22:48:11 +01:00
|
|
|
_soundOffFl = muteAll || (ConfMan.hasKey("sfx_mute") && ConfMan.getBool("sfx_mute"));
|
2012-12-24 11:36:53 +01:00
|
|
|
_voiceOffFl = muteAll || (ConfMan.hasKey("speech_mute") && ConfMan.getBool("speech_mute"));
|
2012-11-11 15:21:30 +11:00
|
|
|
|
|
|
|
// Update the volume levels
|
2012-12-27 19:08:10 +01:00
|
|
|
_musicVolume = MIN(255, ConfMan.getInt("music_volume")) * 16 / 255;
|
|
|
|
_soundVolume = MIN(255, ConfMan.getInt("sfx_volume")) * 16 / 255;
|
|
|
|
_voiceVolume = MIN(255, ConfMan.getInt("speech_volume")) * 16 / 255;
|
2012-11-11 15:21:30 +11:00
|
|
|
|
2012-11-11 20:58:33 +11:00
|
|
|
// Update any active sounds
|
2012-11-11 15:21:30 +11:00
|
|
|
for (int idx = 0; idx < SWAV_COUNT; ++idx) {
|
2012-11-11 18:58:45 +11:00
|
|
|
if (Swav[idx]._active) {
|
2012-12-27 19:08:10 +01:00
|
|
|
int volume = (idx == 20) ? (_voiceVolume * 255 / 16) : (_soundVolume * 255 / 16);
|
2012-11-11 20:58:33 +11:00
|
|
|
_vm->_mixer->setChannelVolume(Swav[idx]._soundHandle, volume);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int idx = 0; idx < MWAV_COUNT; ++idx) {
|
|
|
|
if (Mwav[idx]._active) {
|
2012-12-27 19:08:10 +01:00
|
|
|
_vm->_mixer->setChannelVolume(Mwav[idx]._soundHandle, _musicVolume * 255 / 16);
|
2012-11-11 15:21:30 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundManager::updateScummVMSoundSettings() {
|
2012-12-27 19:08:10 +01:00
|
|
|
ConfMan.setBool("mute", _musicOffFl && _soundOffFl && _voiceOffFl);
|
|
|
|
ConfMan.setBool("music_mute", _musicOffFl);
|
2012-12-25 22:48:11 +01:00
|
|
|
ConfMan.setBool("sfx_mute", _soundOffFl);
|
2012-12-24 11:36:53 +01:00
|
|
|
ConfMan.setBool("speech_mute", _voiceOffFl);
|
2012-11-11 15:21:30 +11:00
|
|
|
|
2012-12-27 19:08:10 +01:00
|
|
|
ConfMan.setInt("music_volume", _musicVolume * 255 / 16);
|
|
|
|
ConfMan.setInt("sfx_volume", _soundVolume * 255 / 16);
|
|
|
|
ConfMan.setInt("speech_volume", _voiceVolume * 255 / 16);
|
2012-11-11 20:00:57 +11:00
|
|
|
|
|
|
|
ConfMan.flushToDisk();
|
2012-11-11 15:21:30 +11:00
|
|
|
}
|
|
|
|
|
2012-12-02 17:16:00 +11:00
|
|
|
Audio::RewindableAudioStream *SoundManager::makeSoundStream(Common::SeekableReadStream *stream) {
|
|
|
|
if (_vm->getPlatform() == Common::kPlatformWindows)
|
2012-12-14 01:49:22 +01:00
|
|
|
return Audio::makeAPCStream(stream, DisposeAfterUse::YES);
|
2012-12-02 17:16:00 +11:00
|
|
|
else
|
2012-12-14 01:49:22 +01:00
|
|
|
return Audio::makeWAVStream(stream, DisposeAfterUse::YES);
|
2012-12-02 17:16:00 +11:00
|
|
|
}
|
|
|
|
|
2012-12-03 07:48:37 +01:00
|
|
|
// Blatant rip from gob engine. Hi DrMcCoy!
|
|
|
|
Common::String SoundManager::setExtension(const Common::String &str, const Common::String &ext) {
|
|
|
|
if (str.empty())
|
|
|
|
return str;
|
|
|
|
|
|
|
|
const char *dot = strrchr(str.c_str(), '.');
|
|
|
|
if (dot)
|
|
|
|
return Common::String(str.c_str(), dot - str.c_str()) + ext;
|
|
|
|
|
|
|
|
return str + ext;
|
|
|
|
}
|
2012-09-08 21:43:33 +10:00
|
|
|
} // End of namespace Hopkins
|