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.

251 lines
9.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef SND_CHANNELS_H
  7. #define SND_CHANNELS_H
  8. #include "mathlib/vector.h"
  9. #include "phonon/phonon_3d.h"
  10. #if defined( _WIN32 )
  11. #pragma once
  12. #endif
  13. class CSfxTable;
  14. class CAudioMixer;
  15. class CSosOperatorStackList;
  16. typedef int SoundSource;
  17. // DO NOT REORDER: indices to fvolume arrays in channel_t
  18. #define IFRONT_LEFT 0 // NOTE: must correspond to order of fvolume array below!
  19. #define IFRONT_RIGHT 1
  20. #define IREAR_LEFT 2
  21. #define IREAR_RIGHT 3
  22. #define IFRONT_CENTER 4
  23. #define IFRONT_CENTER0 5 // dummy slot - center channel is mono, but mixers reference volume[1] slot
  24. #define IFRONT_LEFTD 6 // start of doppler right array
  25. #define IFRONT_RIGHTD 7
  26. #define IREAR_LEFTD 8
  27. #define IREAR_RIGHTD 9
  28. #define IFRONT_CENTERD 10
  29. #define IFRONT_CENTERD0 11 // dummy slot - center channel is mono, but mixers reference volume[1] slot
  30. #define CCHANVOLUMES 12
  31. struct gain_t
  32. {
  33. float ob_gain; // gain drop if sound source obscured from listener
  34. float ob_gain_target; // target gain while crossfading between ob_gain & ob_gain_target
  35. float ob_gain_inc; // crossfade increment
  36. };
  37. struct hrtf_info_t
  38. {
  39. Vector vec; // Sound source relative to the listener, updated every frame for channels using HRTF.
  40. float lerp; // 1.0 = use phonon fully, 0.0 = don't use phonon at all.
  41. bool follow_entity; // If true, we update the position of the entity every frame, otherwise we use the position of the sound.
  42. bool bilinear_filtering; // If true, we use more expensive bilinear filtering for this sound.
  43. bool debug_lock_position; // If true, the vec will not be modified after the sound starts.
  44. };
  45. //-----------------------------------------------------------------------------
  46. // Purpose: Each currently playing wave is stored in a channel
  47. //-----------------------------------------------------------------------------
  48. // NOTE: 128bytes. These are memset to zero at some points. Do not add virtuals without changing that pattern.
  49. // UNDONE: now 300 bytes...
  50. struct channel_t
  51. {
  52. int guid; // incremented each time a channel is allocated (to match with channel free in tools, etc.)
  53. int userdata; // user specified data for syncing to tools
  54. hrtf_info_t hrtf;
  55. CSfxTable *sfx; // the actual sound
  56. CAudioMixer *pMixer; // The sound's instance data for this channel
  57. CSosOperatorStackList *m_pStackList; // The operator stack for this channel
  58. HSOUNDSCRIPTHASH m_nSoundScriptHash;
  59. // speaker channel volumes, indexed using IFRONT_LEFT to IFRONT_CENTER.
  60. // NOTE: never access these fvolume[] elements directly! Use channel helpers in snd_dma.cpp.
  61. float fvolume[CCHANVOLUMES]; // 0.0-255.0 current output volumes
  62. float fvolume_target[CCHANVOLUMES]; // 0.0-255.0 target output volumes
  63. float fvolume_inc[CCHANVOLUMES]; // volume increment, per frame, moves volume[i] to vol_target[i] (per spatialization)
  64. SoundSource soundsource; // see iclientsound.h for description.
  65. int entchannel; // sound channel (CHAN_STREAM, CHAN_VOICE, etc.)
  66. int speakerentity; // if a sound is being played through a speaker entity (e.g., on a monitor,), this is the
  67. // entity upon which to show the lips moving, if the sound has sentence data
  68. short master_vol; // 0-255 master volume
  69. short basePitch; // base pitch percent (100% is normal pitch playback)
  70. float pitch; // real-time pitch after any modulation or shift by dynamic data
  71. int mixgroups[8]; // sound belongs to these mixgroups: world, actor, player weapon, explosion etc.
  72. int last_mixgroupid;// last mixgroupid selected
  73. float last_vol; // last volume after spatialization
  74. Vector origin; // origin of sound effect
  75. Vector direction; // direction of the sound
  76. float dist_mult; // distance multiplier (attenuation/clipK)
  77. float m_flSoundLevel; // storing actual spl to avoid switching back and forth from dist_mult
  78. float dspmix; // 0 - 1.0 proportion of dsp to mix with original sound, based on distance
  79. // NOTE: this gets multiplied by g_dsp_volume in snd_mix.cpp, which is a culum of
  80. // other dsp setttings!
  81. float dspface; // -1.0 - 1.0 (1.0 = facing listener)
  82. float distmix; // 0 - 1.0 proportion based on distance from listner (1.0 - 100% wav right - far)
  83. float dsp_mix_min; // for dspmix calculation - set by current preset in SND_GetDspMix
  84. float dsp_mix_max; // for dspmix calculation - set by current preset in SND_GetDspMix
  85. float radius; // Radius of this sound effect (spatialization is different within the radius)
  86. gain_t gain[ MAX_SPLITSCREEN_CLIENTS ];
  87. short activeIndex;
  88. char wavtype; // 0 default, CHAR_DOPPLER, CHAR_DIRECTIONAL, CHAR_DISTVARIANT
  89. char pad;
  90. char sample_prev[8]; // last sample(s) in previous input data buffer - space for 2, 16 bit, stereo samples
  91. int initialStreamPosition;
  92. int skipInitialSamples;
  93. union
  94. {
  95. unsigned int flagsword;
  96. struct
  97. {
  98. bool bUpdatePositions : 1; // if true, assume sound source can move and update according to entity
  99. bool isSentence : 1; // true if playing linked sentence
  100. bool bdry : 1; // if true, bypass all dsp processing for this sound (ie: music)
  101. bool bSpeaker : 1; // true if sound is playing through in-game speaker entity.
  102. bool bstereowav : 1; // if true, a stereo .wav file is the sample data source
  103. bool delayed_start : 1; // If true, sound had a delay and so same sound on same channel won't channel steal from it
  104. bool fromserver : 1; // for snd_show, networked sounds get colored differently than local sounds
  105. bool bfirstpass : 1; // true if this is first time sound is spatialized
  106. bool bTraced : 1; // true if channel was already checked this frame for obscuring
  107. bool bfast_pitch : 1; // true if using low quality pitch (fast, but no interpolation)
  108. bool m_bIsFreeingChannel : 1; // true when inside S_FreeChannel - prevents reentrance
  109. bool m_bCompatibilityAttenuation : 1; // True when we want to use goldsrc compatibility mode for the attenuation
  110. // In that case, dist_mul is set to a relatively meaningful value in StartDynamic/StartStaticSound,
  111. // but we interpret it totally differently in SND_GetGain.
  112. bool m_bShouldPause : 1; // if true, sound should pause when the game is paused
  113. bool m_bIgnorePhonemes : 1; // if true, we don't want to drive animation w/ phoneme data
  114. bool m_bHasMouth : 1; // needs to output mouth records
  115. bool m_bMouthEnvelope : 1; // needs mouth wave envelope follower
  116. bool m_bShouldSaveRestore : 1; // Should be saved and restored
  117. bool m_bUpdateDelayForChoreo : 1; // Should update snd_delay_for_choreo with IO latency.
  118. bool m_bInEyeSound : 1; // This sound is playing from the viewpoint of the camera.
  119. } flags;
  120. };
  121. };
  122. //-----------------------------------------------------------------------------
  123. //-----------------------------------------------------------------------------
  124. #define MAX_CHANNELS 128
  125. #define MAX_DYNAMIC_CHANNELS 32
  126. //-----------------------------------------------------------------------------
  127. //-----------------------------------------------------------------------------
  128. extern channel_t channels[MAX_CHANNELS];
  129. // 0 to MAX_DYNAMIC_CHANNELS-1 = normal entity sounds
  130. // MAX_DYNAMIC_CHANNELS to total_channels = static sounds
  131. extern int total_channels;
  132. class CChannelList
  133. {
  134. public:
  135. int Count();
  136. int GetChannelIndex( int listIndex );
  137. channel_t *GetChannel( int listIndex );
  138. void RemoveChannelFromList( int listIndex );
  139. bool IsQuashed( int listIndex );
  140. int m_count;
  141. short m_list[MAX_CHANNELS];
  142. bool m_quashed[MAX_CHANNELS]; // if true, the channel should be advanced, but not mixed, because it's been heuristically suppressed
  143. bool m_hasSpeakerChannels : 1;
  144. bool m_hasDryChannels : 1;
  145. bool m_has11kChannels : 1;
  146. bool m_has22kChannels : 1;
  147. bool m_has44kChannels : 1;
  148. };
  149. inline int CChannelList::Count()
  150. {
  151. return m_count;
  152. }
  153. inline int CChannelList::GetChannelIndex( int listIndex )
  154. {
  155. return m_list[listIndex];
  156. }
  157. inline channel_t *CChannelList::GetChannel( int listIndex )
  158. {
  159. return &channels[GetChannelIndex(listIndex)];
  160. }
  161. inline bool CChannelList::IsQuashed( int listIndex )
  162. {
  163. return m_quashed[listIndex];
  164. }
  165. inline void CChannelList::RemoveChannelFromList( int listIndex )
  166. {
  167. // decrease the count by one, and swap the deleted channel with
  168. // the last one.
  169. m_count--;
  170. if ( m_count > 0 && listIndex != m_count )
  171. {
  172. m_list[listIndex] = m_list[m_count];
  173. m_quashed[listIndex] = m_quashed[m_count];
  174. }
  175. }
  176. struct activethreadsound_t
  177. {
  178. int m_nGuid;
  179. float m_flElapsedTime;
  180. };
  181. class CActiveChannels
  182. {
  183. public:
  184. void Add( channel_t *pChannel );
  185. void Remove( channel_t *pChannel );
  186. void GetActiveChannels( CChannelList &list ) const;
  187. void CopyActiveSounds( CUtlVector<activethreadsound_t> &list ) const;
  188. channel_t * FindActiveChannelByGuid( int guid ) const;
  189. void DumpChannelInfo( CUtlBuffer &buf );
  190. void Init();
  191. int GetActiveCount() { return m_count; }
  192. private:
  193. int m_count;
  194. short m_list[MAX_CHANNELS];
  195. };
  196. extern CActiveChannels g_ActiveChannels;
  197. //=============================================================================
  198. #endif // SND_CHANNELS_H