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.

107 lines
3.6 KiB

  1. //========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef SND_MIX_BUF_H
  8. #define SND_MIX_BUF_H
  9. #if defined( _WIN32 )
  10. #pragma once
  11. #endif
  12. // OPTIMIZE: note that making this larger will not increase performance (12/27/03)
  13. #define PAINTBUFFER_SIZE 1020 // 44k: was 512
  14. #define PAINTBUFFER (g_curpaintbuffer)
  15. #define REARPAINTBUFFER (g_currearpaintbuffer)
  16. #define CENTERPAINTBUFFER (g_curcenterpaintbuffer)
  17. #define CPAINTBUFFERS 6
  18. // !!! if this is changed, it much be changed in native assembly too !!!
  19. struct portable_samplepair_t
  20. {
  21. int left;
  22. int right;
  23. };
  24. // This should match the struct portable_samplepair_t
  25. enum Channels
  26. {
  27. CHANNEL_LEFT = 0,
  28. CHANNEL_RIGHT = 1,
  29. };
  30. // sound mixing buffer
  31. #define CPAINTFILTERMEM 3
  32. #define CPAINTFILTERS 4 // maximum number of consecutive upsample passes per paintbuffer
  33. struct paintbuffer_t
  34. {
  35. bool factive; // if true, mix to this paintbuffer using flags
  36. bool fsurround; // if true, mix to front and rear paintbuffers using flags
  37. bool fsurround_center; // if true, mix to front, rear and center paintbuffers using flags
  38. int flags; // SOUND_BUSS_ROOM, SOUND_BUSS_FACING, SOUND_BUSS_FACINGAWAY, SOUND_BUSS_SPEAKER, SOUND_BUSS_DRY
  39. portable_samplepair_t *pbuf; // front stereo mix buffer, for 2 or 4 channel mixing
  40. portable_samplepair_t *pbufrear; // rear mix buffer, for 4 channel mixing
  41. portable_samplepair_t *pbufcenter; // center mix buffer, for 5 channel mixing
  42. int ifilter; // current filter memory buffer to use for upsampling pass
  43. portable_samplepair_t fltmem[CPAINTFILTERS][CPAINTFILTERMEM]; // filter memory, for upsampling with linear or cubic interpolation
  44. portable_samplepair_t fltmemrear[CPAINTFILTERS][CPAINTFILTERMEM]; // filter memory, for upsampling with linear or cubic interpolation
  45. portable_samplepair_t fltmemcenter[CPAINTFILTERS][CPAINTFILTERMEM]; // filter memory, for upsampling with linear or cubic interpolation
  46. };
  47. extern "C"
  48. {
  49. extern portable_samplepair_t *g_paintbuffer;
  50. // temp paintbuffer - not included in main list of paintbuffers
  51. extern portable_samplepair_t *g_temppaintbuffer;
  52. extern paintbuffer_t *g_paintBuffers;
  53. extern void MIX_SetCurrentPaintbuffer( int ipaintbuffer );
  54. extern int MIX_GetCurrentPaintbufferIndex( void );
  55. extern paintbuffer_t *MIX_GetCurrentPaintbufferPtr( void );
  56. extern void MIX_ClearAllPaintBuffers( int SampleCount, bool clearFilters );
  57. extern bool MIX_InitAllPaintbuffers(void);
  58. extern void MIX_FreeAllPaintbuffers(void);
  59. extern portable_samplepair_t *g_curpaintbuffer;
  60. extern portable_samplepair_t *g_currearpaintbuffer;
  61. extern portable_samplepair_t *g_curcenterpaintbuffer;
  62. };
  63. // must be at least PAINTBUFFER_SIZE+1 for upsampling
  64. #define PAINTBUFFER_MEM_SIZE (PAINTBUFFER_SIZE+4)
  65. // size in samples of copy buffer used by pitch shifters in mixing
  66. #if defined(_GAMECONSOLE)
  67. #define TEMP_COPY_BUFFER_SIZE (PAINTBUFFER_MEM_SIZE * 2)
  68. #else
  69. // allow more memory for this on PC for developers to pitch-shift their way through dialog
  70. #define TEMP_COPY_BUFFER_SIZE (PAINTBUFFER_MEM_SIZE * 4)
  71. #endif
  72. // hard clip input value to -32767 <= y <= 32767
  73. #define CLIP(x) ((x) > 32767 ? 32767 : ((x) < -32767 ? -32767 : (x)))
  74. // Branch-less version of CLIP on PPC - Much better.
  75. FORCEINLINE
  76. int iclip( int nInput )
  77. {
  78. int nResult = iclamp( nInput, -32767, +32767 ); // Interestingly it should actually be -32768 but the old code did not use the correct value. Keep the old value for the moment.
  79. Assert( nResult == CLIP( nInput ) );
  80. return nResult;
  81. }
  82. #endif // SND_MIX_BUF_H