Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
5.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Client-server neutral sound interface
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef IENGINESOUND_H
  8. #define IENGINESOUND_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "basetypes.h"
  13. #include "interface.h"
  14. #include "soundflags.h"
  15. #include "irecipientfilter.h"
  16. #include "utlvector.h"
  17. #include "engine/SndInfo.h"
  18. //-----------------------------------------------------------------------------
  19. // forward declaration
  20. //-----------------------------------------------------------------------------
  21. class Vector;
  22. // Handy defines for EmitSound
  23. #define SOUND_FROM_UI_PANEL -2 // Sound being played inside a UI panel on the client
  24. #define SOUND_FROM_LOCAL_PLAYER -1
  25. #define SOUND_FROM_WORLD 0
  26. // These are used to feed a soundlevel to the sound system and have it use
  27. // goldsrc-type attenuation. We should use this as little as possible and
  28. // phase it out as soon as possible.
  29. // Take a regular sndlevel and convert it to compatibility mode.
  30. #define SNDLEVEL_TO_COMPATIBILITY_MODE( x ) ((soundlevel_t)(int)( (x) + 256 ))
  31. // Take a compatibility-mode sndlevel and get the REAL sndlevel out of it.
  32. #define SNDLEVEL_FROM_COMPATIBILITY_MODE( x ) ((soundlevel_t)(int)( (x) - 256 ))
  33. // Tells if the given sndlevel is marked as compatibility mode.
  34. #define SNDLEVEL_IS_COMPATIBILITY_MODE( x ) ( (x) >= soundlevel_t(256) )
  35. //-----------------------------------------------------------------------------
  36. // Client-server neutral effects interface
  37. //-----------------------------------------------------------------------------
  38. #define IENGINESOUND_CLIENT_INTERFACE_VERSION "IEngineSoundClient003"
  39. #define IENGINESOUND_SERVER_INTERFACE_VERSION "IEngineSoundServer003"
  40. abstract_class IEngineSound
  41. {
  42. public:
  43. // Precache a particular sample
  44. virtual bool PrecacheSound( const char *pSample, bool bPreload = false, bool bIsUISound = false ) = 0;
  45. virtual bool IsSoundPrecached( const char *pSample ) = 0;
  46. virtual void PrefetchSound( const char *pSample ) = 0;
  47. // Just loads the file header and checks for duration (not hooked up for .mp3's yet)
  48. // Is accessible to server and client though
  49. virtual float GetSoundDuration( const char *pSample ) = 0;
  50. // Pitch of 100 is no pitch shift. Pitch > 100 up to 255 is a higher pitch, pitch < 100
  51. // down to 1 is a lower pitch. 150 to 70 is the realistic range.
  52. // EmitSound with pitch != 100 should be used sparingly, as it's not quite as
  53. // fast (the pitchshift mixer is not native coded).
  54. // NOTE: setting iEntIndex to -1 will cause the sound to be emitted from the local
  55. // player (client-side only)
  56. virtual void EmitSound( IRecipientFilter& filter, int iEntIndex, int iChannel, const char *pSample,
  57. float flVolume, float flAttenuation, int iFlags = 0, int iPitch = PITCH_NORM, int iSpecialDSP = 0,
  58. const Vector *pOrigin = NULL, const Vector *pDirection = NULL, CUtlVector< Vector >* pUtlVecOrigins = NULL, bool bUpdatePositions = true, float soundtime = 0.0f, int speakerentity = -1 ) = 0;
  59. virtual void EmitSound( IRecipientFilter& filter, int iEntIndex, int iChannel, const char *pSample,
  60. float flVolume, soundlevel_t iSoundlevel, int iFlags = 0, int iPitch = PITCH_NORM, int iSpecialDSP = 0,
  61. const Vector *pOrigin = NULL, const Vector *pDirection = NULL, CUtlVector< Vector >* pUtlVecOrigins = NULL, bool bUpdatePositions = true, float soundtime = 0.0f, int speakerentity = -1 ) = 0;
  62. virtual void EmitSentenceByIndex( IRecipientFilter& filter, int iEntIndex, int iChannel, int iSentenceIndex,
  63. float flVolume, soundlevel_t iSoundlevel, int iFlags = 0, int iPitch = PITCH_NORM,int iSpecialDSP = 0,
  64. const Vector *pOrigin = NULL, const Vector *pDirection = NULL, CUtlVector< Vector >* pUtlVecOrigins = NULL, bool bUpdatePositions = true, float soundtime = 0.0f, int speakerentity = -1 ) = 0;
  65. virtual void StopSound( int iEntIndex, int iChannel, const char *pSample ) = 0;
  66. // stop all active sounds (client only)
  67. virtual void StopAllSounds(bool bClearBuffers) = 0;
  68. // Set the room type for a player (client only)
  69. virtual void SetRoomType( IRecipientFilter& filter, int roomType ) = 0;
  70. // Set the dsp preset for a player (client only)
  71. virtual void SetPlayerDSP( IRecipientFilter& filter, int dspType, bool fastReset ) = 0;
  72. // emit an "ambient" sound that isn't spatialized
  73. // only available on the client, assert on server
  74. virtual void EmitAmbientSound( const char *pSample, float flVolume, int iPitch = PITCH_NORM, int flags = 0, float soundtime = 0.0f ) = 0;
  75. // virtual EntChannel_t CreateEntChannel() = 0;
  76. virtual float GetDistGainFromSoundLevel( soundlevel_t soundlevel, float dist ) = 0;
  77. // Client .dll only functions
  78. virtual int GetGuidForLastSoundEmitted() = 0;
  79. virtual bool IsSoundStillPlaying( int guid ) = 0;
  80. virtual void StopSoundByGuid( int guid ) = 0;
  81. // Set's master volume (0.0->1.0)
  82. virtual void SetVolumeByGuid( int guid, float fvol ) = 0;
  83. // Retrieves list of all active sounds
  84. virtual void GetActiveSounds( CUtlVector< SndInfo_t >& sndlist ) = 0;
  85. virtual void PrecacheSentenceGroup( const char *pGroupName ) = 0;
  86. virtual void NotifyBeginMoviePlayback() = 0;
  87. virtual void NotifyEndMoviePlayback() = 0;
  88. };
  89. #endif // IENGINESOUND_H