sound.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. enum WaveKind
  2. {
  3. WAVEEFFECT,
  4. WAVEEFFECTEX,
  5. WAVESPEECH,
  6. WAVEMUSIC,
  7. WAVESPEECHEX,
  8. WAVEENVIRONMENT,
  9. WAVEENVIRONMENTEX,
  10. WAVEWEAPONS,
  11. WAVEWEAPONSEX,
  12. WAVEATTALWAYS,
  13. WAVEUI
  14. }
  15. //@}
  16. //----------------------------------------------
  17. /**
  18. * \defgroup SoundController API
  19. * @{
  20. */
  21. enum SoundControllerAction
  22. {
  23. None,
  24. Limit,
  25. Overwrite
  26. }
  27. /*!
  28. Overrides or limits soundmap value for a sound cotroller
  29. \param controllerName the sound controller name. One of: rain,night,meadow,trees,hills,houses,windy,deadBody,sea,forest,altitudeGround,altitudeSea,altitudeSurface,daytime,shooting,coast,waterDepth,overcast,fog,snowfall,caveSmall,caveBig
  30. \param action what action will be used on the normal landscape sound controller value
  31. \param value the new value of sound controller
  32. */
  33. proto native void SetSoundControllerOverride(string controllerName, float value, SoundControllerAction action);
  34. /*!
  35. Overrides all the environment controllers to be muted
  36. */
  37. proto native void MuteAllSoundControllers();
  38. /*!
  39. Removes all the previously set overrides of sound controllers
  40. */
  41. proto native void ResetAllSoundControllers();
  42. //@}
  43. class AbstractSoundScene
  44. {
  45. private void AbstractSoundScene() {}
  46. private void ~AbstractSoundScene() {}
  47. proto native AbstractWave Play2D(SoundObject soundObject, SoundObjectBuilder soundBuilder);
  48. proto native AbstractWave Play3D(SoundObject soundObject, SoundObjectBuilder soundBuilder);
  49. proto native SoundObject BuildSoundObject(SoundObjectBuilder soundObjectbuilder);
  50. proto native float GetRadioVolume();
  51. proto native void SetRadioVolume(float vol, float time);
  52. proto native float GetSpeechExVolume();
  53. proto native void SetSpeechExVolume(float vol, float time);
  54. proto native float GetMusicVolume();
  55. proto native void SetMusicVolume(float vol, float time);
  56. proto native float GetSoundVolume();
  57. proto native void SetSoundVolume(float vol, float time);
  58. proto native float GetVOIPVolume();
  59. proto native void SetVOIPVolume(float vol, float time);
  60. proto native float GetSilenceThreshold();
  61. proto native float GetAudioLevel();
  62. }
  63. class SoundObjectBuilder
  64. {
  65. void SoundObjectBuilder(SoundParams soundParams);
  66. SoundObject BuildSoundObject()
  67. {
  68. return GetGame().GetSoundScene().BuildSoundObject(this);
  69. }
  70. proto native void Initialize(SoundParams soundParams);
  71. proto native void AddEnvSoundVariables(vector position);
  72. proto native void AddVariable(string name, float value);
  73. proto void AddVariables(notnull array<string> names, array<float> values = null);
  74. //! Deprecated - same functionality, just poor naming
  75. void UpdateEnvSoundControllers(vector position)
  76. {
  77. AddEnvSoundVariables(position);
  78. }
  79. //! Deprecated - same functionality, just poor naming
  80. void SetVariable(string name, float value)
  81. {
  82. AddVariable(name, value);
  83. }
  84. }
  85. class SoundObject
  86. {
  87. void SoundObject(SoundParams soundParams);
  88. proto void UpdateVariables(notnull array<float> values);
  89. //! Note: 'SoundObject' is not an Entity, and therefore can not be accessed by using 'IEntity.GetChildren',
  90. //! though internally 'SoundObject.SetParent' is similiar to 'IEntity.AddChild' by creating an 'EntityHierarchyComponent'
  91. proto native void SetParent(IEntity parent, int pivot = -1);
  92. proto native IEntity GetParent();
  93. proto native int GetHierarchyPivot();
  94. //! Note: Sets the position locally if parented, retrieves globally with the sound offset
  95. proto native void SetPosition(vector position);
  96. proto native vector GetPosition();
  97. //! Note: Sets the speed locally if parented, retrieves globally with the parent speed
  98. proto native void SetSpeed(vector speed);
  99. proto native vector GetSpeed();
  100. proto native void SetOcclusionObstruction(float occlusion, float obstruction);
  101. proto native void SetKind(WaveKind kind);
  102. proto native void Initialize(SoundParams soundParams);
  103. }
  104. //soundsys.hpp
  105. class SoundParams
  106. {
  107. void SoundParams(string name);
  108. proto native bool Load(string name);
  109. proto native bool IsValid();
  110. proto string GetName();
  111. }
  112. class AbstractWaveEvents
  113. {
  114. ref ScriptInvoker Event_OnSoundWaveStarted = new ScriptInvoker();
  115. ref ScriptInvoker Event_OnSoundWaveStopped = new ScriptInvoker();
  116. ref ScriptInvoker Event_OnSoundWaveLoaded = new ScriptInvoker();
  117. ref ScriptInvoker Event_OnSoundWaveHeaderLoaded = new ScriptInvoker();
  118. ref ScriptInvoker Event_OnSoundWaveEnded = new ScriptInvoker();
  119. }
  120. class AbstractWave
  121. {
  122. private void InitEvents()
  123. {
  124. AbstractWaveEvents events = new AbstractWaveEvents();
  125. SetUserData(events);
  126. }
  127. #ifdef DIAG_DEVELOPER
  128. private void AbstractWave() { InitEvents(); }
  129. private void ~AbstractWave() {}
  130. #else
  131. void AbstractWave() { InitEvents(); }
  132. #endif
  133. proto void SetUserData(Managed inst);
  134. proto Managed GetUserData();
  135. proto void Play();
  136. void PlayWithOffset(float offset)
  137. {
  138. Play();
  139. SetStartOffset(offset);
  140. }
  141. //proto native void Mute();
  142. proto void Stop();
  143. proto void Restart();
  144. proto void SetStartOffset(float offset);
  145. //! WARNING: Blocking! Waits for header to load
  146. proto float GetLength();
  147. //! Current position in percentage of total length
  148. proto float GetCurrPosition();
  149. proto void Loop(bool setLoop);
  150. proto float GetVolume();
  151. proto void SetVolume(float value);
  152. proto void SetVolumeRelative(float value);
  153. proto void SetFrequency(float value);
  154. proto float GetFrequency();
  155. proto void SetPosition(vector position, vector velocity = "0 0 0");
  156. proto void SetFadeInFactor(float volume);
  157. proto void SetFadeOutFactor(float volume);
  158. proto void SetDoppler(bool setDoppler);
  159. proto void Skip(float timeSec);
  160. proto bool IsHeaderLoaded();
  161. AbstractWaveEvents GetEvents()
  162. {
  163. return AbstractWaveEvents.Cast(GetUserData());
  164. }
  165. void OnPlay()
  166. {
  167. GetEvents().Event_OnSoundWaveStarted.Invoke(this);
  168. }
  169. void OnStop()
  170. {
  171. GetEvents().Event_OnSoundWaveStopped.Invoke(this);
  172. }
  173. void OnLoad()
  174. {
  175. GetEvents().Event_OnSoundWaveLoaded.Invoke(this);
  176. }
  177. void OnHeaderLoad()
  178. {
  179. GetEvents().Event_OnSoundWaveHeaderLoaded.Invoke(this);
  180. }
  181. void OnEnd()
  182. {
  183. GetEvents().Event_OnSoundWaveEnded.Invoke(this);
  184. }
  185. }