spatial_sound_2d_server.h 6.0 KB

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