2009-11-12 15:24:11 +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.
|
|
|
|
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-01-12 00:51:37 +00:00
|
|
|
#include "common/config-manager.h"
|
2010-02-15 00:20:53 +00:00
|
|
|
#include "sci/sound/audio.h"
|
2010-01-05 01:22:16 +00:00
|
|
|
#include "sci/sound/music.h"
|
|
|
|
#include "sci/sound/soundcmd.h"
|
2009-11-12 15:24:11 +00:00
|
|
|
|
2010-06-23 15:23:37 +00:00
|
|
|
#include "sci/engine/kernel.h"
|
2010-11-19 08:18:24 +00:00
|
|
|
#include "sci/engine/object.h"
|
2010-01-29 11:03:54 +00:00
|
|
|
#include "sci/engine/selector.h"
|
|
|
|
|
2009-11-12 15:24:11 +00:00
|
|
|
namespace Sci {
|
|
|
|
|
2010-01-25 01:39:44 +00:00
|
|
|
SoundCommandParser::SoundCommandParser(ResourceManager *resMan, SegManager *segMan, Kernel *kernel, AudioPlayer *audio, SciVersion soundVersion) :
|
2010-01-18 22:39:56 +00:00
|
|
|
_resMan(resMan), _segMan(segMan), _kernel(kernel), _audio(audio), _soundVersion(soundVersion) {
|
2009-12-20 13:38:13 +00:00
|
|
|
|
2010-06-30 13:49:05 +00:00
|
|
|
_music = new SciMusic(_soundVersion);
|
|
|
|
_music->init();
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SoundCommandParser::~SoundCommandParser() {
|
2010-01-12 18:40:43 +00:00
|
|
|
delete _music;
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundInit(int argc, reg_t *argv, reg_t acc) {
|
2010-07-29 10:58:01 +00:00
|
|
|
debugC(2, kDebugLevelSound, "kDoSound(init): %04x:%04x", PRINT_REG(argv[0]));
|
2010-07-09 12:06:41 +00:00
|
|
|
processInitSound(argv[0]);
|
|
|
|
return acc;
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
void SoundCommandParser::processInitSound(reg_t obj) {
|
2010-05-29 23:37:15 +00:00
|
|
|
int resourceId = readSelectorValue(_segMan, obj, SELECTOR(number));
|
2009-12-20 14:27:43 +00:00
|
|
|
|
2010-01-27 21:11:24 +00:00
|
|
|
// Check if a track with the same sound object is already playing
|
|
|
|
MusicEntry *oldSound = _music->getSlot(obj);
|
|
|
|
if (oldSound)
|
2010-07-09 12:06:41 +00:00
|
|
|
processDisposeSound(obj);
|
2010-01-27 21:11:24 +00:00
|
|
|
|
2009-12-20 14:27:43 +00:00
|
|
|
MusicEntry *newSound = new MusicEntry();
|
2010-05-19 14:19:16 +00:00
|
|
|
newSound->resourceId = resourceId;
|
|
|
|
if (resourceId && _resMan->testResource(ResourceId(kResourceTypeSound, resourceId)))
|
|
|
|
newSound->soundRes = new SoundResource(resourceId, _resMan, _soundVersion);
|
2010-01-03 18:06:48 +00:00
|
|
|
else
|
|
|
|
newSound->soundRes = 0;
|
2010-01-03 21:17:58 +00:00
|
|
|
|
2009-12-20 14:27:43 +00:00
|
|
|
newSound->soundObj = obj;
|
2010-05-29 23:37:15 +00:00
|
|
|
newSound->loop = readSelectorValue(_segMan, obj, SELECTOR(loop));
|
|
|
|
newSound->priority = readSelectorValue(_segMan, obj, SELECTOR(pri)) & 0xFF;
|
2010-05-28 09:29:05 +00:00
|
|
|
if (_soundVersion >= SCI_VERSION_1_EARLY)
|
2010-05-29 23:37:15 +00:00
|
|
|
newSound->volume = CLIP<int>(readSelectorValue(_segMan, obj, SELECTOR(vol)), 0, MUSIC_VOLUME_MAX);
|
2009-12-28 20:10:15 +00:00
|
|
|
|
2010-07-18 16:02:16 +00:00
|
|
|
debugC(2, kDebugLevelSound, "kDoSound(init): %04x:%04x number %d, loop %d, prio %d, vol %d", PRINT_REG(obj),
|
|
|
|
resourceId, newSound->loop, newSound->priority, newSound->volume);
|
2010-06-12 11:41:22 +00:00
|
|
|
|
2009-12-22 20:44:03 +00:00
|
|
|
// In SCI1.1 games, sound effects are started from here. If we can find
|
|
|
|
// a relevant audio resource, play it, otherwise switch to synthesized
|
|
|
|
// effects. If the resource exists, play it using map 65535 (sound
|
|
|
|
// effects map)
|
2010-09-06 19:00:43 +00:00
|
|
|
bool checkAudioResource = getSciVersion() >= SCI_VERSION_1_1;
|
|
|
|
if (g_sci->getGameId() == GID_HOYLE4)
|
|
|
|
checkAudioResource = false; // hoyle 4 has garbled audio resources in place of the sound resources
|
2010-09-06 19:03:55 +00:00
|
|
|
// if we play those, we will only make the user deaf and break speakers. Sierra SCI doesn't play anything
|
|
|
|
// on soundblaster. FIXME: check, why this is
|
2009-12-22 20:44:03 +00:00
|
|
|
|
2010-09-06 19:00:43 +00:00
|
|
|
if (checkAudioResource && _resMan->testResource(ResourceId(kResourceTypeAudio, resourceId))) {
|
2009-12-22 20:44:03 +00:00
|
|
|
// Found a relevant audio resource, play it
|
|
|
|
int sampleLen;
|
2010-05-19 14:19:16 +00:00
|
|
|
newSound->pStreamAud = _audio->getAudioStream(resourceId, 65535, &sampleLen);
|
2010-01-01 18:57:14 +00:00
|
|
|
newSound->soundType = Audio::Mixer::kSpeechSoundType;
|
2009-12-22 20:44:03 +00:00
|
|
|
} else {
|
2010-01-03 21:51:30 +00:00
|
|
|
if (newSound->soundRes)
|
|
|
|
_music->soundInitSnd(newSound);
|
2009-12-22 20:44:03 +00:00
|
|
|
}
|
SCI/new music code:
- Resolved a deadlock with the mixer, and added appropriate mutexes (a result of the fact that SCI mixes MIDI and digital audio in the same list)
- Fixed sound playing when loading games, by properly resetting the MIDI driver
- Reverted savegame version to 14 - the changes in versions 15 and 16 don't have any effect on the currently enabled old music code, and the new music code is disabled by default, and is still prone to changes
- Now saving/loading signal, loop and hold for each sound, as well as reverb
- Added stub code for setting reverb and channel hold
- The signal, loop and hold values of each song are cached, like in SSCI and like what happens in Greg's SCI implementation. This allows a clear separation of the engine code from the rest of the engine. Reverted commits 46792 and 46797
- Removed duplicate song list accessing code
- Song cues are now updated in kAnimate for SCI0, like the old music code does, to compensate for the fact that SCI0 didn't poll for music changes via cmdUpdateCues, like what SCI01 and newer do
- Cleanup
svn-id: r46812
2010-01-01 06:41:52 +00:00
|
|
|
|
|
|
|
_music->pushBackSlot(newSound);
|
|
|
|
|
2010-01-03 21:51:30 +00:00
|
|
|
if (newSound->soundRes || newSound->pStreamAud) {
|
|
|
|
// Notify the engine
|
|
|
|
if (_soundVersion <= SCI_VERSION_0_LATE)
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(state), kSoundInitialized);
|
2010-01-03 21:51:30 +00:00
|
|
|
else
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelector(_segMan, obj, SELECTOR(nodePtr), obj);
|
2009-12-31 08:10:51 +00:00
|
|
|
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelector(_segMan, obj, SELECTOR(handle), obj);
|
2010-01-03 21:51:30 +00:00
|
|
|
}
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundPlay(int argc, reg_t *argv, reg_t acc) {
|
2010-07-29 10:58:01 +00:00
|
|
|
debugC(2, kDebugLevelSound, "kDoSound(play): %04x:%04x", PRINT_REG(argv[0]));
|
2010-07-09 12:06:41 +00:00
|
|
|
processPlaySound(argv[0]);
|
|
|
|
return acc;
|
|
|
|
}
|
2009-11-12 15:24:11 +00:00
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
void SoundCommandParser::processPlaySound(reg_t obj) {
|
2009-12-27 11:43:34 +00:00
|
|
|
MusicEntry *musicSlot = _music->getSlot(obj);
|
|
|
|
if (!musicSlot) {
|
2010-07-10 13:19:20 +00:00
|
|
|
warning("kDoSound(play): Slot not found (%04x:%04x)", PRINT_REG(obj));
|
2009-12-23 16:33:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-12-22 20:44:03 +00:00
|
|
|
|
2010-05-29 23:37:15 +00:00
|
|
|
int resourceId = obj.segment ? readSelectorValue(_segMan, obj, SELECTOR(number)) : -1;
|
2009-12-22 20:44:03 +00:00
|
|
|
|
2010-05-19 14:19:16 +00:00
|
|
|
if (musicSlot->resourceId != resourceId) { // another sound loaded into struct
|
2010-07-09 12:06:41 +00:00
|
|
|
processDisposeSound(obj);
|
|
|
|
processInitSound(obj);
|
2009-12-25 13:52:40 +00:00
|
|
|
// Find slot again :)
|
2009-12-27 11:43:34 +00:00
|
|
|
musicSlot = _music->getSlot(obj);
|
2009-12-23 16:33:12 +00:00
|
|
|
}
|
2009-12-22 20:44:03 +00:00
|
|
|
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelector(_segMan, obj, SELECTOR(handle), obj);
|
2009-12-31 08:10:51 +00:00
|
|
|
|
2009-12-27 15:24:33 +00:00
|
|
|
if (_soundVersion >= SCI_VERSION_1_EARLY) {
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelector(_segMan, obj, SELECTOR(nodePtr), obj);
|
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(min), 0);
|
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(sec), 0);
|
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(frame), 0);
|
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(signal), 0);
|
2009-12-23 18:34:19 +00:00
|
|
|
} else {
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(state), kSoundPlaying);
|
2009-12-23 16:43:24 +00:00
|
|
|
}
|
2009-12-23 20:13:54 +00:00
|
|
|
|
2010-05-29 23:37:15 +00:00
|
|
|
musicSlot->loop = readSelectorValue(_segMan, obj, SELECTOR(loop));
|
|
|
|
musicSlot->priority = readSelectorValue(_segMan, obj, SELECTOR(priority));
|
2010-05-28 09:29:05 +00:00
|
|
|
if (_soundVersion >= SCI_VERSION_1_EARLY)
|
2010-05-29 23:37:15 +00:00
|
|
|
musicSlot->volume = readSelectorValue(_segMan, obj, SELECTOR(vol));
|
2010-06-12 11:41:22 +00:00
|
|
|
|
2010-07-18 16:02:16 +00:00
|
|
|
debugC(2, kDebugLevelSound, "kDoSound(play): %04x:%04x number %d, loop %d, prio %d, vol %d", PRINT_REG(obj),
|
|
|
|
resourceId, musicSlot->loop, musicSlot->priority, musicSlot->volume);
|
2010-06-12 11:41:22 +00:00
|
|
|
|
2009-12-26 11:54:57 +00:00
|
|
|
_music->soundPlay(musicSlot);
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-08-02 21:20:43 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundRestore(int argc, reg_t *argv, reg_t acc) {
|
|
|
|
// Called after loading, to restore the playlist
|
|
|
|
// We don't really use or need this
|
|
|
|
return acc;
|
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundDummy(int argc, reg_t *argv, reg_t acc) {
|
2009-11-12 15:24:11 +00:00
|
|
|
warning("cmdDummy invoked"); // not supposed to occur
|
2010-07-09 12:06:41 +00:00
|
|
|
return acc;
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundDispose(int argc, reg_t *argv, reg_t acc) {
|
2010-07-29 10:58:01 +00:00
|
|
|
debugC(2, kDebugLevelSound, "kDoSound(dispose): %04x:%04x", PRINT_REG(argv[0]));
|
2010-07-09 12:06:41 +00:00
|
|
|
processDisposeSound(argv[0]);
|
|
|
|
return acc;
|
|
|
|
}
|
2009-12-23 18:34:19 +00:00
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
void SoundCommandParser::processDisposeSound(reg_t obj) {
|
2009-12-27 11:43:34 +00:00
|
|
|
MusicEntry *musicSlot = _music->getSlot(obj);
|
|
|
|
if (!musicSlot) {
|
2010-07-10 13:19:20 +00:00
|
|
|
warning("kDoSound(dispose): Slot not found (%04x:%04x)", PRINT_REG(obj));
|
2009-11-29 14:48:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-12-20 14:27:43 +00:00
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
processStopSound(obj, false);
|
2009-12-20 14:27:43 +00:00
|
|
|
|
2009-12-27 11:43:34 +00:00
|
|
|
_music->soundKill(musicSlot);
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(handle), 0);
|
2009-12-27 15:24:33 +00:00
|
|
|
if (_soundVersion >= SCI_VERSION_1_EARLY)
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelector(_segMan, obj, SELECTOR(nodePtr), NULL_REG);
|
2009-12-23 18:34:19 +00:00
|
|
|
else
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(state), kSoundStopped);
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundStop(int argc, reg_t *argv, reg_t acc) {
|
2010-07-29 10:58:01 +00:00
|
|
|
debugC(2, kDebugLevelSound, "kDoSound(stop): %04x:%04x", PRINT_REG(argv[0]));
|
2010-07-09 12:06:41 +00:00
|
|
|
processStopSound(argv[0], false);
|
|
|
|
return acc;
|
2010-05-03 17:54:47 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
void SoundCommandParser::processStopSound(reg_t obj, bool sampleFinishedPlaying) {
|
2009-12-27 11:43:34 +00:00
|
|
|
MusicEntry *musicSlot = _music->getSlot(obj);
|
|
|
|
if (!musicSlot) {
|
2010-07-10 13:19:20 +00:00
|
|
|
warning("kDoSound(stop): Slot not found (%04x:%04x)", PRINT_REG(obj));
|
2009-11-29 14:48:15 +00:00
|
|
|
return;
|
2009-12-20 14:27:43 +00:00
|
|
|
}
|
|
|
|
|
2010-01-29 19:02:13 +00:00
|
|
|
if (_soundVersion <= SCI_VERSION_0_LATE) {
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(state), kSoundStopped);
|
2010-01-29 19:02:13 +00:00
|
|
|
} else {
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(handle), 0);
|
2010-01-29 17:45:30 +00:00
|
|
|
}
|
2009-12-20 14:27:43 +00:00
|
|
|
|
2010-06-29 20:50:52 +00:00
|
|
|
// Set signal selector in sound SCI0 games only, when the sample has
|
|
|
|
// finished playing. If we don't set it at all, we get a problem when using
|
|
|
|
// vaporizer on the 2 guys. If we set it all the time, we get no music in
|
|
|
|
// sq3new and kq1.
|
|
|
|
// FIXME: This *may* be wrong, it's impossible to find out in Sierra DOS
|
|
|
|
// SCI, because SCI0 under DOS didn't have sfx drivers included.
|
|
|
|
// We need to set signal in sound SCI1+ games all the time.
|
2010-05-03 17:54:47 +00:00
|
|
|
if ((_soundVersion > SCI_VERSION_0_LATE) || sampleFinishedPlaying)
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(signal), SIGNAL_OFFSET);
|
2010-05-03 17:54:47 +00:00
|
|
|
|
2009-12-27 11:43:34 +00:00
|
|
|
musicSlot->dataInc = 0;
|
SCI/new music code:
- Resolved a deadlock with the mixer, and added appropriate mutexes (a result of the fact that SCI mixes MIDI and digital audio in the same list)
- Fixed sound playing when loading games, by properly resetting the MIDI driver
- Reverted savegame version to 14 - the changes in versions 15 and 16 don't have any effect on the currently enabled old music code, and the new music code is disabled by default, and is still prone to changes
- Now saving/loading signal, loop and hold for each sound, as well as reverb
- Added stub code for setting reverb and channel hold
- The signal, loop and hold values of each song are cached, like in SSCI and like what happens in Greg's SCI implementation. This allows a clear separation of the engine code from the rest of the engine. Reverted commits 46792 and 46797
- Removed duplicate song list accessing code
- Song cues are now updated in kAnimate for SCI0, like the old music code does, to compensate for the fact that SCI0 didn't poll for music changes via cmdUpdateCues, like what SCI01 and newer do
- Cleanup
svn-id: r46812
2010-01-01 06:41:52 +00:00
|
|
|
musicSlot->signal = 0;
|
2009-12-27 11:43:34 +00:00
|
|
|
_music->soundStop(musicSlot);
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundPause(int argc, reg_t *argv, reg_t acc) {
|
2010-07-29 10:58:01 +00:00
|
|
|
if (argc == 1)
|
|
|
|
debugC(2, kDebugLevelSound, "kDoSound(pause): %04x:%04x", PRINT_REG(argv[0]));
|
|
|
|
else
|
|
|
|
debugC(2, kDebugLevelSound, "kDoSound(pause): %04x:%04x, %04x:%04x", PRINT_REG(argv[0]), PRINT_REG(argv[1]));
|
|
|
|
|
2010-07-09 16:05:47 +00:00
|
|
|
if (_soundVersion <= SCI_VERSION_0_LATE) {
|
2010-07-09 18:11:42 +00:00
|
|
|
// SCI0 games give us 0/1 for either resuming or pausing the current music
|
|
|
|
// this one doesn't count, so pausing 2 times and resuming once means here that we are supposed to resume
|
2010-07-09 16:05:47 +00:00
|
|
|
uint16 value = argv[0].toUint16();
|
|
|
|
MusicEntry *musicSlot = _music->getActiveSci0MusicSlot();
|
|
|
|
switch (value) {
|
|
|
|
case 1:
|
2010-07-09 18:11:42 +00:00
|
|
|
if ((musicSlot) && (musicSlot->status == kSoundPlaying)) {
|
2010-07-09 16:05:47 +00:00
|
|
|
_music->soundPause(musicSlot);
|
2010-07-09 18:11:42 +00:00
|
|
|
writeSelectorValue(_segMan, musicSlot->soundObj, SELECTOR(state), kSoundPaused);
|
|
|
|
}
|
2010-07-09 16:05:47 +00:00
|
|
|
return make_reg(0, 0);
|
|
|
|
case 0:
|
|
|
|
if ((musicSlot) && (musicSlot->status == kSoundPaused)) {
|
|
|
|
_music->soundResume(musicSlot);
|
2010-07-09 18:11:42 +00:00
|
|
|
writeSelectorValue(_segMan, musicSlot->soundObj, SELECTOR(state), kSoundPlaying);
|
2010-07-09 16:05:47 +00:00
|
|
|
return make_reg(0, 1);
|
|
|
|
}
|
|
|
|
return make_reg(0, 0);
|
|
|
|
default:
|
2010-07-10 13:19:20 +00:00
|
|
|
error("kDoSound(pause): parameter 0 is invalid for sound-sci0");
|
2010-07-09 16:05:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t obj = argv[0];
|
|
|
|
uint16 value = argc > 1 ? argv[1].toUint16() : 0;
|
2010-01-21 21:28:32 +00:00
|
|
|
if (!obj.segment) { // pause the whole playlist
|
|
|
|
_music->pauseAll(value);
|
|
|
|
} else { // pause a playlist slot
|
|
|
|
MusicEntry *musicSlot = _music->getSlot(obj);
|
2009-12-28 22:35:53 +00:00
|
|
|
if (!musicSlot) {
|
2010-08-02 21:20:43 +00:00
|
|
|
// This happens quite frequently
|
|
|
|
debugC(2, kDebugLevelSound, "kDoSound(pause): Slot not found (%04x:%04x)", PRINT_REG(obj));
|
2010-07-09 12:06:41 +00:00
|
|
|
return acc;
|
2009-12-28 22:35:53 +00:00
|
|
|
}
|
2009-12-20 14:27:43 +00:00
|
|
|
|
2010-07-09 18:11:42 +00:00
|
|
|
_music->soundToggle(musicSlot, value);
|
2010-01-21 21:28:32 +00:00
|
|
|
}
|
2010-07-09 12:06:41 +00:00
|
|
|
return acc;
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
// SCI0 only command
|
2010-07-20 11:17:33 +00:00
|
|
|
// It's called right after restoring a game - it's responsible to kick off playing music again
|
|
|
|
// we don't need this at all, so we don't do anything here
|
|
|
|
reg_t SoundCommandParser::kDoSoundResumeAfterRestore(int argc, reg_t *argv, reg_t acc) {
|
2010-07-09 12:06:41 +00:00
|
|
|
return acc;
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundMute(int argc, reg_t *argv, reg_t acc) {
|
2010-08-01 19:57:03 +00:00
|
|
|
uint16 previousState = _music->soundGetSoundOn();
|
2010-07-29 10:58:01 +00:00
|
|
|
if (argc > 0) {
|
|
|
|
debugC(2, kDebugLevelSound, "kDoSound(mute): %d", argv[0].toUint16());
|
2010-07-09 12:06:41 +00:00
|
|
|
_music->soundSetSoundOn(argv[0].toUint16());
|
2010-07-29 10:58:01 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:57:03 +00:00
|
|
|
return make_reg(0, previousState);
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundMasterVolume(int argc, reg_t *argv, reg_t acc) {
|
|
|
|
acc = make_reg(0, _music->soundGetMasterVolume());
|
2010-01-13 17:34:42 +00:00
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
if (argc > 0) {
|
2010-07-10 13:19:20 +00:00
|
|
|
debugC(2, kDebugLevelSound, "kDoSound(masterVolume): %d", argv[0].toSint16());
|
2010-09-01 19:20:17 +00:00
|
|
|
int vol = CLIP<int16>(argv[0].toSint16(), 0, MUSIC_MASTERVOLUME_MAX);
|
|
|
|
vol = vol * Audio::Mixer::kMaxMixerVolume / MUSIC_MASTERVOLUME_MAX;
|
2010-01-12 00:51:37 +00:00
|
|
|
ConfMan.setInt("music_volume", vol);
|
|
|
|
ConfMan.setInt("sfx_volume", vol);
|
|
|
|
g_engine->syncSoundSettings();
|
|
|
|
}
|
2010-07-09 12:06:41 +00:00
|
|
|
return acc;
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundFade(int argc, reg_t *argv, reg_t acc) {
|
|
|
|
reg_t obj = argv[0];
|
2009-11-17 06:39:28 +00:00
|
|
|
|
2009-12-27 11:43:34 +00:00
|
|
|
MusicEntry *musicSlot = _music->getSlot(obj);
|
|
|
|
if (!musicSlot) {
|
2010-08-18 07:58:38 +00:00
|
|
|
debugC(2, kDebugLevelSound, "kDoSound(fade): Slot not found (%04x:%04x)", PRINT_REG(obj));
|
2010-07-09 12:06:41 +00:00
|
|
|
return acc;
|
2009-12-22 12:35:48 +00:00
|
|
|
}
|
2009-12-23 16:33:12 +00:00
|
|
|
|
2009-12-29 23:25:24 +00:00
|
|
|
int volume = musicSlot->volume;
|
2010-01-03 23:30:23 +00:00
|
|
|
|
2010-06-08 09:36:27 +00:00
|
|
|
// If sound is not playing currently, set signal directly
|
|
|
|
if (musicSlot->status != kSoundPlaying) {
|
2010-07-18 16:22:16 +00:00
|
|
|
debugC(2, kDebugLevelSound, "kDoSound(fade): %04x:%04x fading requested, but sound is currently not playing", PRINT_REG(obj));
|
2010-06-08 09:36:27 +00:00
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(signal), SIGNAL_OFFSET);
|
2010-07-09 12:06:41 +00:00
|
|
|
return acc;
|
2010-06-08 09:36:27 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
switch (argc) {
|
|
|
|
case 1: // SCI0
|
2010-06-29 20:50:52 +00:00
|
|
|
// SCI0 fades out all the time and when fadeout is done it will also
|
|
|
|
// stop the music from playing
|
2010-01-03 23:30:23 +00:00
|
|
|
musicSlot->fadeTo = 0;
|
|
|
|
musicSlot->fadeStep = -5;
|
2010-01-04 15:17:46 +00:00
|
|
|
musicSlot->fadeTickerStep = 10 * 16667 / _music->soundGetTempo();
|
2010-01-03 23:30:23 +00:00
|
|
|
musicSlot->fadeTicker = 0;
|
|
|
|
break;
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
case 4: // SCI01+
|
|
|
|
case 5: // SCI1+ (SCI1 late sound scheme), with fade and continue
|
|
|
|
musicSlot->fadeTo = CLIP<uint16>(argv[1].toUint16(), 0, MUSIC_VOLUME_MAX);
|
2010-08-04 09:15:37 +00:00
|
|
|
// sometimes we get objects in that position, fix it up (ffs. workarounds)
|
|
|
|
if (!argv[1].segment)
|
|
|
|
musicSlot->fadeStep = volume > musicSlot->fadeTo ? -argv[3].toUint16() : argv[3].toUint16();
|
|
|
|
else
|
|
|
|
musicSlot->fadeStep = volume > musicSlot->fadeTo ? -5 : 5;
|
2010-07-09 12:06:41 +00:00
|
|
|
musicSlot->fadeTickerStep = argv[2].toUint16() * 16667 / _music->soundGetTempo();
|
2010-01-03 23:30:23 +00:00
|
|
|
musicSlot->fadeTicker = 0;
|
2010-07-09 12:06:41 +00:00
|
|
|
musicSlot->stopAfterFading = (argc == 5) ? (argv[4].toUint16() != 0) : false;
|
2010-01-03 23:30:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-07-10 13:19:20 +00:00
|
|
|
error("kDoSound(fade): unsupported argc %d", argc);
|
2010-01-03 23:30:23 +00:00
|
|
|
}
|
2009-12-29 23:25:24 +00:00
|
|
|
|
2010-07-18 16:02:16 +00:00
|
|
|
debugC(2, kDebugLevelSound, "kDoSound(fade): %04x:%04x to %d, step %d, ticker %d", PRINT_REG(obj), musicSlot->fadeTo, musicSlot->fadeStep, musicSlot->fadeTickerStep);
|
2010-07-09 12:06:41 +00:00
|
|
|
return acc;
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundGetPolyphony(int argc, reg_t *argv, reg_t acc) {
|
2010-11-25 02:21:07 +00:00
|
|
|
// KQ5CD uses this to determine if it should play digital audio or not.
|
|
|
|
// For Adlib cards, digital audio is played, whereas MIDI is played for GM cards.
|
|
|
|
// Thus, tell it that we're using an Adlib in room 119 (Sierra logo screen),
|
|
|
|
// so that the digital audio is always preferred.
|
|
|
|
if (g_sci->getGameId() == GID_KQ5 && g_sci->getEngineState()->currentRoomNumber() == 119)
|
|
|
|
return make_reg(0, 9); // Adlib, i.e. digital music
|
2010-07-09 12:06:41 +00:00
|
|
|
return make_reg(0, _music->soundGetVoices()); // Get the number of voices
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundUpdate(int argc, reg_t *argv, reg_t acc) {
|
|
|
|
reg_t obj = argv[0];
|
2009-12-22 20:44:03 +00:00
|
|
|
|
2010-07-29 10:58:01 +00:00
|
|
|
debugC(2, kDebugLevelSound, "kDoSound(update): %04x:%04x", PRINT_REG(argv[0]));
|
|
|
|
|
2009-12-27 11:43:34 +00:00
|
|
|
MusicEntry *musicSlot = _music->getSlot(obj);
|
|
|
|
if (!musicSlot) {
|
2010-07-10 13:19:20 +00:00
|
|
|
warning("kDoSound(update): Slot not found (%04x:%04x)", PRINT_REG(obj));
|
2010-07-09 12:06:41 +00:00
|
|
|
return acc;
|
2009-11-29 14:48:15 +00:00
|
|
|
}
|
2009-12-20 14:27:43 +00:00
|
|
|
|
2010-05-29 23:37:15 +00:00
|
|
|
musicSlot->loop = readSelectorValue(_segMan, obj, SELECTOR(loop));
|
|
|
|
int16 objVol = CLIP<int>(readSelectorValue(_segMan, obj, SELECTOR(vol)), 0, 255);
|
2009-12-26 11:54:57 +00:00
|
|
|
if (objVol != musicSlot->volume)
|
|
|
|
_music->soundSetVolume(musicSlot, objVol);
|
2010-05-29 23:37:15 +00:00
|
|
|
uint32 objPrio = readSelectorValue(_segMan, obj, SELECTOR(pri));
|
2010-05-19 14:19:16 +00:00
|
|
|
if (objPrio != musicSlot->priority)
|
2009-12-26 11:54:57 +00:00
|
|
|
_music->soundSetPriority(musicSlot, objPrio);
|
2010-07-09 12:06:41 +00:00
|
|
|
return acc;
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundUpdateCues(int argc, reg_t *argv, reg_t acc) {
|
|
|
|
processUpdateCues(argv[0]);
|
|
|
|
return acc;
|
|
|
|
}
|
2009-12-20 16:35:37 +00:00
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
void SoundCommandParser::processUpdateCues(reg_t obj) {
|
2009-12-27 11:43:34 +00:00
|
|
|
MusicEntry *musicSlot = _music->getSlot(obj);
|
|
|
|
if (!musicSlot) {
|
2010-07-10 13:19:20 +00:00
|
|
|
warning("kDoSound(updateCues): Slot not found (%04x:%04x)", PRINT_REG(obj));
|
2009-11-29 14:48:15 +00:00
|
|
|
return;
|
2009-12-20 16:35:37 +00:00
|
|
|
}
|
2010-01-01 16:05:26 +00:00
|
|
|
|
|
|
|
if (musicSlot->pStreamAud) {
|
2010-01-08 20:11:27 +00:00
|
|
|
// Update digital sound effect slots
|
2010-01-07 17:45:17 +00:00
|
|
|
uint currentLoopCounter = 0;
|
|
|
|
|
|
|
|
if (musicSlot->pLoopStream)
|
|
|
|
currentLoopCounter = musicSlot->pLoopStream->getCompleteIterations();
|
|
|
|
|
2010-01-01 22:15:52 +00:00
|
|
|
if (currentLoopCounter != musicSlot->sampleLoopCounter) {
|
|
|
|
// during last time we looped at least one time, update loop accordingly
|
|
|
|
musicSlot->loop -= currentLoopCounter - musicSlot->sampleLoopCounter;
|
|
|
|
musicSlot->sampleLoopCounter = currentLoopCounter;
|
|
|
|
}
|
2010-07-19 07:29:17 +00:00
|
|
|
if (musicSlot->status == kSoundPlaying) {
|
|
|
|
if (!_music->soundIsActive(musicSlot)) {
|
|
|
|
processStopSound(obj, true);
|
|
|
|
} else {
|
|
|
|
_music->updateAudioStreamTicker(musicSlot);
|
|
|
|
}
|
2010-07-19 07:37:22 +00:00
|
|
|
} else if (musicSlot->status == kSoundPaused) {
|
|
|
|
_music->updateAudioStreamTicker(musicSlot);
|
2010-01-01 16:05:26 +00:00
|
|
|
}
|
2010-01-01 22:15:52 +00:00
|
|
|
// We get a flag from MusicEntry::doFade() here to set volume for the stream
|
2010-01-02 15:54:08 +00:00
|
|
|
if (musicSlot->fadeSetVolume) {
|
2010-09-06 18:23:03 +00:00
|
|
|
_music->soundSetSampleVolume(musicSlot, musicSlot->volume);
|
2010-01-02 15:54:08 +00:00
|
|
|
musicSlot->fadeSetVolume = false;
|
2010-01-01 22:15:52 +00:00
|
|
|
}
|
2010-05-10 20:32:55 +00:00
|
|
|
} else if (musicSlot->pMidiParser) {
|
2010-01-08 20:11:27 +00:00
|
|
|
// Update MIDI slots
|
|
|
|
if (musicSlot->signal == 0) {
|
2010-05-29 23:37:15 +00:00
|
|
|
if (musicSlot->dataInc != readSelectorValue(_segMan, obj, SELECTOR(dataInc))) {
|
2010-06-10 09:18:57 +00:00
|
|
|
if (SELECTOR(dataInc) > -1)
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(dataInc), musicSlot->dataInc);
|
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(signal), musicSlot->dataInc + 127);
|
2010-01-08 20:11:27 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Sync the signal of the sound object
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(signal), musicSlot->signal);
|
2010-01-08 20:25:42 +00:00
|
|
|
// We need to do this especially because state selector needs to get updated
|
|
|
|
if (musicSlot->signal == SIGNAL_OFFSET)
|
2010-07-09 12:06:41 +00:00
|
|
|
processStopSound(obj, false);
|
2010-01-02 15:02:41 +00:00
|
|
|
}
|
2010-05-10 20:32:55 +00:00
|
|
|
} else {
|
2010-06-29 20:50:52 +00:00
|
|
|
// Slot actually has no data (which would mean that a sound-resource w/
|
|
|
|
// unsupported data is used.
|
2010-05-10 20:32:55 +00:00
|
|
|
// (example lsl5 - sound resource 744 - it's roland exclusive
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(signal), SIGNAL_OFFSET);
|
2010-06-29 20:50:52 +00:00
|
|
|
// If we don't set signal here, at least the switch to the mud wrestling
|
|
|
|
// room in lsl5 will not work.
|
2010-01-01 16:05:26 +00:00
|
|
|
}
|
|
|
|
|
2010-01-02 17:16:59 +00:00
|
|
|
if (musicSlot->fadeCompleted) {
|
|
|
|
musicSlot->fadeCompleted = false;
|
2010-05-18 19:59:43 +00:00
|
|
|
// We need signal for sci0 at least in iceman as well (room 14, fireworks)
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(signal), SIGNAL_OFFSET);
|
2010-01-04 15:17:46 +00:00
|
|
|
if (_soundVersion <= SCI_VERSION_0_LATE) {
|
2010-07-09 12:06:41 +00:00
|
|
|
processStopSound(obj, false);
|
2010-01-04 15:17:46 +00:00
|
|
|
} else {
|
2010-01-11 14:26:13 +00:00
|
|
|
if (musicSlot->stopAfterFading)
|
2010-07-09 12:06:41 +00:00
|
|
|
processStopSound(obj, false);
|
2010-01-04 15:17:46 +00:00
|
|
|
}
|
2010-01-02 17:16:59 +00:00
|
|
|
}
|
|
|
|
|
2010-01-01 16:15:20 +00:00
|
|
|
// Sync loop selector for SCI0
|
|
|
|
if (_soundVersion <= SCI_VERSION_0_LATE)
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(loop), musicSlot->loop);
|
2009-12-23 16:33:12 +00:00
|
|
|
|
SCI/new music code:
- Resolved a deadlock with the mixer, and added appropriate mutexes (a result of the fact that SCI mixes MIDI and digital audio in the same list)
- Fixed sound playing when loading games, by properly resetting the MIDI driver
- Reverted savegame version to 14 - the changes in versions 15 and 16 don't have any effect on the currently enabled old music code, and the new music code is disabled by default, and is still prone to changes
- Now saving/loading signal, loop and hold for each sound, as well as reverb
- Added stub code for setting reverb and channel hold
- The signal, loop and hold values of each song are cached, like in SSCI and like what happens in Greg's SCI implementation. This allows a clear separation of the engine code from the rest of the engine. Reverted commits 46792 and 46797
- Removed duplicate song list accessing code
- Song cues are now updated in kAnimate for SCI0, like the old music code does, to compensate for the fact that SCI0 didn't poll for music changes via cmdUpdateCues, like what SCI01 and newer do
- Cleanup
svn-id: r46812
2010-01-01 06:41:52 +00:00
|
|
|
musicSlot->signal = 0;
|
|
|
|
|
|
|
|
if (_soundVersion >= SCI_VERSION_1_EARLY) {
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(min), musicSlot->ticker / 3600);
|
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(sec), musicSlot->ticker % 3600 / 60);
|
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(frame), musicSlot->ticker);
|
SCI/new music code:
- Resolved a deadlock with the mixer, and added appropriate mutexes (a result of the fact that SCI mixes MIDI and digital audio in the same list)
- Fixed sound playing when loading games, by properly resetting the MIDI driver
- Reverted savegame version to 14 - the changes in versions 15 and 16 don't have any effect on the currently enabled old music code, and the new music code is disabled by default, and is still prone to changes
- Now saving/loading signal, loop and hold for each sound, as well as reverb
- Added stub code for setting reverb and channel hold
- The signal, loop and hold values of each song are cached, like in SSCI and like what happens in Greg's SCI implementation. This allows a clear separation of the engine code from the rest of the engine. Reverted commits 46792 and 46797
- Removed duplicate song list accessing code
- Song cues are now updated in kAnimate for SCI0, like the old music code does, to compensate for the fact that SCI0 didn't poll for music changes via cmdUpdateCues, like what SCI01 and newer do
- Cleanup
svn-id: r46812
2010-01-01 06:41:52 +00:00
|
|
|
}
|
2010-01-01 16:05:26 +00:00
|
|
|
}
|
2009-11-12 15:24:11 +00:00
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundSendMidi(int argc, reg_t *argv, reg_t acc) {
|
|
|
|
reg_t obj = argv[0];
|
2010-07-09 12:30:34 +00:00
|
|
|
byte channel = argv[1].toUint16() & 0xf;
|
|
|
|
byte midiCmd = argv[2].toUint16() & 0xff;
|
2010-07-09 12:06:41 +00:00
|
|
|
|
2010-07-16 13:37:19 +00:00
|
|
|
// TODO: first there is a 4-parameter variant of this call which needs to get reversed
|
|
|
|
// second the current code isn't 100% accurate, sierra sci does checks on the 4th parameter
|
|
|
|
if (argc == 4)
|
|
|
|
return acc;
|
|
|
|
|
2010-07-09 12:30:34 +00:00
|
|
|
uint16 controller = argv[3].toUint16();
|
|
|
|
uint16 param = argv[4].toUint16();
|
2010-07-09 12:06:41 +00:00
|
|
|
|
2010-07-29 10:58:01 +00:00
|
|
|
debugC(2, kDebugLevelSound, "kDoSound(sendMidi): %04x:%04x, %d, %d, %d, %d", PRINT_REG(obj), channel, midiCmd, controller, param);
|
2010-07-09 12:06:41 +00:00
|
|
|
if (channel)
|
|
|
|
channel--; // channel is given 1-based, we are using 0-based
|
|
|
|
|
|
|
|
uint32 midiCommand = (channel | midiCmd) | ((uint32)controller << 8) | ((uint32)param << 16);
|
|
|
|
|
2010-06-17 11:54:54 +00:00
|
|
|
MusicEntry *musicSlot = _music->getSlot(obj);
|
|
|
|
if (!musicSlot) {
|
|
|
|
// TODO: maybe it's possible to call this with obj == 0:0 and send directly?!
|
|
|
|
// if so, allow it
|
|
|
|
//_music->sendMidiCommand(_midiCommand);
|
2010-07-10 13:19:20 +00:00
|
|
|
warning("kDoSound(sendMidi): Slot not found (%04x:%04x)", PRINT_REG(obj));
|
2010-07-09 12:06:41 +00:00
|
|
|
return acc;
|
2010-06-17 11:54:54 +00:00
|
|
|
}
|
2010-07-09 12:06:41 +00:00
|
|
|
_music->sendMidiCommand(musicSlot, midiCommand);
|
|
|
|
return acc;
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-11-24 14:21:31 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundGlobalReverb(int argc, reg_t *argv, reg_t acc) {
|
2010-11-24 16:01:30 +00:00
|
|
|
byte prevReverb = _music->getCurrentReverb();
|
|
|
|
byte reverb = argv[0].toUint16() & 0xF;
|
2010-11-24 14:21:31 +00:00
|
|
|
|
2010-11-24 16:01:30 +00:00
|
|
|
if (argc == 1) {
|
|
|
|
debugC(2, kDebugLevelSound, "doSoundGlobalReverb: %d", argv[0].toUint16() & 0xF);
|
|
|
|
if (reverb <= 10)
|
|
|
|
_music->setGlobalReverb(reverb);
|
|
|
|
}
|
2010-11-24 14:21:31 +00:00
|
|
|
|
2010-11-24 16:01:30 +00:00
|
|
|
return make_reg(0, prevReverb);
|
SCI/new music code:
- Resolved a deadlock with the mixer, and added appropriate mutexes (a result of the fact that SCI mixes MIDI and digital audio in the same list)
- Fixed sound playing when loading games, by properly resetting the MIDI driver
- Reverted savegame version to 14 - the changes in versions 15 and 16 don't have any effect on the currently enabled old music code, and the new music code is disabled by default, and is still prone to changes
- Now saving/loading signal, loop and hold for each sound, as well as reverb
- Added stub code for setting reverb and channel hold
- The signal, loop and hold values of each song are cached, like in SSCI and like what happens in Greg's SCI implementation. This allows a clear separation of the engine code from the rest of the engine. Reverted commits 46792 and 46797
- Removed duplicate song list accessing code
- Song cues are now updated in kAnimate for SCI0, like the old music code does, to compensate for the fact that SCI0 didn't poll for music changes via cmdUpdateCues, like what SCI01 and newer do
- Cleanup
svn-id: r46812
2010-01-01 06:41:52 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundSetHold(int argc, reg_t *argv, reg_t acc) {
|
|
|
|
reg_t obj = argv[0];
|
|
|
|
|
2010-07-29 10:58:01 +00:00
|
|
|
debugC(2, kDebugLevelSound, "doSoundSetHold: %04x:%04x, %d", PRINT_REG(argv[0]), argv[1].toUint16());
|
|
|
|
|
SCI/new music code:
- Resolved a deadlock with the mixer, and added appropriate mutexes (a result of the fact that SCI mixes MIDI and digital audio in the same list)
- Fixed sound playing when loading games, by properly resetting the MIDI driver
- Reverted savegame version to 14 - the changes in versions 15 and 16 don't have any effect on the currently enabled old music code, and the new music code is disabled by default, and is still prone to changes
- Now saving/loading signal, loop and hold for each sound, as well as reverb
- Added stub code for setting reverb and channel hold
- The signal, loop and hold values of each song are cached, like in SSCI and like what happens in Greg's SCI implementation. This allows a clear separation of the engine code from the rest of the engine. Reverted commits 46792 and 46797
- Removed duplicate song list accessing code
- Song cues are now updated in kAnimate for SCI0, like the old music code does, to compensate for the fact that SCI0 didn't poll for music changes via cmdUpdateCues, like what SCI01 and newer do
- Cleanup
svn-id: r46812
2010-01-01 06:41:52 +00:00
|
|
|
MusicEntry *musicSlot = _music->getSlot(obj);
|
|
|
|
if (!musicSlot) {
|
2010-07-10 13:19:20 +00:00
|
|
|
warning("kDoSound(setHold): Slot not found (%04x:%04x)", PRINT_REG(obj));
|
2010-07-09 12:06:41 +00:00
|
|
|
return acc;
|
SCI/new music code:
- Resolved a deadlock with the mixer, and added appropriate mutexes (a result of the fact that SCI mixes MIDI and digital audio in the same list)
- Fixed sound playing when loading games, by properly resetting the MIDI driver
- Reverted savegame version to 14 - the changes in versions 15 and 16 don't have any effect on the currently enabled old music code, and the new music code is disabled by default, and is still prone to changes
- Now saving/loading signal, loop and hold for each sound, as well as reverb
- Added stub code for setting reverb and channel hold
- The signal, loop and hold values of each song are cached, like in SSCI and like what happens in Greg's SCI implementation. This allows a clear separation of the engine code from the rest of the engine. Reverted commits 46792 and 46797
- Removed duplicate song list accessing code
- Song cues are now updated in kAnimate for SCI0, like the old music code does, to compensate for the fact that SCI0 didn't poll for music changes via cmdUpdateCues, like what SCI01 and newer do
- Cleanup
svn-id: r46812
2010-01-01 06:41:52 +00:00
|
|
|
}
|
|
|
|
|
2010-01-02 15:37:17 +00:00
|
|
|
// Set the special hold marker ID where the song should be looped at.
|
2010-07-09 12:06:41 +00:00
|
|
|
musicSlot->hold = argv[1].toSint16();
|
|
|
|
return acc;
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundGetAudioCapability(int argc, reg_t *argv, reg_t acc) {
|
2009-11-12 15:24:11 +00:00
|
|
|
// Tests for digital audio support
|
2010-07-09 12:06:41 +00:00
|
|
|
return make_reg(0, 1);
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundStopAll(int argc, reg_t *argv, reg_t acc) {
|
2010-07-19 22:11:06 +00:00
|
|
|
// TODO: this can't be right, this gets called in kq1 - e.g. being in witch house, getting the note
|
|
|
|
// now the point jingle plays and after a messagebox they call this - and would stop the background effects with it
|
|
|
|
// this doesn't make sense, so i disable it for now
|
|
|
|
return acc;
|
|
|
|
|
SCI/new music code:
- Resolved a deadlock with the mixer, and added appropriate mutexes (a result of the fact that SCI mixes MIDI and digital audio in the same list)
- Fixed sound playing when loading games, by properly resetting the MIDI driver
- Reverted savegame version to 14 - the changes in versions 15 and 16 don't have any effect on the currently enabled old music code, and the new music code is disabled by default, and is still prone to changes
- Now saving/loading signal, loop and hold for each sound, as well as reverb
- Added stub code for setting reverb and channel hold
- The signal, loop and hold values of each song are cached, like in SSCI and like what happens in Greg's SCI implementation. This allows a clear separation of the engine code from the rest of the engine. Reverted commits 46792 and 46797
- Removed duplicate song list accessing code
- Song cues are now updated in kAnimate for SCI0, like the old music code does, to compensate for the fact that SCI0 didn't poll for music changes via cmdUpdateCues, like what SCI01 and newer do
- Cleanup
svn-id: r46812
2010-01-01 06:41:52 +00:00
|
|
|
Common::StackLock(_music->_mutex);
|
|
|
|
|
|
|
|
const MusicList::iterator end = _music->getPlayListEnd();
|
|
|
|
for (MusicList::iterator i = _music->getPlayListStart(); i != end; ++i) {
|
2010-01-29 19:02:13 +00:00
|
|
|
if (_soundVersion <= SCI_VERSION_0_LATE) {
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, (*i)->soundObj, SELECTOR(state), kSoundStopped);
|
2010-01-29 19:02:13 +00:00
|
|
|
} else {
|
2010-07-09 12:06:41 +00:00
|
|
|
writeSelectorValue(_segMan, (*i)->soundObj, SELECTOR(handle), 0);
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, (*i)->soundObj, SELECTOR(signal), SIGNAL_OFFSET);
|
2010-01-29 17:45:30 +00:00
|
|
|
}
|
SCI/new music code:
- Resolved a deadlock with the mixer, and added appropriate mutexes (a result of the fact that SCI mixes MIDI and digital audio in the same list)
- Fixed sound playing when loading games, by properly resetting the MIDI driver
- Reverted savegame version to 14 - the changes in versions 15 and 16 don't have any effect on the currently enabled old music code, and the new music code is disabled by default, and is still prone to changes
- Now saving/loading signal, loop and hold for each sound, as well as reverb
- Added stub code for setting reverb and channel hold
- The signal, loop and hold values of each song are cached, like in SSCI and like what happens in Greg's SCI implementation. This allows a clear separation of the engine code from the rest of the engine. Reverted commits 46792 and 46797
- Removed duplicate song list accessing code
- Song cues are now updated in kAnimate for SCI0, like the old music code does, to compensate for the fact that SCI0 didn't poll for music changes via cmdUpdateCues, like what SCI01 and newer do
- Cleanup
svn-id: r46812
2010-01-01 06:41:52 +00:00
|
|
|
|
|
|
|
(*i)->dataInc = 0;
|
|
|
|
_music->soundStop(*i);
|
|
|
|
}
|
2010-07-09 12:06:41 +00:00
|
|
|
return acc;
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundSetVolume(int argc, reg_t *argv, reg_t acc) {
|
|
|
|
reg_t obj = argv[0];
|
|
|
|
int16 value = argv[1].toSint16();
|
2009-12-22 20:44:03 +00:00
|
|
|
|
2009-12-27 11:43:34 +00:00
|
|
|
MusicEntry *musicSlot = _music->getSlot(obj);
|
|
|
|
if (!musicSlot) {
|
2010-01-25 01:39:44 +00:00
|
|
|
// Do not throw a warning if the sound can't be found, as in some games
|
2010-06-29 20:50:52 +00:00
|
|
|
// this is called before the actual sound is loaded (e.g. SQ4CD, with
|
|
|
|
// the drum sounds of the energizer bunny at the beginning), so this is
|
|
|
|
// normal behavior.
|
2010-01-03 13:28:59 +00:00
|
|
|
//warning("cmdSetSoundVolume: Slot not found (%04x:%04x)", PRINT_REG(obj));
|
2010-07-09 12:06:41 +00:00
|
|
|
return acc;
|
2009-12-20 14:27:43 +00:00
|
|
|
}
|
|
|
|
|
2010-07-10 13:19:20 +00:00
|
|
|
debugC(2, kDebugLevelSound, "kDoSound(setVolume): %d", value);
|
2010-01-01 17:53:37 +00:00
|
|
|
|
2010-01-01 21:04:20 +00:00
|
|
|
value = CLIP<int>(value, 0, MUSIC_VOLUME_MAX);
|
2009-12-25 14:02:28 +00:00
|
|
|
|
2009-12-27 11:43:34 +00:00
|
|
|
if (musicSlot->volume != value) {
|
|
|
|
musicSlot->volume = value;
|
|
|
|
_music->soundSetVolume(musicSlot, value);
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(vol), value);
|
2009-11-29 14:48:15 +00:00
|
|
|
}
|
2010-07-09 12:06:41 +00:00
|
|
|
return acc;
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundSetPriority(int argc, reg_t *argv, reg_t acc) {
|
|
|
|
reg_t obj = argv[0];
|
|
|
|
int16 value = argv[1].toSint16();
|
2009-12-22 20:44:03 +00:00
|
|
|
|
2010-07-29 10:58:01 +00:00
|
|
|
debugC(2, kDebugLevelSound, "kDoSound(setPriority): %04x:%04x, %d", PRINT_REG(obj), value);
|
|
|
|
|
2010-01-02 01:41:39 +00:00
|
|
|
MusicEntry *musicSlot = _music->getSlot(obj);
|
|
|
|
if (!musicSlot) {
|
2010-08-04 13:35:56 +00:00
|
|
|
debugC(2, kDebugLevelSound, "kDoSound(setPriority): Slot not found (%04x:%04x)", PRINT_REG(obj));
|
2010-07-09 12:06:41 +00:00
|
|
|
return acc;
|
2010-01-02 01:41:39 +00:00
|
|
|
}
|
|
|
|
|
2009-12-22 13:31:52 +00:00
|
|
|
if (value == -1) {
|
2010-01-02 01:41:39 +00:00
|
|
|
// Set priority from the song data
|
2010-05-19 14:19:16 +00:00
|
|
|
Resource *song = _resMan->findResource(ResourceId(kResourceTypeSound, musicSlot->resourceId), 0);
|
2010-01-02 01:41:39 +00:00
|
|
|
if (song->data[0] == 0xf0)
|
|
|
|
_music->soundSetPriority(musicSlot, song->data[1]);
|
|
|
|
else
|
2010-07-10 13:19:20 +00:00
|
|
|
warning("kDoSound(setPriority): Attempt to unset song priority when there is no built-in value");
|
2010-01-02 01:41:39 +00:00
|
|
|
|
2009-12-20 14:27:43 +00:00
|
|
|
//pSnd->prio=0;field_15B=0
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(flags), readSelectorValue(_segMan, obj, SELECTOR(flags)) & 0xFD);
|
2009-12-20 14:27:43 +00:00
|
|
|
} else {
|
2010-01-02 01:41:39 +00:00
|
|
|
// Scripted priority
|
|
|
|
|
2009-12-20 14:27:43 +00:00
|
|
|
//pSnd->field_15B=1;
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(flags), readSelectorValue(_segMan, obj, SELECTOR(flags)) | 2);
|
2009-12-20 14:27:43 +00:00
|
|
|
//DoSOund(0xF,hobj,w)
|
2009-11-29 14:48:15 +00:00
|
|
|
}
|
2010-07-09 12:06:41 +00:00
|
|
|
return acc;
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundSetLoop(int argc, reg_t *argv, reg_t acc) {
|
|
|
|
reg_t obj = argv[0];
|
|
|
|
int16 value = argv[1].toSint16();
|
2009-12-22 20:44:03 +00:00
|
|
|
|
2010-07-29 10:58:01 +00:00
|
|
|
debugC(2, kDebugLevelSound, "kDoSound(setLoop): %04x:%04x, %d", PRINT_REG(obj), value);
|
|
|
|
|
2009-12-27 11:43:34 +00:00
|
|
|
MusicEntry *musicSlot = _music->getSlot(obj);
|
|
|
|
if (!musicSlot) {
|
2010-01-02 01:09:49 +00:00
|
|
|
// Apparently, it's perfectly normal for a game to call cmdSetSoundLoop
|
|
|
|
// before actually initializing the sound and adding it to the playlist
|
|
|
|
// with cmdInitSound. Usually, it doesn't matter if the game doesn't
|
|
|
|
// request to loop the sound, so in this case, don't throw any warning,
|
2010-06-29 20:50:52 +00:00
|
|
|
// otherwise do, because the sound won't be looped.
|
2010-01-02 01:09:49 +00:00
|
|
|
if (value == -1) {
|
2010-07-10 13:19:20 +00:00
|
|
|
warning("kDoSound(setLoop): Slot not found (%04x:%04x) and the song was requested to be looped", PRINT_REG(obj));
|
2010-01-02 01:09:49 +00:00
|
|
|
} else {
|
|
|
|
// Doesn't really matter
|
|
|
|
}
|
2010-07-09 12:06:41 +00:00
|
|
|
return acc;
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
2009-12-23 16:33:12 +00:00
|
|
|
if (value == -1) {
|
SCI/new music code:
- Resolved a deadlock with the mixer, and added appropriate mutexes (a result of the fact that SCI mixes MIDI and digital audio in the same list)
- Fixed sound playing when loading games, by properly resetting the MIDI driver
- Reverted savegame version to 14 - the changes in versions 15 and 16 don't have any effect on the currently enabled old music code, and the new music code is disabled by default, and is still prone to changes
- Now saving/loading signal, loop and hold for each sound, as well as reverb
- Added stub code for setting reverb and channel hold
- The signal, loop and hold values of each song are cached, like in SSCI and like what happens in Greg's SCI implementation. This allows a clear separation of the engine code from the rest of the engine. Reverted commits 46792 and 46797
- Removed duplicate song list accessing code
- Song cues are now updated in kAnimate for SCI0, like the old music code does, to compensate for the fact that SCI0 didn't poll for music changes via cmdUpdateCues, like what SCI01 and newer do
- Cleanup
svn-id: r46812
2010-01-01 06:41:52 +00:00
|
|
|
musicSlot->loop = 0xFFFF;
|
2009-12-23 16:33:12 +00:00
|
|
|
} else {
|
SCI/new music code:
- Resolved a deadlock with the mixer, and added appropriate mutexes (a result of the fact that SCI mixes MIDI and digital audio in the same list)
- Fixed sound playing when loading games, by properly resetting the MIDI driver
- Reverted savegame version to 14 - the changes in versions 15 and 16 don't have any effect on the currently enabled old music code, and the new music code is disabled by default, and is still prone to changes
- Now saving/loading signal, loop and hold for each sound, as well as reverb
- Added stub code for setting reverb and channel hold
- The signal, loop and hold values of each song are cached, like in SSCI and like what happens in Greg's SCI implementation. This allows a clear separation of the engine code from the rest of the engine. Reverted commits 46792 and 46797
- Removed duplicate song list accessing code
- Song cues are now updated in kAnimate for SCI0, like the old music code does, to compensate for the fact that SCI0 didn't poll for music changes via cmdUpdateCues, like what SCI01 and newer do
- Cleanup
svn-id: r46812
2010-01-01 06:41:52 +00:00
|
|
|
musicSlot->loop = 1; // actually plays the music once
|
2009-12-23 16:33:12 +00:00
|
|
|
}
|
SCI/new music code:
- Resolved a deadlock with the mixer, and added appropriate mutexes (a result of the fact that SCI mixes MIDI and digital audio in the same list)
- Fixed sound playing when loading games, by properly resetting the MIDI driver
- Reverted savegame version to 14 - the changes in versions 15 and 16 don't have any effect on the currently enabled old music code, and the new music code is disabled by default, and is still prone to changes
- Now saving/loading signal, loop and hold for each sound, as well as reverb
- Added stub code for setting reverb and channel hold
- The signal, loop and hold values of each song are cached, like in SSCI and like what happens in Greg's SCI implementation. This allows a clear separation of the engine code from the rest of the engine. Reverted commits 46792 and 46797
- Removed duplicate song list accessing code
- Song cues are now updated in kAnimate for SCI0, like the old music code does, to compensate for the fact that SCI0 didn't poll for music changes via cmdUpdateCues, like what SCI01 and newer do
- Cleanup
svn-id: r46812
2010-01-01 06:41:52 +00:00
|
|
|
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, obj, SELECTOR(loop), musicSlot->loop);
|
2010-07-09 12:06:41 +00:00
|
|
|
return acc;
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
reg_t SoundCommandParser::kDoSoundSuspend(int argc, reg_t *argv, reg_t acc) {
|
2009-11-12 15:24:11 +00:00
|
|
|
// TODO
|
2010-07-10 13:19:20 +00:00
|
|
|
warning("kDoSound(suspend): STUB");
|
2010-07-09 12:06:41 +00:00
|
|
|
return acc;
|
2009-11-12 15:24:11 +00:00
|
|
|
}
|
|
|
|
|
2010-01-01 16:05:26 +00:00
|
|
|
void SoundCommandParser::updateSci0Cues() {
|
2010-05-19 21:10:43 +00:00
|
|
|
bool noOnePlaying = true;
|
|
|
|
MusicEntry *pWaitingForPlay = NULL;
|
|
|
|
|
2010-01-01 16:05:26 +00:00
|
|
|
const MusicList::iterator end = _music->getPlayListEnd();
|
|
|
|
for (MusicList::iterator i = _music->getPlayListStart(); i != end; ++i) {
|
2010-01-02 19:01:34 +00:00
|
|
|
// Is the sound stopped, and the sound object updated too? If yes, skip
|
2010-06-29 20:50:52 +00:00
|
|
|
// this sound, as SCI0 only allows one active song.
|
2010-05-23 13:22:58 +00:00
|
|
|
if ((*i)->isQueued) {
|
2010-05-19 21:10:43 +00:00
|
|
|
pWaitingForPlay = (*i);
|
2010-06-29 20:50:52 +00:00
|
|
|
// FIXME(?): In iceman 2 songs are queued when playing the door
|
|
|
|
// sound - if we use the first song for resuming then it's the wrong
|
|
|
|
// one. Both songs have same priority. Maybe the new sound function
|
|
|
|
// in sci0 is somehow responsible.
|
2010-05-19 21:10:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
2010-01-02 19:01:34 +00:00
|
|
|
if ((*i)->signal == 0 && (*i)->status != kSoundPlaying)
|
|
|
|
continue;
|
|
|
|
|
2010-07-09 12:06:41 +00:00
|
|
|
processUpdateCues((*i)->soundObj);
|
2010-05-19 21:10:43 +00:00
|
|
|
noOnePlaying = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (noOnePlaying && pWaitingForPlay) {
|
|
|
|
// If there is a queued entry, play it now ffs: SciMusic::soundPlay()
|
|
|
|
pWaitingForPlay->isQueued = false;
|
|
|
|
_music->soundPlay(pWaitingForPlay);
|
2010-01-01 16:05:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-28 20:10:15 +00:00
|
|
|
void SoundCommandParser::clearPlayList() {
|
|
|
|
_music->clearPlayList();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundCommandParser::printPlayList(Console *con) {
|
|
|
|
_music->printPlayList(con);
|
|
|
|
}
|
|
|
|
|
2010-01-23 14:39:03 +00:00
|
|
|
void SoundCommandParser::printSongInfo(reg_t obj, Console *con) {
|
|
|
|
_music->printSongInfo(obj, con);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundCommandParser::stopAllSounds() {
|
|
|
|
_music->stopAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundCommandParser::startNewSound(int number) {
|
|
|
|
Common::StackLock lock(_music->_mutex);
|
|
|
|
|
|
|
|
// Overwrite the first sound in the playlist
|
|
|
|
MusicEntry *song = *_music->getPlayListStart();
|
|
|
|
reg_t soundObj = song->soundObj;
|
2010-07-09 12:06:41 +00:00
|
|
|
processDisposeSound(soundObj);
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, soundObj, SELECTOR(number), number);
|
2010-07-09 12:06:41 +00:00
|
|
|
processInitSound(soundObj);
|
|
|
|
processPlaySound(soundObj);
|
2010-01-23 14:39:03 +00:00
|
|
|
}
|
|
|
|
|
2010-01-12 00:51:37 +00:00
|
|
|
void SoundCommandParser::setMasterVolume(int vol) {
|
2010-09-01 19:20:17 +00:00
|
|
|
// 0...15
|
2010-01-12 00:51:37 +00:00
|
|
|
_music->soundSetMasterVolume(vol);
|
|
|
|
}
|
|
|
|
|
2010-01-21 21:28:32 +00:00
|
|
|
void SoundCommandParser::pauseAll(bool pause) {
|
|
|
|
_music->pauseAll(pause);
|
|
|
|
}
|
|
|
|
|
2010-09-02 21:50:00 +00:00
|
|
|
MusicType SoundCommandParser::getMusicType() const {
|
|
|
|
assert(_music);
|
|
|
|
return _music->soundGetMusicType();
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:24:11 +00:00
|
|
|
} // End of namespace Sci
|