2013-06-25 20:50:27 +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.
|
|
|
|
*
|
|
|
|
* 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.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2013-06-25 20:50:27 +00:00
|
|
|
* 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.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2013-06-25 20:50:27 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-10-03 21:50:25 +00:00
|
|
|
#include "ngi/ngi.h"
|
2020-10-03 21:47:47 +00:00
|
|
|
|
|
|
|
#include "ngi/objects.h"
|
|
|
|
#include "ngi/scene.h"
|
|
|
|
#include "ngi/sound.h"
|
|
|
|
#include "ngi/ngiarchive.h"
|
|
|
|
#include "ngi/messages.h"
|
|
|
|
#include "ngi/statics.h"
|
2014-05-30 05:03:17 +00:00
|
|
|
|
2016-09-11 21:05:09 +00:00
|
|
|
#include "common/config-manager.h"
|
2014-01-03 14:03:27 +00:00
|
|
|
#include "common/memstream.h"
|
2016-04-14 14:43:56 +00:00
|
|
|
#include "audio/mixer.h"
|
2014-01-03 14:03:27 +00:00
|
|
|
#include "audio/audiostream.h"
|
2014-01-06 05:40:25 +00:00
|
|
|
#include "audio/decoders/vorbis.h"
|
2014-01-03 14:03:27 +00:00
|
|
|
#include "audio/decoders/wave.h"
|
2013-06-25 20:50:27 +00:00
|
|
|
|
2020-10-03 21:55:39 +00:00
|
|
|
namespace NGI {
|
2013-06-25 20:50:27 +00:00
|
|
|
|
2017-03-23 22:35:37 +00:00
|
|
|
bool SoundList::load(MfcArchive &file, const Common::String &fname) {
|
2016-07-27 21:36:53 +00:00
|
|
|
debugC(5, kDebugLoading, "SoundList::load()");
|
2013-07-12 06:03:02 +00:00
|
|
|
|
2017-11-12 16:16:34 +00:00
|
|
|
uint32 count = file.readUint32LE();
|
|
|
|
_soundItems.resize(count);
|
2013-06-25 20:50:27 +00:00
|
|
|
|
2017-03-22 02:50:37 +00:00
|
|
|
if (!fname.empty()) {
|
2017-11-12 16:16:34 +00:00
|
|
|
_libHandle.reset(makeNGIArchive(fname));
|
2013-06-25 20:50:27 +00:00
|
|
|
} else {
|
2017-11-12 16:16:34 +00:00
|
|
|
_libHandle.reset();
|
2013-06-25 20:50:27 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 16:16:34 +00:00
|
|
|
for (uint i = 0; i < count; i++) {
|
|
|
|
_soundItems[i].load(file, _libHandle.get());
|
2013-06-25 20:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-23 22:35:37 +00:00
|
|
|
bool SoundList::loadFile(const Common::String &fname, const Common::String &libname) {
|
2013-06-25 20:50:27 +00:00
|
|
|
Common::File file;
|
|
|
|
|
|
|
|
if (!file.open(fname))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
MfcArchive archive(&file);
|
|
|
|
|
|
|
|
return load(archive, libname);
|
|
|
|
}
|
|
|
|
|
2014-04-26 18:58:20 +00:00
|
|
|
Sound *SoundList::getSoundItemById(int id) {
|
2017-11-12 16:16:34 +00:00
|
|
|
for (uint i = 0; i < _soundItems.size(); ++i) {
|
|
|
|
if (_soundItems[i].getId() == id)
|
|
|
|
return &_soundItems[i];
|
2014-04-26 18:58:20 +00:00
|
|
|
}
|
2017-11-12 16:16:34 +00:00
|
|
|
return nullptr;
|
2014-04-26 18:58:20 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 16:16:34 +00:00
|
|
|
Sound::Sound() :
|
|
|
|
_id(0),
|
|
|
|
_soundData(nullptr),
|
|
|
|
_handle(new Audio::SoundHandle()),
|
|
|
|
_objectId(0) {}
|
2013-06-25 20:50:27 +00:00
|
|
|
|
2014-01-08 16:48:34 +00:00
|
|
|
Sound::~Sound() {
|
2014-04-26 14:34:24 +00:00
|
|
|
freeSound();
|
2016-04-14 14:43:56 +00:00
|
|
|
delete _handle;
|
2014-01-08 16:48:34 +00:00
|
|
|
}
|
2013-06-25 20:50:27 +00:00
|
|
|
|
|
|
|
bool Sound::load(MfcArchive &file, NGIArchive *archive) {
|
2016-07-27 21:36:53 +00:00
|
|
|
debugC(5, kDebugLoading, "Sound::load()");
|
2013-07-12 06:03:02 +00:00
|
|
|
|
2013-06-25 20:50:27 +00:00
|
|
|
MemoryObject::load(file);
|
|
|
|
|
|
|
|
_id = file.readUint32LE();
|
2016-12-20 00:06:58 +00:00
|
|
|
/*_description = */file.readPascalString();
|
2013-06-25 20:50:27 +00:00
|
|
|
|
2020-10-04 20:25:19 +00:00
|
|
|
assert(g_nmi->_gameProjectVersion >= 6);
|
2013-06-25 20:50:27 +00:00
|
|
|
|
|
|
|
_objectId = file.readUint16LE();
|
|
|
|
|
2013-07-16 20:54:18 +00:00
|
|
|
if (archive && archive->hasFile(_memfilename)) {
|
|
|
|
Common::SeekableReadStream *s = archive->createReadStreamForMember(_memfilename);
|
2013-06-25 20:50:27 +00:00
|
|
|
|
|
|
|
_soundData = (byte *)calloc(s->size(), 1);
|
|
|
|
|
|
|
|
s->read(_soundData, s->size());
|
|
|
|
|
|
|
|
delete s;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-20 18:28:32 +00:00
|
|
|
void Sound::updateVolume() {
|
2016-10-16 21:25:38 +00:00
|
|
|
// not needed in our implementation
|
2013-07-20 18:28:32 +00:00
|
|
|
}
|
|
|
|
|
2013-08-19 20:19:00 +00:00
|
|
|
void Sound::setPanAndVolumeByStaticAni() {
|
2014-05-30 05:03:17 +00:00
|
|
|
if (!_objectId)
|
|
|
|
return;
|
|
|
|
|
2020-10-04 20:25:19 +00:00
|
|
|
StaticANIObject *ani = g_nmi->_currentScene->getStaticANIObject1ById(_objectId, -1);
|
2014-05-30 05:03:17 +00:00
|
|
|
if (!ani)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int a, b;
|
|
|
|
|
2020-10-04 20:25:19 +00:00
|
|
|
if (ani->_ox >= g_nmi->_sceneRect.left) {
|
2014-05-30 05:03:17 +00:00
|
|
|
int par, pan;
|
|
|
|
|
2020-10-04 20:25:19 +00:00
|
|
|
if (ani->_ox <= g_nmi->_sceneRect.right) {
|
2014-05-30 05:03:17 +00:00
|
|
|
int dx;
|
|
|
|
|
2020-10-04 20:25:19 +00:00
|
|
|
if (ani->_oy <= g_nmi->_sceneRect.bottom) {
|
|
|
|
if (ani->_oy >= g_nmi->_sceneRect.top) {
|
|
|
|
setPanAndVolume(g_nmi->_sfxVolume, 0);
|
2014-05-30 05:03:17 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2020-10-04 20:25:19 +00:00
|
|
|
dx = g_nmi->_sceneRect.top - ani->_oy;
|
2014-05-30 05:03:17 +00:00
|
|
|
} else {
|
2020-10-04 20:25:19 +00:00
|
|
|
dx = ani->_oy - g_nmi->_sceneRect.bottom;
|
2014-05-30 05:03:17 +00:00
|
|
|
}
|
|
|
|
|
2016-09-04 12:42:52 +00:00
|
|
|
par = 0;
|
2014-05-30 05:03:17 +00:00
|
|
|
|
|
|
|
if (dx > 800) {
|
|
|
|
setPanAndVolume(-3500, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pan = -3500;
|
2020-10-04 20:25:19 +00:00
|
|
|
a = g_nmi->_sfxVolume - (-3500);
|
2014-05-30 05:03:17 +00:00
|
|
|
b = 800 - dx;
|
|
|
|
} else {
|
2020-10-04 20:25:19 +00:00
|
|
|
int dx = ani->_ox - g_nmi->_sceneRect.right;
|
2014-05-30 05:03:17 +00:00
|
|
|
|
|
|
|
if (dx > 800) {
|
|
|
|
setPanAndVolume(-3500, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pan = -3500;
|
|
|
|
par = dx * (-3500) / -800;
|
2020-10-04 20:25:19 +00:00
|
|
|
a = g_nmi->_sfxVolume - (-3500);
|
2014-05-30 05:03:17 +00:00
|
|
|
b = 800 - dx;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 pp = b * a;
|
|
|
|
|
|
|
|
setPanAndVolume(pan + pp / 800, par);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-04 20:25:19 +00:00
|
|
|
int dx = g_nmi->_sceneRect.left - ani->_ox;
|
2014-05-30 05:03:17 +00:00
|
|
|
if (dx <= 800) {
|
2020-10-04 20:25:19 +00:00
|
|
|
int32 s = (800 - dx) * (g_nmi->_sfxVolume - (-3500));
|
2014-05-30 05:03:17 +00:00
|
|
|
int32 p = -3500 + s / 800;
|
|
|
|
|
2020-10-04 20:25:19 +00:00
|
|
|
if (p > g_nmi->_sfxVolume)
|
|
|
|
p = g_nmi->_sfxVolume;
|
2014-05-30 05:03:17 +00:00
|
|
|
|
|
|
|
setPanAndVolume(p, dx * (-3500) / 800);
|
|
|
|
} else {
|
|
|
|
setPanAndVolume(-3500, 0);
|
|
|
|
}
|
2013-08-19 20:19:00 +00:00
|
|
|
}
|
|
|
|
|
2014-04-19 14:01:29 +00:00
|
|
|
void Sound::setPanAndVolume(int vol, int pan) {
|
2020-10-04 20:25:19 +00:00
|
|
|
g_nmi->_mixer->setChannelVolume(*_handle, MIN((vol + 10000) / 39, 255)); // -10000..0
|
|
|
|
g_nmi->_mixer->setChannelBalance(*_handle, CLIP(pan / 78, -127, 127)); // -10000..10000
|
2014-04-19 14:01:29 +00:00
|
|
|
}
|
|
|
|
|
2014-04-26 13:25:01 +00:00
|
|
|
void Sound::play(int flag) {
|
2016-04-14 14:43:56 +00:00
|
|
|
Audio::SoundHandle *handle = getHandle();
|
2014-04-26 14:00:11 +00:00
|
|
|
|
2020-10-04 20:25:19 +00:00
|
|
|
if (g_nmi->_mixer->isSoundHandleActive(*handle)) { // We need to restart the music
|
|
|
|
g_nmi->_mixer->stopHandle(*handle);
|
2016-11-30 19:00:50 +00:00
|
|
|
}
|
2014-04-26 14:00:11 +00:00
|
|
|
|
|
|
|
byte *soundData = loadData();
|
|
|
|
Common::MemoryReadStream *dataStream = new Common::MemoryReadStream(soundData, getDataSize());
|
|
|
|
Audio::RewindableAudioStream *wav = Audio::makeWAVStream(dataStream, DisposeAfterUse::YES);
|
|
|
|
Audio::AudioStream *audioStream = new Audio::LoopingAudioStream(wav, (flag == 1) ? 0 : 1);
|
|
|
|
|
2020-10-04 20:25:19 +00:00
|
|
|
g_nmi->_mixer->playStream(Audio::Mixer::kSFXSoundType, handle, audioStream);
|
2014-04-26 13:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sound::freeSound() {
|
2014-04-26 14:32:41 +00:00
|
|
|
stop();
|
|
|
|
|
|
|
|
free(_soundData);
|
2014-04-26 13:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Sound::getVolume() {
|
2020-10-04 20:25:19 +00:00
|
|
|
return g_nmi->_mixer->getChannelVolume(*_handle) * 39; // 0..10000
|
2014-04-26 13:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sound::stop() {
|
2020-10-04 20:25:19 +00:00
|
|
|
g_nmi->_mixer->stopHandle(*_handle);
|
2014-04-26 13:25:01 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 22:00:50 +00:00
|
|
|
void NGIEngine::setSceneMusicParameters(GameVar *gvar) {
|
2014-04-26 12:00:36 +00:00
|
|
|
stopSoundStream2();
|
|
|
|
|
2017-11-14 18:48:41 +00:00
|
|
|
if (_mixer->isSoundHandleActive(_soundStream3))
|
|
|
|
_mixer->stopHandle(_soundStream4);
|
2014-04-26 12:00:36 +00:00
|
|
|
|
|
|
|
if (_musicLocal)
|
|
|
|
stopAllSoundStreams();
|
|
|
|
|
|
|
|
GameVar *var = gvar->getSubVarByName("MUSIC");
|
|
|
|
|
2017-03-22 03:22:36 +00:00
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
_sceneTracks[i].clear();
|
2014-04-26 12:00:36 +00:00
|
|
|
|
|
|
|
_numSceneTracks = 0;
|
|
|
|
_sceneTrackHasSequence = false;
|
|
|
|
|
|
|
|
if (!var)
|
|
|
|
return;
|
|
|
|
|
2014-01-06 05:40:25 +00:00
|
|
|
_musicGameVar = var;
|
2014-04-26 12:00:36 +00:00
|
|
|
|
|
|
|
GameVar *tr = var->getSubVarByName("TRACKS");
|
|
|
|
if (tr) {
|
|
|
|
GameVar *sub = tr->_subVars;
|
|
|
|
|
|
|
|
while (sub) {
|
|
|
|
if (_musicAllowed & sub->_value.intValue) {
|
2017-03-22 03:22:36 +00:00
|
|
|
_sceneTracks[_numSceneTracks] = sub->_varName;
|
2014-04-26 12:00:36 +00:00
|
|
|
|
|
|
|
_numSceneTracks++;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub = sub->_nextVarObj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_musicMinDelay = var->getSubVarAsInt("MINDELAY");
|
|
|
|
_musicMaxDelay = var->getSubVarAsInt("MAXDELAY");
|
|
|
|
_musicLocal = var->getSubVarAsInt("LOCAL");
|
|
|
|
|
|
|
|
GameVar *seq = var->getSubVarByName("SEQUENCE");
|
|
|
|
|
|
|
|
if (seq) {
|
|
|
|
_sceneTrackHasSequence = true;
|
|
|
|
|
2017-03-22 03:22:36 +00:00
|
|
|
_trackName = seq->_value.stringValue;
|
2014-04-26 12:00:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_musicLocal)
|
|
|
|
stopAllSoundStreams();
|
|
|
|
|
|
|
|
if (!_sceneTrackIsPlaying || _musicLocal)
|
|
|
|
_trackStartDelay = var->getSubVarAsInt("STARTDELAY");
|
2013-07-23 10:33:28 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 22:00:50 +00:00
|
|
|
void NGIEngine::updateTrackDelay() {
|
2016-11-25 17:44:14 +00:00
|
|
|
_sceneTrackIsPlaying = false;
|
|
|
|
_trackStartDelay = _musicMinDelay + (_musicMaxDelay - _musicMinDelay) * (_updateTicks % 10) / 9;
|
|
|
|
}
|
|
|
|
|
2020-10-03 22:00:50 +00:00
|
|
|
void NGIEngine::startSceneTrack() {
|
2016-11-25 09:43:39 +00:00
|
|
|
if (_sceneTrackIsPlaying) {
|
2017-11-14 18:48:41 +00:00
|
|
|
if (!_mixer->isSoundHandleActive(_soundStream1)) { // Simulate end of sound callback
|
2016-11-25 17:44:14 +00:00
|
|
|
updateTrackDelay();
|
2016-11-25 09:43:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-26 11:47:18 +00:00
|
|
|
if (!_sceneTrackIsPlaying && _numSceneTracks > 0) {
|
|
|
|
if (_trackStartDelay > 0) {
|
|
|
|
_trackStartDelay--;
|
2014-04-26 11:34:12 +00:00
|
|
|
} else {
|
|
|
|
int trackNum = getSceneTrack();
|
|
|
|
|
|
|
|
if (trackNum == -1) {
|
2017-03-22 03:22:36 +00:00
|
|
|
_sceneTracksCurrentTrack = "silence";
|
2014-04-26 11:34:12 +00:00
|
|
|
|
2014-04-26 11:47:18 +00:00
|
|
|
_trackStartDelay = 2880;
|
|
|
|
_sceneTrackIsPlaying = 0;
|
2014-04-26 11:34:12 +00:00
|
|
|
} else {
|
2017-03-22 03:22:36 +00:00
|
|
|
_sceneTracksCurrentTrack = _sceneTracks[trackNum];
|
2014-04-26 11:34:12 +00:00
|
|
|
|
2014-04-26 11:47:18 +00:00
|
|
|
startSoundStream1(_sceneTracksCurrentTrack);
|
2014-04-26 11:34:12 +00:00
|
|
|
|
2014-04-26 11:47:18 +00:00
|
|
|
_sceneTrackIsPlaying = true;
|
2014-04-26 11:34:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-03 22:00:50 +00:00
|
|
|
int NGIEngine::getSceneTrack() {
|
2014-04-26 11:43:08 +00:00
|
|
|
int res;
|
2014-04-26 11:34:12 +00:00
|
|
|
|
2014-04-26 11:43:08 +00:00
|
|
|
if (_sceneTrackHasSequence) {
|
|
|
|
int num = _musicGameVar->getSubVarAsInt("TRACKS");
|
|
|
|
|
|
|
|
if (_trackName[num + 1] == 's') { // 'silence'
|
|
|
|
res = -1;
|
|
|
|
} else {
|
|
|
|
res = _trackName[num + 1] - '0';
|
|
|
|
|
|
|
|
if (res < 0 || res >= _numSceneTracks)
|
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int track = num + 1;
|
|
|
|
|
2017-11-25 18:33:45 +00:00
|
|
|
if (num + 2 >= (int)_trackName.size())
|
2014-04-26 11:43:08 +00:00
|
|
|
track = 0;
|
|
|
|
|
|
|
|
_musicGameVar->setSubVarAsInt("TRACKS", track);
|
|
|
|
} else {
|
|
|
|
res = _numSceneTracks * (_updateTicks % 10) / 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2014-04-26 11:34:12 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 22:00:50 +00:00
|
|
|
void NGIEngine::startSoundStream1(const Common::String &trackName) {
|
2014-04-26 11:34:12 +00:00
|
|
|
stopAllSoundStreams();
|
|
|
|
|
2016-11-29 18:39:04 +00:00
|
|
|
playOggSound(trackName, _soundStream1);
|
|
|
|
}
|
|
|
|
|
2020-10-03 22:00:50 +00:00
|
|
|
void NGIEngine::playOggSound(const Common::String &trackName, Audio::SoundHandle &stream) {
|
2014-01-06 05:40:25 +00:00
|
|
|
#ifdef USE_VORBIS
|
2017-11-14 18:48:41 +00:00
|
|
|
if (_mixer->isSoundHandleActive(stream))
|
2014-01-06 05:40:25 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
Common::File *track = new Common::File();
|
|
|
|
if (!track->open(trackName)) {
|
2017-03-22 03:22:36 +00:00
|
|
|
warning("Could not open %s", trackName.c_str());
|
2014-01-06 05:40:25 +00:00
|
|
|
delete track;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Audio::RewindableAudioStream *ogg = Audio::makeVorbisStream(track, DisposeAfterUse::YES);
|
2017-11-14 18:48:41 +00:00
|
|
|
_mixer->playStream(Audio::Mixer::kMusicSoundType, &stream, ogg);
|
2014-01-06 05:40:25 +00:00
|
|
|
#endif
|
2013-08-11 10:39:05 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 22:00:50 +00:00
|
|
|
void NGIEngine::stopAllSounds() {
|
2016-11-29 09:28:11 +00:00
|
|
|
for (int i = 0; i < _currSoundListCount; i++)
|
|
|
|
for (int j = 0; j < _currSoundList1[i]->getCount(); j++) {
|
2017-11-12 16:16:34 +00:00
|
|
|
_currSoundList1[i]->getSoundByIndex(j).stop();
|
2016-11-29 09:28:11 +00:00
|
|
|
}
|
2013-08-11 14:18:42 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 22:00:50 +00:00
|
|
|
void NGIEngine::toggleMute() {
|
2014-04-26 11:47:18 +00:00
|
|
|
if (_soundEnabled) {
|
|
|
|
_sfxVolume = _sfxVolume != -10000 ? -10000 : 0;
|
2014-04-26 10:13:07 +00:00
|
|
|
|
|
|
|
updateSoundVolume();
|
|
|
|
}
|
2013-08-11 14:18:42 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 22:00:50 +00:00
|
|
|
void NGIEngine::playSound(int id, int flag) {
|
2014-04-26 12:06:23 +00:00
|
|
|
Sound *sound = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < _currSoundListCount; i++) {
|
2014-04-26 18:58:20 +00:00
|
|
|
sound = _currSoundList1[i]->getSoundItemById(id);
|
2014-04-26 12:06:23 +00:00
|
|
|
|
|
|
|
if (sound)
|
|
|
|
break;
|
|
|
|
}
|
2014-04-26 11:47:18 +00:00
|
|
|
|
2014-01-03 14:03:27 +00:00
|
|
|
if (!sound) {
|
|
|
|
warning("playSound: Can't find sound with ID %d", id);
|
|
|
|
return;
|
|
|
|
}
|
2014-04-26 12:06:23 +00:00
|
|
|
|
2014-04-26 14:00:11 +00:00
|
|
|
sound->play(flag);
|
2013-12-22 22:21:35 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 22:00:50 +00:00
|
|
|
void NGIEngine::playTrack(GameVar *sceneVar, const char *name, bool delayed) {
|
2017-11-14 18:48:41 +00:00
|
|
|
if (_mixer->isSoundHandleActive(_soundStream3))
|
|
|
|
_mixer->stopHandle(_soundStream4);
|
2014-04-26 11:22:50 +00:00
|
|
|
|
2016-11-29 09:51:20 +00:00
|
|
|
stopSoundStream2();
|
2014-04-26 11:22:50 +00:00
|
|
|
|
2014-04-26 11:47:18 +00:00
|
|
|
if (_musicLocal)
|
2014-04-26 11:22:50 +00:00
|
|
|
stopAllSoundStreams();
|
|
|
|
|
|
|
|
GameVar *var = sceneVar->getSubVarByName(name);
|
|
|
|
|
2017-03-22 03:22:36 +00:00
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
_sceneTracks[i].clear();
|
2014-04-26 11:22:50 +00:00
|
|
|
|
2014-04-26 11:47:18 +00:00
|
|
|
_numSceneTracks = 0;
|
|
|
|
_sceneTrackHasSequence = false;
|
2014-04-26 11:22:50 +00:00
|
|
|
|
|
|
|
if (!var)
|
|
|
|
return;
|
|
|
|
|
2014-04-26 11:47:18 +00:00
|
|
|
_musicGameVar = var;
|
2014-04-26 11:22:50 +00:00
|
|
|
|
|
|
|
GameVar *tr = var->getSubVarByName("TRACKS");
|
|
|
|
if (tr) {
|
|
|
|
GameVar *sub = tr->_subVars;
|
|
|
|
|
|
|
|
while (sub) {
|
2014-04-26 11:47:18 +00:00
|
|
|
if (_musicAllowed & sub->_value.intValue) {
|
2017-03-22 03:22:36 +00:00
|
|
|
_sceneTracks[_numSceneTracks] = sub->_varName;
|
2014-04-26 11:22:50 +00:00
|
|
|
|
2014-04-26 11:47:18 +00:00
|
|
|
_numSceneTracks++;
|
2014-04-26 11:22:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub = sub->_nextVarObj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-26 11:47:18 +00:00
|
|
|
_musicMinDelay = var->getSubVarAsInt("MINDELAY");
|
|
|
|
_musicMaxDelay = var->getSubVarAsInt("MAXDELAY");
|
|
|
|
_musicLocal = var->getSubVarAsInt("LOCAL");
|
2014-04-26 11:22:50 +00:00
|
|
|
|
|
|
|
GameVar *seq = var->getSubVarByName("SEQUENCE");
|
2014-04-26 11:47:18 +00:00
|
|
|
|
2014-04-26 11:22:50 +00:00
|
|
|
if (seq) {
|
2014-04-26 11:47:18 +00:00
|
|
|
_sceneTrackHasSequence = true;
|
2014-04-26 11:22:50 +00:00
|
|
|
|
2017-03-22 03:22:36 +00:00
|
|
|
_trackName = seq->_value.stringValue;
|
2014-04-26 11:22:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (delayed) {
|
2014-04-26 11:47:18 +00:00
|
|
|
if (_sceneTrackIsPlaying && _numSceneTracks == 1) {
|
2017-03-22 03:22:36 +00:00
|
|
|
if (_sceneTracksCurrentTrack != _sceneTracks[0])
|
2014-04-26 11:22:50 +00:00
|
|
|
stopAllSoundStreams();
|
|
|
|
}
|
|
|
|
|
2014-04-26 11:47:18 +00:00
|
|
|
_trackStartDelay = var->getSubVarAsInt("STARTDELAY");
|
2014-04-26 11:22:50 +00:00
|
|
|
}
|
2013-08-11 14:18:42 +00:00
|
|
|
}
|
|
|
|
|
2013-08-11 19:47:46 +00:00
|
|
|
void global_messageHandler_handleSound(ExCommand *cmd) {
|
2020-10-04 20:25:19 +00:00
|
|
|
if (!g_nmi->_soundEnabled)
|
2014-04-26 13:25:01 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
Sound *snd = 0;
|
|
|
|
|
2020-10-04 20:25:19 +00:00
|
|
|
for (int i = 0; i < g_nmi->_currSoundListCount; i++)
|
|
|
|
if ((snd = g_nmi->_currSoundList1[i]->getSoundItemById(cmd->_messageNum)) != NULL)
|
2016-10-16 21:25:38 +00:00
|
|
|
break;
|
2014-04-26 13:25:01 +00:00
|
|
|
|
|
|
|
if (!snd)
|
|
|
|
return;
|
|
|
|
|
2017-12-03 19:07:35 +00:00
|
|
|
if (cmd->_z & 1) {
|
2020-10-04 20:25:19 +00:00
|
|
|
if (!g_nmi->_flgSoundList && (cmd->_z & 4))
|
2014-04-26 13:25:01 +00:00
|
|
|
snd->freeSound();
|
|
|
|
|
|
|
|
snd->updateVolume();
|
|
|
|
|
2020-10-04 20:25:19 +00:00
|
|
|
if (snd->_objectId && g_nmi->_currentScene->getStaticANIObject1ById(snd->_objectId, -1))
|
2014-04-26 13:25:01 +00:00
|
|
|
snd->setPanAndVolumeByStaticAni();
|
|
|
|
else
|
2020-10-04 20:25:19 +00:00
|
|
|
snd->setPanAndVolume(g_nmi->_sfxVolume, 0);
|
2014-04-26 13:25:01 +00:00
|
|
|
|
|
|
|
if (snd->getVolume() > -3500)
|
2016-09-04 21:54:43 +00:00
|
|
|
snd->play(cmd->_param);
|
2017-12-03 19:07:35 +00:00
|
|
|
} else if (cmd->_z & 2) {
|
2014-04-26 13:25:01 +00:00
|
|
|
snd->stop();
|
|
|
|
}
|
2013-08-11 19:47:46 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 22:00:50 +00:00
|
|
|
void NGIEngine::stopSoundStream2() {
|
2016-11-25 17:44:14 +00:00
|
|
|
_stream2playing = false;
|
|
|
|
|
2017-11-14 18:48:41 +00:00
|
|
|
if (_mixer->isSoundHandleActive(_soundStream3)) {
|
|
|
|
_mixer->stopHandle(_soundStream2);
|
|
|
|
_mixer->stopHandle(_soundStream3);
|
2016-11-25 17:44:14 +00:00
|
|
|
}
|
2013-12-01 14:50:04 +00:00
|
|
|
}
|
2013-08-11 14:18:42 +00:00
|
|
|
|
2020-10-03 22:00:50 +00:00
|
|
|
void NGIEngine::stopAllSoundStreams() {
|
2017-11-14 18:48:41 +00:00
|
|
|
_mixer->stopHandle(_soundStream1);
|
|
|
|
_mixer->stopHandle(_soundStream2);
|
|
|
|
_mixer->stopHandle(_soundStream3);
|
|
|
|
_mixer->stopHandle(_soundStream4);
|
2016-11-25 17:44:14 +00:00
|
|
|
|
2016-11-29 09:28:11 +00:00
|
|
|
_stream2playing = false;
|
2013-12-06 22:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 22:00:50 +00:00
|
|
|
void NGIEngine::stopAllSoundInstances(int id) {
|
2014-04-27 08:07:41 +00:00
|
|
|
for (int i = 0; i < _currSoundListCount; i++) {
|
|
|
|
Sound *sound = _currSoundList1[i]->getSoundItemById(id);
|
2014-04-26 11:47:18 +00:00
|
|
|
|
2014-04-27 08:07:41 +00:00
|
|
|
if (sound)
|
|
|
|
sound->stop();
|
2014-01-03 14:03:27 +00:00
|
|
|
}
|
2013-12-14 15:38:14 +00:00
|
|
|
}
|
2013-08-11 14:18:42 +00:00
|
|
|
|
2020-10-03 22:00:50 +00:00
|
|
|
void NGIEngine::updateSoundVolume() {
|
2016-09-11 21:05:09 +00:00
|
|
|
ConfMan.setInt("sfx_volume", MAX((_sfxVolume + 10000) / 39, 255));
|
|
|
|
syncSoundSettings();
|
|
|
|
|
2014-04-26 10:18:55 +00:00
|
|
|
for (int i = 0; i < _currSoundListCount; i++)
|
2016-09-11 21:08:03 +00:00
|
|
|
for (int j = 0; j < _currSoundList1[i]->getCount(); j++) {
|
2017-11-12 16:16:34 +00:00
|
|
|
_currSoundList1[i]->getSoundByIndex(j).setPanAndVolume(_sfxVolume, 0);
|
2014-04-26 10:18:55 +00:00
|
|
|
}
|
2014-01-24 15:21:50 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 22:00:50 +00:00
|
|
|
void NGIEngine::setMusicVolume(int vol) {
|
2014-04-18 18:18:04 +00:00
|
|
|
_musicVolume = vol;
|
|
|
|
|
2016-09-11 21:05:09 +00:00
|
|
|
ConfMan.setInt("music_volume", _musicVolume);
|
|
|
|
syncSoundSettings();
|
2014-04-18 18:09:12 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 21:55:39 +00:00
|
|
|
} // End of namespace NGI
|