FilteredSound.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWAudio *
  23. * *
  24. * $Archive:: /Commando/Code/WWAudio/FilteredSound.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/25/02 12:09p $*
  29. * *
  30. * $Revision:: 5 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "filteredsound.h"
  36. #include "wwaudio.h"
  37. #include "soundscene.h"
  38. #include "soundchunkids.h"
  39. #include "persistfactory.h"
  40. #include "soundhandle.h"
  41. //////////////////////////////////////////////////////////////////////////////////
  42. //
  43. // Static factories
  44. //
  45. //////////////////////////////////////////////////////////////////////////////////
  46. SimplePersistFactoryClass<FilteredSoundClass, CHUNKID_FILTERED_SOUND> _FilteredSoundPersistFactory;
  47. /////////////////////////////////////////////////////////////////////////////////
  48. //
  49. // FilteredSoundClass
  50. //
  51. /////////////////////////////////////////////////////////////////////////////////
  52. FilteredSoundClass::FilteredSoundClass (void)
  53. : m_hFilter (INVALID_MILES_HANDLE)
  54. {
  55. return ;
  56. }
  57. ////////////////////////////////////////////////////////////////////////////////////////////////
  58. //
  59. // FilteredSoundClass
  60. //
  61. ////////////////////////////////////////////////////////////////////////////////////////////////
  62. FilteredSoundClass::FilteredSoundClass (const FilteredSoundClass &src)
  63. : m_hFilter (INVALID_MILES_HANDLE),
  64. SoundPseudo3DClass (src)
  65. {
  66. (*this) = src;
  67. return ;
  68. }
  69. /////////////////////////////////////////////////////////////////////////////////
  70. //
  71. // ~FilteredSoundClass
  72. //
  73. /////////////////////////////////////////////////////////////////////////////////
  74. FilteredSoundClass::~FilteredSoundClass (void)
  75. {
  76. return ;
  77. }
  78. ////////////////////////////////////////////////////////////////////////////////////////////////
  79. //
  80. // operator=
  81. //
  82. ////////////////////////////////////////////////////////////////////////////////////////////////
  83. const FilteredSoundClass &
  84. FilteredSoundClass::operator= (const FilteredSoundClass &src)
  85. {
  86. // Call the base class
  87. SoundPseudo3DClass::operator= (src);
  88. return (*this);
  89. }
  90. /////////////////////////////////////////////////////////////////////////////////
  91. //
  92. // Initialize_Miles_Handle
  93. //
  94. /////////////////////////////////////////////////////////////////////////////////
  95. void
  96. FilteredSoundClass::Initialize_Miles_Handle (void)
  97. {
  98. SoundPseudo3DClass::Initialize_Miles_Handle ();
  99. m_hFilter = WWAudioClass::Get_Instance ()->Get_Reverb_Filter ();
  100. if ((m_SoundHandle != NULL) &&
  101. (m_hFilter != INVALID_MILES_HANDLE)) {
  102. //
  103. // Pass the filter onto the sample
  104. //
  105. ::AIL_set_sample_processor (m_SoundHandle->Get_HSAMPLE (), DP_FILTER, m_hFilter);
  106. //
  107. // Change the reverb's settings to simulate a 'tinny' effect.
  108. //
  109. F32 reverb_level = 0.3F;
  110. F32 reverb_reflect = 0.01F;
  111. F32 reverb_decay = 0.535F;
  112. ::AIL_set_filter_sample_preference (m_SoundHandle->Get_HSAMPLE (),
  113. "Reverb level",
  114. &reverb_level);
  115. ::AIL_set_filter_sample_preference (m_SoundHandle->Get_HSAMPLE (),
  116. "Reverb reflect time",
  117. &reverb_reflect);
  118. ::AIL_set_filter_sample_preference (m_SoundHandle->Get_HSAMPLE (),
  119. "Reverb decay time",
  120. &reverb_decay);
  121. }
  122. Update_Volume ();
  123. return ;
  124. }
  125. /////////////////////////////////////////////////////////////////////////////////
  126. //
  127. // Update_Volume
  128. //
  129. /////////////////////////////////////////////////////////////////////////////////
  130. void
  131. FilteredSoundClass::Update_Volume (void)
  132. {
  133. if (m_SoundHandle != NULL) {
  134. // Determine the listener's position and the sound's position
  135. SoundSceneClass *scene = WWAudioClass::Get_Instance ()->Get_Sound_Scene ();
  136. if (scene != NULL) {
  137. Listener3DClass *listener = scene->Peek_2nd_Listener ();
  138. if (listener != NULL) {
  139. Vector3 listener_pos = listener->Get_Position ();
  140. Vector3 sound_pos = m_Transform.Get_Translation ();
  141. // Determine a normalized volume from the position
  142. float distance = (sound_pos - listener_pos).Quick_Length ();
  143. Update_Pseudo_Volume (distance);
  144. }
  145. }
  146. }
  147. return ;
  148. }
  149. /////////////////////////////////////////////////////////////////////////////////
  150. //
  151. // Get_Factory
  152. //
  153. /////////////////////////////////////////////////////////////////////////////////
  154. const PersistFactoryClass &
  155. FilteredSoundClass::Get_Factory (void) const
  156. {
  157. return _FilteredSoundPersistFactory;
  158. }