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.

167 lines
5.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_WAVE_SOURCE_H
  14. #define SND_WAVE_SOURCE_H
  15. #pragma once
  16. #include "snd_audio_source.h"
  17. class IterateRIFF;
  18. #include "sentence.h"
  19. #include "snd_sfx.h"
  20. //=============================================================================
  21. // Functions to create audio sources from wave files or from wave data.
  22. //=============================================================================
  23. extern CAudioSource* Audio_CreateMemoryWave( CSfxTable *pSfx );
  24. extern CAudioSource* Audio_CreateStreamedWave( CSfxTable *pSfx );
  25. class CAudioSourceWave : public CAudioSource
  26. {
  27. public:
  28. CAudioSourceWave( CSfxTable *pSfx );
  29. CAudioSourceWave( CSfxTable *pSfx, CAudioSourceCachedInfo *info );
  30. virtual ~CAudioSourceWave( void );
  31. virtual int GetType( void );
  32. virtual void GetCacheData( CAudioSourceCachedInfo *info );
  33. void Setup( const char *pFormat, int formatSize, IterateRIFF &walk );
  34. virtual int SampleRate( void );
  35. virtual int SampleSize( void );
  36. virtual int SampleCount( void );
  37. virtual int Format( void );
  38. virtual int DataSize( void );
  39. void *GetHeader( void );
  40. virtual bool IsVoiceSource();
  41. virtual bool IsPlayerVoice() { return false; }
  42. virtual void ParseChunk( IterateRIFF &walk, int chunkName );
  43. virtual void ParseSentence( IterateRIFF &walk );
  44. void ConvertSamples( char *pData, int sampleCount );
  45. bool IsLooped( void );
  46. bool IsStereoWav( void );
  47. bool IsStreaming( void );
  48. int GetCacheStatus( void );
  49. int64 ConvertLoopedPosition( int64 samplePosition );
  50. void CacheLoad( void );
  51. void CacheUnload( void );
  52. virtual int ZeroCrossingBefore( int sample );
  53. virtual int ZeroCrossingAfter( int sample );
  54. virtual void ReferenceAdd( CAudioMixer *pMixer );
  55. virtual void ReferenceRemove( CAudioMixer *pMixer );
  56. virtual bool CanDelete( void );
  57. virtual CSentence *GetSentence( void );
  58. const char *GetName(char *pBuf, size_t bufLen );
  59. virtual int GetQuality( void );
  60. virtual bool IsAsyncLoad();
  61. virtual void CheckAudioSourceCache();
  62. virtual char const *GetFileName( char *pOutBuffer, size_t bufLen );
  63. // 360 uses alternate play once semantics
  64. virtual void SetPlayOnce( bool bIsPlayOnce ) { m_bIsPlayOnce = IsPC() ? bIsPlayOnce : false; }
  65. virtual bool IsPlayOnce() { return IsPC() ? m_bIsPlayOnce : false; }
  66. virtual void SetSentenceWord( bool bIsWord ) { m_bIsSentenceWord = bIsWord; }
  67. virtual bool IsSentenceWord() { return m_bIsSentenceWord; }
  68. int GetLoopingInfo( int *pLoopBlock, int *pNumLeadingSamples, int *pNumTrailingSamples );
  69. virtual int SampleToStreamPosition( int samplePosition ) { return 0; }
  70. virtual int StreamToSamplePosition( int streamPosition ) { return 0; }
  71. // TERROR: limit data read while rebuilding cache
  72. void SetRebuildingCache( void ) { m_bIsRebuildingCache = true; }
  73. protected:
  74. void ParseCueChunk( IterateRIFF &walk );
  75. void ParseSamplerChunk( IterateRIFF &walk );
  76. void Init( const char *pHeaderBuffer, int headerSize );
  77. bool GetStartupData( int &nFileSize );
  78. bool GetXboxAudioStartupData();
  79. //-----------------------------------------------------------------------------
  80. // Purpose:
  81. // Output : byte
  82. //-----------------------------------------------------------------------------
  83. inline byte *GetCachedDataPointer()
  84. {
  85. VPROF("CAudioSourceWave::GetCachedDataPointer");
  86. CAudioSourceCachedInfo *info = m_AudioCacheHandle.Get( CAudioSource::AUDIO_SOURCE_WAV, m_pSfx->IsPrecachedSound(), m_pSfx, &m_nCachedDataSize );
  87. if ( !info )
  88. {
  89. Assert( !"CAudioSourceWave::GetCachedDataPointer info == NULL" );
  90. return NULL;
  91. }
  92. return (byte *)info->CachedData();
  93. }
  94. int m_bits;
  95. int m_rate;
  96. int m_channels;
  97. int m_format;
  98. int m_sampleSize;
  99. int m_loopStart;
  100. int m_sampleCount; // can be "samples" or "bytes", depends on format
  101. CSfxTable *m_pSfx;
  102. CSentence *m_pTempSentence;
  103. int m_dataStart; // offset of sample data
  104. int m_dataSize; // size of sample data
  105. char *m_pHeader;
  106. int m_nHeaderSize;
  107. CAudioSourceCachedInfoHandle_t m_AudioCacheHandle;
  108. int m_nCachedDataSize;
  109. // number of actual samples (regardless of format)
  110. // compressed formats alter definition of m_sampleCount
  111. // used to spare expensive calcs by decoders
  112. int m_numDecodedSamples;
  113. // additional data needed by xma decoder to for looping
  114. unsigned short m_loopBlock; // the block the loop occurs in
  115. unsigned short m_numLeadingSamples; // number of leader samples in the loop block to discard
  116. unsigned short m_numTrailingSamples; // number of trailing samples in the final block to discard
  117. unsigned short m_quality;
  118. unsigned int m_bNoSentence : 1;
  119. unsigned int m_bIsPlayOnce : 1;
  120. unsigned int m_bIsSentenceWord : 1;
  121. unsigned int m_bIsRebuildingCache : 1; // TERROR: limit data read while rebuilding cache
  122. private:
  123. CAudioSourceWave( const CAudioSourceWave & ); // not implemented, not allowed
  124. int m_refCount;
  125. #ifdef _DEBUG
  126. // Only set in debug mode so you can see the name.
  127. const char *m_pDebugName;
  128. #endif
  129. };
  130. PathTypeFilter_t GetAudioPathFilter();
  131. #endif // SND_WAVE_SOURCE_H