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.

114 lines
4.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: This abstracts the various hardware dependent implementations of sound
  4. // At the time of this writing there are Windows WAVEOUT, Direct Sound,
  5. // and Null implementations.
  6. //
  7. //=====================================================================================//
  8. #ifndef SND_DEVICE_H
  9. #define SND_DEVICE_H
  10. #pragma once
  11. #include "snd_fixedint.h"
  12. #include "snd_mix_buf.h"
  13. // sound engine rate defines
  14. #if 0 // def _PS3
  15. #define SOUND_DMA_SPEED 48000 // hardware playback rate
  16. #else
  17. #define SOUND_DMA_SPEED 44100 // hardware playback rate
  18. #endif
  19. #define SOUND_11k 11025 // 11khz sample rate
  20. #define SOUND_22k 22050 // 22khz sample rate
  21. #define SOUND_44k 44100 // 44khz sample rate
  22. #define SOUND_ALL_RATES 1 // mix all sample rates
  23. #define SOUND_MIX_WET 0 // mix only samples that don't have channel set to 'dry' or 'speaker' (default)
  24. #define SOUND_MIX_DRY 1 // mix only samples with channel set to 'dry' (ie: music)
  25. #define SOUND_MIX_SPEAKER 2 // mix only samples with channel set to 'speaker'
  26. #define SOUND_BUSS_ROOM (1<<0) // mix samples using channel dspmix value (based on distance from player)
  27. #define SOUND_BUSS_FACING (1<<1) // mix samples using channel dspface value (source facing)
  28. #define SOUND_BUSS_FACINGAWAY (1<<2) // mix samples using 1-dspface
  29. #define SOUND_BUSS_SPEAKER (1<<3) // mix ch->bspeaker samples in mono to speaker buffer
  30. #define SOUND_BUSS_DRY (1<<4) // mix ch->bdry samples into dry buffer
  31. class Vector;
  32. struct channel_t;
  33. #if defined(_WIN32) || defined(_WIN64)
  34. #define USE_AUDIO_DEVICE_V1 1
  35. #endif
  36. #if USE_AUDIO_DEVICE_V1
  37. // General interface to an audio device
  38. abstract_class IAudioDevice
  39. {
  40. public:
  41. virtual ~IAudioDevice() {}
  42. // Detect the sound hardware and create a compatible device
  43. // NOTE: This should NEVER fail. There is a function called Audio_GetNullDevice
  44. // which will create a "null" device that makes no sound. If we can't create a real
  45. // sound device, this will return a device of that type. All of the interface
  46. // functions can be called on the null device, but it will not, of course, make sound.
  47. static IAudioDevice *AutoDetectInit();
  48. // This initializes the sound hardware. true on success, false on failure
  49. virtual bool Init( void ) = 0;
  50. // This releases all sound hardware
  51. virtual void Shutdown( void ) = 0;
  52. // stop outputting sound, but be ready to resume on UnPause
  53. virtual void Pause( void ) = 0;
  54. // return to normal operation after a Pause()
  55. virtual void UnPause( void ) = 0;
  56. // Called before painting channels, must calculated the endtime and return it (once per frame)
  57. virtual int64 PaintBegin( float, int64 soundtime, int64 paintedtime ) = 0;
  58. virtual void PaintEnd() {}
  59. // replaces SNDDMA_GetDMAPos, gets the output sample position for tracking
  60. virtual int GetOutputPosition( void ) = 0;
  61. // Fill the output buffer with silence (e.g. during pause)
  62. virtual void ClearBuffer( void ) = 0;
  63. virtual void TransferSamples( int end ) = 0;
  64. // device parameters
  65. virtual int DeviceSampleCount( void ) = 0; // Total samples in buffer
  66. inline const char *Name() { return m_pName; }
  67. inline int ChannelCount() { return m_nChannels; }
  68. inline int BitsPerSample() { return m_nSampleBits; }
  69. inline int SampleRate() { return m_nSampleRate; }
  70. virtual bool IsSurround() { return m_nChannels > 2 ? true : false; }
  71. virtual bool IsSurroundCenter() { return m_nChannels > 4 ? true : false; }
  72. inline bool IsActive() { return m_bIsActive; }
  73. inline bool IsHeadphone() { return m_bIsHeadphone; } // mixing makes some choices differently for stereo vs headphones, expose that here.
  74. inline int DeviceSampleBytes() { return BitsPerSample() / 8; }
  75. protected:
  76. // NOTE: Derived classes MUST initialize these before returning a device from a factory
  77. const char *m_pName;
  78. int m_nChannels;
  79. int m_nSampleBits;
  80. int m_nSampleRate;
  81. bool m_bIsActive;
  82. bool m_bIsHeadphone;
  83. };
  84. extern IAudioDevice *Audio_GetNullDevice( void );
  85. #else
  86. #include "soundsystem/lowlevel.h"
  87. inline IAudioDevice2 *Audio_GetNullDevice()
  88. {
  89. return Audio_CreateNullDevice();
  90. }
  91. #endif
  92. #endif // SND_DEVICE_H