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.

105 lines
3.8 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //===========================================================================//
  9. #ifndef SND_DEVICE_H
  10. #define SND_DEVICE_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. #include "tier0/platform.h"
  15. //-----------------------------------------------------------------------------
  16. // 4.28 fixed point stuff for real-time resampling
  17. //-----------------------------------------------------------------------------
  18. #define FIX_BITS 28
  19. #define FIX_SCALE (1 << FIX_BITS)
  20. #define FIX_MASK ((1 << FIX_BITS)-1)
  21. #define FIX_FLOAT(a) ((int)((a) * FIX_SCALE))
  22. #define FIX(a) (((int)(a)) << FIX_BITS)
  23. #define FIX_INTPART(a) (((int)(a)) >> FIX_BITS)
  24. #define FIX_FRACTION(a,b) (FIX(a)/(b))
  25. #define FIX_FRACPART(a) ((a) & FIX_MASK)
  26. typedef unsigned int fixedint;
  27. //-----------------------------------------------------------------------------
  28. // sound rate defines
  29. //-----------------------------------------------------------------------------
  30. #define SOUND_DMA_SPEED 44100 // hardware playback rate
  31. #define SOUND_11k 11025 // 11khz sample rate
  32. #define SOUND_22k 22050 // 22khz sample rate
  33. #define SOUND_44k 44100 // 44khz sample rate
  34. #define SOUND_ALL_RATES 1 // mix all sample rates
  35. //-----------------------------------------------------------------------------
  36. // Information about the channel
  37. //-----------------------------------------------------------------------------
  38. struct channel_t
  39. {
  40. int leftvol;
  41. int rightvol;
  42. float pitch;
  43. };
  44. //-----------------------------------------------------------------------------
  45. // The audio device is responsible for mixing
  46. //-----------------------------------------------------------------------------
  47. abstract_class IAudioDevice
  48. {
  49. public:
  50. // This initializes the sound hardware. true on success, false on failure
  51. virtual bool Init( void ) = 0;
  52. // This releases all sound hardware
  53. virtual void Shutdown( void ) = 0;
  54. // device parameters
  55. virtual const char *DeviceName( void ) const = 0;
  56. virtual int DeviceChannels( void ) const = 0; // 1 = mono, 2 = stereo
  57. virtual int DeviceSampleBits( void ) const = 0; // bits per sample (8 or 16)
  58. virtual int DeviceSampleBytes( void ) const = 0; // above / 8
  59. virtual int DeviceSampleRate( void ) const = 0; // Actual DMA speed
  60. virtual int DeviceSampleCount( void ) const = 0; // Total samples in buffer
  61. // Called each time a new paint buffer is mixed (may be multiple times per frame)
  62. virtual void MixBegin( void ) = 0;
  63. // Main mixing routines
  64. virtual void Mix8Mono( channel_t *pChannel, char *pData, int outputOffset, int inputOffset, fixedint rateScaleFix, int outCount, int timecompress, bool forward = true ) = 0;
  65. virtual void Mix8Stereo( channel_t *pChannel, char *pData, int outputOffset, int inputOffset, fixedint rateScaleFix, int outCount, int timecompress, bool forward = true ) = 0;
  66. virtual void Mix16Mono( channel_t *pChannel, short *pData, int outputOffset, int inputOffset, fixedint rateScaleFix, int outCount, int timecompress, bool forward = true ) = 0;
  67. virtual void Mix16Stereo( channel_t *pChannel, short *pData, int outputOffset, int inputOffset, fixedint rateScaleFix, int outCount, int timecompress, bool forward = true ) = 0;
  68. // Size of the paint buffer in samples
  69. virtual int PaintBufferSampleCount( void ) const = 0;
  70. // Adds a mixer to be mixed
  71. virtual void AddSource( CAudioMixer *pSource ) = 0;
  72. // Stops all sounds
  73. virtual void StopSounds( void ) = 0;
  74. // Updates sound mixing
  75. virtual void Update( float time ) = 0;
  76. // Resets the device
  77. virtual void Flush( void ) = 0;
  78. virtual int FindSourceIndex( CAudioMixer *pSource ) = 0;
  79. virtual CAudioMixer *GetMixerForSource( CAudioSource *source ) = 0;
  80. virtual void FreeChannel( int channelIndex ) = 0;
  81. };
  82. #endif // SND_DEVICE_H