diff --git a/src/platform/C4SoundLoaders.h b/src/platform/C4SoundLoaders.h index 408dce9ef..78a79a260 100644 --- a/src/platform/C4SoundLoaders.h +++ b/src/platform/C4SoundLoaders.h @@ -17,6 +17,7 @@ #define INC_C4SoundLoaders #include +#include #include namespace C4SoundLoaders diff --git a/src/platform/C4SoundSystem.cpp b/src/platform/C4SoundSystem.cpp index 14f87de7d..13344a8ff 100644 --- a/src/platform/C4SoundSystem.cpp +++ b/src/platform/C4SoundSystem.cpp @@ -26,12 +26,70 @@ #include #include #include +#include #include -#if AUDIO_TK == AUDIO_TK_SDL_MIXER -#define USE_RWOPS -#include -#endif +class C4SoundEffect +{ + friend class C4SoundInstance; +public: + C4SoundEffect(); + ~C4SoundEffect(); +public: + char Name[C4MaxSoundName+1]; + int32_t Instances; + int32_t SampleRate, Length; + C4SoundHandle pSample; + C4SoundInstance *FirstInst; + C4SoundEffect *Next; +public: + void Clear(); + bool Load(const char *szFileName, C4Group &hGroup); + bool Load(BYTE *pData, size_t iDataLen, bool fRaw=false); // load directly from memory + void Execute(); + C4SoundInstance *New(bool fLoop = false, int32_t iVolume = 100, C4Object *pObj = NULL, int32_t iCustomFalloffDistance = 0); + C4SoundInstance *GetInstance(C4Object *pObj); + void ClearPointers(C4Object *pObj); + int32_t GetStartedInstanceCount(int32_t iX, int32_t iY, int32_t iRad); // local + int32_t GetStartedInstanceCount(); // global +protected: + void AddInst(C4SoundInstance *pInst); + void RemoveInst(C4SoundInstance *pInst); +}; + +class C4SoundInstance +{ + friend class C4SoundEffect; +protected: + C4SoundInstance(); +public: + ~C4SoundInstance(); +protected: + C4SoundEffect *pEffect; + int32_t iVolume, iPan, iChannel; + C4TimeMilliseconds tStarted; + int32_t iNearInstanceMax; + bool fLooping; + C4Object *pObj; + int32_t iFalloffDistance; + C4SoundInstance *pNext; +public: + C4Object *getObj() const { return pObj; } + bool isStarted() const { return iChannel != -1; } + void Clear(); + bool Create(C4SoundEffect *pEffect, bool fLoop = false, int32_t iVolume = 100, C4Object *pObj = NULL, int32_t iNearInstanceMax = 0, int32_t iFalloffDistance = 0); + bool CheckStart(); + bool Start(); + bool Stop(); + bool Playing(); + void Execute(); + void SetVolume(int32_t inVolume) { iVolume = inVolume; } + void SetPan(int32_t inPan) { iPan = inPan; } + void SetVolumeByPos(int32_t x, int32_t y); + void SetObj(C4Object *pnObj) { pObj = pnObj; } + void ClearPointers(C4Object *pObj); + bool Inside(int32_t iX, int32_t iY, int32_t iRad); +}; using namespace C4SoundLoaders; diff --git a/src/platform/C4SoundSystem.h b/src/platform/C4SoundSystem.h index 4be8c2b90..a5797159e 100644 --- a/src/platform/C4SoundSystem.h +++ b/src/platform/C4SoundSystem.h @@ -21,7 +21,6 @@ #define INC_C4SoundSystem #include -#include const int32_t C4MaxSoundName=100, @@ -29,73 +28,11 @@ const int32_t C4NearSoundRadius=50, C4AudibilityRadius=700; -class C4Object; -class C4SoundInstance; - -class C4SoundEffect -{ - friend class C4SoundInstance; -public: - C4SoundEffect(); - ~C4SoundEffect(); -public: - char Name[C4MaxSoundName+1]; - int32_t Instances; - int32_t SampleRate, Length; - C4SoundHandle pSample; - C4SoundInstance *FirstInst; - C4SoundEffect *Next; -public: - void Clear(); - bool Load(const char *szFileName, C4Group &hGroup); - bool Load(BYTE *pData, size_t iDataLen, bool fRaw=false); // load directly from memory - void Execute(); - C4SoundInstance *New(bool fLoop = false, int32_t iVolume = 100, C4Object *pObj = NULL, int32_t iCustomFalloffDistance = 0); - C4SoundInstance *GetInstance(C4Object *pObj); - void ClearPointers(C4Object *pObj); - int32_t GetStartedInstanceCount(int32_t iX, int32_t iY, int32_t iRad); // local - int32_t GetStartedInstanceCount(); // global -protected: - void AddInst(C4SoundInstance *pInst); - void RemoveInst(C4SoundInstance *pInst); -}; - -class C4SoundInstance -{ - friend class C4SoundEffect; -protected: - C4SoundInstance(); -public: - ~C4SoundInstance(); -protected: - C4SoundEffect *pEffect; - int32_t iVolume, iPan, iChannel; - C4TimeMilliseconds tStarted; - int32_t iNearInstanceMax; - bool fLooping; - C4Object *pObj; - int32_t iFalloffDistance; - C4SoundInstance *pNext; -public: - C4Object *getObj() const { return pObj; } - bool isStarted() const { return iChannel != -1; } - void Clear(); - bool Create(C4SoundEffect *pEffect, bool fLoop = false, int32_t iVolume = 100, C4Object *pObj = NULL, int32_t iNearInstanceMax = 0, int32_t iFalloffDistance = 0); - bool CheckStart(); - bool Start(); - bool Stop(); - bool Playing(); - void Execute(); - void SetVolume(int32_t inVolume) { iVolume = inVolume; } - void SetPan(int32_t inPan) { iPan = inPan; } - void SetVolumeByPos(int32_t x, int32_t y); - void SetObj(C4Object *pnObj) { pObj = pnObj; } - void ClearPointers(C4Object *pObj); - bool Inside(int32_t iX, int32_t iY, int32_t iRad); -}; - const int32_t SoundUnloadTime=60, SoundMaxUnloadSize=100000; +class C4SoundInstance; +class C4SoundEffect; + class C4SoundSystem { public: @@ -116,9 +53,9 @@ protected: int32_t RemoveEffect(const char *szFilename); }; -class C4SoundInstance *StartSoundEffect(const char *szSndName, bool fLoop = false, int32_t iVolume = 100, C4Object *pObj=NULL, int32_t iCustomFalloffDistance=0); -class C4SoundInstance *StartSoundEffectAt(const char *szSndName, int32_t iX, int32_t iY, int32_t iVolume = 100, int32_t iCustomFallofDistance=0); -class C4SoundInstance *GetSoundInstance(const char *szSndName, C4Object *pObj); +C4SoundInstance *StartSoundEffect(const char *szSndName, bool fLoop = false, int32_t iVolume = 100, C4Object *pObj=NULL, int32_t iCustomFalloffDistance=0); +C4SoundInstance *StartSoundEffectAt(const char *szSndName, int32_t iX, int32_t iY, int32_t iVolume = 100, int32_t iCustomFallofDistance=0); +C4SoundInstance *GetSoundInstance(const char *szSndName, C4Object *pObj); void StopSoundEffect(const char *szSndName, C4Object *pObj); void SoundLevel(const char *szSndName, C4Object *pObj, int32_t iLevel); void SoundPan(const char *szSndName, C4Object *pObj, int32_t iPan);