SCI: Renamed sfx_state_t -> SfxState, preparing it to become a class eventually

svn-id: r40958
This commit is contained in:
Max Horn 2009-05-28 10:54:30 +00:00
parent e23e1ffcb7
commit d70504c910
8 changed files with 213 additions and 213 deletions

View file

@ -220,7 +220,7 @@ int game_init_sound(EngineState *s, int sound_flags) {
sound_flags |= SFX_STATE_FLAG_MULTIPLAY; sound_flags |= SFX_STATE_FLAG_MULTIPLAY;
s->sfx_init_flags = sound_flags; s->sfx_init_flags = sound_flags;
sfx_init(&s->sound, s->resmgr, sound_flags); sfx_init(&s->_sound, s->resmgr, sound_flags);
return 0; return 0;
} }
@ -593,7 +593,7 @@ int game_exit(EngineState *s) {
s->_executionStack.clear(); s->_executionStack.clear();
if (!s->successor) { if (!s->successor) {
sfx_exit(&s->sound); sfx_exit(&s->_sound);
// Reinit because some other code depends on having a valid state // Reinit because some other code depends on having a valid state
game_init_sound(s, SFX_STATE_FLAG_NOSOUND); game_init_sound(s, SFX_STATE_FLAG_NOSOUND);
} }

View file

@ -127,7 +127,7 @@ static void script_set_priority(EngineState *s, reg_t obj, int priority) {
flags &= ~SCI1_SOUND_FLAG_SCRIPTED_PRI; flags &= ~SCI1_SOUND_FLAG_SCRIPTED_PRI;
} else flags |= SCI1_SOUND_FLAG_SCRIPTED_PRI; } else flags |= SCI1_SOUND_FLAG_SCRIPTED_PRI;
sfx_song_renice(&s->sound, FROBNICATE_HANDLE(obj), priority); sfx_song_renice(&s->_sound, FROBNICATE_HANDLE(obj), priority);
PUT_SEL32V(obj, flags, flags); PUT_SEL32V(obj, flags, flags);
} }
@ -150,7 +150,7 @@ void process_sound_events(EngineState *s) { /* Get all sound events, apply their
return; return;
/* SCI01 and later explicitly poll for everything */ /* SCI01 and later explicitly poll for everything */
while ((result = sfx_poll(&s->sound, &handle, &cue))) { while ((result = sfx_poll(&s->_sound, &handle, &cue))) {
reg_t obj = DEFROBNICATE_HANDLE(handle); reg_t obj = DEFROBNICATE_HANDLE(handle);
if (!is_object(s, obj)) { if (!is_object(s, obj)) {
warning("Non-object %04x:%04x received sound signal (%d/%d)", PRINT_REG(obj), result, cue); warning("Non-object %04x:%04x received sound signal (%d/%d)", PRINT_REG(obj), result, cue);
@ -264,7 +264,7 @@ reg_t kDoSound_SCI0(EngineState *s, int funct_nr, int argc, reg_t *argv) {
case _K_SCI0_SOUND_INIT_HANDLE: case _K_SCI0_SOUND_INIT_HANDLE:
if (obj.segment) { if (obj.segment) {
sciprintf("Initializing song number %d\n", GET_SEL32V(obj, number)); sciprintf("Initializing song number %d\n", GET_SEL32V(obj, number));
SCRIPT_ASSERT_ZERO(sfx_add_song(&s->sound, SCRIPT_ASSERT_ZERO(sfx_add_song(&s->_sound,
build_iterator(s, number, build_iterator(s, number,
SCI_SONG_ITERATOR_TYPE_SCI0, SCI_SONG_ITERATOR_TYPE_SCI0,
handle), handle),
@ -276,9 +276,9 @@ reg_t kDoSound_SCI0(EngineState *s, int funct_nr, int argc, reg_t *argv) {
case _K_SCI0_SOUND_PLAY_HANDLE: case _K_SCI0_SOUND_PLAY_HANDLE:
if (obj.segment) { if (obj.segment) {
sfx_song_set_status(&s->sound, sfx_song_set_status(&s->_sound,
handle, SOUND_STATUS_PLAYING); handle, SOUND_STATUS_PLAYING);
sfx_song_set_loops(&s->sound, sfx_song_set_loops(&s->_sound,
handle, GET_SEL32V(obj, loop)); handle, GET_SEL32V(obj, loop));
PUT_SEL32V(obj, state, _K_SOUND_STATUS_PLAYING); PUT_SEL32V(obj, state, _K_SOUND_STATUS_PLAYING);
} }
@ -289,14 +289,14 @@ reg_t kDoSound_SCI0(EngineState *s, int funct_nr, int argc, reg_t *argv) {
case _K_SCI0_SOUND_DISPOSE_HANDLE: case _K_SCI0_SOUND_DISPOSE_HANDLE:
if (obj.segment) { if (obj.segment) {
sfx_remove_song(&s->sound, handle); sfx_remove_song(&s->_sound, handle);
} }
PUT_SEL32V(obj, handle, 0x0000); PUT_SEL32V(obj, handle, 0x0000);
break; break;
case _K_SCI0_SOUND_STOP_HANDLE: case _K_SCI0_SOUND_STOP_HANDLE:
if (obj.segment) { if (obj.segment) {
sfx_song_set_status(&s->sound, sfx_song_set_status(&s->_sound,
handle, SOUND_STATUS_STOPPED); handle, SOUND_STATUS_STOPPED);
PUT_SEL32V(obj, state, SOUND_STATUS_STOPPED); PUT_SEL32V(obj, state, SOUND_STATUS_STOPPED);
} }
@ -304,7 +304,7 @@ reg_t kDoSound_SCI0(EngineState *s, int funct_nr, int argc, reg_t *argv) {
case _K_SCI0_SOUND_SUSPEND_HANDLE: case _K_SCI0_SOUND_SUSPEND_HANDLE:
if (obj.segment) { if (obj.segment) {
sfx_song_set_status(&s->sound, sfx_song_set_status(&s->_sound,
handle, SOUND_STATUS_SUSPENDED); handle, SOUND_STATUS_SUSPENDED);
PUT_SEL32V(obj, state, SOUND_STATUS_SUSPENDED); PUT_SEL32V(obj, state, SOUND_STATUS_SUSPENDED);
} }
@ -312,7 +312,7 @@ reg_t kDoSound_SCI0(EngineState *s, int funct_nr, int argc, reg_t *argv) {
case _K_SCI0_SOUND_RESUME_HANDLE: case _K_SCI0_SOUND_RESUME_HANDLE:
if (obj.segment) { if (obj.segment) {
sfx_song_set_status(&s->sound, sfx_song_set_status(&s->_sound,
handle, SOUND_STATUS_PLAYING); handle, SOUND_STATUS_PLAYING);
PUT_SEL32V(obj, state, SOUND_STATUS_PLAYING); PUT_SEL32V(obj, state, SOUND_STATUS_PLAYING);
} }
@ -337,15 +337,15 @@ reg_t kDoSound_SCI0(EngineState *s, int funct_nr, int argc, reg_t *argv) {
int vol = SKPV_OR_ALT(1, -1); int vol = SKPV_OR_ALT(1, -1);
if (vol != -1) if (vol != -1)
sfx_set_volume(&s->sound, vol << 0xf); sfx_set_volume(&s->_sound, vol << 0xf);
else else
s->r_acc = make_reg(0, sfx_get_volume(&s->sound) >> 0xf); s->r_acc = make_reg(0, sfx_get_volume(&s->_sound) >> 0xf);
} }
break; break;
case _K_SCI0_SOUND_UPDATE_VOL_PRI: case _K_SCI0_SOUND_UPDATE_VOL_PRI:
if (obj.segment) { if (obj.segment) {
sfx_song_set_loops(&s->sound, sfx_song_set_loops(&s->_sound,
handle, GET_SEL32V(obj, loop)); handle, GET_SEL32V(obj, loop));
script_set_priority(s, obj, GET_SEL32V(obj, pri)); script_set_priority(s, obj, GET_SEL32V(obj, pri));
} }
@ -356,7 +356,7 @@ reg_t kDoSound_SCI0(EngineState *s, int funct_nr, int argc, reg_t *argv) {
/* FIXME: The next couple of lines actually STOP the handle, rather /* FIXME: The next couple of lines actually STOP the handle, rather
** than fading it! */ ** than fading it! */
if (obj.segment) { if (obj.segment) {
sfx_song_set_status(&s->sound, sfx_song_set_status(&s->_sound,
handle, SOUND_STATUS_STOPPED); handle, SOUND_STATUS_STOPPED);
PUT_SEL32V(obj, state, SOUND_STATUS_STOPPED); PUT_SEL32V(obj, state, SOUND_STATUS_STOPPED);
PUT_SEL32V(obj, signal, -1); PUT_SEL32V(obj, signal, -1);
@ -368,7 +368,7 @@ reg_t kDoSound_SCI0(EngineState *s, int funct_nr, int argc, reg_t *argv) {
break; break;
case _K_SCI0_SOUND_PLAY_NEXT: case _K_SCI0_SOUND_PLAY_NEXT:
/* sfx_all_stop(&s->sound);*/ /* sfx_all_stop(&s->_sound);*/
break; break;
default: default:
@ -459,9 +459,9 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) {
int vol = SKPV_OR_ALT(1, -1); int vol = SKPV_OR_ALT(1, -1);
if (vol != -1) if (vol != -1)
sfx_set_volume(&s->sound, vol << 0xf); sfx_set_volume(&s->_sound, vol << 0xf);
else else
s->r_acc = make_reg(0, sfx_get_volume(&s->sound) >> 0xf); s->r_acc = make_reg(0, sfx_get_volume(&s->_sound) >> 0xf);
break; break;
} }
case _K_SCI01_SOUND_MUTE_SOUND : { case _K_SCI01_SOUND_MUTE_SOUND : {
@ -490,13 +490,13 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) {
RESTORE_BEHAVIOR rb = (RESTORE_BEHAVIOR) UKPV(2); /* Too lazy to look up a default value for this */ RESTORE_BEHAVIOR rb = (RESTORE_BEHAVIOR) UKPV(2); /* Too lazy to look up a default value for this */
if (obj.segment) { if (obj.segment) {
sfx_song_set_status(&s->sound, sfx_song_set_status(&s->_sound,
handle, SOUND_STATUS_PLAYING); handle, SOUND_STATUS_PLAYING);
sfx_song_set_loops(&s->sound, sfx_song_set_loops(&s->_sound,
handle, looping); handle, looping);
sfx_song_renice(&s->sound, sfx_song_renice(&s->_sound,
handle, pri); handle, pri);
song_lib_set_restore_behavior(s->sound.songlib, handle, rb); song_lib_set_restore_behavior(s->_sound._songlib, handle, rb);
} }
break; break;
@ -508,7 +508,7 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) {
if (obj.segment && (s->resmgr->testResource(kResourceTypeSound, number))) { if (obj.segment && (s->resmgr->testResource(kResourceTypeSound, number))) {
sciprintf("Initializing song number %d\n", number); sciprintf("Initializing song number %d\n", number);
SCRIPT_ASSERT_ZERO(sfx_add_song(&s->sound, SCRIPT_ASSERT_ZERO(sfx_add_song(&s->_sound,
build_iterator(s, number, build_iterator(s, number,
SCI_SONG_ITERATOR_TYPE_SCI1, SCI_SONG_ITERATOR_TYPE_SCI1,
handle), handle),
@ -520,9 +520,9 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) {
} }
case _K_SCI01_SOUND_DISPOSE_HANDLE : { case _K_SCI01_SOUND_DISPOSE_HANDLE : {
if (obj.segment) { if (obj.segment) {
sfx_song_set_status(&s->sound, sfx_song_set_status(&s->_sound,
handle, SOUND_STATUS_STOPPED); handle, SOUND_STATUS_STOPPED);
sfx_remove_song(&s->sound, handle); sfx_remove_song(&s->_sound, handle);
} }
break; break;
} }
@ -538,9 +538,9 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) {
//int vol = GET_SEL32V(obj, vol); //int vol = GET_SEL32V(obj, vol);
int pri = GET_SEL32V(obj, pri); int pri = GET_SEL32V(obj, pri);
sfx_song_set_loops(&s->sound, sfx_song_set_loops(&s->_sound,
handle, looping); handle, looping);
sfx_song_renice(&s->sound, handle, pri); sfx_song_renice(&s->_sound, handle, pri);
SCIkdebug(SCIkSOUND, "[sound01-update-handle] -- CUE %04x:%04x"); SCIkdebug(SCIkSOUND, "[sound01-update-handle] -- CUE %04x:%04x");
@ -554,7 +554,7 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) {
case _K_SCI01_SOUND_STOP_HANDLE : { case _K_SCI01_SOUND_STOP_HANDLE : {
PUT_SEL32V(obj, signal, -1); PUT_SEL32V(obj, signal, -1);
if (obj.segment) { if (obj.segment) {
sfx_song_set_status(&s->sound, sfx_song_set_status(&s->_sound,
handle, SOUND_STATUS_STOPPED); handle, SOUND_STATUS_STOPPED);
} }
break; break;
@ -565,7 +565,7 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) {
SOUND_STATUS_SUSPENDED : SOUND_STATUS_PLAYING; SOUND_STATUS_SUSPENDED : SOUND_STATUS_PLAYING;
if (obj.segment) { if (obj.segment) {
sfx_song_set_status(&s->sound, sfx_song_set_status(&s->_sound,
handle, setstate); handle, setstate);
} }
break; break;
@ -577,7 +577,7 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) {
/* FIXME: The next couple of lines actually STOP the song right away */ /* FIXME: The next couple of lines actually STOP the song right away */
PUT_SEL32V(obj, signal, -1); PUT_SEL32V(obj, signal, -1);
if (obj.segment) { if (obj.segment) {
sfx_song_set_status(&s->sound, sfx_song_set_status(&s->_sound,
handle, SOUND_STATUS_STOPPED); handle, SOUND_STATUS_STOPPED);
} }
break; break;
@ -591,7 +591,7 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) {
int cue = 0; int cue = 0;
while (result == SI_LOOP) while (result == SI_LOOP)
result = sfx_poll_specific(&s->sound, handle, &cue); result = sfx_poll_specific(&s->_sound, handle, &cue);
switch (result) { switch (result) {
@ -637,7 +637,7 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) {
/* } */ /* } */
/* break; */ /* break; */
/* case 0xFF: /\* May be unnecessary *\/ */ /* case 0xFF: /\* May be unnecessary *\/ */
/* sfx_song_set_status(&s->sound, */ /* sfx_song_set_status(&s->_sound, */
/* handle, SOUND_STATUS_STOPPED); */ /* handle, SOUND_STATUS_STOPPED); */
/* break; */ /* break; */
/* default : */ /* default : */
@ -665,7 +665,7 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) {
int controller = UKPV(3); int controller = UKPV(3);
int param = UKPV(4); int param = UKPV(4);
sfx_send_midi(&s->sound, handle, sfx_send_midi(&s->_sound, handle,
channel, midiCmd, controller, param); channel, midiCmd, controller, param);
break; break;
} }
@ -810,12 +810,12 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) {
int looping = GET_SEL32V(obj, loop); int looping = GET_SEL32V(obj, loop);
//int vol = GET_SEL32V(obj, vol); //int vol = GET_SEL32V(obj, vol);
int pri = GET_SEL32V(obj, pri); int pri = GET_SEL32V(obj, pri);
song_t *song = song_lib_find(s->sound.songlib, handle); song_t *song = song_lib_find(s->_sound._songlib, handle);
if (GET_SEL32V(obj, nodePtr) && (song && number != song->resource_num)) { if (GET_SEL32V(obj, nodePtr) && (song && number != song->resource_num)) {
sfx_song_set_status(&s->sound, sfx_song_set_status(&s->_sound,
handle, SOUND_STATUS_STOPPED); handle, SOUND_STATUS_STOPPED);
sfx_remove_song(&s->sound, handle); sfx_remove_song(&s->_sound, handle);
PUT_SEL32(obj, nodePtr, NULL_REG); PUT_SEL32(obj, nodePtr, NULL_REG);
} }
@ -826,7 +826,7 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) {
} }
sciprintf("Initializing song number %d\n", number); sciprintf("Initializing song number %d\n", number);
SCRIPT_ASSERT_ZERO(sfx_add_song(&s->sound, SCRIPT_ASSERT_ZERO(sfx_add_song(&s->_sound,
build_iterator(s, number, build_iterator(s, number,
SCI_SONG_ITERATOR_TYPE_SCI1, SCI_SONG_ITERATOR_TYPE_SCI1,
handle), handle),
@ -836,11 +836,11 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) {
} }
if (obj.segment) { if (obj.segment) {
sfx_song_set_status(&s->sound, sfx_song_set_status(&s->_sound,
handle, SOUND_STATUS_PLAYING); handle, SOUND_STATUS_PLAYING);
sfx_song_set_loops(&s->sound, sfx_song_set_loops(&s->_sound,
handle, looping); handle, looping);
sfx_song_renice(&s->sound, sfx_song_renice(&s->_sound,
handle, pri); handle, pri);
} }
@ -852,14 +852,14 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) {
//int pri = GET_SEL32V(obj, pri); //int pri = GET_SEL32V(obj, pri);
if (GET_SEL32V(obj, nodePtr)) { if (GET_SEL32V(obj, nodePtr)) {
sfx_song_set_status(&s->sound, sfx_song_set_status(&s->_sound,
handle, SOUND_STATUS_STOPPED); handle, SOUND_STATUS_STOPPED);
sfx_remove_song(&s->sound, handle); sfx_remove_song(&s->_sound, handle);
} }
if (obj.segment && (s->resmgr->testResource(kResourceTypeSound, number))) { if (obj.segment && (s->resmgr->testResource(kResourceTypeSound, number))) {
sciprintf("Initializing song number %d\n", number); sciprintf("Initializing song number %d\n", number);
SCRIPT_ASSERT_ZERO(sfx_add_song(&s->sound, SCRIPT_ASSERT_ZERO(sfx_add_song(&s->_sound,
build_iterator(s, number, build_iterator(s, number,
SCI_SONG_ITERATOR_TYPE_SCI1, SCI_SONG_ITERATOR_TYPE_SCI1,
handle), handle),
@ -871,16 +871,16 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) {
} }
case _K_SCI1_SOUND_DISPOSE_HANDLE : { case _K_SCI1_SOUND_DISPOSE_HANDLE : {
if (obj.segment) { if (obj.segment) {
sfx_song_set_status(&s->sound, sfx_song_set_status(&s->_sound,
handle, SOUND_STATUS_STOPPED); handle, SOUND_STATUS_STOPPED);
sfx_remove_song(&s->sound, handle); sfx_remove_song(&s->_sound, handle);
} }
break; break;
} }
case _K_SCI1_SOUND_STOP_HANDLE : { case _K_SCI1_SOUND_STOP_HANDLE : {
PUT_SEL32V(obj, signal, -1); PUT_SEL32V(obj, signal, -1);
if (obj.segment) { if (obj.segment) {
sfx_song_set_status(&s->sound, sfx_song_set_status(&s->_sound,
handle, SOUND_STATUS_STOPPED); handle, SOUND_STATUS_STOPPED);
} }
break; break;
@ -898,7 +898,7 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) {
FADE_ACTION_FADE_AND_STOP : FADE_ACTION_FADE_AND_STOP :
FADE_ACTION_FADE_AND_CONT; FADE_ACTION_FADE_AND_CONT;
sfx_song_set_fade(&s->sound, sfx_song_set_fade(&s->_sound,
handle, handle,
&fade); &fade);
@ -908,7 +908,7 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) {
PUT_SEL32V(obj, signal, -1); PUT_SEL32V(obj, signal, -1);
PUT_SEL32V(obj, nodePtr, 0); PUT_SEL32V(obj, nodePtr, 0);
PUT_SEL32V(obj, handle, 0); PUT_SEL32V(obj, handle, 0);
sfx_song_set_status(&s->sound, sfx_song_set_status(&s->_sound,
handle, SOUND_STATUS_STOPPED); handle, SOUND_STATUS_STOPPED);
} else { } else {
// FIXME: Support fade-and-continue. For now, send signal right away. // FIXME: Support fade-and-continue. For now, send signal right away.
@ -920,7 +920,7 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) {
case _K_SCI1_SOUND_HOLD_HANDLE : { case _K_SCI1_SOUND_HOLD_HANDLE : {
int value = SKPV(2); int value = SKPV(2);
sfx_song_set_hold(&s->sound, sfx_song_set_hold(&s->_sound,
handle, value); handle, value);
break; break;
} }
@ -948,7 +948,7 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) {
int cue = 0; int cue = 0;
while (result == SI_LOOP) while (result == SI_LOOP)
result = sfx_poll_specific(&s->sound, handle, &cue); result = sfx_poll_specific(&s->_sound, handle, &cue);
switch (result) { switch (result) {
@ -978,7 +978,7 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) {
break; break;
} }
case _K_SCI1_SOUND_MIDI_SEND : { case _K_SCI1_SOUND_MIDI_SEND : {
sfx_send_midi(&s->sound, handle, sfx_send_midi(&s->_sound, handle,
UKPV(2), UKPV(3), UKPV(4), UKPV(5)); UKPV(2), UKPV(3), UKPV(4), UKPV(5));
break; break;
} }
@ -1006,19 +1006,19 @@ reg_t kDoAudio(EngineState *s, int funct_nr, int argc, reg_t *argv) {
Audio::Mixer *mixer = g_system->getMixer(); Audio::Mixer *mixer = g_system->getMixer();
int sampleLen = 0; int sampleLen = 0;
if (!s->sound.audioResource) if (!s->_sound._audioResource)
s->sound.audioResource = new AudioResource(s->resmgr, s->version); s->_sound._audioResource = new AudioResource(s->resmgr, s->version);
switch (UKPV(0)) { switch (UKPV(0)) {
case kSciAudioWPlay: case kSciAudioWPlay:
case kSciAudioPlay: case kSciAudioPlay:
s->sound.audioResource->stop(); s->_sound._audioResource->stop();
if (argc == 2) { // KQ5CD, KQ6 floppy if (argc == 2) { // KQ5CD, KQ6 floppy
Audio::AudioStream *audioStream = s->sound.audioResource->getAudioStream(UKPV(1), &sampleLen); Audio::AudioStream *audioStream = s->_sound._audioResource->getAudioStream(UKPV(1), &sampleLen);
if (audioStream) if (audioStream)
mixer->playInputStream(Audio::Mixer::kSpeechSoundType, s->sound.audioResource->getAudioHandle(), audioStream); mixer->playInputStream(Audio::Mixer::kSpeechSoundType, s->_sound._audioResource->getAudioHandle(), audioStream);
} else if (argc == 6) { // SQ4CD or newer } else if (argc == 6) { // SQ4CD or newer
// TODO // TODO
warning("kDoAudio: Play called with new semantics - 5 parameters: %d %d %d %d %d", UKPV(1), UKPV(2), UKPV(3), UKPV(4), UKPV(5)); warning("kDoAudio: Play called with new semantics - 5 parameters: %d %d %d %d %d", UKPV(1), UKPV(2), UKPV(3), UKPV(4), UKPV(5));
@ -1027,18 +1027,18 @@ reg_t kDoAudio(EngineState *s, int funct_nr, int argc, reg_t *argv) {
} }
return make_reg(0, sampleLen); // return sample length in ticks return make_reg(0, sampleLen); // return sample length in ticks
case kSciAudioStop: case kSciAudioStop:
s->sound.audioResource->stop(); s->_sound._audioResource->stop();
break; break;
case kSciAudioPause: case kSciAudioPause:
s->sound.audioResource->pause(); s->_sound._audioResource->pause();
break; break;
case kSciAudioResume: case kSciAudioResume:
s->sound.audioResource->resume(); s->_sound._audioResource->resume();
break; break;
case kSciAudioPosition: case kSciAudioPosition:
return make_reg(0, s->sound.audioResource->getAudioPosition()); return make_reg(0, s->_sound._audioResource->getAudioPosition());
case kSciAudioRate: case kSciAudioRate:
s->sound.audioResource->setAudioRate(UKPV(1)); s->_sound._audioResource->setAudioRate(UKPV(1));
break; break;
case kSciAudioVolume: case kSciAudioVolume:
mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, UKPV(1)); mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, UKPV(1));
@ -1048,7 +1048,7 @@ reg_t kDoAudio(EngineState *s, int funct_nr, int argc, reg_t *argv) {
// In SCI1.1: tests for digital audio support // In SCI1.1: tests for digital audio support
return make_reg(0, 1); return make_reg(0, 1);
} else { } else {
s->sound.audioResource->setAudioLang(SKPV(1)); s->_sound._audioResource->setAudioLang(SKPV(1));
} }
break; break;
default: default:
@ -1062,15 +1062,15 @@ reg_t kDoSync(EngineState *s, int funct_nr, int argc, reg_t *argv) {
switch (UKPV(0)) { switch (UKPV(0)) {
case kSciAudioSyncStart: case kSciAudioSyncStart:
if (argc == 3) { // KQ5CD, KQ6 floppy if (argc == 3) { // KQ5CD, KQ6 floppy
if (s->sound.soundSync) { if (s->_sound._soundSync) {
s->resmgr->unlockResource(s->sound.soundSync, s->sound.soundSync->number, kResourceTypeSync); s->resmgr->unlockResource(s->_sound._soundSync, s->_sound._soundSync->number, kResourceTypeSync);
} }
// Load sound sync resource and lock it // Load sound sync resource and lock it
s->sound.soundSync = (ResourceSync *)s->resmgr->findResource(kResourceTypeSync, UKPV(2), 1); s->_sound._soundSync = (ResourceSync *)s->resmgr->findResource(kResourceTypeSync, UKPV(2), 1);
if (s->sound.soundSync) { if (s->_sound._soundSync) {
s->sound.soundSync->startSync(s, argv[1]); s->_sound._soundSync->startSync(s, argv[1]);
} else { } else {
// Notify the scripts to stop sound sync // Notify the scripts to stop sound sync
PUT_SEL32V(argv[1], syncCue, -1); PUT_SEL32V(argv[1], syncCue, -1);
@ -1083,15 +1083,15 @@ reg_t kDoSync(EngineState *s, int funct_nr, int argc, reg_t *argv) {
} }
break; break;
case kSciAudioSyncNext: case kSciAudioSyncNext:
if (s->sound.soundSync) { if (s->_sound._soundSync) {
s->sound.soundSync->nextSync(s, argv[1]); s->_sound._soundSync->nextSync(s, argv[1]);
} }
break; break;
case kSciAudioSyncStop: case kSciAudioSyncStop:
if (s->sound.soundSync) { if (s->_sound._soundSync) {
s->sound.soundSync->stopSync(); s->_sound._soundSync->stopSync();
s->resmgr->unlockResource(s->sound.soundSync, s->sound.soundSync->number, kResourceTypeSync); s->resmgr->unlockResource(s->_sound._soundSync, s->_sound._soundSync->number, kResourceTypeSync);
s->sound.soundSync = NULL; s->_sound._soundSync = NULL;
} }
break; break;
default: default:

View file

@ -231,8 +231,8 @@ void syncWithSerializer(Common::Serializer &s, Class &obj) {
sync_reg_t(s, obj.reg); sync_reg_t(s, obj.reg);
} }
static void sync_sfx_state_t(Common::Serializer &s, sfx_state_t &obj) { static void sync_sfx_state_t(Common::Serializer &s, SfxState &obj) {
sync_songlib_t(s, obj.songlib); sync_songlib_t(s, obj._songlib);
} }
static void sync_SavegameMetadata(Common::Serializer &s, SavegameMetadata &obj) { static void sync_SavegameMetadata(Common::Serializer &s, SavegameMetadata &obj) {
@ -268,7 +268,7 @@ void EngineState::saveLoadWithSerializer(Common::Serializer &s) {
syncArray<Class>(s, _classtable); syncArray<Class>(s, _classtable);
sync_sfx_state_t(s, sound); sync_sfx_state_t(s, _sound);
} }
void LocalVariables::saveLoadWithSerializer(Common::Serializer &s) { void LocalVariables::saveLoadWithSerializer(Common::Serializer &s) {
@ -695,10 +695,10 @@ static void reconstruct_sounds(EngineState *s) {
song_t *seeker; song_t *seeker;
SongIteratorType it_type = s->resmgr->_sciVersion >= SCI_VERSION_01 ? SCI_SONG_ITERATOR_TYPE_SCI1 : SCI_SONG_ITERATOR_TYPE_SCI0; SongIteratorType it_type = s->resmgr->_sciVersion >= SCI_VERSION_01 ? SCI_SONG_ITERATOR_TYPE_SCI1 : SCI_SONG_ITERATOR_TYPE_SCI0;
if (s->sound.songlib.lib) if (s->_sound._songlib.lib)
seeker = *(s->sound.songlib.lib); seeker = *(s->_sound._songlib.lib);
else { else {
song_lib_init(&s->sound.songlib); song_lib_init(&s->_sound._songlib);
seeker = NULL; seeker = NULL;
} }
@ -720,7 +720,7 @@ static void reconstruct_sounds(EngineState *s) {
oldstatus = seeker->status; oldstatus = seeker->status;
seeker->status = SOUND_STATUS_STOPPED; seeker->status = SOUND_STATUS_STOPPED;
seeker->it = ff; seeker->it = ff;
sfx_song_set_status(&s->sound, seeker->handle, oldstatus); sfx_song_set_status(&s->_sound, seeker->handle, oldstatus);
seeker = seeker->next; seeker = seeker->next;
} }
} }
@ -770,7 +770,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
retval->saveLoadWithSerializer(ser); // FIXME: Error handling? retval->saveLoadWithSerializer(ser); // FIXME: Error handling?
sfx_exit(&s->sound); sfx_exit(&s->_sound);
// Set exec stack base to zero // Set exec stack base to zero
retval->execution_stack_base = 0; retval->execution_stack_base = 0;
@ -783,11 +783,11 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
retval->resmgr = s->resmgr; retval->resmgr = s->resmgr;
temp = retval->sound.songlib; temp = retval->_sound._songlib;
sfx_init(&retval->sound, retval->resmgr, s->sfx_init_flags); sfx_init(&retval->_sound, retval->resmgr, s->sfx_init_flags);
retval->sfx_init_flags = s->sfx_init_flags; retval->sfx_init_flags = s->sfx_init_flags;
song_lib_free(retval->sound.songlib); song_lib_free(retval->_sound._songlib);
retval->sound.songlib = temp; retval->_sound._songlib = temp;
_reset_graphics_input(retval); _reset_graphics_input(retval);
reconstruct_stack(retval); reconstruct_stack(retval);
@ -851,11 +851,11 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
retval->pic_priority_table = (int*)gfxop_get_pic_metainfo(retval->gfx_state); retval->pic_priority_table = (int*)gfxop_get_pic_metainfo(retval->gfx_state);
retval->_gameName = obj_get_name(retval, retval->game_obj); retval->_gameName = obj_get_name(retval, retval->game_obj);
retval->sound.it = NULL; retval->_sound._it = NULL;
retval->sound.flags = s->sound.flags; retval->_sound._flags = s->_sound._flags;
retval->sound.song = NULL; retval->_sound._song = NULL;
retval->sound.suspended = s->sound.suspended; retval->_sound._suspended = s->_sound._suspended;
retval->sound.debug = s->sound.debug; retval->_sound._debug = s->_sound._debug;
reconstruct_sounds(retval); reconstruct_sounds(retval);
// Message state: // Message state:

View file

@ -555,7 +555,7 @@ int objinfo(EngineState *s, reg_t pos);
void song_lib_dump(const songlib_t &songlib, int line); void song_lib_dump(const songlib_t &songlib, int line);
static int c_songlib_print(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) { static int c_songlib_print(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
song_lib_dump(s->sound.songlib, __LINE__); song_lib_dump(s->_sound._songlib, __LINE__);
return 0; return 0;
} }
@ -2343,7 +2343,7 @@ static int c_sfx_debuglog(EngineState *s, const Common::Array<cmd_param_t> &cmdP
{"Song cue polling and delivery", 'c', SFX_DEBUG_CUES} {"Song cue polling and delivery", 'c', SFX_DEBUG_CUES}
}; };
return c_handle_config_update(sfx_debug_modes, SFX_DEBUG_MODES, "sound subsystem", (int *)&(s->sound.debug), cmdParams); return c_handle_config_update(sfx_debug_modes, SFX_DEBUG_MODES, "sound subsystem", (int *)&(s->_sound._debug), cmdParams);
} }
static int c_sfx_remove(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) { static int c_sfx_remove(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
@ -2351,8 +2351,8 @@ static int c_sfx_remove(EngineState *s, const Common::Array<cmd_param_t> &cmdPar
int handle = FROBNICATE_HANDLE(id); int handle = FROBNICATE_HANDLE(id);
if (id.segment) { if (id.segment) {
sfx_song_set_status(&s->sound, handle, SOUND_STATUS_STOPPED); sfx_song_set_status(&s->_sound, handle, SOUND_STATUS_STOPPED);
sfx_remove_song(&s->sound, handle); sfx_remove_song(&s->_sound, handle);
PUT_SEL32V(id, signal, -1); PUT_SEL32V(id, signal, -1);
PUT_SEL32V(id, nodePtr, 0); PUT_SEL32V(id, nodePtr, 0);
PUT_SEL32V(id, handle, 0); PUT_SEL32V(id, handle, 0);
@ -3250,7 +3250,7 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *
const char *commandstring; const char *commandstring;
// Suspend music playing // Suspend music playing
sfx_suspend(&s->sound, 1); sfx_suspend(&s->_sound, 1);
commandstring = _debug_get_input(); commandstring = _debug_get_input();
@ -3263,7 +3263,7 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *
sciprintf("\n"); sciprintf("\n");
// Resume music playing // Resume music playing
sfx_suspend(&s->sound, 0); sfx_suspend(&s->_sound, 0);
} }
} }

View file

@ -37,7 +37,6 @@ EngineState::EngineState() : _dirseeker(this) {
gfx_state = 0; gfx_state = 0;
old_screen = 0; old_screen = 0;
memset(&sound, 0, sizeof(sound)); // FIXME: Remove this once/if we C++ify sfx_state_t
sfx_init_flags = 0; sfx_init_flags = 0;
sound_volume = 0; sound_volume = 0;
sound_mute = 0; sound_mute = 0;

View file

@ -129,7 +129,7 @@ public:
GfxState *gfx_state; /**< Graphics state and driver */ GfxState *gfx_state; /**< Graphics state and driver */
gfx_pixmap_t *old_screen; /**< Old screen content: Stored during kDrawPic() for kAnimate() */ gfx_pixmap_t *old_screen; /**< Old screen content: Stored during kDrawPic() for kAnimate() */
sfx_state_t sound; /**< sound subsystem */ SfxState _sound; /**< sound subsystem */
int sfx_init_flags; /**< flags the sfx subsystem was initialised with */ int sfx_init_flags; /**< flags the sfx subsystem was initialised with */
unsigned int sound_volume; /**< 0x0 -> 0xf Current volume of sound system */ unsigned int sound_volume; /**< 0x0 -> 0xf Current volume of sound system */
unsigned int sound_mute; /**< 0 = not, else == saved value */ unsigned int sound_mute; /**< 0 = not, else == saved value */

View file

@ -63,10 +63,10 @@ int sfx_get_player_polyphony() {
return 0; return 0;
} }
static void _freeze_time(sfx_state_t *self) { static void _freeze_time(SfxState *self) {
/* Freezes the top song delay time */ /* Freezes the top song delay time */
const Audio::Timestamp ctime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC); const Audio::Timestamp ctime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC);
song_t *song = self->song; song_t *song = self->_song;
while (song) { while (song) {
song->_delay = song->_wakeupTime.frameDiff(ctime); song->_delay = song->_wakeupTime.frameDiff(ctime);
@ -77,13 +77,25 @@ static void _freeze_time(sfx_state_t *self) {
} }
} }
static void _thaw_time(SfxState *self) {
/* inverse of _freeze_time() */
const Audio::Timestamp ctime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC);
song_t *song = self->_song;
while (song) {
song->_wakeupTime = ctime.addFrames(song->_delay);
song = song->next_playing;
}
}
#if 0 #if 0
// Unreferenced - removed // Unreferenced - removed
static void _dump_playing_list(sfx_state_t *self, char *msg) { static void _dump_playing_list(SfxState *self, char *msg) {
song_t *song = self->song; song_t *song = self->_song;
fprintf(stderr, "[] Song list : [ "); fprintf(stderr, "[] Song list : [ ");
song = *(self->songlib.lib); song = *(self->_songlib.lib);
while (song) { while (song) {
fprintf(stderr, "%08lx:%d ", song->handle, song->status); fprintf(stderr, "%08lx:%d ", song->handle, song->status);
song = song->next_playing; song = song->next_playing;
@ -101,12 +113,12 @@ static void _dump_playing_list(sfx_state_t *self, char *msg) {
} }
#endif #endif
static void _dump_songs(sfx_state_t *self) { static void _dump_songs(SfxState *self) {
#if 0 #if 0
song_t *song = self->song; song_t *song = self->_song;
fprintf(stderr, "Cue iterators:\n"); fprintf(stderr, "Cue iterators:\n");
song = *(self->songlib.lib); song = *(self->_songlib.lib);
while (song) { while (song) {
fprintf(stderr, " **\tHandle %08x (p%d): status %d\n", fprintf(stderr, " **\tHandle %08x (p%d): status %d\n",
song->handle, song->priority, song->status); song->handle, song->priority, song->status);
@ -121,20 +133,8 @@ static void _dump_songs(sfx_state_t *self) {
#endif #endif
} }
static void _thaw_time(sfx_state_t *self) { static int is_playing(SfxState *self, song_t *song) {
/* inverse of _freeze_time() */ song_t *playing_song = self->_song;
const Audio::Timestamp ctime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC);
song_t *song = self->song;
while (song) {
song->_wakeupTime = ctime.addFrames(song->_delay);
song = song->next_playing;
}
}
static int is_playing(sfx_state_t *self, song_t *song) {
song_t *playing_song = self->song;
/* _dump_playing_list(self, "is-playing");*/ /* _dump_playing_list(self, "is-playing");*/
@ -146,7 +146,7 @@ static int is_playing(sfx_state_t *self, song_t *song) {
return 0; return 0;
} }
static void _sfx_set_song_status(sfx_state_t *self, song_t *song, int status) { static void _sfx_set_song_status(SfxState *self, song_t *song, int status) {
const Audio::Timestamp ctime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC); const Audio::Timestamp ctime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC);
switch (status) { switch (status) {
@ -190,10 +190,10 @@ static void _sfx_set_song_status(sfx_state_t *self, song_t *song, int status) {
} }
/* Update internal state iff only one song may be played */ /* Update internal state iff only one song may be played */
static void _update_single_song(sfx_state_t *self) { static void _update_single_song(SfxState *self) {
song_t *newsong = song_lib_find_active(self->songlib); song_t *newsong = song_lib_find_active(self->_songlib);
if (newsong != self->song) { if (newsong != self->_song) {
_freeze_time(self); /* Store song delay time */ _freeze_time(self); /* Store song delay time */
if (player) if (player)
@ -212,18 +212,18 @@ static void _update_single_song(sfx_state_t *self) {
} else { } else {
/* Turn off sound */ /* Turn off sound */
} }
if (self->song) { if (self->_song) {
if (self->song->status == SOUND_STATUS_PLAYING) if (self->_song->status == SOUND_STATUS_PLAYING)
_sfx_set_song_status(self, newsong, _sfx_set_song_status(self, newsong,
SOUND_STATUS_WAITING); SOUND_STATUS_WAITING);
} }
if (self->debug & SFX_DEBUG_SONGS) { if (self->_debug & SFX_DEBUG_SONGS) {
sciprintf("[SFX] Changing active song:"); sciprintf("[SFX] Changing active song:");
if (!self->song) if (!self->_song)
sciprintf(" New song:"); sciprintf(" New song:");
else else
sciprintf(" pausing %08lx, now playing", self->song->handle); sciprintf(" pausing %08lx, now playing", self->_song->handle);
if (newsong) if (newsong)
sciprintf(" %08lx\n", newsong->handle); sciprintf(" %08lx\n", newsong->handle);
@ -232,7 +232,7 @@ static void _update_single_song(sfx_state_t *self) {
} }
self->song = newsong; self->_song = newsong;
_thaw_time(self); /* Recover song delay time */ _thaw_time(self); /* Recover song delay time */
if (newsong && player) { if (newsong && player) {
@ -244,10 +244,10 @@ static void _update_single_song(sfx_state_t *self) {
} }
static void _update_multi_song(sfx_state_t *self) { static void _update_multi_song(SfxState *self) {
song_t *oldfirst = self->song; song_t *oldfirst = self->_song;
song_t *oldseeker; song_t *oldseeker;
song_t *newsong = song_lib_find_active(self->songlib); song_t *newsong = song_lib_find_active(self->_songlib);
song_t *newseeker; song_t *newseeker;
song_t not_playing_anymore; /* Dummy object, referenced by song_t not_playing_anymore; /* Dummy object, referenced by
** songs which are no longer ** songs which are no longer
@ -279,7 +279,7 @@ static void _update_multi_song(sfx_state_t *self) {
for (newseeker = newsong; newseeker; for (newseeker = newsong; newseeker;
newseeker = newseeker->next_playing) { newseeker = newseeker->next_playing) {
newseeker->next_playing newseeker->next_playing
= song_lib_find_next_active(self->songlib, = song_lib_find_next_active(self->_songlib,
newseeker); newseeker);
if (newseeker == newseeker->next_playing) { BREAKPOINT(); } if (newseeker == newseeker->next_playing) { BREAKPOINT(); }
@ -287,7 +287,7 @@ static void _update_multi_song(sfx_state_t *self) {
/* We now need to update the currently playing song list, because we're /* We now need to update the currently playing song list, because we're
** going to use some functions that require this list to be in a sane ** going to use some functions that require this list to be in a sane
** state (particularly is_playing(), indirectly */ ** state (particularly is_playing(), indirectly */
self->song = newsong; self->_song = newsong;
/* Third, stop all old songs */ /* Third, stop all old songs */
for (oldseeker = oldfirst; oldseeker; for (oldseeker = oldfirst; oldseeker;
@ -295,7 +295,7 @@ static void _update_multi_song(sfx_state_t *self) {
if (oldseeker->next_playing == &not_playing_anymore) { if (oldseeker->next_playing == &not_playing_anymore) {
_sfx_set_song_status(self, oldseeker, _sfx_set_song_status(self, oldseeker,
SOUND_STATUS_SUSPENDED); SOUND_STATUS_SUSPENDED);
if (self->debug & SFX_DEBUG_SONGS) { if (self->_debug & SFX_DEBUG_SONGS) {
sciprintf("[SFX] Stopping song %lx\n", oldseeker->handle); sciprintf("[SFX] Stopping song %lx\n", oldseeker->handle);
} }
if (player && oldseeker->it) if (player && oldseeker->it)
@ -305,7 +305,7 @@ static void _update_multi_song(sfx_state_t *self) {
for (newseeker = newsong; newseeker; newseeker = newseeker->next_playing) { for (newseeker = newsong; newseeker; newseeker = newseeker->next_playing) {
if (newseeker->status != SOUND_STATUS_PLAYING && player) { if (newseeker->status != SOUND_STATUS_PLAYING && player) {
if (self->debug & SFX_DEBUG_SONGS) if (self->_debug & SFX_DEBUG_SONGS)
sciprintf("[SFX] Adding song %lx\n", newseeker->it->ID); sciprintf("[SFX] Adding song %lx\n", newseeker->it->ID);
SongIterator *clonesong = newseeker->it->clone(newseeker->_delay); SongIterator *clonesong = newseeker->it->clone(newseeker->_delay);
@ -315,14 +315,14 @@ static void _update_multi_song(sfx_state_t *self) {
SOUND_STATUS_PLAYING); SOUND_STATUS_PLAYING);
} }
self->song = newsong; self->_song = newsong;
_thaw_time(self); _thaw_time(self);
/* _dump_playing_list(self, "after");*/ /* _dump_playing_list(self, "after");*/
} }
/* Update internal state */ /* Update internal state */
static void _update(sfx_state_t *self) { static void _update(SfxState *self) {
if (self->flags & SFX_STATE_FLAG_MULTIPLAY) if (self->_flags & SFX_STATE_FLAG_MULTIPLAY)
_update_multi_song(self); _update_multi_song(self);
else else
_update_single_song(self); _update_single_song(self);
@ -344,13 +344,13 @@ int sfx_play_iterator_pcm(SongIterator *it, song_handle_t handle) {
#define DELAY (1000000 / SFX_TICKS_PER_SEC) #define DELAY (1000000 / SFX_TICKS_PER_SEC)
void sfx_init(sfx_state_t *self, ResourceManager *resmgr, int flags) { void sfx_init(SfxState *self, ResourceManager *resmgr, int flags) {
song_lib_init(&self->songlib); song_lib_init(&self->_songlib);
self->song = NULL; self->_song = NULL;
self->flags = flags; self->_flags = flags;
self->debug = 0; /* Disable all debugging by default */ self->_debug = 0; /* Disable all debugging by default */
self->soundSync = NULL; self->_soundSync = NULL;
self->audioResource = NULL; self->_audioResource = NULL;
player = NULL; player = NULL;
@ -386,7 +386,7 @@ void sfx_init(sfx_state_t *self, ResourceManager *resmgr, int flags) {
} }
} }
void sfx_exit(sfx_state_t *self) { void sfx_exit(SfxState *self) {
#ifdef DEBUG_SONG_API #ifdef DEBUG_SONG_API
fprintf(stderr, "[sfx-core] Uninitialising\n"); fprintf(stderr, "[sfx-core] Uninitialising\n");
#endif #endif
@ -399,20 +399,20 @@ void sfx_exit(sfx_state_t *self) {
g_system->getMixer()->stopAll(); g_system->getMixer()->stopAll();
song_lib_free(self->songlib); song_lib_free(self->_songlib);
// Delete audio resources for CD talkie games // Delete audio resources for CD talkie games
if (self->audioResource) { if (self->_audioResource) {
delete self->audioResource; delete self->_audioResource;
self->audioResource = 0; self->_audioResource = 0;
} }
} }
void sfx_suspend(sfx_state_t *self, int suspend) { void sfx_suspend(SfxState *self, int suspend) {
#ifdef DEBUG_SONG_API #ifdef DEBUG_SONG_API
fprintf(stderr, "[sfx-core] Suspending? = %d\n", suspend); fprintf(stderr, "[sfx-core] Suspending? = %d\n", suspend);
#endif #endif
if (suspend && (!self->suspended)) { if (suspend && (!self->_suspended)) {
/* suspend */ /* suspend */
_freeze_time(self); _freeze_time(self);
@ -420,7 +420,7 @@ void sfx_suspend(sfx_state_t *self, int suspend) {
player->pause(); player->pause();
/* Suspend song player */ /* Suspend song player */
} else if (!suspend && (self->suspended)) { } else if (!suspend && (self->_suspended)) {
/* unsuspend */ /* unsuspend */
_thaw_time(self); _thaw_time(self);
@ -430,19 +430,19 @@ void sfx_suspend(sfx_state_t *self, int suspend) {
/* Unsuspend song player */ /* Unsuspend song player */
} }
self->suspended = suspend; self->_suspended = suspend;
} }
int sfx_poll(sfx_state_t *self, song_handle_t *handle, int *cue) { int sfx_poll(SfxState *self, song_handle_t *handle, int *cue) {
/* Polls the sound server for cues etc. /* Polls the sound server for cues etc.
** Returns : (int) 0 if the cue queue is empty, SI_LOOP, SI_CUE, or SI_FINISHED otherwise ** Returns : (int) 0 if the cue queue is empty, SI_LOOP, SI_CUE, or SI_FINISHED otherwise
** (song_handle_t) *handle: The affected handle ** (song_handle_t) *handle: The affected handle
** (int) *cue: The sound cue number (if SI_CUE) ** (int) *cue: The sound cue number (if SI_CUE)
*/ */
if (!self->song) if (!self->_song)
return 0; /* No milk today */ return 0; /* No milk today */
*handle = self->song->handle; *handle = self->_song->handle;
#ifdef DEBUG_SONG_API #ifdef DEBUG_SONG_API
fprintf(stderr, "[sfx-core] Polling any (%08lx)\n", *handle); fprintf(stderr, "[sfx-core] Polling any (%08lx)\n", *handle);
@ -450,9 +450,9 @@ int sfx_poll(sfx_state_t *self, song_handle_t *handle, int *cue) {
return sfx_poll_specific(self, *handle, cue); return sfx_poll_specific(self, *handle, cue);
} }
int sfx_poll_specific(sfx_state_t *self, song_handle_t handle, int *cue) { int sfx_poll_specific(SfxState *self, song_handle_t handle, int *cue) {
const Audio::Timestamp ctime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC); const Audio::Timestamp ctime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC);
song_t *song = self->song; song_t *song = self->_song;
while (song && song->handle != handle) while (song && song->handle != handle)
song = song->next_playing; song = song->next_playing;
@ -460,7 +460,7 @@ int sfx_poll_specific(sfx_state_t *self, song_handle_t handle, int *cue) {
if (!song) if (!song)
return 0; /* Song not playing */ return 0; /* Song not playing */
if (self->debug & SFX_DEBUG_CUES) { if (self->_debug & SFX_DEBUG_CUES) {
fprintf(stderr, "[SFX:CUE] Polled song %08lx ", handle); fprintf(stderr, "[SFX:CUE] Polled song %08lx ", handle);
} }
@ -480,7 +480,7 @@ int sfx_poll_specific(sfx_state_t *self, song_handle_t handle, int *cue) {
case SI_LOOP: case SI_LOOP:
case SI_RELATIVE_CUE: case SI_RELATIVE_CUE:
case SI_ABSOLUTE_CUE: case SI_ABSOLUTE_CUE:
if (self->debug & SFX_DEBUG_CUES) { if (self->_debug & SFX_DEBUG_CUES) {
sciprintf(" => "); sciprintf(" => ");
if (result == SI_FINISHED) if (result == SI_FINISHED)
@ -504,7 +504,7 @@ int sfx_poll_specific(sfx_state_t *self, song_handle_t handle, int *cue) {
break; break;
} }
} }
if (self->debug & SFX_DEBUG_CUES) { if (self->_debug & SFX_DEBUG_CUES) {
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
} }
@ -514,8 +514,8 @@ int sfx_poll_specific(sfx_state_t *self, song_handle_t handle, int *cue) {
/* Song basics */ /* Song basics */
/*****************/ /*****************/
int sfx_add_song(sfx_state_t *self, SongIterator *it, int priority, song_handle_t handle, int number) { int sfx_add_song(SfxState *self, SongIterator *it, int priority, song_handle_t handle, int number) {
song_t *song = song_lib_find(self->songlib, handle); song_t *song = song_lib_find(self->_songlib, handle);
#ifdef DEBUG_SONG_API #ifdef DEBUG_SONG_API
fprintf(stderr, "[sfx-core] Adding song: %08lx at %d, it=%p\n", handle, priority, it); fprintf(stderr, "[sfx-core] Adding song: %08lx at %d, it=%p\n", handle, priority, it);
@ -545,7 +545,7 @@ int sfx_add_song(sfx_state_t *self, SongIterator *it, int priority, song_handle_
delete it; delete it;
return -1; return -1;
} else } else
song_lib_remove(self->songlib, handle); /* No duplicates */ song_lib_remove(self->_songlib, handle); /* No duplicates */
} }
@ -554,21 +554,21 @@ int sfx_add_song(sfx_state_t *self, SongIterator *it, int priority, song_handle_
song->hold = 0; song->hold = 0;
song->loops = 0; song->loops = 0;
song->_wakeupTime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC); song->_wakeupTime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC);
song_lib_add(self->songlib, song); song_lib_add(self->_songlib, song);
self->song = NULL; /* As above */ self->_song = NULL; /* As above */
_update(self); _update(self);
return 0; return 0;
} }
void sfx_remove_song(sfx_state_t *self, song_handle_t handle) { void sfx_remove_song(SfxState *self, song_handle_t handle) {
#ifdef DEBUG_SONG_API #ifdef DEBUG_SONG_API
fprintf(stderr, "[sfx-core] Removing song: %08lx\n", handle); fprintf(stderr, "[sfx-core] Removing song: %08lx\n", handle);
#endif #endif
if (self->song && self->song->handle == handle) if (self->_song && self->_song->handle == handle)
self->song = NULL; self->_song = NULL;
song_lib_remove(self->songlib, handle); song_lib_remove(self->_songlib, handle);
_update(self); _update(self);
} }
@ -580,8 +580,8 @@ void sfx_remove_song(sfx_state_t *self, song_handle_t handle) {
#define ASSERT_SONG(s) if (!(s)) { warning("Looking up song handle %08lx failed in %s, L%d", handle, __FILE__, __LINE__); return; } #define ASSERT_SONG(s) if (!(s)) { warning("Looking up song handle %08lx failed in %s, L%d", handle, __FILE__, __LINE__); return; }
void sfx_song_set_status(sfx_state_t *self, song_handle_t handle, int status) { void sfx_song_set_status(SfxState *self, song_handle_t handle, int status) {
song_t *song = song_lib_find(self->songlib, handle); song_t *song = song_lib_find(self->_songlib, handle);
ASSERT_SONG(song); ASSERT_SONG(song);
#ifdef DEBUG_SONG_API #ifdef DEBUG_SONG_API
fprintf(stderr, "[sfx-core] Setting song status to %d" fprintf(stderr, "[sfx-core] Setting song status to %d"
@ -593,12 +593,12 @@ void sfx_song_set_status(sfx_state_t *self, song_handle_t handle, int status) {
_update(self); _update(self);
} }
void sfx_song_set_fade(sfx_state_t *self, song_handle_t handle, void sfx_song_set_fade(SfxState *self, song_handle_t handle,
fade_params_t *params) { fade_params_t *params) {
#ifdef DEBUG_SONG_API #ifdef DEBUG_SONG_API
static const char *stopmsg[] = {"??? Should not happen", "Do not stop afterwards", "Stop afterwards"}; static const char *stopmsg[] = {"??? Should not happen", "Do not stop afterwards", "Stop afterwards"};
#endif #endif
song_t *song = song_lib_find(self->songlib, handle); song_t *song = song_lib_find(self->_songlib, handle);
ASSERT_SONG(song); ASSERT_SONG(song);
@ -614,8 +614,8 @@ void sfx_song_set_fade(sfx_state_t *self, song_handle_t handle,
_update(self); _update(self);
} }
void sfx_song_renice(sfx_state_t *self, song_handle_t handle, int priority) { void sfx_song_renice(SfxState *self, song_handle_t handle, int priority) {
song_t *song = song_lib_find(self->songlib, handle); song_t *song = song_lib_find(self->_songlib, handle);
ASSERT_SONG(song); ASSERT_SONG(song);
#ifdef DEBUG_SONG_API #ifdef DEBUG_SONG_API
fprintf(stderr, "[sfx-core] Renicing song %08lx to %d\n", fprintf(stderr, "[sfx-core] Renicing song %08lx to %d\n",
@ -627,8 +627,8 @@ void sfx_song_renice(sfx_state_t *self, song_handle_t handle, int priority) {
_update(self); _update(self);
} }
void sfx_song_set_loops(sfx_state_t *self, song_handle_t handle, int loops) { void sfx_song_set_loops(SfxState *self, song_handle_t handle, int loops) {
song_t *song = song_lib_find(self->songlib, handle); song_t *song = song_lib_find(self->_songlib, handle);
SongIterator::Message msg = SongIterator::Message(handle, SIMSG_SET_LOOPS(loops)); SongIterator::Message msg = SongIterator::Message(handle, SIMSG_SET_LOOPS(loops));
ASSERT_SONG(song); ASSERT_SONG(song);
@ -644,8 +644,8 @@ void sfx_song_set_loops(sfx_state_t *self, song_handle_t handle, int loops) {
player->iterator_message(msg); player->iterator_message(msg);
} }
void sfx_song_set_hold(sfx_state_t *self, song_handle_t handle, int hold) { void sfx_song_set_hold(SfxState *self, song_handle_t handle, int hold) {
song_t *song = song_lib_find(self->songlib, handle); song_t *song = song_lib_find(self->_songlib, handle);
SongIterator::Message msg = SongIterator::Message(handle, SIMSG_SET_HOLD(hold)); SongIterator::Message msg = SongIterator::Message(handle, SIMSG_SET_HOLD(hold));
ASSERT_SONG(song); ASSERT_SONG(song);
@ -668,7 +668,7 @@ static const int MIDI_cmdlen[16] = {0, 0, 0, 0, 0, 0, 0, 0,
static const song_handle_t midi_send_base = 0xffff0000; static const song_handle_t midi_send_base = 0xffff0000;
Common::Error sfx_send_midi(sfx_state_t *self, song_handle_t handle, int channel, Common::Error sfx_send_midi(SfxState *self, song_handle_t handle, int channel,
int command, int arg1, int arg2) { int command, int arg1, int arg2) {
byte buffer[5]; byte buffer[5];
@ -713,21 +713,21 @@ Common::Error sfx_send_midi(sfx_state_t *self, song_handle_t handle, int channel
return Common::kNoError; return Common::kNoError;
} }
int sfx_get_volume(sfx_state_t *self) { int sfx_get_volume(SfxState *self) {
warning("FIXME: Implement volume"); warning("FIXME: Implement volume");
return 0; return 0;
} }
void sfx_set_volume(sfx_state_t *self, int volume) { void sfx_set_volume(SfxState *self, int volume) {
warning("FIXME: Implement volume"); warning("FIXME: Implement volume");
} }
void sfx_all_stop(sfx_state_t *self) { void sfx_all_stop(SfxState *self) {
#ifdef DEBUG_SONG_API #ifdef DEBUG_SONG_API
fprintf(stderr, "[sfx-core] All stop\n"); fprintf(stderr, "[sfx-core] All stop\n");
#endif #endif
song_lib_free(self->songlib); song_lib_free(self->_songlib);
_update(self); _update(self);
} }

View file

@ -48,61 +48,62 @@ struct fade_params_t;
#define SFX_DEBUG_CUES (1 << 1) /* Debug cues, loops, and #define SFX_DEBUG_CUES (1 << 1) /* Debug cues, loops, and
** song completions */ ** song completions */
struct sfx_state_t { class SfxState {
SongIterator *it; /* The song iterator at the heart of things */ public: // FIXME, make private
unsigned int flags; /* SFX_STATE_FLAG_* */ SongIterator *_it; /**< The song iterator at the heart of things */
songlib_t songlib; /* Song library */ uint _flags; /**< SFX_STATE_FLAG_* */
song_t *song; /* Active song, or start of active song chain */ songlib_t _songlib; /**< Song library */
int suspended; /* Whether we are suspended */ song_t *_song; /**< Active song, or start of active song chain */
unsigned int debug; /* Debug flags */ bool _suspended; /**< Whether we are suspended */
ResourceSync *soundSync; /* Used by kDoSync for speech syncing in CD talkie games */ uint _debug; /**< Debug flags */
AudioResource *audioResource; /* Used for audio resources in CD talkie games */ ResourceSync *_soundSync; /**< Used by kDoSync for speech syncing in CD talkie games */
AudioResource *_audioResource; /**< Used for audio resources in CD talkie games */
}; };
/***********/ /***********/
/* General */ /* General */
/***********/ /***********/
void sfx_init(sfx_state_t *self, ResourceManager *resmgr, int flags); void sfx_init(SfxState *self, ResourceManager *resmgr, int flags);
/* Initializes the sound engine /* Initializes the sound engine
** Parameters: (ResourceManager *) resmgr: Resource manager for initialization ** Parameters: (ResourceManager *) resmgr: Resource manager for initialization
** (int) flags: SFX_STATE_FLAG_* ** (int) flags: SFX_STATE_FLAG_*
*/ */
void sfx_exit(sfx_state_t *self); void sfx_exit(SfxState *self);
/* Deinitializes the sound subsystem /* Deinitializes the sound subsystem
*/ */
void sfx_suspend(sfx_state_t *self, int suspend); void sfx_suspend(SfxState *self, int suspend);
/* Suspends/unsuspends the sound sybsystem /* Suspends/unsuspends the sound sybsystem
** Parameters: (int) suspend: Whether to suspend (non-null) or to unsuspend ** Parameters: (int) suspend: Whether to suspend (non-null) or to unsuspend
*/ */
int sfx_poll(sfx_state_t *self, song_handle_t *handle, int *cue); int sfx_poll(SfxState *self, song_handle_t *handle, int *cue);
/* Polls the sound server for cues etc. /* Polls the sound server for cues etc.
** Returns : (int) 0 if the cue queue is empty, SI_LOOP, SI_CUE, or SI_FINISHED otherwise ** Returns : (int) 0 if the cue queue is empty, SI_LOOP, SI_CUE, or SI_FINISHED otherwise
** (song_handle_t) *handle: The affected handle ** (song_handle_t) *handle: The affected handle
** (int) *cue: The sound cue number (if SI_CUE), or the loop number (if SI_LOOP) ** (int) *cue: The sound cue number (if SI_CUE), or the loop number (if SI_LOOP)
*/ */
int sfx_poll_specific(sfx_state_t *self, song_handle_t handle, int *cue); int sfx_poll_specific(SfxState *self, song_handle_t handle, int *cue);
/* Polls the sound server for cues etc. /* Polls the sound server for cues etc.
** Parameters: (song_handle_t) handle: The handle to poll ** Parameters: (song_handle_t) handle: The handle to poll
** Returns : (int) 0 if the cue queue is empty, SI_LOOP, SI_CUE, or SI_FINISHED otherwise ** Returns : (int) 0 if the cue queue is empty, SI_LOOP, SI_CUE, or SI_FINISHED otherwise
** (int) *cue: The sound cue number (if SI_CUE), or the loop number (if SI_LOOP) ** (int) *cue: The sound cue number (if SI_CUE), or the loop number (if SI_LOOP)
*/ */
int sfx_get_volume(sfx_state_t *self); int sfx_get_volume(SfxState *self);
/* Determines the current global volume settings /* Determines the current global volume settings
** Returns : (int) The global volume, between 0 (silent) and 127 (max. volume) ** Returns : (int) The global volume, between 0 (silent) and 127 (max. volume)
*/ */
void sfx_set_volume(sfx_state_t *self, int volume); void sfx_set_volume(SfxState *self, int volume);
/* Determines the current global volume settings /* Determines the current global volume settings
** Parameters: (int) volume: The new global volume, between 0 and 127 (see above) ** Parameters: (int) volume: The new global volume, between 0 and 127 (see above)
*/ */
void sfx_all_stop(sfx_state_t *self); void sfx_all_stop(SfxState *self);
/* Stops all songs currently playing, purges song library /* Stops all songs currently playing, purges song library
*/ */
@ -111,7 +112,7 @@ void sfx_all_stop(sfx_state_t *self);
/* Song basics */ /* Song basics */
/*****************/ /*****************/
int sfx_add_song(sfx_state_t *self, SongIterator *it, int priority, song_handle_t handle, int resnum); int sfx_add_song(SfxState *self, SongIterator *it, int priority, song_handle_t handle, int resnum);
/* Adds a song to the internal sound library /* Adds a song to the internal sound library
** Parameters: (SongIterator *) it: The iterator describing the song ** Parameters: (SongIterator *) it: The iterator describing the song
** (int) priority: Initial song priority (higher <-> more important) ** (int) priority: Initial song priority (higher <-> more important)
@ -120,7 +121,7 @@ int sfx_add_song(sfx_state_t *self, SongIterator *it, int priority, song_handle_
*/ */
void sfx_remove_song(sfx_state_t *self, song_handle_t handle); void sfx_remove_song(SfxState *self, song_handle_t handle);
/* Deletes a song and its associated song iterator from the song queue /* Deletes a song and its associated song iterator from the song queue
** Parameters: (song_handle_t) handle: The song to remove ** Parameters: (song_handle_t) handle: The song to remove
*/ */
@ -131,7 +132,7 @@ void sfx_remove_song(sfx_state_t *self, song_handle_t handle);
/**********************/ /**********************/
void sfx_song_set_status(sfx_state_t *self, song_handle_t handle, int status); void sfx_song_set_status(SfxState *self, song_handle_t handle, int status);
/* Sets the song status, i.e. whether it is playing, suspended, or stopped. /* Sets the song status, i.e. whether it is playing, suspended, or stopped.
** Parameters: (song_handle_t) handle: Handle of the song to modify ** Parameters: (song_handle_t) handle: Handle of the song to modify
** (int) status: The song status the song should assume ** (int) status: The song status the song should assume
@ -139,25 +140,25 @@ void sfx_song_set_status(sfx_state_t *self, song_handle_t handle, int status);
** as far as this function is concerned. ** as far as this function is concerned.
*/ */
void sfx_song_renice(sfx_state_t *self, song_handle_t handle, int priority); void sfx_song_renice(SfxState *self, song_handle_t handle, int priority);
/* Sets the new song priority /* Sets the new song priority
** Parameters: (song_handle_t) handle: The handle to modify ** Parameters: (song_handle_t) handle: The handle to modify
** (int) priority: The priority to set ** (int) priority: The priority to set
*/ */
void sfx_song_set_loops(sfx_state_t *self, song_handle_t handle, int loops); void sfx_song_set_loops(SfxState *self, song_handle_t handle, int loops);
/* Sets the number of loops for the specified song /* Sets the number of loops for the specified song
** Parameters: (song_handle_t) handle: The song handle to reference ** Parameters: (song_handle_t) handle: The song handle to reference
** (int) loops: Number of loops to set ** (int) loops: Number of loops to set
*/ */
void sfx_song_set_hold(sfx_state_t *self, song_handle_t handle, int hold); void sfx_song_set_hold(SfxState *self, song_handle_t handle, int hold);
/* Sets the number of loops for the specified song /* Sets the number of loops for the specified song
** Parameters: (song_handle_t) handle: The song handle to reference ** Parameters: (song_handle_t) handle: The song handle to reference
** (int) hold: Number of loops to setn ** (int) hold: Number of loops to setn
*/ */
void sfx_song_set_fade(sfx_state_t *self, song_handle_t handle, fade_params_t *fade_setup); void sfx_song_set_fade(SfxState *self, song_handle_t handle, fade_params_t *fade_setup);
/* Instructs a song to be faded out /* Instructs a song to be faded out
** Parameters: (song_handle_t) handle: The song handle to reference ** Parameters: (song_handle_t) handle: The song handle to reference
** (fade_params_t *) fade_setup: The precise fade-out configuration to use ** (fade_params_t *) fade_setup: The precise fade-out configuration to use
@ -165,7 +166,7 @@ void sfx_song_set_fade(sfx_state_t *self, song_handle_t handle, fade_params_t *f
// Previously undocumented: // Previously undocumented:
Common::Error sfx_send_midi(sfx_state_t *self, song_handle_t handle, int channel, Common::Error sfx_send_midi(SfxState *self, song_handle_t handle, int channel,
int command, int arg1, int arg2); int command, int arg1, int arg2);