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.

127 lines
6.1 KiB

  1. //========= Copyright 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. #define SOUND_DMA_SPEED 44100 // hardware playback rate
  15. #define SOUND_11k 11025 // 11khz sample rate
  16. #define SOUND_22k 22050 // 22khz sample rate
  17. #define SOUND_44k 44100 // 44khz sample rate
  18. #define SOUND_ALL_RATES 1 // mix all sample rates
  19. #define SOUND_MIX_WET 0 // mix only samples that don't have channel set to 'dry' or 'speaker' (default)
  20. #define SOUND_MIX_DRY 1 // mix only samples with channel set to 'dry' (ie: music)
  21. #define SOUND_MIX_SPEAKER 2 // mix only samples with channel set to 'speaker'
  22. #define SOUND_MIX_SPECIAL_DSP 3 // mix only samples with channel set to 'special dsp'
  23. #define SOUND_BUSS_ROOM (1<<0) // mix samples using channel dspmix value (based on distance from player)
  24. #define SOUND_BUSS_FACING (1<<1) // mix samples using channel dspface value (source facing)
  25. #define SOUND_BUSS_FACINGAWAY (1<<2) // mix samples using 1-dspface
  26. #define SOUND_BUSS_SPEAKER (1<<3) // mix ch->bspeaker samples in mono to speaker buffer
  27. #define SOUND_BUSS_DRY (1<<4) // mix ch->bdry samples into dry buffer
  28. #define SOUND_BUSS_SPECIAL_DSP (1<<5) // mix ch->bspecialdsp samples into special dsp buffer
  29. class Vector;
  30. struct channel_t;
  31. // UNDONE: Create a simulated audio device to replace the old -simsound functionality?
  32. // General interface to an audio device
  33. abstract_class IAudioDevice
  34. {
  35. public:
  36. // Add a virtual destructor to silence the clang warning.
  37. // This is harmless but not important since the only derived class
  38. // doesn't have a destructor.
  39. virtual ~IAudioDevice() {}
  40. // Detect the sound hardware and create a compatible device
  41. // NOTE: This should NEVER fail. There is a function called Audio_GetNullDevice
  42. // which will create a "null" device that makes no sound. If we can't create a real
  43. // sound device, this will return a device of that type. All of the interface
  44. // functions can be called on the null device, but it will not, of course, make sound.
  45. static IAudioDevice *AutoDetectInit( bool waveOnly );
  46. // This is needed by some of the routines to avoid doing work when you've got a null device
  47. virtual bool IsActive( void ) = 0;
  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. // The volume of the "dry" mix (no effects).
  57. // This should return 0 on all implementations that don't need a separate dry mix
  58. virtual float MixDryVolume( void ) = 0;
  59. // Should we mix sounds to a 3D (quadraphonic) sound buffer (front/rear both stereo)
  60. virtual bool Should3DMix( void ) = 0;
  61. // This is called when the application stops all sounds
  62. // NOTE: Stopping each channel and clearing the sound buffer are done separately
  63. virtual void StopAllSounds( void ) = 0;
  64. // Called before painting channels, must calculated the endtime and return it (once per frame)
  65. virtual int PaintBegin( float, int soundtime, int paintedtime ) = 0;
  66. // Called when all channels are painted (once per frame)
  67. virtual void PaintEnd( void ) = 0;
  68. // Called to set the volumes on a channel with the given gain & dot parameters
  69. virtual void SpatializeChannel( int volume[6], int master_vol, const Vector& sourceDir, float gain, float mono ) = 0;
  70. // The device should apply DSP up to endtime in the current paint buffer
  71. // this is called during painting
  72. virtual void ApplyDSPEffects( int idsp, portable_samplepair_t *pbuffront, portable_samplepair_t *pbufrear, portable_samplepair_t *pbufcenter, int samplecount ) = 0;
  73. // replaces SNDDMA_GetDMAPos, gets the output sample position for tracking
  74. virtual int GetOutputPosition( void ) = 0;
  75. // Fill the output buffer with silence (e.g. during pause)
  76. virtual void ClearBuffer( void ) = 0;
  77. // Called each frame with the listener's coordinate system
  78. virtual void UpdateListener( const Vector& position, const Vector& forward, const Vector& right, const Vector& up ) = 0;
  79. // Called each time a new paint buffer is mixed (may be multiple times per frame)
  80. virtual void MixBegin( int sampleCount ) = 0;
  81. virtual void MixUpsample( int sampleCount, int filtertype ) = 0;
  82. // sink sound data
  83. virtual void Mix8Mono( channel_t *pChannel, char *pData, int outputOffset, int inputOffset, fixedint rateScaleFix, int outCount, int timecompress ) = 0;
  84. virtual void Mix8Stereo( channel_t *pChannel, char *pData, int outputOffset, int inputOffset, fixedint rateScaleFix, int outCount, int timecompress ) = 0;
  85. virtual void Mix16Mono( channel_t *pChannel, short *pData, int outputOffset, int inputOffset, fixedint rateScaleFix, int outCount, int timecompress ) = 0;
  86. virtual void Mix16Stereo( channel_t *pChannel, short *pData, int outputOffset, int inputOffset, fixedint rateScaleFix, int outCount, int timecompress ) = 0;
  87. // Reset a channel
  88. virtual void ChannelReset( int entnum, int channelIndex, float distanceMod ) = 0;
  89. virtual void TransferSamples( int end ) = 0;
  90. // device parameters
  91. virtual const char *DeviceName( void ) = 0;
  92. virtual int DeviceChannels( void ) = 0; // 1 = mono, 2 = stereo
  93. virtual int DeviceSampleBits( void ) = 0; // bits per sample (8 or 16)
  94. virtual int DeviceSampleBytes( void ) = 0; // above / 8
  95. virtual int DeviceDmaSpeed( void ) = 0; // Actual DMA speed
  96. virtual int DeviceSampleCount( void ) = 0; // Total samples in buffer
  97. virtual bool IsSurround( void ) = 0; // surround enabled, could be quad or 5.1
  98. virtual bool IsSurroundCenter( void ) = 0; // surround enabled as 5.1
  99. virtual bool IsHeadphone( void ) = 0;
  100. };
  101. extern IAudioDevice *Audio_GetNullDevice( void );
  102. #endif // SND_DEVICE_H