spatial_sound_server.h 6.2 KB

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