spatial_sound_server.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*************************************************************************/
  2. /* spatial_sound_server.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef SPATIAL_SOUND_SERVER_H
  31. #define SPATIAL_SOUND_SERVER_H
  32. #include "bsp_tree.h"
  33. #include "object.h"
  34. #include "servers/audio_server.h"
  35. class SpatialSoundServer : public Object {
  36. OBJ_TYPE(SpatialSoundServer, Object);
  37. static SpatialSoundServer *singleton;
  38. public:
  39. enum {
  40. SOURCE_INVALID_VOICE = -1,
  41. SOURCE_NEXT_VOICE = -2,
  42. };
  43. typedef int SourceVoiceID;
  44. /* SPACE */
  45. virtual RID space_create() = 0;
  46. /* ROOM */
  47. virtual RID room_create() = 0;
  48. virtual void room_set_space(RID p_room, RID p_space) = 0;
  49. virtual RID room_get_space(RID p_room) const = 0;
  50. virtual void room_set_bounds(RID p_room, const BSP_Tree &p_bounds) = 0;
  51. virtual BSP_Tree room_get_bounds(RID p_room) const = 0;
  52. virtual void room_set_transform(RID p_room, const Transform &p_transform) = 0;
  53. virtual Transform room_get_transform(RID p_room) const = 0;
  54. enum RoomParam {
  55. ROOM_PARAM_SPEED_OF_SOUND_SCALE,
  56. ROOM_PARAM_DOPPLER_FACTOR,
  57. ROOM_PARAM_PITCH_SCALE,
  58. ROOM_PARAM_VOLUME_SCALE_DB,
  59. ROOM_PARAM_REVERB_SEND,
  60. ROOM_PARAM_CHORUS_SEND,
  61. ROOM_PARAM_ATTENUATION_SCALE,
  62. ROOM_PARAM_ATTENUATION_HF_CUTOFF,
  63. ROOM_PARAM_ATTENUATION_HF_FLOOR_DB,
  64. ROOM_PARAM_ATTENUATION_HF_RATIO_EXP,
  65. ROOM_PARAM_ATTENUATION_REVERB_SCALE,
  66. ROOM_PARAM_MAX
  67. };
  68. virtual void room_set_param(RID p_room, RoomParam p_param, float p_value) = 0;
  69. virtual float room_get_param(RID p_room, RoomParam p_param) const = 0;
  70. enum RoomReverb {
  71. ROOM_REVERB_SMALL,
  72. ROOM_REVERB_MEDIUM,
  73. ROOM_REVERB_LARGE,
  74. ROOM_REVERB_HALL
  75. };
  76. virtual void room_set_reverb(RID p_room, RoomReverb p_reverb) = 0;
  77. virtual RoomReverb room_get_reverb(RID p_room) const = 0;
  78. virtual void room_set_level(RID p_room, int p_level) = 0;
  79. virtual int room_get_level(RID p_room) const = 0;
  80. //useful for underwater or rooms with very strange conditions
  81. virtual void room_set_force_params_to_all_sources(RID p_room, bool p_force) = 0;
  82. virtual bool room_is_forcing_params_to_all_sources(RID p_room) const = 0;
  83. /* SOURCE */
  84. virtual RID source_create(RID p_space) = 0;
  85. virtual void source_set_transform(RID p_source, const Transform &p_transform) = 0;
  86. virtual Transform source_get_transform(RID p_source) const = 0;
  87. virtual void source_set_polyphony(RID p_source, int p_voice_count) = 0;
  88. virtual int source_get_polyphony(RID p_source) const = 0;
  89. enum SourceParam {
  90. SOURCE_PARAM_VOLUME_DB,
  91. SOURCE_PARAM_PITCH_SCALE,
  92. SOURCE_PARAM_ATTENUATION_MIN_DISTANCE,
  93. SOURCE_PARAM_ATTENUATION_MAX_DISTANCE,
  94. SOURCE_PARAM_ATTENUATION_DISTANCE_EXP,
  95. SOURCE_PARAM_EMISSION_CONE_DEGREES,
  96. SOURCE_PARAM_EMISSION_CONE_ATTENUATION_DB,
  97. SOURCE_PARAM_MAX
  98. };
  99. virtual void source_set_param(RID p_source, SourceParam p_param, float p_value) = 0;
  100. virtual float source_get_param(RID p_source, SourceParam p_param) const = 0;
  101. virtual void source_set_audio_stream(RID p_source, AudioServer::AudioStream *p_stream) = 0; //null to unset
  102. virtual SourceVoiceID source_play_sample(RID p_source, RID p_sample, int p_mix_rate, int p_voice = SOURCE_NEXT_VOICE, int p_priority = 0) = 0;
  103. //voices
  104. virtual void source_voice_set_pitch_scale(RID p_source, SourceVoiceID p_voice, float p_pitch_scale) = 0;
  105. virtual void source_voice_set_volume_scale_db(RID p_source, SourceVoiceID p_voice, float p_volume_db) = 0;
  106. virtual bool source_is_voice_active(RID p_source, SourceVoiceID p_voice) const = 0;
  107. virtual void source_stop_voice(RID p_source, SourceVoiceID p_voice) = 0;
  108. /* LISTENER */
  109. enum ListenerParam {
  110. LISTENER_PARAM_VOLUME_SCALE_DB,
  111. LISTENER_PARAM_PITCH_SCALE,
  112. LISTENER_PARAM_ATTENUATION_SCALE,
  113. LISTENER_PARAM_RECEPTION_CONE_DEGREES,
  114. LISTENER_PARAM_RECEPTION_CONE_ATTENUATION_DB,
  115. LISTENER_PARAM_MAX
  116. };
  117. virtual RID listener_create() = 0;
  118. virtual void listener_set_space(RID p_listener, RID p_space) = 0;
  119. virtual void listener_set_transform(RID p_listener, const Transform &p_transform) = 0;
  120. virtual Transform listener_get_transform(RID p_listener) const = 0;
  121. virtual void listener_set_param(RID p_listener, ListenerParam p_param, float p_value) = 0;
  122. virtual float listener_get_param(RID p_listener, ListenerParam p_param) const = 0;
  123. /* MISC */
  124. virtual void free(RID p_id) = 0;
  125. virtual void init() = 0;
  126. virtual void update(float p_delta) = 0;
  127. virtual void finish() = 0;
  128. static SpatialSoundServer *get_singleton();
  129. SpatialSoundServer();
  130. };
  131. #endif // SPATIAL_SOUND_SERVER_H