audio_server_javascript.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*************************************************************************/
  2. /* audio_server_javascript.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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 AUDIO_SERVER_JAVASCRIPT_H
  31. #define AUDIO_SERVER_JAVASCRIPT_H
  32. // FIXME: Needs to be ported to the new AudioServer API in 3.0
  33. #if 0
  34. #include "servers/audio_server.h"
  35. class AudioServerJavascript : public AudioServer {
  36. GDCLASS(AudioServerJavascript,AudioServer);
  37. enum {
  38. INTERNAL_BUFFER_SIZE=4096,
  39. STREAM_SCALE_BITS=12
  40. };
  41. AudioMixer *get_mixer();
  42. void audio_mixer_chunk_callback(int p_frames);
  43. struct Sample {
  44. SampleFormat format;
  45. SampleLoopFormat loop_format;
  46. int loop_begin;
  47. int loop_end;
  48. int length;
  49. int index;
  50. int mix_rate;
  51. bool stereo;
  52. Vector<float> tmp_data;
  53. };
  54. mutable RID_Owner<Sample> sample_owner;
  55. int sample_base;
  56. struct Voice {
  57. int index;
  58. float volume;
  59. float pan;
  60. float pan_depth;
  61. float pan_height;
  62. float chorus;
  63. ReverbRoomType reverb_type;
  64. float reverb;
  65. int mix_rate;
  66. int sample_mix_rate;
  67. bool positional;
  68. bool active;
  69. };
  70. mutable RID_Owner<Voice> voice_owner;
  71. int voice_base;
  72. struct Stream {
  73. bool active;
  74. List<Stream*>::Element *E;
  75. AudioStream *audio_stream;
  76. EventStream *event_stream;
  77. float volume_scale;
  78. };
  79. List<Stream*> active_audio_streams;
  80. //List<Stream*> event_streams;
  81. float * internal_buffer;
  82. int internal_buffer_channels;
  83. int32_t * stream_buffer;
  84. mutable RID_Owner<Stream> stream_owner;
  85. float stream_volume;
  86. float stream_volume_scale;
  87. float event_voice_scale;
  88. float fx_volume_scale;
  89. void driver_process_chunk(int p_frames);
  90. int webaudio_mix_rate;
  91. static AudioServerJavascript *singleton;
  92. public:
  93. void mix_to_js(int p_frames);
  94. /* SAMPLE API */
  95. virtual RID sample_create(SampleFormat p_format, bool p_stereo, int p_length);
  96. virtual void sample_set_description(RID p_sample, const String& p_description);
  97. virtual String sample_get_description(RID p_sample) const;
  98. virtual SampleFormat sample_get_format(RID p_sample) const;
  99. virtual bool sample_is_stereo(RID p_sample) const;
  100. virtual int sample_get_length(RID p_sample) const;
  101. virtual const void* sample_get_data_ptr(RID p_sample) const;
  102. virtual void sample_set_data(RID p_sample, const PoolVector<uint8_t>& p_buffer);
  103. virtual PoolVector<uint8_t> sample_get_data(RID p_sample) const;
  104. virtual void sample_set_mix_rate(RID p_sample,int p_rate);
  105. virtual int sample_get_mix_rate(RID p_sample) const;
  106. virtual void sample_set_loop_format(RID p_sample,SampleLoopFormat p_format);
  107. virtual SampleLoopFormat sample_get_loop_format(RID p_sample) const;
  108. virtual void sample_set_loop_begin(RID p_sample,int p_pos);
  109. virtual int sample_get_loop_begin(RID p_sample) const;
  110. virtual void sample_set_loop_end(RID p_sample,int p_pos);
  111. virtual int sample_get_loop_end(RID p_sample) const;
  112. /* VOICE API */
  113. virtual RID voice_create();
  114. virtual void voice_play(RID p_voice, RID p_sample);
  115. virtual void voice_set_volume(RID p_voice, float p_volume);
  116. virtual void voice_set_pan(RID p_voice, float p_pan, float p_depth=0,float height=0); //pan and depth go from -1 to 1
  117. virtual void voice_set_filter(RID p_voice, FilterType p_type, float p_cutoff, float p_resonance, float p_gain=0);
  118. virtual void voice_set_chorus(RID p_voice, float p_chorus );
  119. virtual void voice_set_reverb(RID p_voice, ReverbRoomType p_room_type, float p_reverb);
  120. virtual void voice_set_mix_rate(RID p_voice, int p_mix_rate);
  121. virtual void voice_set_positional(RID p_voice, bool p_positional);
  122. virtual float voice_get_volume(RID p_voice) const;
  123. virtual float voice_get_pan(RID p_voice) const; //pan and depth go from -1 to 1
  124. virtual float voice_get_pan_depth(RID p_voice) const; //pan and depth go from -1 to 1
  125. virtual float voice_get_pan_height(RID p_voice) const; //pan and depth go from -1 to 1
  126. virtual FilterType voice_get_filter_type(RID p_voice) const;
  127. virtual float voice_get_filter_cutoff(RID p_voice) const;
  128. virtual float voice_get_filter_resonance(RID p_voice) const;
  129. virtual float voice_get_chorus(RID p_voice) const;
  130. virtual ReverbRoomType voice_get_reverb_type(RID p_voice) const;
  131. virtual float voice_get_reverb(RID p_voice) const;
  132. virtual int voice_get_mix_rate(RID p_voice) const;
  133. virtual bool voice_is_positional(RID p_voice) const;
  134. virtual void voice_stop(RID p_voice);
  135. virtual bool voice_is_active(RID p_voice) const;
  136. /* STREAM API */
  137. virtual RID audio_stream_create(AudioStream *p_stream);
  138. virtual RID event_stream_create(EventStream *p_stream);
  139. virtual void stream_set_active(RID p_stream, bool p_active);
  140. virtual bool stream_is_active(RID p_stream) const;
  141. virtual void stream_set_volume_scale(RID p_stream, float p_scale);
  142. virtual float stream_set_volume_scale(RID p_stream) const;
  143. /* Audio Physics API */
  144. virtual void free(RID p_id);
  145. virtual void init();
  146. virtual void finish();
  147. virtual void update();
  148. /* MISC config */
  149. virtual void lock();
  150. virtual void unlock();
  151. virtual int get_default_channel_count() const;
  152. virtual int get_default_mix_rate() const;
  153. virtual void set_stream_global_volume_scale(float p_volume);
  154. virtual void set_fx_global_volume_scale(float p_volume);
  155. virtual void set_event_voice_global_volume_scale(float p_volume);
  156. virtual float get_stream_global_volume_scale() const;
  157. virtual float get_fx_global_volume_scale() const;
  158. virtual float get_event_voice_global_volume_scale() const;
  159. virtual uint32_t read_output_peak() const;
  160. static AudioServer *get_singleton();
  161. virtual double get_mix_time() const; //useful for video -> audio sync
  162. virtual double get_output_delay() const;
  163. AudioServerJavascript();
  164. };
  165. #endif // AUDIO_SERVER_JAVASCRIPT_H
  166. #endif