2011-02-14 09:37:27 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TSAGE_SOUND_H
|
|
|
|
#define TSAGE_SOUND_H
|
|
|
|
|
|
|
|
#include "common/scummsys.h"
|
2011-05-01 05:23:30 +00:00
|
|
|
#include "common/list.h"
|
2011-02-14 09:37:27 +00:00
|
|
|
#include "tsage/saveload.h"
|
2011-04-27 11:23:47 +00:00
|
|
|
#include "tsage/core.h"
|
2011-02-14 09:37:27 +00:00
|
|
|
|
|
|
|
namespace tSage {
|
|
|
|
|
2011-05-01 05:23:30 +00:00
|
|
|
class Sound;
|
|
|
|
|
2011-05-01 09:28:30 +00:00
|
|
|
#define SOUND_ARR_SIZE 16
|
2011-05-04 13:13:15 +00:00
|
|
|
#define ROLAND_DRIVER_NUM 2
|
|
|
|
#define ADLIB_DRIVER_NUM 3
|
2011-05-01 09:28:30 +00:00
|
|
|
|
2011-05-01 05:23:30 +00:00
|
|
|
struct trackInfoStruct {
|
|
|
|
int count;
|
2011-05-01 09:28:30 +00:00
|
|
|
int rlbList[SOUND_ARR_SIZE];
|
|
|
|
int arr2[SOUND_ARR_SIZE];
|
|
|
|
};
|
|
|
|
|
2011-05-04 13:13:15 +00:00
|
|
|
enum SoundDriverStatus {SNDSTATUS_FAILED = 0, SNDSTATUS_DETECTED = 1, SNDSTATUS_SKIPPED = 2};
|
|
|
|
|
2011-05-01 09:28:30 +00:00
|
|
|
class SoundDriverEntry {
|
|
|
|
public:
|
2011-05-04 13:13:15 +00:00
|
|
|
int driverNum;
|
|
|
|
SoundDriverStatus status;
|
|
|
|
int field2, field6;
|
|
|
|
Common::String shortDescription;
|
|
|
|
Common::String longDescription;
|
2011-05-01 09:28:30 +00:00
|
|
|
};
|
|
|
|
|
2011-05-18 10:32:40 +00:00
|
|
|
struct GroupData {
|
|
|
|
uint32 groupMask;
|
|
|
|
byte v1;
|
|
|
|
byte v2;
|
|
|
|
const byte *pData;
|
|
|
|
};
|
|
|
|
|
2011-05-01 09:28:30 +00:00
|
|
|
class SoundDriver {
|
2011-05-04 13:13:15 +00:00
|
|
|
public:
|
2011-05-01 09:28:30 +00:00
|
|
|
Common::String _shortDescription, _longDescription;
|
2011-05-04 13:13:15 +00:00
|
|
|
int _driverNum;
|
|
|
|
int _minVersion, _maxVersion;
|
2011-05-12 13:09:48 +00:00
|
|
|
// The following fields were originally held in separate arrays in the SoundManager class
|
|
|
|
uint32 _groupMask;
|
2011-05-18 10:32:40 +00:00
|
|
|
const GroupData *_groupOffset;
|
2011-05-01 09:28:30 +00:00
|
|
|
public:
|
2011-05-12 13:09:48 +00:00
|
|
|
SoundDriver();
|
|
|
|
|
2011-05-01 09:28:30 +00:00
|
|
|
const Common::String &getShortDriverDescription() { return _shortDescription; }
|
|
|
|
const Common::String &getLongDriverDescription() { return _longDescription; }
|
|
|
|
|
2011-05-12 13:09:48 +00:00
|
|
|
virtual bool open() { return true; }
|
|
|
|
virtual void close() {}
|
2011-05-18 10:32:40 +00:00
|
|
|
virtual const GroupData *getGroupData() = 0;
|
2011-05-24 10:07:41 +00:00
|
|
|
virtual void setMasterVolume(int volume) {}
|
2011-05-12 13:09:48 +00:00
|
|
|
virtual void installPatchBank(const byte *data) {}
|
2011-05-24 10:07:41 +00:00
|
|
|
virtual void setVolume0(int channel, int v2, int v3, int volume) {}
|
|
|
|
virtual void setVolume1(int channel, int v2, int v3, int volume) {}
|
2011-05-18 10:32:40 +00:00
|
|
|
virtual void poll() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VoiceStructEntry {
|
|
|
|
int _field0;
|
|
|
|
int _field1;
|
|
|
|
SoundDriver *_driver;
|
|
|
|
int _field4;
|
|
|
|
int _field6;
|
|
|
|
int _field8;
|
|
|
|
int _field9;
|
|
|
|
int _fieldA;
|
|
|
|
int _fieldC;
|
|
|
|
int _fieldD;
|
2011-05-24 10:07:41 +00:00
|
|
|
int _fieldE;
|
|
|
|
int _field10;
|
|
|
|
int _field11;
|
|
|
|
int _field12;
|
|
|
|
int _field13;
|
|
|
|
int _field14;
|
|
|
|
int _field16;
|
|
|
|
int _field18;
|
|
|
|
int _field19;
|
|
|
|
|
|
|
|
int _field1A;
|
|
|
|
int _field1B;
|
2011-05-18 10:32:40 +00:00
|
|
|
};
|
|
|
|
|
2011-05-24 10:07:41 +00:00
|
|
|
enum VoiceType {VOICETYPE_0 = 0, VOICETYPE_1 = 1};
|
|
|
|
|
2011-05-18 10:32:40 +00:00
|
|
|
class VoiceStruct {
|
|
|
|
public:
|
2011-05-24 10:07:41 +00:00
|
|
|
VoiceType _voiceType;
|
2011-05-18 10:32:40 +00:00
|
|
|
int _field1;
|
|
|
|
int _field2;
|
|
|
|
|
|
|
|
Common::Array<VoiceStructEntry> _entries;
|
2011-05-01 05:23:30 +00:00
|
|
|
};
|
|
|
|
|
2011-04-13 19:27:46 +00:00
|
|
|
class SoundManager : public SaveListener {
|
2011-05-01 09:28:30 +00:00
|
|
|
private:
|
2011-05-04 13:13:15 +00:00
|
|
|
SoundDriver *instantiateDriver(int driverNum);
|
2011-05-01 05:23:30 +00:00
|
|
|
public:
|
2011-05-01 09:28:30 +00:00
|
|
|
bool __sndmgrReady;
|
2011-05-01 05:23:30 +00:00
|
|
|
int _minVersion, _maxVersion;
|
|
|
|
Common::List<Sound *> _playList;
|
2011-05-02 11:30:20 +00:00
|
|
|
int _field109[SOUND_ARR_SIZE];
|
2011-05-01 05:23:30 +00:00
|
|
|
uint32 _groupMask;
|
2011-05-01 09:28:30 +00:00
|
|
|
int _volume;
|
2011-05-01 05:23:30 +00:00
|
|
|
int _disableCtr;
|
|
|
|
int _suspendCtr;
|
2011-05-12 13:09:48 +00:00
|
|
|
int _suspendedCount;
|
2011-05-04 13:13:15 +00:00
|
|
|
bool _driversDetected;
|
2011-05-01 05:23:30 +00:00
|
|
|
Common::List<Sound *> _soundList;
|
2011-05-04 13:13:15 +00:00
|
|
|
Common::List<SoundDriverEntry> _availableDrivers;
|
2011-05-01 09:28:30 +00:00
|
|
|
Common::List<SoundDriver *> _installedDrivers;
|
2011-05-02 11:30:20 +00:00
|
|
|
int _field89[SOUND_ARR_SIZE];
|
|
|
|
uint16 _groupList[SOUND_ARR_SIZE];
|
|
|
|
int _fieldE9[SOUND_ARR_SIZE];
|
2011-05-18 10:32:40 +00:00
|
|
|
VoiceStruct *_voiceStructPtrs[SOUND_ARR_SIZE];
|
|
|
|
bool _needToRethink;
|
2011-02-14 09:37:27 +00:00
|
|
|
public:
|
2011-05-01 09:28:30 +00:00
|
|
|
SoundManager();
|
|
|
|
~SoundManager();
|
|
|
|
|
2011-05-18 10:32:40 +00:00
|
|
|
void dispatch();
|
2011-05-04 08:47:12 +00:00
|
|
|
virtual void listenerSynchronize(Serializer &s);
|
2011-02-14 09:37:27 +00:00
|
|
|
virtual void postInit();
|
2011-05-18 10:32:40 +00:00
|
|
|
void syncSounds();
|
2011-02-14 09:37:27 +00:00
|
|
|
|
|
|
|
static void saveNotifier(bool postFlag);
|
|
|
|
void saveNotifierProc(bool postFlag);
|
|
|
|
static void loadNotifier(bool postFlag);
|
|
|
|
void loadNotifierProc(bool postFlag);
|
|
|
|
|
2011-05-04 13:13:15 +00:00
|
|
|
void installConfigDrivers();
|
|
|
|
Common::List<SoundDriverEntry> &buildDriverList(bool detectFlag);
|
|
|
|
Common::List<SoundDriverEntry> &getDriverList(bool detectFlag);
|
2011-05-01 09:28:30 +00:00
|
|
|
void dumpDriverList();
|
2011-05-04 13:13:15 +00:00
|
|
|
void installDriver(int driverNum);
|
|
|
|
bool isInstalled(int driverNum) const;
|
|
|
|
void unInstallDriver(int driverNum);
|
|
|
|
void disableSoundServer();
|
|
|
|
void enableSoundServer();
|
|
|
|
void suspendSoundServer();
|
|
|
|
void restartSoundServer();
|
2011-05-01 05:23:30 +00:00
|
|
|
void checkResVersion(const byte *soundData);
|
|
|
|
int determineGroup(const byte *soundData);
|
|
|
|
int extractPriority(const byte *soundData);
|
|
|
|
int extractLoop(const byte *soundData);
|
2011-05-01 09:28:30 +00:00
|
|
|
bool isOnPlayList(Sound *sound);
|
|
|
|
void extractTrackInfo(trackInfoStruct *trackInfo, const byte *soundData, int groupNum);
|
2011-05-01 05:23:30 +00:00
|
|
|
void addToSoundList(Sound *sound);
|
|
|
|
void removeFromSoundList(Sound *sound);
|
|
|
|
void addToPlayList(Sound *sound);
|
|
|
|
void removeFromPlayList(Sound *sound);
|
|
|
|
void rethinkVoiceTypes();
|
|
|
|
void updateSoundVol(Sound *sound);
|
|
|
|
void updateSoundPri(Sound *sound);
|
|
|
|
void updateSoundLoop(Sound *sound);
|
2011-05-01 09:28:30 +00:00
|
|
|
void setMasterVol(int volume);
|
|
|
|
int getMasterVol() const;
|
|
|
|
void loadSound(int soundNum, bool showErrors);
|
|
|
|
void unloadSound(int soundNum);
|
2011-05-01 05:23:30 +00:00
|
|
|
|
|
|
|
// _so methods
|
2011-05-07 04:13:52 +00:00
|
|
|
static SoundManager &sfManager();
|
2011-05-01 09:28:30 +00:00
|
|
|
static void _sfTerminate();
|
2011-05-01 05:23:30 +00:00
|
|
|
static void _soSetTimeIndex(int timeIndex);
|
|
|
|
static int _sfDetermineGroup(const byte *soundData);
|
|
|
|
static void _sfAddToPlayList(Sound *sound);
|
|
|
|
static void _sfRemoveFromPlayList(Sound *sound);
|
|
|
|
static bool _sfIsOnPlayList(Sound *sound);
|
2011-05-12 13:09:48 +00:00
|
|
|
static void _sfRethinkSoundDrivers();
|
2011-05-01 05:23:30 +00:00
|
|
|
static void _sfRethinkVoiceTypes();
|
|
|
|
static void _sfUpdateVolume(Sound *sound);
|
|
|
|
static void _sfDereferenceAll();
|
|
|
|
static void _sfUpdatePriority(Sound *sound);
|
|
|
|
static void _sfUpdateLoop(Sound *sound);
|
2011-05-01 09:28:30 +00:00
|
|
|
static void _sfSetMasterVol(int volume);
|
|
|
|
static void _sfExtractTrackInfo(trackInfoStruct *trackInfo, const byte *soundData, int groupNum);
|
2011-05-02 11:30:20 +00:00
|
|
|
static void _sfExtractGroupMask();
|
2011-05-04 13:13:15 +00:00
|
|
|
static bool _sfInstallDriver(SoundDriver *driver);
|
|
|
|
static void _sfUnInstallDriver(SoundDriver *driver);
|
2011-05-12 13:09:48 +00:00
|
|
|
static void _sfInstallPatchBank(SoundDriver *driver, const byte *bankData);
|
2011-05-07 04:13:52 +00:00
|
|
|
static void _sfDoAddToPlayList(Sound *sound);
|
|
|
|
static bool _sfDoRemoveFromPlayList(Sound *sound);
|
|
|
|
static void _sfDoUpdateVolume(Sound *sound);
|
2011-05-18 10:32:40 +00:00
|
|
|
static void _sfSoundServer();
|
|
|
|
static void _sfProcessFading();
|
2011-05-24 10:07:41 +00:00
|
|
|
static void _sfUpdateVoiceStructs();
|
2011-04-29 10:19:37 +00:00
|
|
|
};
|
|
|
|
|
2011-04-27 11:23:47 +00:00
|
|
|
class Sound: public EventHandler {
|
2011-04-29 10:19:37 +00:00
|
|
|
private:
|
2011-05-01 05:23:30 +00:00
|
|
|
void _prime(int soundNum, bool queFlag);
|
2011-04-29 10:19:37 +00:00
|
|
|
void _unPrime();
|
2011-05-01 05:23:30 +00:00
|
|
|
void orientAfterRestore();
|
2011-04-29 10:19:37 +00:00
|
|
|
public:
|
2011-05-07 04:13:52 +00:00
|
|
|
int _field0;
|
2011-05-18 10:32:40 +00:00
|
|
|
bool _stopFlag;
|
2011-04-29 10:19:37 +00:00
|
|
|
int _soundNum;
|
2011-05-01 05:23:30 +00:00
|
|
|
int _groupNum;
|
|
|
|
int _soundPriority;
|
2011-04-29 10:19:37 +00:00
|
|
|
int _priority2;
|
2011-05-01 05:23:30 +00:00
|
|
|
int _loop;
|
2011-04-29 10:19:37 +00:00
|
|
|
bool _loopFlag2;
|
|
|
|
int _priority;
|
|
|
|
int _volume;
|
|
|
|
bool _loopFlag;
|
|
|
|
int _pauseCtr;
|
|
|
|
int _muteCtr;
|
|
|
|
int _holdAt;
|
2011-05-01 05:23:30 +00:00
|
|
|
int _cueValue;
|
|
|
|
int _volume1;
|
2011-05-12 13:09:48 +00:00
|
|
|
int _volume3;
|
2011-05-01 05:23:30 +00:00
|
|
|
int _volume2;
|
2011-05-12 13:09:48 +00:00
|
|
|
int _volume5;
|
|
|
|
int _volume4;
|
2011-04-29 10:19:37 +00:00
|
|
|
uint _timeIndex;
|
|
|
|
int _field26;
|
|
|
|
int _field28[SOUND_ARR_SIZE];
|
|
|
|
int _field38[SOUND_ARR_SIZE];
|
|
|
|
int _field48[SOUND_ARR_SIZE];
|
|
|
|
int _field58[SOUND_ARR_SIZE];
|
|
|
|
int _field68[SOUND_ARR_SIZE];
|
|
|
|
int _field78[SOUND_ARR_SIZE];
|
|
|
|
int _field98[SOUND_ARR_SIZE];
|
|
|
|
int _fieldA8[SOUND_ARR_SIZE];
|
|
|
|
int _fieldB8[SOUND_ARR_SIZE];
|
|
|
|
int _fieldC8[SOUND_ARR_SIZE];
|
|
|
|
int _fieldE8[SOUND_ARR_SIZE];
|
|
|
|
trackInfoStruct _trackInfo;
|
2011-05-01 09:28:30 +00:00
|
|
|
byte *_handleList[75];
|
2011-04-29 10:19:37 +00:00
|
|
|
int _field266;
|
|
|
|
int _field268;
|
|
|
|
bool _primed;
|
|
|
|
int _field26C;
|
2011-05-01 05:23:30 +00:00
|
|
|
byte *_field26E;
|
2011-04-27 11:23:47 +00:00
|
|
|
public:
|
2011-05-01 05:23:30 +00:00
|
|
|
Sound();
|
|
|
|
|
|
|
|
void play(int soundNum);
|
2011-04-27 11:23:47 +00:00
|
|
|
void stop();
|
2011-04-27 12:22:20 +00:00
|
|
|
void prime(int soundNum);
|
2011-04-27 11:23:47 +00:00
|
|
|
void unPrime();
|
|
|
|
void go();
|
2011-04-27 12:22:20 +00:00
|
|
|
void halt(void);
|
2011-05-01 05:23:30 +00:00
|
|
|
bool isPlaying();
|
2011-04-27 11:23:47 +00:00
|
|
|
int getSoundNum() const;
|
2011-04-27 12:22:20 +00:00
|
|
|
bool isPrimed() const;
|
2011-04-27 11:23:47 +00:00
|
|
|
bool isPaused() const;
|
|
|
|
bool isMuted() const;
|
2011-05-01 05:23:30 +00:00
|
|
|
void pause(bool flag);
|
|
|
|
void mute(bool flag);
|
2011-05-12 13:09:48 +00:00
|
|
|
void fade(int volume1, int volume2, int volume3, int v4);
|
2011-04-27 11:23:47 +00:00
|
|
|
void setTimeIndex(uint32 timeIndex);
|
|
|
|
uint32 getTimeIndex() const;
|
2011-05-01 05:23:30 +00:00
|
|
|
int getCueValue() const;
|
|
|
|
void setCueValue(int cueValue);
|
2011-04-27 12:22:20 +00:00
|
|
|
void setVol(int volume);
|
|
|
|
int getVol() const;
|
2011-05-01 05:23:30 +00:00
|
|
|
void setPri(int priority);
|
2011-04-27 11:23:47 +00:00
|
|
|
void setLoop(bool flag);
|
|
|
|
int getPri() const;
|
|
|
|
bool getLoop();
|
2011-05-01 05:23:30 +00:00
|
|
|
void holdAt(int amount);
|
2011-04-27 11:23:47 +00:00
|
|
|
void release();
|
2011-05-04 13:13:15 +00:00
|
|
|
|
|
|
|
void orientAfterDriverChange();
|
2011-04-27 11:23:47 +00:00
|
|
|
};
|
|
|
|
|
2011-04-27 12:22:20 +00:00
|
|
|
class ASound: public EventHandler {
|
|
|
|
public:
|
|
|
|
Sound _sound;
|
|
|
|
Action *_action;
|
2011-05-18 10:32:40 +00:00
|
|
|
int _cueValue;
|
2011-04-27 12:22:20 +00:00
|
|
|
|
|
|
|
ASound();
|
|
|
|
virtual void synchronize(Serializer &s);
|
|
|
|
virtual void dispatch();
|
|
|
|
|
|
|
|
void play(int soundNum, Action *action = NULL, int volume = 127);
|
|
|
|
void stop();
|
|
|
|
void prime(int soundNum, Action *action = NULL);
|
|
|
|
void unPrime();
|
|
|
|
void go() { _sound.go(); }
|
|
|
|
void hault(void) { _sound.halt(); }
|
2011-05-01 05:23:30 +00:00
|
|
|
bool isPlaying() { return _sound.isPlaying(); }
|
2011-04-27 12:22:20 +00:00
|
|
|
int getSoundNum() const { return _sound.getSoundNum(); }
|
|
|
|
bool isPaused() const { return _sound.isPaused(); }
|
|
|
|
bool isMuted() const { return _sound.isMuted(); }
|
2011-05-01 05:23:30 +00:00
|
|
|
void pause(bool flag) { _sound.pause(flag); }
|
|
|
|
void mute(bool flag) { _sound.mute(flag); }
|
2011-04-27 12:22:20 +00:00
|
|
|
void fadeIn() { fade(127, 5, 10, 0, NULL); }
|
|
|
|
void fadeOut(Action *action) { fade(0, 5, 10, 1, action); }
|
|
|
|
void fade(int v1, int v2, int v3, int v4, Action *action);
|
|
|
|
void setTimeIndex(uint32 timeIndex) { _sound.setTimeIndex(timeIndex); }
|
|
|
|
uint32 getTimeIndex() const { return _sound.getTimeIndex(); }
|
|
|
|
void setPri(int v) { _sound.setPri(v); }
|
|
|
|
void setLoop(bool flag) { _sound.setLoop(flag); }
|
|
|
|
int getPri() const { return _sound.getPri(); }
|
|
|
|
bool getLoop() { return _sound.getLoop(); }
|
|
|
|
void setVol(int volume) { _sound.setVol(volume); }
|
|
|
|
int getVol() const { return _sound.getVol(); }
|
|
|
|
void holdAt(int v) { _sound.holdAt(v); }
|
|
|
|
void release() { _sound.release(); }
|
|
|
|
};
|
|
|
|
|
2011-05-04 13:13:15 +00:00
|
|
|
class AdlibSoundDriver: public SoundDriver {
|
2011-05-18 10:32:40 +00:00
|
|
|
private:
|
|
|
|
GroupData _groupData;
|
2011-05-04 13:13:15 +00:00
|
|
|
public:
|
2011-05-18 10:32:40 +00:00
|
|
|
AdlibSoundDriver();
|
|
|
|
|
2011-05-12 13:09:48 +00:00
|
|
|
virtual void setVolume(int volume) {}
|
|
|
|
virtual void installPatchBank(const byte *data) {}
|
2011-05-18 10:32:40 +00:00
|
|
|
virtual const GroupData *getGroupData() { return &_groupData; }
|
2011-05-04 13:13:15 +00:00
|
|
|
};
|
|
|
|
|
2011-02-14 09:37:27 +00:00
|
|
|
} // End of namespace tSage
|
|
|
|
|
|
|
|
#endif
|