[Scummvm-cvs-logs] SF.net SVN: scummvm:[46487] scummvm/trunk/engines/sci/sfx
thebluegr at users.sourceforge.net
thebluegr at users.sourceforge.net
Tue Dec 22 21:44:03 CET 2009
Revision: 46487
http://scummvm.svn.sourceforge.net/scummvm/?rev=46487&view=rev
Author: thebluegr
Date: 2009-12-22 20:44:03 +0000 (Tue, 22 Dec 2009)
Log Message:
-----------
SCI/new music code:
- Reverted the code to use local copies of certain sound object selectors, like what was done before
- Simplified and fixed the SCI1.1 digital sound effect playing code
- Removed some duplicate code
- Renamed some sound commands
Modified Paths:
--------------
scummvm/trunk/engines/sci/sfx/music.cpp
scummvm/trunk/engines/sci/sfx/music.h
scummvm/trunk/engines/sci/sfx/soundcmd.cpp
scummvm/trunk/engines/sci/sfx/soundcmd.h
Modified: scummvm/trunk/engines/sci/sfx/music.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/music.cpp 2009-12-22 15:16:12 UTC (rev 46486)
+++ scummvm/trunk/engines/sci/sfx/music.cpp 2009-12-22 20:44:03 UTC (rev 46487)
@@ -42,7 +42,7 @@
}
SciMusic::SciMusic() {
- _segMan = ((SciEngine *)g_engine)->getEngineState()->_segMan; // HACK
+
}
SciMusic::~SciMusic() {
@@ -322,41 +322,13 @@
Audio::Mixer::FLAG_UNSIGNED, 0, 0);
pSnd->hCurrentAud = Audio::SoundHandle();
} else {
- // 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)
- int16 songNumber = GET_SEL32V(_segMan, pSnd->soundObj, number);
- EngineState *s = ((SciEngine *)g_engine)->getEngineState(); // HACK
- AudioPlayer *audio = s->_audio;
- ResourceManager* resMan = s->resMan;
-
- if (resMan->testResource(ResourceId(kResourceTypeAudio, songNumber)) &&
- getSciVersion() >= SCI_VERSION_1_1) {
- // Found a relevant audio resource, play it
- audio->stopAudio();
-
- if (pSnd->pStreamAud)
- delete pSnd->pStreamAud;
- int sampleLen;
- pSnd->pStreamAud = audio->getAudioStream(songNumber, 65535, &sampleLen);
- pSnd->hCurrentAud = Audio::SoundHandle();
-
- PUT_SEL32V(_segMan, pSnd->soundObj, signal, 0);
-
- // FIXME: the scripts are signalled that the sound has stopped before it has
- // actually stopped, observable in the ship flight sequence in the first scene
- // of SQ4CD, right after the intro
- soundPlay(pSnd);
- } else {
- // play MIDI track
- if (pSnd->pMidiParser == NULL) {
- pSnd->pMidiParser = new MidiParser_SCI();
- pSnd->pMidiParser->setMidiDriver(_pMidiDrv);
- pSnd->pMidiParser->setTimerRate(_dwTempo);
- }
- pSnd->pMidiParser->loadMusic(pTrack, pSnd);
+ // play MIDI track
+ if (pSnd->pMidiParser == NULL) {
+ pSnd->pMidiParser = new MidiParser_SCI();
+ pSnd->pMidiParser->setMidiDriver(_pMidiDrv);
+ pSnd->pMidiParser->setTimerRate(_dwTempo);
}
+ pSnd->pMidiParser->loadMusic(pTrack, pSnd);
}
}
@@ -378,8 +350,13 @@
} else if (_playList[i]->pStreamAud) {
if (!_pMixer->isSoundHandleActive(_playList[i]->hCurrentAud)) {
_playList[i]->ticker = 0xFFFF;
- PUT_SEL32V(_segMan, _playList[i]->soundObj, signal, 0xFFFF);
+ _playList[i]->signal = 0xFFFF;
_playList[i]->status = kStopped;
+
+ // Signal the engine scripts that the sound is done playing
+ // FIXME: is there any other place this can be triggered properly?
+ SegManager *segMan = ((SciEngine *)g_engine)->getEngineState()->_segMan;
+ PUT_SEL32V(segMan, _playList[i]->soundObj, signal, SIGNAL_OFFSET);
} else {
_playList[i]->ticker = (uint16)(_pMixer->getSoundElapsedTime(
_playList[i]->hCurrentAud) * 0.06);
@@ -394,18 +371,12 @@
pSnd->FadeTicker--;
else {
pSnd->FadeTicker = pSnd->FadeTickerStep;
- // Get volume for sound
- int16 sndVol = GET_SEL32V(_segMan, pSnd->soundObj, vol);
-
- if (sndVol + pSnd->FadeStep > pSnd->FadeTo) {
- sndVol = pSnd->FadeTo;
+ if (pSnd->volume + pSnd->FadeStep > pSnd->FadeTo) {
+ pSnd->volume = pSnd->FadeTo;
pSnd->FadeStep = 0;
} else
- sndVol += pSnd->FadeStep;
-
- PUT_SEL32V(_segMan, pSnd->soundObj, vol, sndVol);
-
- pSnd->pMidiParser->setVolume(sndVol);
+ pSnd->volume += pSnd->FadeStep;
+ pSnd->pMidiParser->setVolume(pSnd->volume);
}
}
@@ -421,14 +392,11 @@
sortPlayList();
}
- // Get volume for sound
- int16 sndVol = GET_SEL32V(_segMan, pSnd->soundObj, vol);
-
if (pSnd->pStreamAud && !_pMixer->isSoundHandleActive(pSnd->hCurrentAud)) {
_pMixer->playInputStream(Audio::Mixer::kSFXSoundType, &pSnd->hCurrentAud,
- pSnd->pStreamAud, -1, sndVol, 0, false);
+ pSnd->pStreamAud, -1, pSnd->volume, 0, false);
} else if (pSnd->pMidiParser) {
- pSnd->pMidiParser->setVolume(sndVol);
+ pSnd->pMidiParser->setVolume(pSnd->volume);
if (pSnd->status == kStopped)
pSnd->pMidiParser->jumpToTick(0);
}
@@ -517,8 +485,6 @@
// values of ppqn and tempo are found experimentally and may be wrong
_ppqn = 1;
setTempo(16667);
-
- _segMan = ((SciEngine *)g_engine)->getEngineState()->_segMan; // HACK
}
//---------------------------------------------
MidiParser_SCI::~MidiParser_SCI() {
@@ -529,7 +495,7 @@
unloadMusic();
_pTrack = ptrack;
_pSnd = psnd;
- setVolume(GET_SEL32V(_segMan, _pSnd->soundObj, vol));
+ setVolume(psnd->volume);
midiMixChannels();
_num_tracks = 1;
@@ -567,11 +533,10 @@
info.basic.param1 = *(_position._play_pos++);
info.basic.param2 = 0;
if (info.channel() == 0xF) {// SCI special case
- if (info.basic.param1 != 0x7F) {
- PUT_SEL32V(_segMan, _pSnd->soundObj, signal, info.basic.param1);
- } else {
+ if (info.basic.param1 != 0x7F)
+ _pSnd->signal = info.basic.param1;
+ else
_loopTick = _position._play_tick;
- }
}
break;
case 0xD:
@@ -583,10 +548,8 @@
info.basic.param1 = *(_position._play_pos++);
info.basic.param2 = *(_position._play_pos++);
if (info.channel() == 0xF) {// SCI special
- if (info.basic.param1 == 0x60) {
- int dataInc = GET_SEL32V(_segMan, _pSnd->soundObj, dataInc);
- PUT_SEL32V(_segMan, _pSnd->soundObj, dataInc, dataInc++);
- }
+ if (info.basic.param1 == 0x60)
+ _pSnd->dataInc++;
// BF 50 x - set reverb to x
// BF 60 x - dataInc++
// BF 52 x - bHold=x
@@ -640,13 +603,12 @@
info.ext.data = _position._play_pos;
_position._play_pos += info.length;
if (info.ext.type == 0x2F) {// end of track reached
- uint16 loop = GET_SEL32V(_segMan, _pSnd->soundObj, loop);
- if (loop == 0xFFFF) {
+ if (_pSnd->loop) {
jumpToTick(_loopTick);
- PUT_SEL32V(_segMan, _pSnd->soundObj, loop, loop--);
+ _pSnd->loop--;
} else {
_pSnd->status = kStopped;
- PUT_SEL32V(_segMan, _pSnd->soundObj, signal, 0xFFFF);
+ _pSnd->signal = 0xFFFF;
}
}
break;
Modified: scummvm/trunk/engines/sci/sfx/music.h
===================================================================
--- scummvm/trunk/engines/sci/sfx/music.h 2009-12-22 15:16:12 UTC (rev 46486)
+++ scummvm/trunk/engines/sci/sfx/music.h 2009-12-22 20:44:03 UTC (rev 46487)
@@ -55,8 +55,6 @@
typedef uint16 SCIHANDLE;
typedef uint16 HEAPHANDLE;
-class SegManager;
-
enum kTrackType {
kTrackAdlib = 0,
kTrackGameBlaster = 9,
@@ -72,18 +70,24 @@
class MidiParser_SCI;
struct MusicEntry {
- SoundResource *soundRes;
reg_t soundObj;
- int16 prio; // stored for faster sound sorting
- MidiParser_SCI *pMidiParser;
- // Variables used for music fading
+ SoundResource *soundRes;
+ uint16 resnum;
+
+ uint16 dataInc;
uint16 ticker;
+ uint16 signal;
+ byte prio;
+ byte loop;
+ byte volume;
+
byte FadeTo;
short FadeStep;
uint32 FadeTicker;
uint32 FadeTickerStep;
+ MidiParser_SCI *pMidiParser;
Audio::AudioStream* pStreamAud;
Audio::SoundHandle hCurrentAud;
kSndStatus status;
@@ -146,7 +150,6 @@
bool _bMultiMidi; // use adlib's digital track if midi track don't have one
private:
static void miditimerCallback(void *p);
- SegManager *_segMan;
};
class MidiParser_SCI : public MidiParser {
@@ -175,9 +178,6 @@
MusicEntry *_pSnd;
uint32 _loopTick;
byte _volume;
-
-private:
- SegManager *_segMan;
};
} // end of namespace
Modified: scummvm/trunk/engines/sci/sfx/soundcmd.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/soundcmd.cpp 2009-12-22 15:16:12 UTC (rev 46486)
+++ scummvm/trunk/engines/sci/sfx/soundcmd.cpp 2009-12-22 20:44:03 UTC (rev 46487)
@@ -156,10 +156,10 @@
SOUNDCOMMAND(cmdDisposeHandle);
SOUNDCOMMAND(cmdMuteSound);
SOUNDCOMMAND(cmdStopHandle);
- SOUNDCOMMAND(cmdSuspendHandle);
+ SOUNDCOMMAND(cmdPauseHandle);
SOUNDCOMMAND(cmdResumeHandle);
SOUNDCOMMAND(cmdVolume);
- SOUNDCOMMAND(cmdUpdateVolumePriority);
+ SOUNDCOMMAND(cmdUpdateHandle);
SOUNDCOMMAND(cmdFadeHandle);
SOUNDCOMMAND(cmdGetPolyphony);
SOUNDCOMMAND(cmdGetPlayNext);
@@ -174,7 +174,7 @@
SOUNDCOMMAND(cmdDisposeHandle);
SOUNDCOMMAND(cmdPlayHandle);
SOUNDCOMMAND(cmdStopHandle);
- SOUNDCOMMAND(cmdSuspendHandle);
+ SOUNDCOMMAND(cmdPauseHandle);
SOUNDCOMMAND(cmdFadeHandle);
SOUNDCOMMAND(cmdUpdateCues);
SOUNDCOMMAND(cmdSendMidi);
@@ -192,7 +192,7 @@
SOUNDCOMMAND(cmdDisposeHandle);
SOUNDCOMMAND(cmdPlayHandle);
SOUNDCOMMAND(cmdStopHandle);
- SOUNDCOMMAND(cmdSuspendHandle);
+ SOUNDCOMMAND(cmdPauseHandle);
SOUNDCOMMAND(cmdFadeHandle);
SOUNDCOMMAND(cmdHoldHandle);
SOUNDCOMMAND(cmdDummy);
@@ -202,7 +202,7 @@
SOUNDCOMMAND(cmdUpdateCues);
SOUNDCOMMAND(cmdSendMidi);
SOUNDCOMMAND(cmdReverb);
- SOUNDCOMMAND(cmdUpdateVolumePriority);
+ SOUNDCOMMAND(cmdUpdateHandle);
break;
default:
warning("Sound command parser: unknown DoSound type %d", doSoundVersion);
@@ -242,8 +242,11 @@
}
void SoundCommandParser::cmdInitHandle(reg_t obj, int16 value) {
- int number = obj.segment ? GET_SEL32V(_segMan, obj, number) : -1;
+ if (!obj.segment)
+ return;
+ int number = obj.segment ? GET_SEL32V(_segMan, obj, number) : 0;
+
#ifdef USE_OLD_MUSIC_FUNCTIONS
SongHandle handle = FROBNICATE_HANDLE(obj);
@@ -283,10 +286,15 @@
MusicEntry *newSound = new MusicEntry();
newSound->soundRes = 0;
- if (_resMan->testResource(ResourceId(kResourceTypeSound, number)))
+ newSound->resnum = number;
+ if (number && _resMan->testResource(ResourceId(kResourceTypeSound, number)))
newSound->soundRes = new SoundResource(number, _resMan);
newSound->soundObj = obj;
+ newSound->loop = GET_SEL32V(_segMan, obj, loop) == 0xFFFF ? 1 : 0;
newSound->prio = GET_SEL32V(_segMan, obj, pri) & 0xFF;
+ newSound->volume = GET_SEL32V(_segMan, obj, vol) & 0xFF;
+ newSound->signal = 0;
+ newSound->dataInc = 0;
newSound->pStreamAud = 0;
newSound->pMidiParser = 0;
newSound->ticker = 0;
@@ -297,8 +305,20 @@
newSound->status = kStopped;
_music->_playList.push_back(newSound);
- if (newSound->soundRes)
- _music->soundInitSnd(newSound);
+ // 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)
+
+ if (_resMan->testResource(ResourceId(kResourceTypeAudio, number)) && getSciVersion() >= SCI_VERSION_1_1) {
+ // Found a relevant audio resource, play it
+ int sampleLen;
+ newSound->pStreamAud = _audio->getAudioStream(number, 65535, &sampleLen);
+ newSound->hCurrentAud = Audio::SoundHandle();
+ } else {
+ if (newSound->soundRes)
+ _music->soundInitSnd(newSound);
+ }
#endif
}
@@ -375,18 +395,28 @@
#else
if (!GET_SEL32(_segMan, obj, nodePtr).isNull()) {
- //int number = obj.segment ? GET_SEL32V(_segMan, obj, number) : -1;
+ int slot = _music->findListSlot(obj);
+ if (slot < 0) {
+ warning("cmdPlayHandle: Slot not found");
+ return;
+ }
+
+ int number = obj.segment ? GET_SEL32V(_segMan, obj, number) : -1;
+
+ if (_music->_playList[slot]->resnum != number) { // another sound loaded into struct
+ cmdDisposeHandle(obj, value);
+ cmdInitHandle(obj, value);
+ }
+
PUT_SEL32V(_segMan, obj, handle, 0x1234);
PUT_SEL32V(_segMan, obj, signal, 0);
PUT_SEL32V(_segMan, obj, min, 0);
PUT_SEL32V(_segMan, obj, sec, 0);
PUT_SEL32V(_segMan, obj, frame, 0);
- int slot = _music->findListSlot(obj);
- if (slot < 0) {
- warning("cmdPlayHandle: Slot not found");
- return;
- }
- _music->_playList[slot]->prio = GET_SEL32V(_segMan, obj, priority) & 0xFF;
+
+ _music->_playList[slot]->loop = GET_SEL32V(_segMan, obj, loop) == 0xFFFF ? 1 : 0;
+ _music->_playList[slot]->prio = GET_SEL32V(_segMan, obj, priority);
+ _music->_playList[slot]->volume = GET_SEL32V(_segMan, obj, vol);
_music->soundPlay(_music->_playList[slot]);
}
#endif
@@ -455,13 +485,14 @@
PUT_SEL32V(_segMan, obj, signal, SIGNAL_OFFSET);
if (!GET_SEL32(_segMan, obj, nodePtr).isNull()) {
- PUT_SEL32V(_segMan, obj, dataInc, 0);
+ _music->_playList[slot]->dataInc = 0;
+ _music->_playList[slot]->signal = SIGNAL_OFFSET;
_music->soundStop(_music->_playList[slot]);
}
#endif
}
-void SoundCommandParser::cmdSuspendHandle(reg_t obj, int16 value) {
+void SoundCommandParser::cmdPauseHandle(reg_t obj, int16 value) {
if (!obj.segment)
return;
@@ -473,7 +504,7 @@
#else
int slot = _music->findListSlot(obj);
if (slot < 0) {
- warning("cmdSuspendHandle: Slot not found");
+ warning("cmdPauseHandle: Slot not found");
return;
}
@@ -487,6 +518,8 @@
}
void SoundCommandParser::cmdResumeHandle(reg_t obj, int16 value) {
+ // SCI0 only command
+
if (!obj.segment)
return;
@@ -596,14 +629,32 @@
}
void SoundCommandParser::cmdUpdateHandle(reg_t obj, int16 value) {
-#ifndef USE_OLD_MUSIC_FUNCTIONS
+ if (!obj.segment)
+ return;
+
+#ifdef USE_OLD_MUSIC_FUNCTIONS
+ SongHandle handle = FROBNICATE_HANDLE(obj);
+ if (!_hasNodePtr && obj.segment) {
+ _state->sfx_song_set_loops(handle, GET_SEL32V(_segMan, obj, loop));
+ script_set_priority(_resMan, _segMan, _state, obj, GET_SEL32V(_segMan, obj, pri));
+ }
+#else
int slot = _music->findListSlot(obj);
if (slot < 0) {
warning("cmdUpdateHandle: Slot not found");
return;
}
- _music->_playList[slot]->prio = GET_SEL32V(_segMan, obj, priority) & 0xFF;
+ if (!GET_SEL32(_segMan, obj, nodePtr).isNull()) {
+ _music->_playList[slot]->loop = (GET_SEL32V(_segMan, obj, loop) == 0xFFFF ? 1 : 0);
+ uint32 objVol = GET_SEL32V(_segMan, obj, vol);
+ if (objVol != _music->_playList[slot]->volume)
+ _music->soundSetVolume(_music->_playList[slot], objVol);
+ uint32 objPrio = GET_SEL32V(_segMan, obj, vol);
+ if (objPrio != _music->_playList[slot]->prio)
+ _music->soundSetPriority(_music->_playList[slot], objPrio);
+ }
+
#endif
}
@@ -690,16 +741,18 @@
if (!GET_SEL32(_segMan, obj, nodePtr).isNull()) {
uint16 signal = GET_SEL32V(_segMan, obj, signal);
- int16 dataInc = GET_SEL32V(_segMan, obj, dataInc);
-
switch (signal) {
case 0:
- PUT_SEL32V(_segMan, obj, signal, dataInc + 127);
+ if (_music->_playList[slot]->dataInc != GET_SEL32V(_segMan, obj, dataInc)) {
+ PUT_SEL32V(_segMan, obj, dataInc, _music->_playList[slot]->dataInc);
+ PUT_SEL32V(_segMan, obj, signal, _music->_playList[slot]->dataInc + 127);
+ }
break;
case 0xFFFF:
cmdStopHandle(obj, value);
break;
default:
+ PUT_SEL32V(_segMan, obj, signal, _music->_playList[slot]->signal);
break;
}
@@ -743,21 +796,30 @@
}
void SoundCommandParser::cmdSetHandleVolume(reg_t obj, int16 value) {
+ if (!obj.segment)
+ return;
+
#ifndef USE_OLD_MUSIC_FUNCTIONS
int slot = _music->findListSlot(obj);
if (slot < 0) {
- warning("cmdUpdateVolumePriority: Slot not found");
+ warning("cmdSetHandleVolume: Slot not found");
return;
}
if (!GET_SEL32(_segMan, obj, nodePtr).isNull()) {
- _music->soundSetVolume(_music->_playList[slot], value);
- PUT_SEL32V(_segMan, obj, vol, value);
+ if (_music->_playList[slot]->volume != value) {
+ _music->_playList[slot]->volume = value;
+ _music->soundSetVolume(_music->_playList[slot], value);
+ PUT_SEL32V(_segMan, obj, vol, value);
+ }
}
#endif
}
void SoundCommandParser::cmdSetHandlePriority(reg_t obj, int16 value) {
+ if (!obj.segment)
+ return;
+
#ifdef USE_OLD_MUSIC_FUNCTIONS
script_set_priority(_resMan, _segMan, _state, obj, value);
#else
@@ -779,11 +841,26 @@
}
void SoundCommandParser::cmdSetHandleLoop(reg_t obj, int16 value) {
+ if (!obj.segment)
+ return;
+
if (!GET_SEL32(_segMan, obj, nodePtr).isNull()) {
- PUT_SEL32V(_segMan, obj, loop, value == -1 ? 0xFFFF : 1);
#ifdef USE_OLD_MUSIC_FUNCTIONS
- SongHandle handle = FROBNICATE_HANDLE(obj);
- _state->sfx_song_set_loops(handle, value);
+ SongHandle handle = FROBNICATE_HANDLE(obj);
+ _state->sfx_song_set_loops(handle, value);
+#else
+ int slot = _music->findListSlot(obj);
+ if (slot < 0) {
+ warning("cmdSetHandleLoop: Slot not found");
+ return;
+ }
+ if (value == -1) {
+ _music->_playList[slot]->loop = 1;
+ PUT_SEL32V(_segMan, obj, loop, 0xFFFF);
+ } else {
+ _music->_playList[slot]->loop = 0;
+ PUT_SEL32V(_segMan, obj, loop, 1);
+ }
#endif
}
}
@@ -793,25 +870,4 @@
warning("STUB: cmdSuspendSound");
}
-void SoundCommandParser::cmdUpdateVolumePriority(reg_t obj, int16 value) {
-#ifdef USE_OLD_MUSIC_FUNCTIONS
- SongHandle handle = FROBNICATE_HANDLE(obj);
- if (!_hasNodePtr && obj.segment) {
- _state->sfx_song_set_loops(handle, GET_SEL32V(_segMan, obj, loop));
- script_set_priority(_resMan, _segMan, _state, obj, GET_SEL32V(_segMan, obj, pri));
- }
-#else
- int slot = _music->findListSlot(obj);
- if (slot < 0) {
- warning("cmdUpdateVolumePriority: Slot not found");
- return;
- }
-
- if (!GET_SEL32(_segMan, obj, nodePtr).isNull()) {
- _music->soundSetVolume(_music->_playList[slot], GET_SEL32V(_segMan, obj, vol));
- _music->soundSetPriority(_music->_playList[slot], GET_SEL32V(_segMan, obj, priority));
- }
-#endif
-}
-
} // End of namespace Sci
Modified: scummvm/trunk/engines/sci/sfx/soundcmd.h
===================================================================
--- scummvm/trunk/engines/sci/sfx/soundcmd.h 2009-12-22 15:16:12 UTC (rev 46486)
+++ scummvm/trunk/engines/sci/sfx/soundcmd.h 2009-12-22 20:44:03 UTC (rev 46487)
@@ -74,7 +74,7 @@
void cmdPlayHandle(reg_t obj, int16 value);
void cmdDummy(reg_t obj, int16 value);
void cmdMuteSound(reg_t obj, int16 value);
- void cmdSuspendHandle(reg_t obj, int16 value);
+ void cmdPauseHandle(reg_t obj, int16 value);
void cmdResumeHandle(reg_t obj, int16 value);
void cmdStopHandle(reg_t obj, int16 value);
void cmdDisposeHandle(reg_t obj, int16 value);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list