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.

161 lines
4.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef SFMPHONEMEEXTRACTOR_H
  7. #define SFMPHONEMEEXTRACTOR_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "phonemeextractor/PhonemeExtractor.h"
  12. #include "tier1/UtlString.h"
  13. #include "sentence.h"
  14. #include "dme_controls/logpreview.h"
  15. //-----------------------------------------------------------------------------
  16. // Forward declarations
  17. //-----------------------------------------------------------------------------
  18. class CDmeSoundClip;
  19. class CDmeGameSound;
  20. class CDmeAnimationSet;
  21. //-----------------------------------------------------------------------------
  22. // Info about a particular phoneme to extract
  23. //-----------------------------------------------------------------------------
  24. class CExtractInfo
  25. {
  26. public:
  27. CExtractInfo();
  28. CExtractInfo( const CExtractInfo& src );
  29. ~CExtractInfo();
  30. void ClearTags();
  31. // Filled in by caller
  32. CDmeSoundClip *m_pClip;
  33. CDmeGameSound *m_pSound;
  34. CUtlString m_sHintText;
  35. bool m_bUseSentence;
  36. // Filled in by Extract()
  37. CSentence m_Sentence;
  38. float m_flDuration;
  39. bool m_bSentenceValid;
  40. // Must be passed in when calling for Apply, will be created and passed back for Extract
  41. CUtlVector< CBasePhonemeTag * > m_ApplyTags;
  42. };
  43. //-----------------------------------------------------------------------------
  44. // Extraction type
  45. //-----------------------------------------------------------------------------
  46. enum SFMPhonemeExtractType_t
  47. {
  48. EXTRACT_WIPE_RANGE = 0, // Wipe logs from start of first selected clip to end of last selected clip
  49. EXTRACT_WIPE_CLIP, // Wipe all log entries (for facial controls) over entire clip
  50. EXTRACT_WIPE_SOUNDS, // Leave logs untouched, except underneath each selected .wav file
  51. NUM_EXTRACT_WIPE_TYPES,
  52. };
  53. //-----------------------------------------------------------------------------
  54. // Filter type
  55. //-----------------------------------------------------------------------------
  56. enum SFMPhonemeFilterType_t
  57. {
  58. EXTRACT_FILTER_HOLD, // hold for phoneme duration
  59. EXTRACT_FILTER_LINEAR, // linearly blend from phoneme start to next phoneme
  60. EXTRACT_FILTER_FIXED_WIDTH, // hold and linearly falloff before and after
  61. NUM_EXTRACT_FILTER_TYPES,
  62. };
  63. //-----------------------------------------------------------------------------
  64. // Extraction information
  65. //-----------------------------------------------------------------------------
  66. struct ExtractDesc_t
  67. {
  68. SFMPhonemeExtractType_t m_nExtractType;
  69. SFMPhonemeFilterType_t m_nFilterType;
  70. bool m_bCreateBookmarks;
  71. CUtlVector< CExtractInfo > m_WorkList; // One or more .wavs to extract from
  72. CUtlVector< LogPreview_t > m_ControlList; // List of facial controls
  73. CDmeFilmClip *m_pMovie;
  74. CDmeFilmClip *m_pShot;
  75. CDmeAnimationSet *m_pSet;
  76. float m_flSampleRateHz;
  77. float m_flSampleFilterSize;
  78. };
  79. //-----------------------------------------------------------------------------
  80. // Main interface for phoneme extraction
  81. //-----------------------------------------------------------------------------
  82. class ISFMPhonemeExtractor
  83. {
  84. public:
  85. virtual ~ISFMPhonemeExtractor() {};
  86. virtual bool Init() = 0;
  87. virtual void Shutdown() = 0;
  88. virtual int GetAPICount() = 0;
  89. virtual void GetAPIInfo( int nIndex, CUtlString* pPrintName, PE_APITYPE *pAPIType ) = 0;
  90. virtual void Extract( const PE_APITYPE& apiType, ExtractDesc_t& info, bool bWritePhonemesToWavFiles = false ) = 0;
  91. virtual void ReApply( ExtractDesc_t& info ) = 0;
  92. virtual bool GetSentence( CDmeGameSound *pGameSound, CSentence& sentence ) = 0;
  93. };
  94. extern ISFMPhonemeExtractor *sfm_phonemeextractor;
  95. //-----------------------------------------------------------------------------
  96. // inline methods of CExtractInfo
  97. //-----------------------------------------------------------------------------
  98. inline CExtractInfo::CExtractInfo() : m_pClip( 0 ), m_pSound( 0 ),
  99. m_bSentenceValid( false ), m_bUseSentence( false ), m_flDuration( 0.0f )
  100. {
  101. }
  102. inline CExtractInfo::CExtractInfo( const CExtractInfo& src )
  103. {
  104. m_pClip = src.m_pClip;
  105. m_pSound = src.m_pSound;
  106. m_sHintText = src.m_sHintText;
  107. m_Sentence = src.m_Sentence;
  108. m_bSentenceValid = src.m_bSentenceValid;
  109. m_bUseSentence = src.m_bUseSentence;
  110. m_flDuration = src.m_flDuration;
  111. ClearTags();
  112. for ( int i = 0; i < src.m_ApplyTags.Count(); ++i )
  113. {
  114. CBasePhonemeTag *newTag = new CBasePhonemeTag( *src.m_ApplyTags[ i ] );
  115. m_ApplyTags.AddToTail( newTag );
  116. }
  117. }
  118. inline CExtractInfo::~CExtractInfo()
  119. {
  120. ClearTags();
  121. }
  122. inline void CExtractInfo::ClearTags()
  123. {
  124. for ( int i = 0; i < m_ApplyTags.Count(); ++i )
  125. {
  126. delete m_ApplyTags[ i ];
  127. }
  128. m_ApplyTags.RemoveAll();
  129. }
  130. #endif // PHONEMEEXTRACTOR_H