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.

119 lines
4.4 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 bool SetSamplePosition( int position ) = 0;
  60. virtual void SetLoopPosition( int position ) = 0;
  61. virtual int GetStartPosition( void ) = 0;
  62. virtual bool GetActive( void ) = 0;
  63. virtual void SetActive( bool active ) = 0;
  64. virtual void SetModelIndex( int index ) = 0;
  65. virtual int GetModelIndex( void ) const = 0;
  66. virtual void SetDirection( bool forward ) = 0;
  67. virtual bool GetDirection( void ) const = 0;
  68. virtual void SetAutoDelete( bool autodelete ) = 0;
  69. virtual bool GetAutoDelete( void ) const = 0;
  70. };
  71. //-----------------------------------------------------------------------------
  72. // Purpose: A source is an abstraction for a stream, cached file, or procedural
  73. // source of audio.
  74. //-----------------------------------------------------------------------------
  75. class CSentence;
  76. class CAudioSource
  77. {
  78. public:
  79. CAudioSource( void );
  80. virtual ~CAudioSource( void );
  81. // Create an instance (mixer) of this audio source
  82. virtual CAudioMixer *CreateMixer( void ) = 0;
  83. virtual int GetOutputData( void **pData, int samplePosition, int sampleCount, bool forward = true ) = 0;
  84. virtual int SampleRate( void ) = 0;
  85. virtual int SampleSize( void ) = 0;
  86. virtual int SampleCount( void ) = 0;
  87. virtual float TrueSampleSize( void ) = 0;
  88. virtual bool IsLooped( void ) = 0;
  89. virtual bool IsStreaming( void ) = 0;
  90. virtual float GetRunningLength( void ) = 0;
  91. virtual CSentence *GetSentence( void ) { return NULL; };
  92. };
  93. extern CAudioSource *AudioSource_Create( const char *pName );
  94. #endif // SND_AUDIO_SOURCE_H