Counter Strike : Global Offensive Source Code
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.

332 lines
9.7 KiB

  1. //===== Copyright 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: client sound i/o functions
  4. //
  5. //===========================================================================//
  6. #ifndef SOUND_H
  7. #define SOUND_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "basetypes.h"
  12. #include "datamap.h"
  13. #include "mathlib/vector.h"
  14. #include "mathlib/mathlib.h"
  15. #include "tier1/strtools.h"
  16. #include "soundflags.h"
  17. #include "utlvector.h"
  18. #include "engine/SndInfo.h"
  19. #include "cdll_int.h"
  20. #include "SoundEmitterSystem/isoundemittersystembase.h"
  21. DECLARE_LOGGING_CHANNEL( LOG_SOUND_OPERATOR_SYSTEM );
  22. #define MAX_SFX 2048
  23. #define AUDIOSOURCE_CACHE_ROOTDIR "maps/soundcache"
  24. class CSfxTable;
  25. enum soundlevel_t;
  26. struct SoundInfo_t;
  27. struct AudioState_t;
  28. struct channel_t;
  29. class IFileList;
  30. void S_Init (void);
  31. void S_Shutdown (void);
  32. bool S_IsInitted();
  33. void S_StopAllSounds(bool clear);
  34. bool S_GetPreventSound( void );
  35. #if !USE_AUDIO_DEVICE_V1
  36. struct audio_device_description_t;
  37. void S_GetAudioDeviceList( CUtlVector<audio_device_description_t> &audioList );
  38. #endif
  39. class CAudioState
  40. {
  41. public:
  42. CAudioState() {}
  43. bool IsAnyPlayerUnderwater() const;
  44. AudioState_t &GetPerUser( int nSlot = -1 );
  45. const AudioState_t &GetPerUser( int nSlot = -1 ) const;
  46. private:
  47. AudioState_t m_PerUser[ MAX_SPLITSCREEN_CLIENTS ];
  48. };
  49. void S_Update( const CAudioState *pAudioState );
  50. void S_ExtraUpdate (void);
  51. void S_ClearBuffer (void);
  52. void S_BlockSound (void);
  53. void S_UnblockSound (void);
  54. void S_UpdateWindowFocus( bool bWindowHasFocus );
  55. float S_GetMasterVolume( void );
  56. void S_SoundFade( float percent, float holdtime, float intime, float outtime );
  57. void S_OnLoadScreen(bool value);
  58. void S_EnableThreadedMixing( bool bEnable );
  59. void S_EnableMusic( bool bEnable );
  60. void S_PreventSound(bool bSetting);
  61. struct StartSoundParams_t
  62. {
  63. StartSoundParams_t() :
  64. m_nSoundScriptHash( SOUNDEMITTER_INVALID_HASH ),
  65. m_pSoundEntryName( NULL ),
  66. staticsound( false ),
  67. userdata( 0 ),
  68. soundsource( 0 ),
  69. entchannel( CHAN_AUTO ),
  70. pSfx( 0 ),
  71. bUpdatePositions( true ),
  72. fvol( 1.0f ),
  73. soundlevel( SNDLVL_NORM ),
  74. flags( SND_NOFLAGS ),
  75. pitch( PITCH_NORM ),
  76. fromserver( false ),
  77. delay( 0.0f ),
  78. speakerentity( -1 ),
  79. bToolSound( false ),
  80. initialStreamPosition( 0 ),
  81. skipInitialSamples( 0 ),
  82. m_nQueuedGUID( UNINT_GUID ),
  83. m_bIsScriptHandle( false ),
  84. m_pOperatorsKV( NULL ),
  85. opStackElapsedTime( 0.0f ),
  86. opStackElapsedStopTime( 0.0f ),
  87. m_bDelayedStart( false ),
  88. m_bInEyeSound( false ),
  89. m_bHRTFFollowEntity( false ),
  90. m_bHRTFBilinear( false ),
  91. m_bHRTFLock( false )
  92. {
  93. origin.Init();
  94. direction.Init();
  95. }
  96. void Copy( StartSoundParams_t &destParams )
  97. {
  98. destParams.userdata = userdata;
  99. destParams.soundsource = soundsource;
  100. destParams.entchannel = entchannel;
  101. destParams.pSfx = pSfx;
  102. VectorCopy( origin, destParams.origin );
  103. VectorCopy( direction, destParams.direction );
  104. destParams.fvol = fvol;
  105. destParams.soundlevel = soundlevel;
  106. destParams.flags = flags;
  107. destParams.pitch = pitch;
  108. destParams.delay = delay;
  109. destParams.speakerentity = speakerentity;
  110. destParams.initialStreamPosition = initialStreamPosition;
  111. destParams.skipInitialSamples = skipInitialSamples;
  112. destParams.m_nQueuedGUID = m_nQueuedGUID;
  113. destParams.m_nSoundScriptHash = m_nSoundScriptHash;
  114. destParams.m_pSoundEntryName = m_pSoundEntryName;
  115. destParams.m_pOperatorsKV = m_pOperatorsKV;
  116. destParams.opStackElapsedTime = opStackElapsedTime;
  117. destParams.opStackElapsedStopTime = opStackElapsedStopTime;
  118. destParams.staticsound = staticsound;
  119. destParams.bUpdatePositions = bUpdatePositions;
  120. destParams.fromserver = fromserver;
  121. destParams.bToolSound = bToolSound;
  122. destParams.m_bIsScriptHandle = m_bIsScriptHandle;
  123. destParams.m_bDelayedStart = m_bDelayedStart;
  124. destParams.m_bInEyeSound = m_bInEyeSound;
  125. destParams.m_bHRTFFollowEntity = m_bHRTFFollowEntity;
  126. destParams.m_bHRTFBilinear = m_bHRTFBilinear;
  127. destParams.m_bHRTFLock = m_bHRTFLock;
  128. }
  129. void CopyNewFromParams( StartSoundParams_t &destParams )
  130. {
  131. destParams.userdata = userdata;
  132. // destParams.soundsource = soundsource;
  133. // destParams.entchannel = entchannel;
  134. destParams.pSfx = pSfx;
  135. VectorCopy( origin, destParams.origin );
  136. VectorCopy( direction,destParams.direction );
  137. destParams.fvol = fvol;
  138. destParams.soundlevel = soundlevel;
  139. destParams.flags = flags;
  140. destParams.pitch = pitch;
  141. destParams.delay = delay;
  142. destParams.speakerentity = speakerentity;
  143. // destParams.initialStreamPosition = initialStreamPosition;
  144. // destParams.skipInitialSamples = skipInitialSamples;
  145. // destParams.m_nQueuedGUID = m_nQueuedGUID;
  146. // destParams.m_nSoundScriptHash = m_nSoundScriptHash;
  147. // destParams.m_pSoundEntryName = m_pSoundEntryName;
  148. // destParams.m_pOperatorsKV = m_pOperatorsKV;
  149. // destParams.opStackElapsedTime = opStackElapsedTime;
  150. // destParams.opStackElapsedStopTime = opStackElapsedStopTime;
  151. destParams.staticsound = staticsound;
  152. destParams.bUpdatePositions = bUpdatePositions;
  153. destParams.fromserver = fromserver;
  154. destParams.bToolSound = bToolSound;
  155. destParams.m_bIsScriptHandle =m_bIsScriptHandle;
  156. destParams.m_bInEyeSound = m_bInEyeSound;
  157. destParams.m_bHRTFFollowEntity = m_bHRTFFollowEntity;
  158. destParams.m_bHRTFBilinear = m_bHRTFBilinear;
  159. destParams.m_bHRTFLock = m_bHRTFLock;
  160. /* destParams.m_bDelayedStart = m_bDelayedStart;*/
  161. }
  162. int userdata;
  163. int soundsource;
  164. int entchannel;
  165. CSfxTable *pSfx;
  166. Vector origin;
  167. Vector direction;
  168. float fvol;
  169. soundlevel_t soundlevel;
  170. int flags;
  171. int pitch;
  172. float delay;
  173. int speakerentity;
  174. int initialStreamPosition;
  175. int skipInitialSamples;
  176. int m_nQueuedGUID;
  177. HSOUNDSCRIPTHASH m_nSoundScriptHash;
  178. const char *m_pSoundEntryName;
  179. KeyValues *m_pOperatorsKV;
  180. float opStackElapsedTime;
  181. float opStackElapsedStopTime;
  182. bool staticsound : 1;
  183. bool bUpdatePositions : 1;
  184. bool fromserver : 1;
  185. bool bToolSound : 1;
  186. bool m_bIsScriptHandle : 1;
  187. bool m_bDelayedStart : 1;
  188. bool m_bInEyeSound : 1;
  189. bool m_bHRTFFollowEntity : 1;
  190. bool m_bHRTFBilinear : 1;
  191. bool m_bHRTFLock : 1;
  192. static const int UNINT_GUID = -1;
  193. static const int GENERATE_GUID = -2; // Generate GUID regardless of the other vol and pitch flags.
  194. };
  195. int S_StartSoundEntry( StartSoundParams_t &pStartParams, int nSeed, bool bFromQueue = false );
  196. int S_StartSound( StartSoundParams_t& params );
  197. void S_StopSound ( int entnum, int entchannel );
  198. enum clocksync_index_t
  199. {
  200. CLOCK_SYNC_CLIENT = 0,
  201. CLOCK_SYNC_SERVER,
  202. NUM_CLOCK_SYNCS
  203. };
  204. extern float S_ComputeDelayForSoundtime( float soundtime, clocksync_index_t syncIndex );
  205. void S_StopSoundByGuid( int guid, bool bForceSync = false );
  206. float S_SoundDuration( channel_t * pChannel );
  207. float S_SoundDurationByGuid( int guid );
  208. int S_GetGuidForLastSoundEmitted();
  209. bool S_IsSoundStillPlaying( int guid );
  210. bool S_GetSoundChannelVolume( const char* sound, float &flVolumeLeft, float &flVolumeRight );
  211. void S_GetActiveSounds( CUtlVector< SndInfo_t >& sndlist );
  212. void S_SetVolumeByGuid( int guid, float fvol );
  213. float S_GetElapsedTime( const channel_t * pChannel );
  214. float S_GetElapsedTimeByGuid( int guid );
  215. bool S_IsLoopingSoundByGuid( int guid );
  216. void S_ReloadSound( const char *pSample );
  217. float S_GetMono16Samples( const char *pszName, CUtlVector< short >& sampleList );
  218. CSfxTable *S_DummySfx( const char *name );
  219. CSfxTable *S_PrecacheSound (const char *sample );
  220. void S_PrefetchSound( char const *name, bool bPlayOnce );
  221. void S_MarkUISound( CSfxTable *pSfx );
  222. void S_ReloadFilesInList( IFileList *pFilesToReload );
  223. vec_t S_GetNominalClipDist();
  224. extern bool TestSoundChar(const char *pch, char c);
  225. extern char *PSkipSoundChars(const char *pch);
  226. #include "soundchars.h"
  227. // for recording movies
  228. void SND_MovieStart( void );
  229. void SND_MovieEnd( void );
  230. //-------------------------------------
  231. int S_GetCurrentStaticSounds( SoundInfo_t *pResult, int nSizeResult, int entchannel );
  232. //-----------------------------------------------------------------------------
  233. float S_GetGainFromSoundLevel( soundlevel_t soundlevel, vec_t dist );
  234. struct musicsave_t
  235. {
  236. DECLARE_SIMPLE_DATADESC();
  237. char songname[ 128 ];
  238. int sampleposition;
  239. short master_volume;
  240. };
  241. void S_GetCurrentlyPlayingMusic( CUtlVector< musicsave_t >& list );
  242. void S_RestartSong( const musicsave_t *song );
  243. struct channelsave
  244. {
  245. DECLARE_SIMPLE_DATADESC();
  246. char soundName[64];
  247. Vector origin;
  248. soundlevel_t soundLevel;
  249. int soundSource;
  250. int entChannel;
  251. int pitch;
  252. float opStackElapsedTime;
  253. float opStackElapsedStopTime;
  254. short masterVolume;
  255. };
  256. typedef CUtlVector< channelsave > ChannelSaveVector;
  257. void S_GetActiveSaveRestoreChannels( ChannelSaveVector& channelSaves );
  258. void S_RestartChannel( channelsave const& channelSave );
  259. bool S_DSPGetCurrentDASRoomNew(void);
  260. bool S_DSPGetCurrentDASRoomChanged(void);
  261. bool S_DSPGetCurrentDASRoomSkyAbove(void);
  262. float S_DSPGetCurrentDASRoomSkyPercent(void);
  263. enum setmixer_t
  264. {
  265. MIXER_SET = 0,
  266. MIXER_MULT
  267. };
  268. void S_SetMixGroupOfCurrentMixer( const char *szgroupname, const char *szparam, float val, int setMixerType );
  269. int S_GetMixGroupIndex( const char *pMixGroupName );
  270. int S_GetMixLayerIndex(const char *szmixlayername);
  271. void S_SetMixLayerLevel(int index, float level);
  272. void S_SetMixLayerTriggerFactor( const char *pMixLayerName, const char *pMixGroupName, float flFactor );
  273. void S_SetMixLayerTriggerFactor( int nMixLayerIndex, int nMixGroupIndex, float flFactor );
  274. // global pitch scale
  275. void S_SoundSetPitchScale( float flPitchScale );
  276. float S_SoundGetPitchScale( void );
  277. bool S_SOSSetOpvarFloat( const char *pOpVarName, float flValue );
  278. bool S_SOSGetOpvarFloat( const char *pOpVarName, float &flValue );
  279. void S_ValidateSoundCache( char const *pchWavFile );
  280. #if defined( _GAMECONSOLE )
  281. void S_UnloadSound( const char *pName );
  282. #endif
  283. void S_PurgeSoundsDueToLanguageChange();
  284. #endif // SOUND_H