00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __IAUDIO_H__
00012 #define __IAUDIO_H__
00013
00014 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00015 namespace Audio
00016 {
00017 #endif
00018
00020
00022 static const float VOLUME_MIN = 0.0f;
00024 static const float VOLUME_MAX = 1.0f;
00026 static const float PAN_LEFT = -1.0f;
00028 static const float PAN_CENTER = 0.0f;
00030 static const float PAN_RIGHT = 1.0f;
00032 static const float PITCH_ORIGINAL = 1.0f;
00034 static const uint32 MODE_NORMAL = 0x00000000;
00036 static const uint32 MODE_HEADRELATIVE = 0x00000001;
00038 static const uint32 MODE_DISABLE = 0x00000002;
00039
00040
00042
00052 class IAudioBase
00053 {
00054 public:
00061 virtual void Destroy() = 0;
00062
00067 virtual bool IsInitialized() const = 0;
00068
00077 virtual bool Load() = 0;
00084 virtual bool Unload() = 0;
00090 virtual bool IsLoaded() const = 0;
00091
00092 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00093 protected:
00094 virtual ~IAudioBase() {};
00095 #endif
00096
00097 };
00098
00099
00101
00111 class IPlayable : public IAudioBase
00112 {
00113 public:
00114
00120 virtual bool Play() = 0;
00128 virtual bool Pause() = 0;
00133 virtual bool Stop() = 0;
00134
00140 virtual bool IsPlaying() const = 0;
00146 virtual bool IsPaused() const = 0;
00151 virtual bool IsLooping() const = 0;
00152 };
00153
00155
00160 struct SoundProp
00161 {
00165 SoundProp() { Clear(); }
00169 void Clear()
00170 {
00171 m_fVolume = VOLUME_MAX;
00172 m_fPan = PAN_CENTER;
00173 m_fPitch = PITCH_ORIGINAL;
00174 m_nReadCursor = 0;
00175 }
00177 float m_fVolume;
00179 float m_fPan;
00181 float m_fPitch;
00183 uint32 m_nReadCursor;
00184
00185 };
00186
00188
00195 struct SoundInit
00196 {
00200 SoundInit() { Clear(); }
00204 void Clear()
00205 {
00206 m_sFileName.erase();
00207 m_bStreaming = false;
00208 m_bLooping = false;
00209 m_bMusic = false;
00210 m_nPriority = 0;
00211 m_Prop.Clear();
00212 }
00214 std::string m_sFileName;
00216 bool m_bStreaming;
00218 bool m_bLooping;
00220 bool m_bMusic;
00222
00226 uint32 m_nPriority;
00228
00232 SoundProp m_Prop;
00233 };
00234
00235
00237
00242 class ISound : public IPlayable
00243 {
00244 public:
00253 virtual bool Init(const SoundInit& init) = 0;
00254
00261 virtual bool SetProperties(const SoundProp& prop) = 0;
00268 virtual bool GetProperties(SoundProp& prop) const = 0;
00269
00278 virtual bool SetVolume(float fVolume) = 0;
00285 virtual bool GetVolume(float& fVolume) const = 0;
00286
00295 virtual bool SetPan(float fPan) = 0;
00303 virtual bool GetPan(float& fPan) const = 0;
00304
00313 virtual bool SetPitch(float fPitch) = 0;
00319 virtual bool GetPitch(float& fPitch) const = 0;
00320
00327 virtual bool SetReadCursor(uint32 nBytes) = 0;
00334 virtual bool GetReadCursor(uint32& nBytes) const = 0;
00335
00341 virtual bool GetSourceSize(uint32& nBytes) const = 0;
00342 };
00343
00344
00346
00351 struct Sound3DProp
00352 {
00356 Sound3DProp() { Clear(); }
00360 void Clear()
00361 {
00362 m_vPosition.x = 0; m_vPosition.y = 0; m_vPosition.z = 0;
00363 m_vVelocity.x = 0; m_vVelocity.y = 0; m_vVelocity.z = 0;
00364 m_vConeOrientation.x = 0; m_vConeOrientation.y = 0; m_vConeOrientation.z = 1.0f;
00365 m_nInsideConeAngle = 360;
00366 m_nOutsideConeAngle = 360;
00367 m_fConeOutsideVolume = VOLUME_MAX;
00368 m_fMinDistance = 1.0f;
00369 m_fMaxDistance = 1000.0f;
00370 m_nMode = MODE_NORMAL;
00371 m_fVolume = VOLUME_MAX;
00372 m_fPitch = PITCH_ORIGINAL;
00373 m_nReadCursor = 0;
00374 }
00376 AUDIOVECTOR m_vPosition;
00378 AUDIOVECTOR m_vVelocity;
00380 AUDIOVECTOR m_vConeOrientation;
00382
00385 uint32 m_nInsideConeAngle;
00387
00390 uint32 m_nOutsideConeAngle;
00392 float m_fConeOutsideVolume;
00394 float m_fMinDistance;
00396 float m_fMaxDistance;
00398
00401 uint32 m_nMode;
00403 float m_fVolume;
00405 float m_fPitch;
00407 uint32 m_nReadCursor;
00408 };
00409
00410
00412
00418 struct Sound3DInit
00419 {
00423 Sound3DInit() { Clear(); }
00427 void Clear()
00428 {
00429 m_sFileName.erase();
00430 m_bStreaming = false;
00431 m_bLooping = false;
00432 m_bMusic = false;
00433 m_nPriority = 0;
00434 m_Prop.Clear();
00435 }
00437 std::string m_sFileName;
00439 bool m_bStreaming;
00441 bool m_bLooping;
00443 bool m_bMusic;
00445
00449 uint32 m_nPriority;
00451
00455 Sound3DProp m_Prop;
00456 };
00457
00458
00460
00466 class ISound3D : public IPlayable
00467 {
00468 public:
00477 virtual bool Init(const Sound3DInit& init) = 0;
00478
00485 virtual bool SetProperties(const Sound3DProp& prop) = 0;
00492 virtual bool GetProperties(Sound3DProp& prop) const = 0;
00493
00500 virtual bool SetPosition(const AUDIOVECTOR& vPosition) = 0;
00507 virtual bool GetPosition(AUDIOVECTOR& vPosition) const = 0;
00508
00515 virtual bool SetVelocity(const AUDIOVECTOR& vVelocity) = 0;
00522 virtual bool GetVelocity(AUDIOVECTOR& vVelocity) const = 0;
00523
00530 virtual bool SetMaxDistance(float fMaxDist) = 0;
00537 virtual bool GetMaxDistance(float& fMaxDist) const = 0;
00538
00545 virtual bool SetMinDistance(float fMinDist) = 0;
00552 virtual bool GetMinDistance(float& fMinDist) const = 0;
00553
00562 virtual bool SetConeAngles(uint32 nInside, uint32 nOutside) = 0;
00571 virtual bool GetConeAngles(uint32& nInside, uint32& nOutside) const = 0;
00572
00579 virtual bool SetConeOrientation(const AUDIOVECTOR& vOrientation) = 0;
00586 virtual bool GetConeOrientation(AUDIOVECTOR& vOrientation) const = 0;
00587
00595 virtual bool SetConeOutsideVolume(float fVolume) = 0;
00603 virtual bool GetConeOutsideVolume(float& fVolume) const = 0;
00604
00617 virtual bool SetMode(uint32 nMode) = 0;
00624 virtual bool GetMode(uint32& nMode) const = 0;
00625
00634 virtual bool SetVolume(float fVolume) = 0;
00641 virtual bool GetVolume(float& fVolume) const = 0;
00642
00651 virtual bool SetPitch(float fPitch) = 0;
00657 virtual bool GetPitch(float& fPitch) const = 0;
00658
00665 virtual bool SetReadCursor(uint32 nBytes) = 0;
00672 virtual bool GetReadCursor(uint32& nBytes) const = 0;
00673
00679 virtual bool GetSourceSize(uint32& nBytes) const = 0;
00680
00687 virtual IEAXBuffer* EAX() = 0;
00688
00695 virtual IZoomFX* ZoomFX() = 0;
00696
00697
00708 virtual bool QuerySupport(const GUID& guid, uint32 nID, uint32* pTypeSupport) = 0;
00716 virtual bool Get(const GUID& guidProperty, uint32 nID, void* pInstanceData,
00717 uint32 nInstanceLength, void* pPropData, uint32 nPropLength,
00718 uint32* pBytesReturned) = 0;
00729 virtual bool Set(const GUID& guidProperty, uint32 nID, void* pInstanceData,
00730 uint32 nInstanceLength, void* pPropData, uint32 nPropLength,
00731 bool bStoreProperty) = 0;
00732 };
00733
00734
00736
00742 struct DLSInit
00743 {
00747 DLSInit() { Clear(); }
00751 void Clear()
00752 {
00753 m_sFileName.erase();
00754 }
00755
00757 std::string m_sFileName;
00758 };
00759
00761
00768 class IDLS : public IAudioBase
00769 {
00770 public:
00771
00780 virtual bool Init(const DLSInit& init) = 0;
00790 virtual bool Lock() = 0;
00797 virtual bool Unlock() = 0;
00798
00799 };
00800
00801
00803
00809 struct SegmentInit
00810 {
00814 SegmentInit() { Clear(); }
00818 void Clear()
00819 {
00820 m_sFileName.erase();
00821 m_bMusic = true;
00822 m_bLooping = false;
00823 m_pDLS = 0;
00824 }
00826
00830 std::string m_sFileName;
00832 bool m_bLooping;
00834 bool m_bMusic;
00836
00841 IDLS* m_pDLS;
00842
00843 };
00844
00845
00847
00854 class ISegment : public IPlayable
00855 {
00856 public:
00864 virtual bool Init(const SegmentInit& init) = 0;
00865
00866 };
00867
00869
00875 struct AudioScriptInit
00876 {
00880 AudioScriptInit() { Clear(); }
00884 void Clear()
00885 {
00886 m_sFileName.erase();
00887 m_bMusic = true;
00888 }
00890 std::string m_sFileName;
00892 bool m_bMusic;
00893
00894 };
00895
00897
00902 class IAudioScript : public IAudioBase
00903 {
00904 public:
00912 virtual bool Init(const AudioScriptInit& init) = 0;
00913
00921 virtual bool SetVariable(std::string sVarName, int32 iVal) = 0;
00929 virtual bool GetVariable(std::string sVarName, int32& iVal) = 0;
00930
00937 virtual bool CallRoutine(std::string sRoutineName) = 0;
00938 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00939 protected:
00940 virtual ~IAudioScript() {};
00941 #endif
00942 };
00943
00944
00946 struct ListenerProp
00947 {
00949 ListenerProp() { Clear(); }
00951 void Clear()
00952 {
00953 m_vPosition.x = 0.0f; m_vPosition.y = 0.0f; m_vPosition.z = 0.0f;
00954 m_vVelocity.x = 0.0f; m_vVelocity.y = 0.0f; m_vVelocity.z = 0.0f;
00955 m_vOrientFront.x = 0.0f; m_vOrientFront.y = 0.0f; m_vOrientFront.z = 1.0f;
00956 m_vOrientTop.x = 0.0f; m_vOrientTop.y = 1.0f; m_vOrientTop.z = 0.0f;
00957 m_fDistanceFactor = 1.0f;
00958 m_fRolloffFactor = 1.0f;
00959 m_fDopplerFactor = 1.0f;
00960 }
00962 AUDIOVECTOR m_vPosition;
00964 AUDIOVECTOR m_vVelocity;
00966 AUDIOVECTOR m_vOrientFront;
00968 AUDIOVECTOR m_vOrientTop;
00970 float m_fDistanceFactor;
00972
00975 float m_fRolloffFactor;
00977
00980 float m_fDopplerFactor;
00981 };
00982
00984 struct ListenerInit
00985 {
00987 ListenerInit() { Clear(); }
00989 void Clear()
00990 {
00991 m_Prop.Clear();
00992 }
00993 ListenerProp m_Prop;
00994 };
00995
00996
00998
01003 class IListener
01004 {
01005 public:
01006
01013 virtual bool Init(const ListenerInit& init) = 0;
01020 virtual void Term() = 0;
01021
01028 virtual bool SetProperties(const ListenerProp& prop) = 0;
01034 virtual void GetProperties(ListenerProp& prop) const = 0;
01035
01042 virtual bool SetPosition(const AUDIOVECTOR& vPos) = 0;
01048 virtual void GetPosition(AUDIOVECTOR& vPos) const = 0;
01049
01056 virtual bool SetVelocity(const AUDIOVECTOR& vVel) = 0;
01062 virtual void GetVelocity(AUDIOVECTOR& vVel) const = 0;
01063
01071 virtual bool SetOrientation(const AUDIOVECTOR& vFront, const AUDIOVECTOR& vTop) = 0;
01078 virtual void GetOrientation(AUDIOVECTOR& vFront, AUDIOVECTOR& vTop) const = 0;
01079
01086 virtual bool SetDistanceFactor(float fDistanceFactor) = 0;
01092 virtual void GetDistanceFactor(float& fDistanceFactor) const = 0;
01093
01103 virtual bool SetDopplerFactor(float fDopplerFactor) = 0;
01110 virtual void GetDopplerFactor(float& fDopplerFactor) const = 0;
01111
01119 virtual bool SetRolloffFactor(float fRolloffFactor) = 0;
01126 virtual void GetRolloffFactor(float& fRolloffFactor) const = 0;
01127
01138 virtual bool QuerySupport(const GUID& guid, uint32 nID, uint32* pTypeSupport) = 0;
01146 virtual bool Get(const GUID& guidProperty, uint32 nID, void* pInstanceData,
01147 uint32 nInstanceLength, void* pPropData, uint32 nPropLength,
01148 uint32* pBytesReturned) = 0;
01156 virtual bool Set(const GUID& guidProperty, uint32 nID, void* pInstanceData,
01157 uint32 nInstanceLength, void* pPropData, uint32 nPropLength,
01158 bool bStoreProperty) = 0;
01159
01160 virtual IEAXListener* EAX() = 0;
01161 };
01162
01164
01170 class IMusicCallback
01171 {
01172 public:
01176 virtual void OnSegmentStart() {};
01177 };
01178
01179
01181
01185 struct AudioMgrInit
01186 {
01190 AudioMgrInit() { Clear(); }
01194 void Clear()
01195 {
01196 m_hWnd = (HWND)0;
01197 m_bLoadAsyncronously = true;
01198 m_bForceSoftware = false;
01199 m_bUseMusicReverb = true;
01200 m_bUseEAX = true;
01201 m_bUseZoomFX = true;
01202 m_bAutoStream = false;
01203 m_bCacheBuffers = false;
01204 m_n2DHardwareBufferMin = 8;
01205 m_n3DHardwareBufferMin = 8;
01206 m_n2DHardwareBufferMax = 256;
01207 m_n3DHardwareBufferMax = 256;
01208 m_n2DSoftwareBufferMax = 256;
01209 m_n3DSoftwareBufferMax = 256;
01210 m_nSegmentMax = 256;
01211 m_nOptimalSampleBits = 16;
01212 m_nOptimalSampleRate = 44100;
01213 m_sWorkingPath.erase();
01214 m_pAudioStreamFactory = 0;
01215 m_pMusicCallback = 0;
01216 }
01218 HWND m_hWnd;
01220 bool m_bLoadAsyncronously;
01222 bool m_bForceSoftware;
01224 bool m_bUseMusicReverb;
01226 bool m_bUseEAX;
01228 bool m_bUseZoomFX;
01230 bool m_bAutoStream;
01232 bool m_bCacheBuffers;
01234 uint32 m_n2DHardwareBufferMin;
01236 uint32 m_n3DHardwareBufferMin;
01238 uint32 m_n2DHardwareBufferMax;
01240 uint32 m_n3DHardwareBufferMax;
01242 uint32 m_n2DSoftwareBufferMax;
01244 uint32 m_n3DSoftwareBufferMax;
01246 uint32 m_nSegmentMax;
01248 uint32 m_nOptimalSampleBits;
01250 uint32 m_nOptimalSampleRate;
01252
01257 std::string m_sWorkingPath;
01259 IAudioStreamFactory* m_pAudioStreamFactory;
01261 IMusicCallback* m_pMusicCallback;
01262
01263 };
01264
01266
01270 struct AudioMgrStats
01271 {
01275 AudioMgrStats() { Clear(); }
01279 void Clear()
01280 {
01281 m_bForce2DSoftware = false;
01282 m_bForce3DSoftware = false;
01283 m_n2DSoundsLoaded = 0;
01284 m_n3DSoundsLoaded = 0;
01285 m_nSegmentsLoaded = 0;
01286 }
01288 bool m_bForce2DSoftware;
01290 bool m_bForce3DSoftware;
01292 uint32 m_n2DSoundsLoaded;
01294 uint32 m_n3DSoundsLoaded;
01296 uint32 m_nSegmentsLoaded;
01297 };
01298
01299
01301
01308 class IAudioManager
01309 {
01310 public:
01311
01320 virtual bool Init(const AudioMgrInit& init) = 0;
01327 virtual void Term() = 0;
01328
01333 virtual bool IsInitialized() const = 0;
01334
01341 virtual bool GetStats(AudioMgrStats& stats) const = 0;
01342
01348 virtual bool CreateSound(ISound*& pSound) = 0;
01354 virtual bool CreateSound3D(ISound3D*& pSound3D) = 0;
01360 virtual bool CreateSegment(ISegment*& pSegment) = 0;
01366 virtual bool CreateDLS(IDLS*& pDLS) = 0;
01367
01373 virtual bool CreateAudioScript(IAudioScript*& pScript) = 0;
01374
01381 virtual bool GetListener(IListener*& pListener) = 0;
01382
01390 virtual bool SetSoundVolume(float fVolume) = 0;
01397 virtual bool GetSoundVolume(float& fVolume) const = 0;
01398
01406 virtual bool SetMusicVolume(float fVolume) = 0;
01413 virtual bool GetMusicVolume(float& fVolume) const = 0;
01414
01420 virtual bool StopAll() = 0;
01426 virtual bool PauseAll() = 0;
01433 virtual bool ResumeAll() = 0;
01434
01442 virtual bool GetCurrentSegment(ISegment*& pSegment) const = 0;
01450 virtual bool GetNextSegment(ISegment*& pSegment) const = 0;
01451
01460 virtual bool CreateAudioStream(IAudioStream*& pStream) = 0;
01461 };
01462
01468 inline IAudioManager* AudioMgr()
01469 { return AudioLibFactory::GetAudioMgr(); }
01470
01471 #ifndef DOXYGEN_SHOULD_SKIP_THIS
01472 };
01473 #endif
01474
01475 #endif // __IAUDIO_H__