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.

124 lines
4.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //-----------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #ifndef SND_AUDIO_SOURCE_H
  14. #define SND_AUDIO_SOURCE_H
  15. #pragma once
  16. // fixed point stuff for real-time resampling
  17. #define FIX_BITS 28
  18. #define FIX_SCALE (1 << FIX_BITS)
  19. #define FIX_MASK ((1 << FIX_BITS)-1)
  20. #define FIX_FLOAT(a) ((int)((a) * FIX_SCALE))
  21. #define FIX(a) (((int)(a)) << FIX_BITS)
  22. #define FIX_INTPART(a) (((int)(a)) >> FIX_BITS)
  23. #define FIX_FRACTION(a,b) (FIX(a)/(b))
  24. #define FIX_FRACPART(a) ((a) & FIX_MASK)
  25. typedef unsigned int fixedint;
  26. typedef struct channel_s channel_t;
  27. class CAudioSource;
  28. class IAudioDevice
  29. {
  30. public:
  31. // Add a virtual destructor to silence the clang warning.
  32. // This is harmless but not important since the only derived class
  33. // doesn't have a destructor.
  34. virtual ~IAudioDevice() {}
  35. virtual void MixBegin( void ) = 0;
  36. virtual void Mix8Mono( channel_t *pChannel, char *pData, int outputOffset, int inputOffset, int rateScaleFix, int outCount, int timecompress, bool forward = true ) = 0;
  37. virtual void Mix8Stereo( channel_t *pChannel, char *pData, int outputOffset, int inputOffset, int rateScaleFix, int outCount, int timecompress, bool forward = true ) = 0;
  38. virtual void Mix16Mono( channel_t *pChannel, short *pData, int outputOffset, int inputOffset, int rateScaleFix, int outCount, int timecompress, bool forward = true ) = 0;
  39. virtual void Mix16Stereo( channel_t *pChannel, short *pData, int outputOffset, int inputOffset, int rateScaleFix, int outCount, int timecompress, bool forward = true ) = 0;
  40. virtual int MaxSampleCount( void ) = 0;
  41. };
  42. //-----------------------------------------------------------------------------
  43. // Purpose: This is an instance of an audio source.
  44. // Mixers are attached to channels and reference an audio source.
  45. // Mixers are specific to the sample format and source format.
  46. // Mixers are never re-used, so they can track instance data like
  47. // sample position, fractional sample, stream cache, faders, etc.
  48. //-----------------------------------------------------------------------------
  49. class CAudioMixer
  50. {
  51. public:
  52. virtual ~CAudioMixer( void ) {}
  53. // UNDONE: time compress
  54. virtual bool MixDataToDevice( IAudioDevice *pDevice, channel_t *pChannel, int startSample, int sampleCount, int outputRate, bool forward = true ) = 0;
  55. virtual void IncrementSamples( channel_t *pChannel, int startSample, int sampleCount,int outputRate, bool forward = true ) = 0;
  56. virtual bool SkipSamples( channel_t *pChannel, int startSample, int sampleCount, int outputRate, bool forward = true ) = 0;
  57. virtual CAudioSource *GetSource( void ) = 0;
  58. virtual int GetSamplePosition( void ) = 0;
  59. virtual int GetScrubPosition( void ) = 0;
  60. virtual bool SetSamplePosition( int position, bool scrubbing = false ) = 0;
  61. virtual void SetLoopPosition( int position ) = 0;
  62. virtual int GetStartPosition( void ) = 0;
  63. virtual bool GetActive( void ) = 0;
  64. virtual void SetActive( bool active ) = 0;
  65. virtual void SetModelIndex( int index ) = 0;
  66. virtual int GetModelIndex( void ) const = 0;
  67. virtual void SetDirection( bool forward ) = 0;
  68. virtual bool GetDirection( void ) const = 0;
  69. virtual void SetAutoDelete( bool autodelete ) = 0;
  70. virtual bool GetAutoDelete( void ) const = 0;
  71. virtual void SetVolume( float volume ) = 0;
  72. virtual channel_t *GetChannel() = 0;
  73. };
  74. //-----------------------------------------------------------------------------
  75. // Purpose: A source is an abstraction for a stream, cached file, or procedural
  76. // source of audio.
  77. //-----------------------------------------------------------------------------
  78. class CSentence;
  79. class CAudioSource
  80. {
  81. public:
  82. CAudioSource( void );
  83. virtual ~CAudioSource( void );
  84. // Create an instance (mixer) of this audio source
  85. virtual CAudioMixer *CreateMixer( void ) = 0;
  86. virtual int GetOutputData( void **pData, int samplePosition, int sampleCount, bool forward = true ) = 0;
  87. virtual int SampleRate( void ) = 0;
  88. virtual int SampleSize( void ) = 0;
  89. virtual int SampleCount( void ) = 0;
  90. virtual float TrueSampleSize( void ) = 0;
  91. virtual bool IsLooped( void ) = 0;
  92. virtual bool IsStreaming( void ) = 0;
  93. virtual float GetRunningLength( void ) = 0;
  94. virtual int GetNumChannels() = 0;
  95. virtual bool IsStereoWav( void ) = 0;
  96. virtual CSentence *GetSentence( void ) { return NULL; };
  97. };
  98. extern CAudioSource *AudioSource_Create( const char *pName );
  99. #endif // SND_AUDIO_SOURCE_H