metaforce/Runtime/Audio/CSfxManager.hpp

262 lines
9.5 KiB
C++
Raw Normal View History

2018-10-06 20:42:33 -07:00
#pragma once
2015-08-19 19:52:07 -07:00
#include <vector>
#include "../RetroTypes.hpp"
2016-03-04 15:04:53 -08:00
#include "zeus/CVector3f.hpp"
2015-08-19 19:52:07 -07:00
#include "CAudioSys.hpp"
#include "DNAMP1/SFX/SFX.h"
2015-08-19 19:52:07 -07:00
2016-03-04 15:04:53 -08:00
namespace urde
2015-08-19 19:52:07 -07:00
{
class CSfxManager
{
2018-11-02 01:16:16 -07:00
static std::vector<u16>* mpSfxTranslationTable;
2016-04-16 19:50:45 -07:00
public:
2016-12-28 21:53:00 -08:00
2015-11-20 17:16:07 -08:00
enum class ESfxChannels
2015-08-19 19:52:07 -07:00
{
2017-01-22 23:22:17 -08:00
Invalid = -1,
Default = 0,
Game,
PauseScreen
2015-08-19 19:52:07 -07:00
};
2015-11-20 17:16:07 -08:00
enum class ESfxAudibility
2015-08-19 19:52:07 -07:00
{
Aud0,
Aud1,
Aud2,
Aud3
};
2017-01-22 23:22:17 -08:00
enum class EAuxEffect
2015-08-19 19:52:07 -07:00
{
2017-01-22 23:22:17 -08:00
None = -1,
ReverbHi = 0,
Chorus,
ReverbStd,
Delay
2015-08-19 19:52:07 -07:00
};
2016-12-28 21:53:00 -08:00
class CBaseSfxWrapper;
using CSfxHandle = std::shared_ptr<CBaseSfxWrapper>;
/* Original imp, kept for reference
class CSfxHandle
{
static u32 mRefCount;
u32 x0_idx;
public:
CSfxHandle(u32 id)
: x0_idx(++mRefCount << 14 | (id & 0xFFFF)) {}
};
*/
2017-01-22 23:22:17 -08:00
class CSfxChannel
{
friend class CSfxManager;
zeus::CVector3f x0_pos;
zeus::CVector3f xc_;
zeus::CVector3f x18_;
zeus::CVector3f x24_;
/*
2017-01-22 23:22:17 -08:00
float x30_ = 0.f;
float x34_ = 0.f;
float x38_ = 0.f;
u32 x3c_ = 0;
bool x40_ = false;
*/
2017-01-22 23:22:17 -08:00
bool x44_listenerActive = false;
std::unordered_set<CSfxHandle> x48_handles;
};
2016-12-28 21:53:00 -08:00
class CBaseSfxWrapper : public std::enable_shared_from_this<CBaseSfxWrapper>
2015-08-19 19:52:07 -07:00
{
2017-01-22 23:22:17 -08:00
float x4_timeRemaining = 15.f;
s16 x8_rank = 0;
s16 xa_prio;
2016-12-28 21:53:00 -08:00
//CSfxHandle xc_handle;
TAreaId x10_area;
2017-01-24 20:40:19 -08:00
bool x14_24_isActive:1;
bool x14_25_isPlaying:1;
bool x14_26_looped:1;
bool x14_27_inArea:1;
2018-06-01 23:06:25 -07:00
bool x14_28_isReleased:1;
2017-01-24 20:40:19 -08:00
bool x14_29_useAcoustics:1;
2017-04-08 23:14:22 -07:00
protected:
bool m_isEmitter:1;
2018-06-01 23:06:25 -07:00
bool m_isClosed:1;
2015-08-19 19:52:07 -07:00
public:
2016-12-28 21:53:00 -08:00
virtual ~CBaseSfxWrapper() = default;
virtual void SetActive(bool v) { x14_24_isActive = v; }
virtual void SetPlaying(bool v) { x14_25_isPlaying = v; }
virtual void SetRank(short v) { x8_rank = v; }
virtual void SetInArea(bool v) { x14_27_inArea = v; }
virtual bool IsInArea() const { return x14_27_inArea; }
virtual bool IsPlaying() const { return x14_25_isPlaying; }
virtual bool UseAcoustics() const { return x14_29_useAcoustics; }
virtual bool IsLooped() const { return x14_26_looped; }
virtual bool IsActive() const { return x14_24_isActive; }
virtual s16 GetRank() const { return x8_rank; }
virtual s16 GetPriority() const { return xa_prio; }
virtual TAreaId GetArea() const { return x10_area; }
virtual CSfxHandle GetSfxHandle() { return shared_from_this(); }
2015-08-19 19:52:07 -07:00
virtual void Play()=0;
virtual void Stop()=0;
virtual bool Ready()=0;
2016-04-16 19:50:45 -07:00
virtual ESfxAudibility GetAudible(const zeus::CVector3f&)=0;
2018-08-27 22:44:16 -07:00
virtual amuse::ObjToken<amuse::Voice> GetVoice() const=0;
2017-01-22 23:22:17 -08:00
virtual u16 GetSfxId() const=0;
virtual void UpdateEmitterSilent()=0;
virtual void UpdateEmitter()=0;
virtual void SetReverb(float rev)=0;
2017-04-08 23:14:22 -07:00
bool IsEmitter() const { return m_isEmitter; }
2015-08-19 19:52:07 -07:00
2018-06-01 23:06:25 -07:00
void Release() { x14_28_isReleased = true; x4_timeRemaining = 15.f; }
bool IsReleased() const { return x14_28_isReleased; }
void Close() { m_isClosed = true; }
bool IsClosed() const { return m_isClosed; }
2015-08-19 19:52:07 -07:00
2017-01-22 23:22:17 -08:00
float GetTimeRemaining() const { return x4_timeRemaining; }
void SetTimeRemaining(float t) { x4_timeRemaining = t; }
2016-12-28 21:53:00 -08:00
CBaseSfxWrapper(bool looped, s16 prio, /*const CSfxHandle& handle,*/ bool useAcoustics, TAreaId area)
: x8_rank(0), xa_prio(prio), /*xc_handle(handle),*/ x10_area(area), x14_24_isActive(true), x14_25_isPlaying(false),
2018-06-01 23:06:25 -07:00
x14_26_looped(looped), x14_27_inArea(true), x14_28_isReleased(false), m_isClosed(false),
x14_29_useAcoustics(useAcoustics) {}
2015-08-19 19:52:07 -07:00
};
class CSfxEmitterWrapper : public CBaseSfxWrapper
{
2016-12-28 21:53:00 -08:00
float x1a_reverb;
CAudioSys::C3DEmitterParmData x24_parmData;
2018-08-27 22:44:16 -07:00
amuse::ObjToken<amuse::Emitter> x50_emitterHandle;
bool x54_ready = true;
2017-01-22 23:22:17 -08:00
float x55_cachedMaxVol;
2015-08-19 19:52:07 -07:00
public:
bool IsPlaying() const;
void Play();
void Stop();
bool Ready();
2016-04-16 19:50:45 -07:00
ESfxAudibility GetAudible(const zeus::CVector3f&);
2018-08-27 22:44:16 -07:00
amuse::ObjToken<amuse::Voice> GetVoice() const { return x50_emitterHandle->getVoice(); }
2017-01-22 23:22:17 -08:00
u16 GetSfxId() const;
void UpdateEmitterSilent();
void UpdateEmitter();
void SetReverb(float rev);
2017-04-13 12:28:31 -07:00
CAudioSys::C3DEmitterParmData& GetEmitterData() { return x24_parmData; }
2015-08-19 19:52:07 -07:00
2018-08-27 22:44:16 -07:00
amuse::ObjToken<amuse::Emitter> GetHandle() const { return x50_emitterHandle; }
2015-08-19 19:52:07 -07:00
CSfxEmitterWrapper(bool looped, s16 prio, const CAudioSys::C3DEmitterParmData& data,
2016-12-28 21:53:00 -08:00
/*const CSfxHandle& handle,*/ bool useAcoustics, TAreaId area)
2017-04-08 23:14:22 -07:00
: CBaseSfxWrapper(looped, prio, /*handle,*/ useAcoustics, area), x24_parmData(data)
{
m_isEmitter = true;
}
2015-08-19 19:52:07 -07:00
};
class CSfxWrapper : public CBaseSfxWrapper
{
u16 x18_sfxId;
2018-08-27 22:44:16 -07:00
amuse::ObjToken<amuse::Voice> x1c_voiceHandle;
2016-12-28 21:53:00 -08:00
float x20_vol;
float x22_pan;
bool x24_ready = true;
2015-08-19 19:52:07 -07:00
public:
bool IsPlaying() const;
void Play();
void Stop();
bool Ready();
2016-12-28 21:53:00 -08:00
ESfxAudibility GetAudible(const zeus::CVector3f&) { return ESfxAudibility::Aud3; }
2018-08-27 22:44:16 -07:00
amuse::ObjToken<amuse::Voice> GetVoice() const { return x1c_voiceHandle; }
2017-01-22 23:22:17 -08:00
u16 GetSfxId() const;
void UpdateEmitterSilent();
void UpdateEmitter();
void SetReverb(float rev);
2017-04-08 23:14:22 -07:00
void SetVolume(float vol) { x20_vol = vol; }
2015-08-19 19:52:07 -07:00
2016-12-28 21:53:00 -08:00
CSfxWrapper(bool looped, s16 prio, u16 sfxId, float vol, float pan,
/*const CSfxHandle& handle,*/ bool useAcoustics, TAreaId area)
: CBaseSfxWrapper(looped, prio, /*handle,*/ useAcoustics, area),
2017-04-08 23:14:22 -07:00
x18_sfxId(sfxId), x20_vol(vol), x22_pan(pan)
{
m_isEmitter = false;
}
2015-08-19 19:52:07 -07:00
};
static CSfxChannel m_channels[4];
static ESfxChannels m_currentChannel;
static bool m_doUpdate;
static void* m_usedSounds;
static bool m_muted;
static bool m_auxProcessingEnabled;
2016-12-28 21:53:00 -08:00
static float m_reverbAmount;
2017-01-22 23:22:17 -08:00
static EAuxEffect m_activeEffect;
static EAuxEffect m_nextEffect;
2018-08-27 22:44:16 -07:00
static amuse::ObjToken<amuse::Listener> m_listener;
2015-08-19 19:52:07 -07:00
static u16 kMaxPriority;
static u16 kMedPriority;
static u16 kInternalInvalidSfxId;
static u32 kAllAreas;
2017-01-19 19:53:32 -08:00
static bool LoadTranslationTable(CSimplePool* pool, const SObjectTag* tag);
2016-12-28 21:53:00 -08:00
static bool IsAuxProcessingEnabled() { return m_auxProcessingEnabled; }
2017-01-22 23:22:17 -08:00
static void SetChannel(ESfxChannels);
2017-04-14 22:32:25 -07:00
static void KillAll(ESfxChannels);
2017-01-22 23:22:17 -08:00
static void TurnOnChannel(ESfxChannels);
static void TurnOffChannel(ESfxChannels);
2015-08-19 19:52:07 -07:00
static ESfxChannels GetCurrentChannel() {return m_currentChannel;}
2017-09-18 20:59:50 -07:00
static void AddListener(ESfxChannels channel,
2016-04-16 19:50:45 -07:00
const zeus::CVector3f& pos, const zeus::CVector3f& dir,
const zeus::CVector3f& heading, const zeus::CVector3f& up,
float frontRadius, float surroundRadius, float soundSpeed,
2017-09-18 20:59:50 -07:00
u32 flags /* 0x1 for doppler */, float vol);
2016-04-16 19:50:45 -07:00
static void UpdateListener(const zeus::CVector3f& pos, const zeus::CVector3f& dir,
const zeus::CVector3f& heading, const zeus::CVector3f& up,
2017-09-18 20:59:50 -07:00
float vol);
2016-04-24 22:03:38 -07:00
static bool PlaySound(const CSfxHandle& handle);
2017-01-22 23:22:17 -08:00
static void StopSound(const CSfxHandle& handle);
static s16 GetRank(CBaseSfxWrapper* sfx);
static void ApplyReverb();
static float GetReverbAmount();
2017-04-08 13:40:36 -07:00
static void PitchBend(const CSfxHandle& handle, float pitch);
2017-04-08 23:14:22 -07:00
static void SfxVolume(const CSfxHandle& handle, float vol);
2017-08-24 23:18:09 -07:00
static void SfxSpan(const CSfxHandle& handle, float span);
2016-04-24 22:03:38 -07:00
static u16 TranslateSFXID(u16);
2016-12-28 21:53:00 -08:00
static void SfxStop(const CSfxHandle& handle);
static CSfxHandle SfxStart(u16 id, float vol, float pan, bool useAcoustics, s16 prio, bool looped, s32 areaId);
2017-06-11 21:23:34 -07:00
static bool IsPlaying(const CSfxHandle& handle);
2017-04-13 12:28:31 -07:00
static void RemoveEmitter(const CSfxHandle& handle);
static void UpdateEmitter(const CSfxHandle& handle, const zeus::CVector3f& pos, const zeus::CVector3f& dir,
float maxVol);
2017-08-18 23:52:13 -07:00
static CSfxHandle AddEmitter(u16 id, const zeus::CVector3f& pos, const zeus::CVector3f& dir,
bool useAcoustics, bool looped, s16 prio, s32 areaId);
static CSfxHandle AddEmitter(u16 id, const zeus::CVector3f& pos, const zeus::CVector3f& dir, float vol,
bool useAcoustics, bool looped, s16 prio, s32 areaId);
static CSfxHandle AddEmitter(const CAudioSys::C3DEmitterParmData& parmData,
bool useAcoustics, s16 prio, bool looped, s32 areaId);
static void StopAndRemoveAllEmitters();
2017-01-22 23:22:17 -08:00
static void DisableAuxCallback();
static void EnableAuxCallback();
static void PrepareDelayCallback(const amuse::EffectDelayInfo& info);
static void PrepareReverbStdCallback(const amuse::EffectReverbStdInfo& info);
static void PrepareChorusCallback(const amuse::EffectChorusInfo& info);
static void PrepareReverbHiCallback(const amuse::EffectReverbHiInfo& info);
static void DisableAuxProcessing();
static void SetActiveAreas(const rstl::reserved_vector<TAreaId, 10>& areas);
2017-01-22 23:22:17 -08:00
static void Update(float dt);
static void Shutdown();
2015-08-19 19:52:07 -07:00
};
2016-12-28 21:53:00 -08:00
using CSfxHandle = CSfxManager::CSfxHandle;
2015-08-19 19:52:07 -07:00
}