spatial_sound_2d_server.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*************************************************************************/
  2. /* spatial_sound_2d_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_2D_SERVER_H
  31. #define SPATIAL_SOUND_2D_SERVER_H
  32. #include "bsp_tree.h"
  33. #include "object.h"
  34. #include "servers/audio_server.h"
  35. class SpatialSound2DServer : public Object {
  36. OBJ_TYPE(SpatialSound2DServer, Object);
  37. static SpatialSound2DServer *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 DVector<Point2> &p_bounds) = 0;
  51. virtual DVector<Point2> room_get_bounds(RID p_room) const = 0;
  52. virtual void room_set_transform(RID p_room, const Matrix32 &p_transform) = 0;
  53. virtual Matrix32 room_get_transform(RID p_room) const = 0;
  54. enum RoomParam {
  55. ROOM_PARAM_PITCH_SCALE,
  56. ROOM_PARAM_VOLUME_SCALE_DB,
  57. ROOM_PARAM_REVERB_SEND,
  58. ROOM_PARAM_CHORUS_SEND,
  59. ROOM_PARAM_ATTENUATION_SCALE,
  60. ROOM_PARAM_ATTENUATION_HF_CUTOFF,
  61. ROOM_PARAM_ATTENUATION_HF_FLOOR_DB,
  62. ROOM_PARAM_ATTENUATION_HF_RATIO_EXP,
  63. ROOM_PARAM_ATTENUATION_REVERB_SCALE,
  64. ROOM_PARAM_MAX
  65. };
  66. virtual void room_set_param(RID p_room, RoomParam p_param, float p_value) = 0;
  67. virtual float room_get_param(RID p_room, RoomParam p_param) const = 0;
  68. enum RoomReverb {
  69. ROOM_REVERB_SMALL,
  70. ROOM_REVERB_MEDIUM,
  71. ROOM_REVERB_LARGE,
  72. ROOM_REVERB_HALL
  73. };
  74. virtual void room_set_reverb(RID p_room, RoomReverb p_reverb) = 0;
  75. virtual RoomReverb room_get_reverb(RID p_room) const = 0;
  76. virtual void room_set_level(RID p_room, int p_level) = 0;
  77. virtual int room_get_level(RID p_room) const = 0;
  78. //useful for underwater or rooms with very strange conditions
  79. virtual void room_set_force_params_to_all_sources(RID p_room, bool p_force) = 0;
  80. virtual bool room_is_forcing_params_to_all_sources(RID p_room) const = 0;
  81. /* SOURCE */
  82. virtual RID source_create(RID p_space) = 0;
  83. virtual void source_set_transform(RID p_source, const Matrix32 &p_transform) = 0;
  84. virtual Matrix32 source_get_transform(RID p_source) const = 0;
  85. virtual void source_set_polyphony(RID p_source, int p_voice_count) = 0;
  86. virtual int source_get_polyphony(RID p_source) const = 0;
  87. enum SourceParam {
  88. SOURCE_PARAM_VOLUME_DB,
  89. SOURCE_PARAM_PITCH_SCALE,
  90. SOURCE_PARAM_ATTENUATION_MIN_DISTANCE,
  91. SOURCE_PARAM_ATTENUATION_MAX_DISTANCE,
  92. SOURCE_PARAM_ATTENUATION_DISTANCE_EXP,
  93. SOURCE_PARAM_MAX
  94. };
  95. virtual void source_set_param(RID p_source, SourceParam p_param, float p_value) = 0;
  96. virtual float source_get_param(RID p_source, SourceParam p_param) const = 0;
  97. virtual void source_set_audio_stream(RID p_source, AudioServer::AudioStream *p_stream) = 0; //null to unset
  98. 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;
  99. //voices
  100. virtual void source_voice_set_pitch_scale(RID p_source, SourceVoiceID p_voice, float p_pitch_scale) = 0;
  101. virtual void source_voice_set_volume_scale_db(RID p_source, SourceVoiceID p_voice, float p_volume_db) = 0;
  102. virtual bool source_is_voice_active(RID p_source, SourceVoiceID p_voice) const = 0;
  103. virtual void source_stop_voice(RID p_source, SourceVoiceID p_voice) = 0;
  104. /* LISTENER */
  105. enum ListenerParam {
  106. LISTENER_PARAM_VOLUME_SCALE_DB,
  107. LISTENER_PARAM_PITCH_SCALE,
  108. LISTENER_PARAM_ATTENUATION_SCALE,
  109. LISTENER_PARAM_PAN_RANGE,
  110. LISTENER_PARAM_MAX
  111. };
  112. virtual RID listener_create() = 0;
  113. virtual void listener_set_space(RID p_listener, RID p_space) = 0;
  114. virtual void listener_set_transform(RID p_listener, const Matrix32 &p_transform) = 0;
  115. virtual Matrix32 listener_get_transform(RID p_listener) const = 0;
  116. virtual void listener_set_param(RID p_listener, ListenerParam p_param, float p_value) = 0;
  117. virtual float listener_get_param(RID p_listener, ListenerParam p_param) const = 0;
  118. /* MISC */
  119. virtual void free(RID p_id) = 0;
  120. virtual void init() = 0;
  121. virtual void update(float p_delta) = 0;
  122. virtual void finish() = 0;
  123. static SpatialSound2DServer *get_singleton();
  124. SpatialSound2DServer();
  125. };
  126. #endif // SPATIAL_SOUND_2D_SERVER_H