Start CSfxManager

Former-commit-id: 9368bb11c0c1fb8bc9ed2f66b556da35adfa4856
This commit is contained in:
2023-10-22 21:18:22 -07:00
parent bc7339f4b8
commit 88b59fe172
9 changed files with 584 additions and 132 deletions

View File

@@ -1,74 +1,180 @@
#ifndef _CSFXMANAGER
#define _CSFXMANAGER
#include "rstl/optional_object.hpp"
#include "types.h"
#include "Kyoto/Audio/CAudioSys.hpp"
#include "Kyoto/Audio/CSfxHandle.hpp"
struct _SND_REVSTD_DELAYLINE {
int inPoint;
int outPoint;
int length;
float* inputs;
float lastOutput;
};
#include <rstl/auto_ptr.hpp>
#include <rstl/reserved_vector.hpp>
#include <rstl/single_ptr.hpp>
struct _SND_REVSTD_WORK {
struct _SND_REVSTD_DELAYLINE AP[6];
struct _SND_REVSTD_DELAYLINE C[6];
float allPassCoef;
float combCoef[6];
float lpLastout[3];
float level;
float damping;
int preDelayTime;
float* preDelayLine[3];
float* preDelayPtr[3];
};
#include <musyx/musyx.h>
struct SND_AUX_REVERBHI {
uchar pad0[0x1c4];
bool hiDis;
float damping;
float crosstalk;
float coloration;
float time;
float mix;
float preDelay;
};
struct SND_AUX_CHORUS {
uchar pad[144];
uint baseDelay;
uint variation;
uint period;
};
struct SND_AUX_REVERBSTD {
_SND_REVSTD_WORK rv;
bool tempDisableFX;
float damping;
float preDelay;
float coloration;
float time;
float mix;
};
struct SND_AUX_DELAY {
uint currentSize[3];
uint currentPos[3];
uint currentFeedback[3];
uint currentOutput[3];
uint* left;
uint* right;
uint* sur;
uint delay[3]; // delay buffer length in ms per channel
uint feedback[3]; // feedback volume in % per channel
uint output[3]; // output volume in % per channel
};
#include <Kyoto/CFactoryMgr.hpp>
class CVector3f;
class CSfxManager {
public:
enum ESfxChannels { kSC_Invalid = -1, kSC_Default = 0, kSC_Game, kSC_PauseScreen };
enum ESfxChannels {
kSC_Invalid = -1,
kSC_Default = 0,
kSC_Game,
kSC_PauseScreen,
};
enum ESfxAudibility {
kSA_Aud0,
kSA_Aud1,
kSA_Aud2,
kSA_Aud3,
};
enum EAuxEffect {
kAE_None = -1,
kAE_ReverbHi = 0,
kAE_Chorus,
kAE_ReverbStd,
kAE_Delay,
};
class CBaseSfxWrapper {
public:
CBaseSfxWrapper(const bool looped, const short prio, const CSfxHandle handle,
const bool useAcoustics, const int area);
virtual ~CBaseSfxWrapper(){};
virtual void SetActive(bool v);
virtual void SetPlaying(bool v);
virtual void SetRank(short v);
virtual void SetInArea(bool v);
virtual const bool IsLooped() const;
virtual bool IsPlaying() const;
virtual const bool IsActive() const;
virtual const bool IsInArea() const;
virtual const bool UseAcoustics() const;
virtual const short GetRank() const;
virtual const short GetPriority() const;
virtual const int GetArea() const;
virtual const CSfxHandle GetSfxHandle() const;
virtual void Play() = 0;
virtual void Stop() = 0;
virtual const bool Ready() = 0;
virtual short GetAudible(const CVector3f&) = 0;
virtual const SND_VOICEID GetVoice() const = 0;
virtual const SND_FXID GetSfxId() = 0;
virtual void UpdateEmitterSilent() = 0;
virtual void UpdateEmitter() = 0;
virtual void SetReverb(const char rev) = 0;
const bool Available() const;
void Release();
const float GetTimeRemaining();
void SetTimeRemaining(float t);
private:
float x4_timeRemaining;
short x8_rank;
short xa_prio;
CSfxHandle xc_handle;
int x10_area;
bool x14_24_isActive : 1;
bool x14_25_isPlaying : 1;
bool x14_26_looped : 1;
bool x14_27_inArea : 1;
bool x14_28_isReleased : 1;
bool x14_29_useAcoustics : 1;
};
class CSfxEmitterWrapper : public CBaseSfxWrapper {
public:
CSfxEmitterWrapper(const bool looped, const short prio,
CAudioSys::C3DEmitterParmData& emitterData, const CSfxHandle handle,
const bool useAcoustics, const int area);
~CSfxEmitterWrapper();
bool IsPlaying() const override;
void Play() override;
void Stop() override;
const bool Ready() override;
short GetAudible(const CVector3f&) override;
const SND_VOICEID GetVoice() const override;
const SND_FXID GetSfxId() override;
void UpdateEmitterSilent() override;
void UpdateEmitter() override;
void SetReverb(const char rev) override;
const CAudioSys::C3DEmitterParmData& GetEmitter();
const SND_VOICEID GetHandle() const;
private:
SND_PARAMETER x18_para;
SND_PARAMETER_INFO x1c_parameterInfo;
CAudioSys::C3DEmitterParmData x24_emitterData;
SND_VOICEID x50_emitterHandle;
bool x54_ready;
char x55_cachedMaxVol;
};
class CSfxWrapper : public CBaseSfxWrapper {
public:
CSfxWrapper(const bool looped, const short prio, const ushort sfxId, const short vol,
const short pan, const CSfxHandle handle, const bool useAcoustics, const int area);
~CSfxWrapper(); // {}
bool IsPlaying() const override;
void Play() override;
void Stop() override;
const bool Ready() override;
short GetAudible(const CVector3f&) override;
const SND_VOICEID GetVoice() const override;
const SND_FXID GetSfxId() override;
void UpdateEmitterSilent() override;
void UpdateEmitter() override;
void SetReverb(const char rev) override;
void SetVolume(short vol);
private:
SND_FXID x18_sfxId;
SND_VOICEID x1c_voiceHandle;
short x20_vol;
short x22_pan;
bool x24_ready;
};
class CSfxListener {
public:
explicit CSfxListener(const CVector3f pos = CVector3f::Zero(),
const CVector3f dir = CVector3f::Zero(),
const CVector3f vec1 = CVector3f::Zero(),
const CVector3f vec2 = CVector3f::Zero(), const float f1 = 0.f,
const float f2 = 0.f, const float f3 = 0.f, const uint w1 = 0,
const uchar maxVolume = 0)
: x0_(pos)
, xc_(dir)
, x18_(vec1)
, x24_(vec2)
, x30_(f1)
, x34_(f2)
, x38_(f3)
, x3c_(w1)
, x40_(maxVolume) {}
CVector3f x0_;
CVector3f xc_;
CVector3f x18_;
CVector3f x24_;
float x30_;
float x34_;
float x38_;
int x3c_;
char x40_;
};
class CSfxChannel {
public:
CSfxChannel() : x44_(false) {}
CSfxListener x0_listener;
bool x44_;
rstl::reserved_vector< CBaseSfxWrapper*, 72 > x48_;
};
static void Update(float dt);
static void RemoveEmitter(CSfxHandle handle);
@@ -81,28 +187,32 @@ public:
static const short kMedPriority; // 0x7F
static const ushort kInternalInvalidSfxId; // 0xFFFF
static const int kAllAreas; // 0xFFFFFFFF
static CSfxHandle AddEmitter(const ushort id, const CVector3f& pos, const CVector3f& dir,
static CSfxHandle AddEmitter(const SND_FXID id, const CVector3f& pos, const CVector3f& dir,
const bool useAcoustics, const bool looped,
const short prio = kMedPriority, const int areaId = kAllAreas);
static CSfxHandle AddEmitter(const ushort id, const CVector3f& pos, const CVector3f& dir,
uchar vol, const bool useAcoustics, const bool looped,
static CSfxHandle AddEmitter(const SND_FXID id, const CVector3f& pos, const CVector3f& dir,
const uchar vol, const bool useAcoustics, const bool looped,
const short prio = kMedPriority, const int areaId = kAllAreas);
static CSfxHandle AddEmitter(CAudioSys::C3DEmitterParmData& parmData, bool useAcoustics,
const short prio = kMedPriority, const bool looped = false,
int areaId = kAllAreas);
const int areaId = kAllAreas);
static void AddListener(ESfxChannels channel, const CVector3f& pos, const CVector3f& dir,
const CVector3f& vec1, const CVector3f& vec2, float f1, float f2,
float f3, uint w1, const uchar maxVolume);
static void Shutdown();
static void StopAndRemoveAllEmitters();
static ushort TranslateSFXID(ushort);
static void PitchBend(CSfxHandle handle, int pitch);
static ushort GetReverbAmount();
static CSfxHandle SfxStart(ushort id, short vol, short pan, bool useAcoustics,
short prio = kMaxPriority, bool looped = false,
int areaId = kAllAreas);
static void SfxSpan(CSfxHandle, uchar);
static bool IsPlaying(const CSfxHandle& handle);
static void SetChannel(ESfxChannels);
@@ -110,6 +220,7 @@ public:
static void TurnOnChannel(ESfxChannels);
static void TurnOffChannel(ESfxChannels);
static const bool IsAuxProcessingEnabled();
static void DisableAuxCallback();
static void EnableAuxCallback();
static void PrepareDelayCallback(const SND_AUX_DELAY& info);
@@ -117,6 +228,12 @@ public:
static void PrepareChorusCallback(const SND_AUX_CHORUS& info);
static void PrepareReverbHiCallback(const SND_AUX_REVERBHI& info);
static void DisableAuxProcessing();
static CSfxChannel mChannels[4];
static ESfxChannels mCurrentChannel;
static rstl::vector< short >* mTranslationTable;
static rstl::auto_ptr< CToken > mTranslationTableTok;
static rstl::reserved_vector< CSfxEmitterWrapper, 64 > mEmitterWrapperPool;
static rstl::reserved_vector< CSfxWrapper, 64 > mWrapperPool;
};
#endif // _CSFXMANAGER