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.

131 lines
2.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "wavefile.h"
  8. #include "wavebrowser.h"
  9. #include "sentence.h"
  10. #include "ifaceposersound.h"
  11. #include "SoundEmitterSystem/isoundemittersystembase.h"
  12. #include "snd_wave_source.h"
  13. #include "filesystem.h"
  14. #include "UtlBuffer.h"
  15. #include "phonemeeditor.h"
  16. //-----------------------------------------------------------------------------
  17. // Purpose:
  18. // Input : *name -
  19. //-----------------------------------------------------------------------------
  20. CWaveFile::CWaveFile( char const *filename )
  21. {
  22. m_bAsyncLoading = false;
  23. m_bSentenceLoaded = false;
  24. m_Sentence.Reset();
  25. Q_strncpy( m_szName, filename, sizeof( m_szName ) );
  26. Q_snprintf( m_szFileName, sizeof( m_szFileName ), "sound/%s", filename );
  27. }
  28. CWaveFile::~CWaveFile()
  29. {
  30. }
  31. //-----------------------------------------------------------------------------
  32. // Purpose:
  33. // Output : int
  34. //-----------------------------------------------------------------------------
  35. int CWaveFile::GetLanguageId()
  36. {
  37. return GetCloseCaptionLanguageId();
  38. }
  39. bool SceneManager_LoadSentenceFromWavFile( char const *wavfile, CSentence& sentence );
  40. void CWaveFile::EnsureSentence()
  41. {
  42. if ( m_bSentenceLoaded )
  43. return;
  44. m_bSentenceLoaded = true;
  45. if ( m_szFileName[ 0 ] )
  46. {
  47. SceneManager_LoadSentenceFromWavFile( m_szFileName, m_Sentence );
  48. }
  49. }
  50. //-----------------------------------------------------------------------------
  51. // Purpose:
  52. // Output : Returns true on success, false on failure.
  53. //-----------------------------------------------------------------------------
  54. bool CWaveFile::HasLoadedSentenceInfo() const
  55. {
  56. return m_bSentenceLoaded;
  57. }
  58. char const *CWaveFile::GetName() const
  59. {
  60. return m_szName;
  61. }
  62. char const *CWaveFile::GetFileName() const
  63. {
  64. return m_szFileName;
  65. }
  66. char const *CWaveFile::GetSentenceText()
  67. {
  68. EnsureSentence();
  69. return m_Sentence.GetText();
  70. }
  71. int CWaveFile::GetPhonemeCount()
  72. {
  73. EnsureSentence();
  74. return m_Sentence.CountPhonemes();
  75. }
  76. int CWaveFile::GetWordCount()
  77. {
  78. EnsureSentence();
  79. return m_Sentence.m_Words.Count();
  80. }
  81. void CWaveFile::Play()
  82. {
  83. Con_Printf( "Playing '%s' : '%s'\n", GetFileName(), GetSentenceText() );
  84. g_pPhonemeEditor->SetCurrentWaveFile( GetFileName() );
  85. g_pPhonemeEditor->Play();
  86. }
  87. bool CWaveFile::GetVoiceDuck()
  88. {
  89. EnsureSentence();
  90. return m_Sentence.GetVoiceDuck();
  91. }
  92. int CWaveFile::GetIconIndex() const
  93. {
  94. return 0; // IMAGE_WAV;
  95. }
  96. //-----------------------------------------------------------------------------
  97. // Purpose:
  98. // Input : sentence -
  99. //-----------------------------------------------------------------------------
  100. void CWaveFile::SetThreadLoadedSentence( CSentence& sentence )
  101. {
  102. if ( m_bSentenceLoaded )
  103. return;
  104. m_bSentenceLoaded = true;
  105. m_Sentence = sentence;
  106. }