Beginnings of music support for Cruise, based on the cine engine sound code (note that the music played isn't yet correct, though)

svn-id: r41506
This commit is contained in:
Paul Gilbert 2009-06-14 03:39:30 +00:00
parent 95f02dd86f
commit 2f3e5f11cb
7 changed files with 867 additions and 219 deletions

View file

@ -52,26 +52,24 @@ CruiseEngine::CruiseEngine(OSystem * syst, const CRUISEGameDescription *gameDesc
_currentVolumeFile = new Common::File(); _currentVolumeFile = new Common::File();
#endif #endif
Common::addDebugChannel(kCruiseDebugScript, "Script", Common::addDebugChannel(kCruiseDebugScript, "scripts", "Scripts debug level");
"Script debug level"); Common::addDebugChannel(kCruiseDebugSound, "sound", "Sound debug level");
// Setup mixer // Setup mixer
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType,
ConfMan.getInt("sfx_volume")); ConfMan.getInt("sfx_volume"));
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType,
ConfMan.getInt("music_volume")); ConfMan.getInt("music_volume"));
_vm = this; _vm = this;
_debugger = new Debugger(); _debugger = new Debugger();
_music = new MusicPlayer(); _sound = new PCSound(_mixer, this);
_sound = new SoundPlayer();
syst->getEventManager()->registerRandomSource(_rnd, "cruise"); syst->getEventManager()->registerRandomSource(_rnd, "cruise");
} }
CruiseEngine::~CruiseEngine() { CruiseEngine::~CruiseEngine() {
delete _debugger; delete _debugger;
delete _music;
delete _sound; delete _sound;
freeSystem(); freeSystem();

View file

@ -57,8 +57,7 @@ private:
bool _preLoad; bool _preLoad;
Debugger *_debugger; Debugger *_debugger;
MidiDriver *_driver; MidiDriver *_driver;
MusicPlayer *_music; PCSound *_sound;
SoundPlayer *_sound;
bool _mt32, _adlib; bool _mt32, _adlib;
int _musicVolume; int _musicVolume;
Common::StringList _langStrings; Common::StringList _langStrings;
@ -90,8 +89,7 @@ public:
uint32 getFeatures() const; uint32 getFeatures() const;
Common::Language getLanguage() const; Common::Language getLanguage() const;
Common::Platform getPlatform() const; Common::Platform getPlatform() const;
MusicPlayer &music() { return *_music; } PCSound &sound() { return *_sound; }
SoundPlayer &sound() { return *_sound; }
bool mt32() const { return _mt32; } bool mt32() const { return _mt32; }
bool adlib() const { return _adlib; } bool adlib() const { return _adlib; }
virtual GUI::Debugger *getDebugger() { return _debugger; } virtual GUI::Debugger *getDebugger() { return _debugger; }
@ -128,7 +126,8 @@ enum {
}; };
enum { enum {
kCruiseDebugScript = 1 << 0 kCruiseDebugScript = 1 << 0,
kCruiseDebugSound = 1 << 1
}; };
enum { enum {

View file

@ -1354,22 +1354,22 @@ int16 Op_LoadSong(void) {
strcpy(buffer, ptr); strcpy(buffer, ptr);
strToUpper(buffer); strToUpper(buffer);
_vm->music().loadSong(buffer); _vm->sound().loadMusic(buffer);
changeCursor(CURSOR_NORMAL); changeCursor(CURSOR_NORMAL);
return 0; return 0;
} }
int16 Op_PlaySong(void) { int16 Op_PlaySong(void) {
if (_vm->music().songLoaded() && !_vm->music().songPlayed()) if (_vm->sound().songLoaded() && !_vm->sound().songPlayed())
_vm->music().startSong(); _vm->sound().playMusic();
return 0; return 0;
} }
int16 Op_StopSong(void) { int16 Op_StopSong(void) {
if (_vm->music().isPlaying()) if (_vm->sound().isPlaying())
_vm->music().stop(); _vm->sound().stopMusic();
return 0; return 0;
} }
@ -1383,12 +1383,12 @@ int16 Op_RestoreSong(void) {
int16 Op_SongSize(void) { int16 Op_SongSize(void) {
int size, oldSize; int size, oldSize;
if (_vm->music().songLoaded()) { if (_vm->sound().songLoaded()) {
byte *pSize = _vm->music().songData() + 470; oldSize = _vm->sound().numOrders();
oldSize = *pSize;
size = popVar(); size = popVar();
if ((size >= 1) && (size < 128)) if ((size >= 1) && (size < 128))
*pSize = size; _vm->sound().setNumOrders(size);
} else } else
oldSize = 0; oldSize = 0;
@ -1399,35 +1399,34 @@ int16 Op_SetPattern(void) {
int value = popVar(); int value = popVar();
int offset = popVar(); int offset = popVar();
if (_vm->music().songLoaded()) { if (_vm->sound().songLoaded()) {
byte *pData = _vm->music().songData(); _vm->sound().setPattern(offset, value);
*(pData + 472 + offset) = (byte)value;
} }
return 0; return 0;
} }
int16 Op_FadeSong(void) { int16 Op_FadeSong(void) {
_vm->music().fadeSong(); _vm->sound().fadeSong();
return 0; return 0;
} }
int16 Op_FreeSong(void) { int16 Op_FreeSong(void) {
_vm->music().stop(); _vm->sound().stopMusic();
_vm->music().removeSong(); _vm->sound().removeMusic();
return 0; return 0;
} }
int16 Op_SongLoop(void) { int16 Op_SongLoop(void) {
bool oldLooping = _vm->music().looping(); bool oldLooping = _vm->sound().musicLooping();
_vm->music().setLoop(popVar() != 0); _vm->sound().musicLoop(popVar() != 0);
return oldLooping; return oldLooping;
} }
int16 Op_SongPlayed(void) { int16 Op_SongPlayed(void) {
return _vm->music().songPlayed(); return _vm->sound().songPlayed();
} }
void setVar49Value(int value) { void setVar49Value(int value) {
@ -1632,7 +1631,7 @@ int16 Op_GetNodeY(void) {
} }
int16 Op_SetVolume(void) { int16 Op_SetVolume(void) {
int oldVolume = _vm->music().getVolume() >> 2; int oldVolume = _vm->sound().getVolume() >> 2;
int newVolume = popVar(); int newVolume = popVar();
// TODO: The game seems to expect the volume will only range from 0 - 63, so for now // TODO: The game seems to expect the volume will only range from 0 - 63, so for now
@ -1641,7 +1640,7 @@ int16 Op_SetVolume(void) {
if (newVolume > 63) newVolume = 63; if (newVolume > 63) newVolume = 63;
if (newVolume >= 0) { if (newVolume >= 0) {
int volume = 63 - newVolume; int volume = 63 - newVolume;
_vm->music().setVolume(volume << 2); _vm->sound().setVolume(volume << 2);
} }
return oldVolume >> 2; return oldVolume >> 2;

View file

@ -207,7 +207,7 @@ int playerMenu(int menuX, int menuY) {
if (playerMenuEnabled && displayOn) { if (playerMenuEnabled && displayOn) {
if (remdo) { if (remdo) {
_vm->music().removeSong(); _vm->sound().stopMusic();
freeStuff2(); freeStuff2();
} }
/* /*

View file

@ -610,7 +610,7 @@ static void syncCT(Common::Serializer &s) {
static void DoSync(Common::Serializer &s) { static void DoSync(Common::Serializer &s) {
syncBasicInfo(s); syncBasicInfo(s);
_vm->music().doSync(s); _vm->sound().doSync(s);
syncPalette(s, newPal); syncPalette(s, newPal);
syncPalette(s, workpal); syncPalette(s, workpal);

File diff suppressed because it is too large Load diff

View file

@ -33,58 +33,45 @@
namespace Cruise { namespace Cruise {
class MusicPlayer { class CruiseEngine;
class PCSoundDriver;
class PCSoundFxPlayer;
class PCSound {
private: private:
byte _channelVolume[16]; Audio::Mixer *_mixer;
int _fadeVolume; CruiseEngine *_vm;
char _musicName[33]; protected:
PCSoundDriver *_soundDriver;
bool _isPlaying; PCSoundFxPlayer *_player;
bool _songPlayed;
bool _looping;
byte _masterVolume;
byte *_songPointer;
// TODO: lib_SongSize
int _songSize;
void patchMidi(uint32 adr, const byte *data, int size);
byte *loadInstrument(const char *name, int i);
public: public:
MusicPlayer(); PCSound(Audio::Mixer *mixer, CruiseEngine *vm);
~MusicPlayer(); virtual ~PCSound();
void setVolume(int volume); virtual void loadMusic(const char *name);
int getVolume() const { return _masterVolume; } virtual void playMusic();
virtual void stopMusic();
virtual void removeMusic();
virtual void fadeOutMusic();
void stop(); virtual void playSound(int channel, int frequency, const uint8 *data, int size, int volumeStep, int stepCount, int volume, int repeat);
void pause(); virtual void startSound(int channelNum, const byte *ptr, int size, int speed, int volume, bool loop);
void resume(); virtual void stopSound(int channel);
// Common public access methods
void doSync(Common::Serializer &s); void doSync(Common::Serializer &s);
void loadSong(const char *name); void stopChannel(int channel);
void startSong(); bool isPlaying() const;
void stopSong(); bool songLoaded() const;
void removeSong(); bool songPlayed() const;
void fadeSong(); void fadeSong();
uint8 numOrders() const;
bool songLoaded() const { return _songPointer != NULL; } void setNumOrders(uint8 v);
bool songPlayed() const { return _songPlayed; } void setPattern(int offset, uint8 value);
bool isPlaying() const { return _isPlaying; } bool musicLooping() const;
bool looping() const { return _looping; } void musicLoop(bool v);
byte *songData() { return _songPointer; } void startNote(int channel, int volume, int speed);
void setPlaying(bool playing) { _isPlaying = playing; } void setVolume(int volume);
void setLoop(bool loop) { _looping = loop; } uint8 getVolume();
};
class SoundPlayer {
public:
SoundPlayer() {}
void startSound(int channelNum, const byte *ptr, int size, int speed, int volume, bool loop) {}
void startNote(int channelNum, int speed, int volume) {}
void stopChannel(int channelNum) {}
}; };
} // End of namespace Cruise } // End of namespace Cruise