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.

110 lines
4.0 KiB

  1. //========= Copyright 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. // Add a virtual destructor to silence the clang warning.
  51. // This is harmless but not important since the only derived class
  52. // doesn't have a destructor.
  53. virtual ~IAudioDevice() {}
  54. // This initializes the sound hardware. true on success, false on failure
  55. virtual bool Init( void ) = 0;
  56. // This releases all sound hardware
  57. virtual void Shutdown( void ) = 0;
  58. // device parameters
  59. virtual const char *DeviceName( void ) const = 0;
  60. virtual int DeviceChannels( void ) const = 0; // 1 = mono, 2 = stereo
  61. virtual int DeviceSampleBits( void ) const = 0; // bits per sample (8 or 16)
  62. virtual int DeviceSampleBytes( void ) const = 0; // above / 8
  63. virtual int DeviceSampleRate( void ) const = 0; // Actual DMA speed
  64. virtual int DeviceSampleCount( void ) const = 0; // Total samples in buffer
  65. // Called each time a new paint buffer is mixed (may be multiple times per frame)
  66. virtual void MixBegin( void ) = 0;
  67. // Main mixing routines
  68. virtual void Mix8Mono( channel_t *pChannel, char *pData, int outputOffset, int inputOffset, fixedint rateScaleFix, int outCount, int timecompress, bool forward = true ) = 0;
  69. virtual void Mix8Stereo( channel_t *pChannel, char *pData, int outputOffset, int inputOffset, fixedint rateScaleFix, int outCount, int timecompress, bool forward = true ) = 0;
  70. virtual void Mix16Mono( channel_t *pChannel, short *pData, int outputOffset, int inputOffset, fixedint rateScaleFix, int outCount, int timecompress, bool forward = true ) = 0;
  71. virtual void Mix16Stereo( channel_t *pChannel, short *pData, int outputOffset, int inputOffset, fixedint rateScaleFix, int outCount, int timecompress, bool forward = true ) = 0;
  72. // Size of the paint buffer in samples
  73. virtual int PaintBufferSampleCount( void ) const = 0;
  74. // Adds a mixer to be mixed
  75. virtual void AddSource( CAudioMixer *pSource ) = 0;
  76. // Stops all sounds
  77. virtual void StopSounds( void ) = 0;
  78. // Updates sound mixing
  79. virtual void Update( float time ) = 0;
  80. // Resets the device
  81. virtual void Flush( void ) = 0;
  82. virtual int FindSourceIndex( CAudioMixer *pSource ) = 0;
  83. virtual CAudioMixer *GetMixerForSource( CAudioSource *source ) = 0;
  84. virtual void FreeChannel( int channelIndex ) = 0;
  85. };
  86. #endif // SND_DEVICE_H