sound.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. class AbstractSoundScene
  16. {
  17. private void AbstractSoundScene() {}
  18. private void ~AbstractSoundScene() {}
  19. proto native AbstractWave Play2D(SoundObject soundObject, SoundObjectBuilder soundBuilder);
  20. proto native AbstractWave Play3D(SoundObject soundObject, SoundObjectBuilder soundBuilder);
  21. proto native SoundObject BuildSoundObject(SoundObjectBuilder soundObjectbuilder);
  22. proto native float GetRadioVolume();
  23. proto native void SetRadioVolume(float vol, float time);
  24. proto native float GetSpeechExVolume();
  25. proto native void SetSpeechExVolume(float vol, float time);
  26. proto native float GetMusicVolume();
  27. proto native void SetMusicVolume(float vol, float time);
  28. proto native float GetSoundVolume();
  29. proto native void SetSoundVolume(float vol, float time);
  30. proto native float GetVOIPVolume();
  31. proto native void SetVOIPVolume(float vol, float time);
  32. proto native float GetSilenceThreshold();
  33. proto native float GetAudioLevel();
  34. }
  35. class SoundObjectBuilder
  36. {
  37. void SoundObjectBuilder(SoundParams soundParams);
  38. SoundObject BuildSoundObject()
  39. {
  40. return GetGame().GetSoundScene().BuildSoundObject(this);
  41. }
  42. proto native void Initialize(SoundParams soundParams);
  43. proto native void AddEnvSoundVariables(vector position);
  44. proto native void AddVariable(string name, float value);
  45. proto void AddVariables(notnull array<string> names, array<float> values = null);
  46. //! Deprecated - same functionality, just poor naming
  47. void UpdateEnvSoundControllers(vector position)
  48. {
  49. AddEnvSoundVariables(position);
  50. }
  51. //! Deprecated - same functionality, just poor naming
  52. void SetVariable(string name, float value)
  53. {
  54. AddVariable(name, value);
  55. }
  56. }
  57. class SoundObject
  58. {
  59. void SoundObject(SoundParams soundParams);
  60. proto void UpdateVariables(notnull array<float> values);
  61. //! Note: 'SoundObject' is not an Entity, and therefore can not be accessed by using 'IEntity.GetChildren',
  62. //! though internally 'SoundObject.SetParent' is similiar to 'IEntity.AddChild' by creating an 'EntityHierarchyComponent'
  63. proto native void SetParent(IEntity parent, int pivot = -1);
  64. proto native IEntity GetParent();
  65. proto native int GetHierarchyPivot();
  66. //! Note: Sets the position locally if parented, retrieves globally with the sound offset
  67. proto native void SetPosition(vector position);
  68. proto native vector GetPosition();
  69. //! Note: Sets the speed locally if parented, retrieves globally with the parent speed
  70. proto native void SetSpeed(vector speed);
  71. proto native vector GetSpeed();
  72. proto native void SetOcclusionObstruction(float occlusion, float obstruction);
  73. proto native void SetKind(WaveKind kind);
  74. proto native void Initialize(SoundParams soundParams);
  75. }
  76. //soundsys.hpp
  77. class SoundParams
  78. {
  79. void SoundParams(string name);
  80. proto native bool Load(string name);
  81. proto native bool IsValid();
  82. proto string GetName();
  83. }
  84. class AbstractWaveEvents
  85. {
  86. ref ScriptInvoker Event_OnSoundWaveStarted = new ScriptInvoker();
  87. ref ScriptInvoker Event_OnSoundWaveStopped = new ScriptInvoker();
  88. ref ScriptInvoker Event_OnSoundWaveLoaded = new ScriptInvoker();
  89. ref ScriptInvoker Event_OnSoundWaveHeaderLoaded = new ScriptInvoker();
  90. ref ScriptInvoker Event_OnSoundWaveEnded = new ScriptInvoker();
  91. }
  92. class AbstractWave
  93. {
  94. private void InitEvents()
  95. {
  96. AbstractWaveEvents events = new AbstractWaveEvents();
  97. SetUserData(events);
  98. }
  99. #ifdef DIAG_DEVELOPER
  100. private void AbstractWave() { InitEvents(); }
  101. private void ~AbstractWave() {}
  102. #else
  103. void AbstractWave() { InitEvents(); }
  104. #endif
  105. proto void SetUserData(Managed inst);
  106. proto Managed GetUserData();
  107. proto void Play();
  108. void PlayWithOffset(float offset)
  109. {
  110. Play();
  111. SetStartOffset(offset);
  112. }
  113. //proto native void Mute();
  114. proto void Stop();
  115. proto void Restart();
  116. proto void SetStartOffset(float offset);
  117. //! WARNING: Blocking! Waits for header to load
  118. proto float GetLength();
  119. //! Current position in percentage of total length
  120. proto float GetCurrPosition();
  121. proto void Loop(bool setLoop);
  122. proto float GetVolume();
  123. proto void SetVolume(float value);
  124. proto void SetVolumeRelative(float value);
  125. proto void SetFrequency(float value);
  126. proto float GetFrequency();
  127. proto void SetPosition(vector position, vector velocity = "0 0 0");
  128. proto void SetFadeInFactor(float volume);
  129. proto void SetFadeOutFactor(float volume);
  130. proto void SetDoppler(bool setDoppler);
  131. proto void Skip(float timeSec);
  132. proto bool IsHeaderLoaded();
  133. AbstractWaveEvents GetEvents()
  134. {
  135. return AbstractWaveEvents.Cast(GetUserData());
  136. }
  137. void OnPlay()
  138. {
  139. GetEvents().Event_OnSoundWaveStarted.Invoke(this);
  140. }
  141. void OnStop()
  142. {
  143. GetEvents().Event_OnSoundWaveStopped.Invoke(this);
  144. }
  145. void OnLoad()
  146. {
  147. GetEvents().Event_OnSoundWaveLoaded.Invoke(this);
  148. }
  149. void OnHeaderLoad()
  150. {
  151. GetEvents().Event_OnSoundWaveHeaderLoaded.Invoke(this);
  152. }
  153. void OnEnd()
  154. {
  155. GetEvents().Event_OnSoundWaveEnded.Invoke(this);
  156. }
  157. }