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.

160 lines
5.0 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_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. ~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 void ParseChunk( IterateRIFF &walk, int chunkName );
  42. virtual void ParseSentence( IterateRIFF &walk );
  43. void ConvertSamples( char *pData, int sampleCount );
  44. bool IsLooped( void );
  45. bool IsStereoWav( void );
  46. bool IsStreaming( void );
  47. int GetCacheStatus( void );
  48. int ConvertLoopedPosition( int samplePosition );
  49. void CacheLoad( void );
  50. void CacheUnload( void );
  51. virtual int ZeroCrossingBefore( int sample );
  52. virtual int ZeroCrossingAfter( int sample );
  53. virtual void ReferenceAdd( CAudioMixer *pMixer );
  54. virtual void ReferenceRemove( CAudioMixer *pMixer );
  55. virtual bool CanDelete( void );
  56. virtual CSentence *GetSentence( void );
  57. const char *GetName();
  58. virtual bool IsAsyncLoad();
  59. virtual void CheckAudioSourceCache();
  60. virtual char const *GetFileName();
  61. // 360 uses alternate play once semantics
  62. virtual void SetPlayOnce( bool bIsPlayOnce ) { m_bIsPlayOnce = IsPC() ? bIsPlayOnce : false; }
  63. virtual bool IsPlayOnce() { return IsPC() ? m_bIsPlayOnce : false; }
  64. virtual void SetSentenceWord( bool bIsWord ) { m_bIsSentenceWord = bIsWord; }
  65. virtual bool IsSentenceWord() { return m_bIsSentenceWord; }
  66. int GetLoopingInfo( int *pLoopBlock, int *pNumLeadingSamples, int *pNumTrailingSamples );
  67. virtual int SampleToStreamPosition( int samplePosition ) { return 0; }
  68. virtual int StreamToSamplePosition( int streamPosition ) { return 0; }
  69. protected:
  70. void ParseCueChunk( IterateRIFF &walk );
  71. void ParseSamplerChunk( IterateRIFF &walk );
  72. void Init( const char *pHeaderBuffer, int headerSize );
  73. bool GetStartupData( void *dest, int destsize, int& bytesCopied );
  74. bool GetXboxAudioStartupData();
  75. //-----------------------------------------------------------------------------
  76. // Purpose:
  77. // Output : byte
  78. //-----------------------------------------------------------------------------
  79. inline byte *GetCachedDataPointer()
  80. {
  81. VPROF("CAudioSourceWave::GetCachedDataPointer");
  82. CAudioSourceCachedInfo *info = m_AudioCacheHandle.Get( CAudioSource::AUDIO_SOURCE_WAV, m_pSfx->IsPrecachedSound(), m_pSfx, &m_nCachedDataSize );
  83. if ( !info )
  84. {
  85. Assert( !"CAudioSourceWave::GetCachedDataPointer info == NULL" );
  86. return NULL;
  87. }
  88. return (byte *)info->CachedData();
  89. }
  90. int m_bits;
  91. int m_rate;
  92. int m_channels;
  93. int m_format;
  94. int m_sampleSize;
  95. int m_loopStart;
  96. int m_sampleCount; // can be "samples" or "bytes", depends on format
  97. CSfxTable *m_pSfx;
  98. CSentence *m_pTempSentence;
  99. int m_dataStart; // offset of sample data
  100. int m_dataSize; // size of sample data
  101. char *m_pHeader;
  102. int m_nHeaderSize;
  103. CAudioSourceCachedInfoHandle_t m_AudioCacheHandle;
  104. int m_nCachedDataSize;
  105. // number of actual samples (regardless of format)
  106. // compressed formats alter definition of m_sampleCount
  107. // used to spare expensive calcs by decoders
  108. int m_numDecodedSamples;
  109. // additional data needed by xma decoder to for looping
  110. unsigned short m_loopBlock; // the block the loop occurs in
  111. unsigned short m_numLeadingSamples; // number of leader samples in the loop block to discard
  112. unsigned short m_numTrailingSamples; // number of trailing samples in the final block to discard
  113. unsigned short unused;
  114. unsigned int m_bNoSentence : 1;
  115. unsigned int m_bIsPlayOnce : 1;
  116. unsigned int m_bIsSentenceWord : 1;
  117. private:
  118. CAudioSourceWave( const CAudioSourceWave & ); // not implemented, not allowed
  119. int m_refCount;
  120. #ifdef _DEBUG
  121. // Only set in debug mode so you can see the name.
  122. const char *m_pDebugName;
  123. #endif
  124. };
  125. #endif // SND_WAVE_SOURCE_H