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.

119 lines
4.4 KiB

  1. //========= Copyright � 1996-2005, 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. virtual void MixBegin( void ) = 0;
  32. virtual void Mix8Mono( channel_t *pChannel, char *pData, int outputOffset, int inputOffset, int rateScaleFix, int outCount, int timecompress, bool forward = true ) = 0;
  33. virtual void Mix8Stereo( channel_t *pChannel, char *pData, int outputOffset, int inputOffset, int rateScaleFix, int outCount, int timecompress, bool forward = true ) = 0;
  34. virtual void Mix16Mono( channel_t *pChannel, short *pData, int outputOffset, int inputOffset, int rateScaleFix, int outCount, int timecompress, bool forward = true ) = 0;
  35. virtual void Mix16Stereo( channel_t *pChannel, short *pData, int outputOffset, int inputOffset, int rateScaleFix, int outCount, int timecompress, bool forward = true ) = 0;
  36. virtual int MaxSampleCount( void ) = 0;
  37. };
  38. //-----------------------------------------------------------------------------
  39. // Purpose: This is an instance of an audio source.
  40. // Mixers are attached to channels and reference an audio source.
  41. // Mixers are specific to the sample format and source format.
  42. // Mixers are never re-used, so they can track instance data like
  43. // sample position, fractional sample, stream cache, faders, etc.
  44. //-----------------------------------------------------------------------------
  45. class CAudioMixer
  46. {
  47. public:
  48. virtual ~CAudioMixer( void ) {}
  49. // UNDONE: time compress
  50. virtual bool MixDataToDevice( IAudioDevice *pDevice, channel_t *pChannel, int startSample, int sampleCount, int outputRate, bool forward = true ) = 0;
  51. virtual void IncrementSamples( channel_t *pChannel, int startSample, int sampleCount,int outputRate, bool forward = true ) = 0;
  52. virtual bool SkipSamples( channel_t *pChannel, int startSample, int sampleCount, int outputRate, bool forward = true ) = 0;
  53. virtual CAudioSource *GetSource( void ) = 0;
  54. virtual int GetSamplePosition( void ) = 0;
  55. virtual int GetScrubPosition( void ) = 0;
  56. virtual bool SetSamplePosition( int position, bool scrubbing = false ) = 0;
  57. virtual void SetLoopPosition( int position ) = 0;
  58. virtual int GetStartPosition( void ) = 0;
  59. virtual bool GetActive( void ) = 0;
  60. virtual void SetActive( bool active ) = 0;
  61. virtual void SetModelIndex( int index ) = 0;
  62. virtual int GetModelIndex( void ) const = 0;
  63. virtual void SetDirection( bool forward ) = 0;
  64. virtual bool GetDirection( void ) const = 0;
  65. virtual void SetAutoDelete( bool autodelete ) = 0;
  66. virtual bool GetAutoDelete( void ) const = 0;
  67. virtual void SetVolume( float volume ) = 0;
  68. virtual channel_t *GetChannel() = 0;
  69. };
  70. //-----------------------------------------------------------------------------
  71. // Purpose: A source is an abstraction for a stream, cached file, or procedural
  72. // source of audio.
  73. //-----------------------------------------------------------------------------
  74. class CSentence;
  75. class CAudioSource
  76. {
  77. public:
  78. CAudioSource( void );
  79. virtual ~CAudioSource( void );
  80. // Create an instance (mixer) of this audio source
  81. virtual CAudioMixer *CreateMixer( void ) = 0;
  82. virtual int GetOutputData( void **pData, int samplePosition, int sampleCount, bool forward = true ) = 0;
  83. virtual int SampleRate( void ) = 0;
  84. virtual int SampleSize( void ) = 0;
  85. virtual int SampleCount( void ) = 0;
  86. virtual float TrueSampleSize( void ) = 0;
  87. virtual bool IsLooped( void ) = 0;
  88. virtual bool IsStreaming( void ) = 0;
  89. virtual float GetRunningLength( void ) = 0;
  90. virtual int GetNumChannels() = 0;
  91. virtual bool IsStereoWav( void ) = 0;
  92. virtual CSentence *GetSentence( void ) { return NULL; };
  93. };
  94. extern CAudioSource *AudioSource_Create( const char *pName );
  95. #endif // SND_AUDIO_SOURCE_H