aboutsummaryrefslogtreecommitdiff
path: root/engines/sci
diff options
context:
space:
mode:
authorFilippos Karapetis2009-12-19 16:19:53 +0000
committerFilippos Karapetis2009-12-19 16:19:53 +0000
commit0c1b646c7feb649ad8c0f77a5129d5ad1b3d84b1 (patch)
treecd6259241b5be6ee9e3bcc785a673e8a5c2a35bb /engines/sci
parentb32748d81050f66b343b4e028207c2472de49d01 (diff)
downloadscummvm-rg350-0c1b646c7feb649ad8c0f77a5129d5ad1b3d84b1.tar.gz
scummvm-rg350-0c1b646c7feb649ad8c0f77a5129d5ad1b3d84b1.tar.bz2
scummvm-rg350-0c1b646c7feb649ad8c0f77a5129d5ad1b3d84b1.zip
- Started wrapping the current sound code around appropriate defines
- Introduced a new resource type, SoundResource, used in the new music code svn-id: r46421
Diffstat (limited to 'engines/sci')
-rw-r--r--engines/sci/console.cpp12
-rw-r--r--engines/sci/engine/game.cpp6
-rw-r--r--engines/sci/engine/kgraphics.cpp2
-rw-r--r--engines/sci/engine/ksound.cpp1
-rw-r--r--engines/sci/engine/state.h4
-rw-r--r--engines/sci/engine/vm.cpp2
-rw-r--r--engines/sci/resource.cpp81
-rw-r--r--engines/sci/resource.h43
-rw-r--r--engines/sci/sci.h3
9 files changed, 152 insertions, 2 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp
index df7e635751..bf452e8ca9 100644
--- a/engines/sci/console.cpp
+++ b/engines/sci/console.cpp
@@ -40,8 +40,10 @@
#include "sci/gfx/gfx_state_internal.h"
#include "sci/gfx/gfx_widgets.h" // for getPort
#endif
+#ifdef USE_OLD_MUSIC_FUNCTIONS
#include "sci/sfx/songlib.h" // for SongLibrary
#include "sci/sfx/iterator.h" // for SCI_SONG_ITERATOR_TYPE_SCI0
+#endif
#include "sci/sfx/softseq/mididriver.h"
#include "sci/vocabulary.h"
#include "sci/gui/gui.h"
@@ -204,14 +206,18 @@ Console::~Console() {
}
void Console::preEnter() {
+#ifdef USE_OLD_MUSIC_FUNCTIONS
if (_vm->_gamestate)
_vm->_gamestate->_sound.sfx_suspend(true);
+#endif
_vm->_mixer->pauseAll(true);
}
void Console::postEnter() {
+#ifdef USE_OLD_MUSIC_FUNCTIONS
if (_vm->_gamestate)
_vm->_gamestate->_sound.sfx_suspend(false);
+#endif
_vm->_mixer->pauseAll(false);
if (!_videoFile.empty()) {
@@ -1602,6 +1608,7 @@ bool Console::cmdShowMap(int argc, const char **argv) {
bool Console::cmdSongLib(int argc, const char **argv) {
DebugPrintf("Song library:\n");
+#ifdef USE_OLD_MUSIC_FUNCTIONS
Song *seeker = _vm->_gamestate->_sound._songlib._lib;
do {
@@ -1614,6 +1621,7 @@ bool Console::cmdSongLib(int argc, const char **argv) {
DebugPrintf("\n");
} while (seeker);
DebugPrintf("\n");
+#endif
return true;
}
@@ -2523,6 +2531,7 @@ bool Console::cmdIsSample(int argc, const char **argv) {
return true;
}
+#ifdef USE_OLD_MUSIC_FUNCTIONS
Resource *song = _vm->getResourceManager()->findResource(ResourceId(kResourceTypeSound, atoi(argv[1])), 0);
SongIterator *songit;
Audio::AudioStream *data;
@@ -2550,6 +2559,7 @@ bool Console::cmdIsSample(int argc, const char **argv) {
DebugPrintf("Valid song, but not a sample.\n");
delete songit;
+#endif
return true;
}
@@ -2757,6 +2767,7 @@ bool Console::cmdStopSfx(int argc, const char **argv) {
return true;
}
+#ifdef USE_OLD_MUSIC_FUNCTIONS
int handle = id.segment << 16 | id.offset; // frobnicate handle
if (id.segment) {
@@ -2767,6 +2778,7 @@ bool Console::cmdStopSfx(int argc, const char **argv) {
PUT_SEL32V(segMan, id, nodePtr, 0);
PUT_SEL32V(segMan, id, handle, 0);
}
+#endif
return true;
}
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp
index 848e6c5bf7..0d474a9339 100644
--- a/engines/sci/engine/game.cpp
+++ b/engines/sci/engine/game.cpp
@@ -292,11 +292,13 @@ static void _free_graphics_input(EngineState *s) {
#endif
int game_init_sound(EngineState *s, int sound_flags) {
+#ifdef USE_OLD_MUSIC_FUNCTIONS
if (getSciVersion() > SCI_VERSION_0_LATE)
sound_flags |= SFX_STATE_FLAG_MULTIPLAY;
s->sfx_init_flags = sound_flags;
s->_sound.sfx_init(s->resMan, sound_flags);
+#endif
return 0;
}
@@ -417,8 +419,10 @@ int game_init(EngineState *s) {
s->_menubar = new Menubar(); // Create menu bar
#endif
+#ifdef USE_OLD_MUSIC_FUNCTIONS
if (s->sfx_init_flags & SFX_STATE_FLAG_NOSOUND)
game_init_sound(s, 0);
+#endif
// Load game language into printLang property of game object
s->getLanguage();
@@ -429,11 +433,13 @@ int game_init(EngineState *s) {
int game_exit(EngineState *s) {
s->_executionStack.clear();
+#ifdef USE_OLD_MUSIC_FUNCTIONS
if (!s->successor) {
s->_sound.sfx_exit();
// Reinit because some other code depends on having a valid state
game_init_sound(s, SFX_STATE_FLAG_NOSOUND);
}
+#endif
// Note: It's a bad idea to delete the segment manager here
// when loading a game.
diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp
index 61b8d6b886..4f7db7cf34 100644
--- a/engines/sci/engine/kgraphics.cpp
+++ b/engines/sci/engine/kgraphics.cpp
@@ -956,7 +956,9 @@ reg_t kAnimate(EngineState *s, int argc, reg_t *argv) {
bool cycle = (argc > 1) ? ((argv[1].toUint16()) ? true : false) : false;
// Take care of incoming events (kAnimate is called semi-regularly)
+#ifdef USE_OLD_MUSIC_FUNCTIONS
process_sound_events(s);
+#endif
s->_gui->animate(castListReference, cycle, argc, argv);
diff --git a/engines/sci/engine/ksound.cpp b/engines/sci/engine/ksound.cpp
index b471460896..cde332b048 100644
--- a/engines/sci/engine/ksound.cpp
+++ b/engines/sci/engine/ksound.cpp
@@ -25,7 +25,6 @@
#include "sci/sci.h"
#include "sci/engine/state.h"
-#include "sci/sfx/iterator.h"
#include "sci/sfx/soundcmd.h"
#include "sci/engine/kernel.h"
#include "sci/engine/vm.h" // for Object
diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h
index 600717e558..ce304e98d8 100644
--- a/engines/sci/engine/state.h
+++ b/engines/sci/engine/state.h
@@ -43,7 +43,9 @@ namespace Common {
#include "sci/engine/seg_manager.h"
#include "sci/gfx/gfx_system.h"
#include "sci/sfx/audio.h"
+#ifdef USE_OLD_MUSIC_FUNCTIONS
#include "sci/sfx/core.h"
+#endif
#include "sci/sfx/soundcmd.h"
namespace Sci {
@@ -149,7 +151,9 @@ public:
GfxState *gfx_state; /**< Graphics state and driver */
AudioPlayer *_audio;
+#ifdef USE_OLD_MUSIC_FUNCTIONS
SfxState _sound; /**< sound subsystem */
+#endif
SoundCommandParser *_soundCmd;
int sfx_init_flags; /**< flags the sfx subsystem was initialised with */
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index 98569d774e..4011cbcb54 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -1797,7 +1797,9 @@ static EngineState *_game_run(EngineState *&s, int restoring) {
game_exit(s);
script_init_engine(s);
game_init(s);
+#ifdef USE_OLD_MUSIC_FUNCTIONS
s->_sound.sfx_reset_player();
+#endif
_init_stack_base_with_selector(s, s->_kernel->_selectorCache.play);
send_selector(s, s->_gameObj, s->_gameObj, s->stack_base, 2, s->stack_base);
diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp
index 1a8f819926..e5fc218e0e 100644
--- a/engines/sci/resource.cpp
+++ b/engines/sci/resource.cpp
@@ -1808,4 +1808,85 @@ bool ResourceManager::hasSci1Voc900() {
return offset == res->size;
}
+#ifndef USE_OLD_MUSIC_FUNCTIONS
+
+SoundResource::SoundResource(uint32 resNumber, ResourceManager *resMan) : _resMan(resMan) {
+ Resource *res = resNumber ? _resMan->findResource(ResourceId(kResourceTypeSound, resNumber), true) : NULL;
+ if (!res)
+ return;
+
+ _innerResource = res;
+
+ byte *ptr = res->data, *p1;
+ tagChannel *pCh;
+ // count # of tracks
+ nTracks = 0;
+ while ((*ptr++) != 0xFF) {
+ nTracks++;
+ while (*ptr != 0xFF)
+ ptr += 6;
+ ptr++;
+ }
+ aTracks = new tagTrack[nTracks];
+ ptr = res->data;
+ for (int i = 0; i < nTracks; i++) {
+ aTracks[i].type = (kTrackType) * ptr++;
+ // counting # of channels used
+ p1 = ptr;
+ aTracks[i].nChannels = 0;
+ while (*p1 != 0xFF) {
+ p1 += 6;
+ aTracks[i].nChannels++;
+ }
+ aTracks[i].aChannels = new tagChannel[aTracks[i].nChannels];
+ if (aTracks[i].type != 0xF0) // digital track marker - not supported at time
+ {
+ aTracks[i].nDigital = 0xFF; // meanwhile - no ditigal channel associated
+ for (int j = 0; j < aTracks[i].nChannels; j++) {
+ pCh = &aTracks[i].aChannels[j];
+ pCh->unk = READ_LE_UINT16(ptr);
+ pCh->ptr = res->data + READ_LE_UINT16(ptr + 2) + 2;
+ pCh->size = READ_LE_UINT16(ptr + 4) - 2; // not counting channel header
+ pCh->number = *(pCh->ptr - 2);
+ pCh->poly = *(pCh->ptr - 1);
+ pCh->time = pCh->prev = 0;
+ if (pCh->number == 0xFE) // digital channel
+ aTracks[i].nDigital = j;
+ ptr += 6;
+ }
+ }
+ ptr++; // skipping 0xFF that closes channels list
+ }
+ /*
+ digital track ->ptr points to header:
+ [w] sample rate
+ [w] size
+ [w] ? 00 00 maybe compression flag
+ [w] ? size again - decompressed size maybe
+ */
+}
+//----------------------------------------------------
+SoundResource::~SoundResource() {
+ for (int i = 0; i < nTracks; i++)
+ delete[] aTracks[i].aChannels;
+ delete[] aTracks;
+
+ _resMan->unlockResource(_innerResource);
+}
+//----------------------------------------------------
+SoundResource::tagTrack* SoundResource::getTrackByNumber(uint16 number) {
+ if (/*number >= 0 &&*/number < nTracks)
+ return &aTracks[number];
+ return NULL;
+}
+
+SoundResource::tagTrack* SoundResource::getTrackByType(kTrackType type) {
+ for (int i = 0; i < nTracks; i++)
+ if (aTracks[i].type == type)
+ return &aTracks[i];
+ return NULL;
+}
+
+#endif
+
} // End of namespace Sci
diff --git a/engines/sci/resource.h b/engines/sci/resource.h
index 4478bebf31..f25f187c74 100644
--- a/engines/sci/resource.h
+++ b/engines/sci/resource.h
@@ -427,6 +427,49 @@ protected:
void detectSciVersion();
};
+#ifndef USE_OLD_MUSIC_FUNCTIONS
+
+class SoundResource {
+public:
+ enum kTrackType {
+ kTrackAdlib = 0,
+ kTrackGameBlaster = 9,
+ kTrackMT32 = 12,
+ kTrackSpeaker = 18,
+ kTrackTandy = 19
+ };
+
+ struct tagChannel {
+ byte number;
+ byte poly;
+ uint16 unk;
+ uint16 size;
+ byte *ptr;
+ long time;
+ byte prev;
+ };
+
+ struct tagTrack {
+ kTrackType type;
+ byte nDigital;
+ byte nChannels;
+ tagChannel *aChannels;
+ uint sz;
+ };
+public:
+ SoundResource(uint32 resNumber, ResourceManager *resMan);
+ ~SoundResource();
+ tagTrack *getTrackByNumber(uint16 number);
+ tagTrack *getTrackByType(kTrackType type);
+
+private:
+ byte nTracks;
+ tagTrack *aTracks;
+ Resource *_innerResource;
+ ResourceManager *_resMan;
+};
+#endif
+
} // End of namespace Sci
#endif // SCI_SCICORE_RESOURCE_H
diff --git a/engines/sci/sci.h b/engines/sci/sci.h
index 320bb91171..8e8c50d35e 100644
--- a/engines/sci/sci.h
+++ b/engines/sci/sci.h
@@ -41,9 +41,10 @@ struct ADGameDescription;
*/
namespace Sci {
-#define INCLUDE_OLDGFX
// Please uncomment this if you want to use oldgui
//#define USE_OLDGFX
+// Uncomment this to use old music functions
+#define USE_OLD_MUSIC_FUNCTIONS
class Console;
struct EngineState;