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.

185 lines
6.3 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef SND_MP3_SOURCE_H
  8. #define SND_MP3_SOURCE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "snd_audio_source.h"
  13. #include "snd_wave_data.h"
  14. #include "snd_sfx.h"
  15. class IWaveData;
  16. class CAudioMixer;
  17. abstract_class CAudioSourceMP3 : public CAudioSource
  18. {
  19. public:
  20. CAudioSourceMP3( CSfxTable *pSfx );
  21. CAudioSourceMP3( CSfxTable *pSfx, CAudioSourceCachedInfo *info );
  22. virtual ~CAudioSourceMP3();
  23. // Create an instance (mixer) of this audio source
  24. virtual CAudioMixer *CreateMixer( int initialStreamPosition, int skipInitialSamples, bool bUpdateDelayForChoreo, SoundError &soundError, struct hrtf_info_t* pHRTFVec ) = 0;
  25. virtual int GetType( void );
  26. virtual void GetCacheData( CAudioSourceCachedInfo *info );
  27. // Provide samples for the mixer. You can point pData at your own data, or if you prefer to copy the data,
  28. // you can copy it into copyBuf and set pData to copyBuf.
  29. virtual int GetOutputData( void **pData, int64 samplePosition, int sampleCount, char copyBuf[AUDIOSOURCE_COPYBUF_SIZE] ) = 0;
  30. virtual int SampleRate( void ) { return m_sampleRate; }
  31. // Returns true if the source is a voice source.
  32. // This affects the voice_overdrive behavior (all sounds get quieter when
  33. // someone is speaking).
  34. virtual bool IsVoiceSource() { return false; }
  35. virtual bool IsPlayerVoice() { return false; }
  36. virtual int SampleSize( void ) { return 1; }
  37. // Total number of samples in this source. NOTE: Some sources are infinite (mic input), they should return
  38. // a count equal to one second of audio at their current rate.
  39. virtual int SampleCount( void ) { return m_dataSize; }
  40. virtual int Format() { return 0; }
  41. virtual int DataSize( void ) { return 0; }
  42. virtual bool IsLooped( void ) { return false; }
  43. virtual bool IsStereoWav( void ) { return false; }
  44. virtual bool IsStreaming( void ) { return false; }
  45. virtual int GetCacheStatus( void ) { return AUDIO_IS_LOADED; }
  46. virtual void CacheLoad( void ) {}
  47. virtual void CacheUnload( void ) {}
  48. virtual CSentence *GetSentence( void ) { return NULL; }
  49. virtual int GetQuality( void ) { return 0; }
  50. virtual int ZeroCrossingBefore( int sample ) { return sample; }
  51. virtual int ZeroCrossingAfter( int sample ) { return sample; }
  52. // mixer's references
  53. virtual void ReferenceAdd( CAudioMixer *pMixer );
  54. virtual void ReferenceRemove( CAudioMixer *pMixer );
  55. // check reference count, return true if nothing is referencing this
  56. virtual bool CanDelete( void );
  57. virtual bool IsAsyncLoad();
  58. virtual void CheckAudioSourceCache();
  59. virtual char const *GetFileName( char *pOutBuf, size_t bufLen );
  60. virtual void SetPlayOnce( bool isPlayOnce ) { m_bIsPlayOnce = isPlayOnce; }
  61. virtual bool IsPlayOnce() { return m_bIsPlayOnce; }
  62. virtual void SetSentenceWord( bool bIsWord ) { m_bIsSentenceWord = bIsWord; }
  63. virtual bool IsSentenceWord() { return m_bIsSentenceWord; }
  64. virtual int SampleToStreamPosition( int samplePosition ) { return 0; }
  65. virtual int StreamToSamplePosition( int streamPosition ) { return 0; }
  66. protected:
  67. //-----------------------------------------------------------------------------
  68. // Purpose:
  69. // Output : byte
  70. //-----------------------------------------------------------------------------
  71. inline byte *GetCachedDataPointer()
  72. {
  73. VPROF("CAudioSourceMP3::GetCachedDataPointer");
  74. CAudioSourceCachedInfo *info = m_AudioCacheHandle.Get( CAudioSource::AUDIO_SOURCE_MP3, m_pSfx->IsPrecachedSound(), m_pSfx, &m_nCachedDataSize );
  75. if ( !info )
  76. {
  77. Assert( !"CAudioSourceMP3::GetCachedDataPointer info == NULL" );
  78. return NULL;
  79. }
  80. return (byte *)info->CachedData();
  81. }
  82. CAudioSourceCachedInfoHandle_t m_AudioCacheHandle;
  83. int m_nCachedDataSize;
  84. protected:
  85. bool GetStartupData();
  86. CSfxTable *m_pSfx;
  87. int m_sampleRate;
  88. int m_dataSize;
  89. int m_dataStart;
  90. int m_refCount;
  91. bool m_bIsPlayOnce : 1;
  92. bool m_bIsSentenceWord : 1;
  93. };
  94. //-----------------------------------------------------------------------------
  95. // Purpose: Streaming MP3 file
  96. //-----------------------------------------------------------------------------
  97. class CAudioSourceStreamMP3 : public CAudioSourceMP3, public IWaveStreamSource
  98. {
  99. public:
  100. CAudioSourceStreamMP3( CSfxTable *pSfx );
  101. CAudioSourceStreamMP3( CSfxTable *pSfx, CAudioSourceCachedInfo *info );
  102. ~CAudioSourceStreamMP3() {}
  103. bool IsStreaming( void ) { return true; }
  104. bool IsStereoWav(void) { return false; }
  105. CAudioMixer *CreateMixer(int initialStreamPosition, int skipInitialSamples, bool bUpdateDelayForChoreo, SoundError &soundError, struct hrtf_info_t* pHRTFVec);
  106. int GetOutputData( void **pData, int64 samplePosition, int sampleCount, char copyBuf[AUDIOSOURCE_COPYBUF_SIZE] );
  107. // IWaveStreamSource
  108. virtual int64 UpdateLoopingSamplePosition( int64 samplePosition )
  109. {
  110. return samplePosition;
  111. }
  112. virtual void UpdateSamples( char *pData, int sampleCount ) {}
  113. virtual int GetLoopingInfo( int *pLoopBlock, int *pNumLeadingSamples, int *pNumTrailingSamples )
  114. {
  115. return 0;
  116. }
  117. virtual void Prefetch();
  118. private:
  119. CAudioSourceStreamMP3( const CAudioSourceStreamMP3 & ); // not implemented, not accessible
  120. };
  121. class CAudioSourceMP3Cache : public CAudioSourceMP3
  122. {
  123. public:
  124. CAudioSourceMP3Cache( CSfxTable *pSfx );
  125. CAudioSourceMP3Cache( CSfxTable *pSfx, CAudioSourceCachedInfo *info );
  126. ~CAudioSourceMP3Cache( void );
  127. int GetCacheStatus( void );
  128. void CacheLoad( void );
  129. void CacheUnload( void );
  130. // NOTE: "samples" are bytes for MP3
  131. int GetOutputData( void **pData, int64 samplePosition, int sampleCount, char copyBuf[AUDIOSOURCE_COPYBUF_SIZE] );
  132. CAudioMixer *CreateMixer( int initialStreamPosition, int skipInitialSamples, bool bUpdateDelayForChoreo, SoundError &soundError, struct hrtf_info_t* pHRTFVec );
  133. virtual void Prefetch() {}
  134. protected:
  135. virtual char *GetDataPointer( void );
  136. WaveCacheHandle_t m_hCache;
  137. private:
  138. CAudioSourceMP3Cache( const CAudioSourceMP3Cache & );
  139. };
  140. bool Audio_IsMP3( const char *pName );
  141. CAudioSource *Audio_CreateStreamedMP3( CSfxTable *pSfx );
  142. CAudioSource *Audio_CreateMemoryMP3( CSfxTable *pSfx );
  143. CAudioMixer *CreateMP3Mixer( IWaveData *data, int *pSampleRate );
  144. #endif // SND_MP3_SOURCE_H