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.

161 lines
5.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef SOUNDFLAGS_H
  8. #define SOUNDFLAGS_H
  9. #if defined( _WIN32 )
  10. #pragma once
  11. #endif
  12. //-----------------------------------------------------------------------------
  13. // channels
  14. //-----------------------------------------------------------------------------
  15. enum
  16. {
  17. CHAN_REPLACE = -1,
  18. CHAN_AUTO = 0,
  19. CHAN_WEAPON = 1,
  20. CHAN_VOICE = 2,
  21. CHAN_ITEM = 3,
  22. CHAN_BODY = 4,
  23. CHAN_STREAM = 5, // allocate stream channel from the static or dynamic area
  24. CHAN_STATIC = 6, // allocate channel from the static area
  25. CHAN_VOICE2 = 7,
  26. CHAN_VOICE_BASE = 8, // allocate channel for network voice data
  27. CHAN_USER_BASE = (CHAN_VOICE_BASE+128) // Anything >= this number is allocated to game code.
  28. };
  29. //-----------------------------------------------------------------------------
  30. // common volume values
  31. //-----------------------------------------------------------------------------
  32. #define VOL_NORM 1.0f
  33. //-----------------------------------------------------------------------------
  34. // common attenuation values
  35. //-----------------------------------------------------------------------------
  36. #define ATTN_NONE 0.0f
  37. #define ATTN_NORM 0.8f
  38. #define ATTN_IDLE 2.0f
  39. #define ATTN_STATIC 1.25f
  40. #define ATTN_RICOCHET 1.5f
  41. // HL2 world is 8x bigger now! We want to hear gunfire from farther.
  42. // Don't change this without consulting Kelly or Wedge (sjb).
  43. #define ATTN_GUNFIRE 0.27f
  44. enum soundlevel_t
  45. {
  46. SNDLVL_NONE = 0,
  47. SNDLVL_20dB = 20, // rustling leaves
  48. SNDLVL_25dB = 25, // whispering
  49. SNDLVL_30dB = 30, // library
  50. SNDLVL_35dB = 35,
  51. SNDLVL_40dB = 40,
  52. SNDLVL_45dB = 45, // refrigerator
  53. SNDLVL_50dB = 50, // 3.9 // average home
  54. SNDLVL_55dB = 55, // 3.0
  55. SNDLVL_IDLE = 60, // 2.0
  56. SNDLVL_60dB = 60, // 2.0 // normal conversation, clothes dryer
  57. SNDLVL_65dB = 65, // 1.5 // washing machine, dishwasher
  58. SNDLVL_STATIC = 66, // 1.25
  59. SNDLVL_70dB = 70, // 1.0 // car, vacuum cleaner, mixer, electric sewing machine
  60. SNDLVL_NORM = 75,
  61. SNDLVL_75dB = 75, // 0.8 // busy traffic
  62. SNDLVL_80dB = 80, // 0.7 // mini-bike, alarm clock, noisy restaurant, office tabulator, outboard motor, passing snowmobile
  63. SNDLVL_TALKING = 80, // 0.7
  64. SNDLVL_85dB = 85, // 0.6 // average factory, electric shaver
  65. SNDLVL_90dB = 90, // 0.5 // screaming child, passing motorcycle, convertible ride on frw
  66. SNDLVL_95dB = 95,
  67. SNDLVL_100dB = 100, // 0.4 // subway train, diesel truck, woodworking shop, pneumatic drill, boiler shop, jackhammer
  68. SNDLVL_105dB = 105, // helicopter, power mower
  69. SNDLVL_110dB = 110, // snowmobile drvrs seat, inboard motorboat, sandblasting
  70. SNDLVL_120dB = 120, // auto horn, propeller aircraft
  71. SNDLVL_130dB = 130, // air raid siren
  72. SNDLVL_GUNFIRE = 140, // 0.27 // THRESHOLD OF PAIN, gunshot, jet engine
  73. SNDLVL_140dB = 140, // 0.2
  74. SNDLVL_150dB = 150, // 0.2
  75. SNDLVL_180dB = 180, // rocket launching
  76. // NOTE: Valid soundlevel_t values are 0-255.
  77. // 256-511 are reserved for sounds using goldsrc compatibility attenuation.
  78. };
  79. #define MAX_SNDLVL_BITS 9 // Used to encode 0-255 for regular soundlevel_t's and 256-511 for goldsrc-compatible ones.
  80. #define MIN_SNDLVL_VALUE 0
  81. #define MAX_SNDLVL_VALUE ((1<<MAX_SNDLVL_BITS)-1)
  82. #define ATTN_TO_SNDLVL( a ) (soundlevel_t)(int)((a) ? (50 + 20 / ((float)a)) : 0 )
  83. #define SNDLVL_TO_ATTN( a ) ((a > 50) ? (20.0f / (float)(a - 50)) : 4.0 )
  84. // This is a limit due to network encoding.
  85. // It encodes attenuation * 64 in 8 bits, so the maximum is (255 / 64)
  86. #define MAX_ATTENUATION 3.98f
  87. //-----------------------------------------------------------------------------
  88. // Flags to be or-ed together for the iFlags field
  89. //-----------------------------------------------------------------------------
  90. enum SoundFlags_t
  91. {
  92. SND_NOFLAGS = 0, // to keep the compiler happy
  93. SND_CHANGE_VOL = (1<<0), // change sound vol
  94. SND_CHANGE_PITCH = (1<<1), // change sound pitch
  95. SND_STOP = (1<<2), // stop the sound
  96. SND_SPAWNING = (1<<3), // we're spawning, used in some cases for ambients
  97. // not sent over net, only a param between dll and server.
  98. SND_DELAY = (1<<4), // sound has an initial delay
  99. SND_STOP_LOOPING = (1<<5), // stop all looping sounds on the entity.
  100. SND_SPEAKER = (1<<6), // being played again by a microphone through a speaker
  101. SND_SHOULDPAUSE = (1<<7), // this sound should be paused if the game is paused
  102. SND_IGNORE_PHONEMES = (1<<8),
  103. SND_IGNORE_NAME = (1<<9), // used to change all sounds emitted by an entity, regardless of scriptname
  104. SND_DO_NOT_OVERWRITE_EXISTING_ON_CHANNEL = (1<<10),
  105. };
  106. #define SND_FLAG_BITS_ENCODE 11
  107. #define MAX_SOUND_INDEX_BITS 14
  108. #define MAX_SOUNDS (1<<MAX_SOUND_INDEX_BITS)
  109. #if !defined( IN_XBOX_CODELINE )
  110. // +/-4096 msec
  111. #define MAX_SOUND_DELAY_MSEC_ENCODE_BITS (13)
  112. #else
  113. // +/-65536 msec, 64 seconds
  114. #define MAX_SOUND_DELAY_MSEC_ENCODE_BITS (17)
  115. #endif
  116. // Subtract one to leave room for the sign bit
  117. #define MAX_SOUND_DELAY_MSEC (1<<(MAX_SOUND_DELAY_MSEC_ENCODE_BITS-1)) // 4096 msec or about 4 seconds
  118. //-----------------------------------------------------------------------------
  119. // common pitch values
  120. //-----------------------------------------------------------------------------
  121. #define PITCH_NORM 100 // non-pitch shifted
  122. #define PITCH_LOW 95 // other values are possible - 0-255, where 255 is very high
  123. #define PITCH_HIGH 120
  124. #define DEFAULT_SOUND_PACKET_VOLUME 1.0f
  125. #define DEFAULT_SOUND_PACKET_PITCH 100
  126. #define DEFAULT_SOUND_PACKET_DELAY 0.0f
  127. #endif // SOUNDFLAGS_H