audio_server.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. /**************************************************************************/
  2. /* audio_server.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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. #pragma once
  31. #include "core/math/audio_frame.h"
  32. #include "core/object/class_db.h"
  33. #include "core/os/os.h"
  34. #include "core/templates/safe_list.h"
  35. #include "core/variant/variant.h"
  36. #include "servers/audio/audio_effect.h"
  37. #include "servers/audio/audio_filter_sw.h"
  38. #include <atomic>
  39. class AudioDriverDummy;
  40. class AudioSample;
  41. class AudioStream;
  42. class AudioStreamWAV;
  43. class AudioStreamPlayback;
  44. class AudioSamplePlayback;
  45. class AudioDriver {
  46. static AudioDriver *singleton;
  47. uint64_t _last_mix_time = 0;
  48. uint64_t _last_mix_frames = 0;
  49. #ifdef DEBUG_ENABLED
  50. SafeNumeric<uint64_t> prof_ticks;
  51. SafeNumeric<uint64_t> prof_time;
  52. #endif
  53. protected:
  54. Vector<int32_t> input_buffer;
  55. unsigned int input_position = 0;
  56. unsigned int input_size = 0;
  57. void audio_server_process(int p_frames, int32_t *p_buffer, bool p_update_mix_time = true);
  58. void update_mix_time(int p_frames);
  59. void input_buffer_init(int driver_buffer_frames);
  60. void input_buffer_write(int32_t sample);
  61. int _get_configured_mix_rate();
  62. #ifdef DEBUG_ENABLED
  63. _FORCE_INLINE_ void start_counting_ticks() { prof_ticks.set(OS::get_singleton()->get_ticks_usec()); }
  64. _FORCE_INLINE_ void stop_counting_ticks() { prof_time.add(OS::get_singleton()->get_ticks_usec() - prof_ticks.get()); }
  65. #else
  66. _FORCE_INLINE_ void start_counting_ticks() {}
  67. _FORCE_INLINE_ void stop_counting_ticks() {}
  68. #endif
  69. public:
  70. double get_time_since_last_mix(); //useful for video -> audio sync
  71. double get_time_to_next_mix();
  72. enum SpeakerMode {
  73. SPEAKER_MODE_STEREO,
  74. SPEAKER_SURROUND_31,
  75. SPEAKER_SURROUND_51,
  76. SPEAKER_SURROUND_71,
  77. };
  78. static AudioDriver *get_singleton();
  79. void set_singleton();
  80. // Virtual API to implement.
  81. virtual const char *get_name() const = 0;
  82. virtual Error init() = 0;
  83. virtual void start() = 0;
  84. virtual int get_mix_rate() const = 0;
  85. virtual int get_input_mix_rate() const { return get_mix_rate(); }
  86. virtual SpeakerMode get_speaker_mode() const = 0;
  87. virtual float get_latency() { return 0; }
  88. virtual void lock() = 0;
  89. virtual void unlock() = 0;
  90. virtual void finish() = 0;
  91. virtual PackedStringArray get_output_device_list();
  92. virtual String get_output_device();
  93. virtual void set_output_device(const String &p_name) {}
  94. virtual Error input_start() { return FAILED; }
  95. virtual Error input_stop() { return FAILED; }
  96. virtual PackedStringArray get_input_device_list();
  97. virtual String get_input_device() { return "Default"; }
  98. virtual void set_input_device(const String &p_name) {}
  99. //
  100. SpeakerMode get_speaker_mode_by_total_channels(int p_channels) const;
  101. int get_total_channels_by_speaker_mode(SpeakerMode) const;
  102. Vector<int32_t> get_input_buffer() { return input_buffer; }
  103. unsigned int get_input_position() { return input_position; }
  104. unsigned int get_input_size() { return input_size; }
  105. #ifdef DEBUG_ENABLED
  106. uint64_t get_profiling_time() const { return prof_time.get(); }
  107. void reset_profiling_time() { prof_time.set(0); }
  108. #endif
  109. // Samples handling.
  110. virtual bool is_stream_registered_as_sample(const Ref<AudioStream> &p_stream) const {
  111. return false;
  112. }
  113. virtual void register_sample(const Ref<AudioSample> &p_sample) {}
  114. virtual void unregister_sample(const Ref<AudioSample> &p_sample) {}
  115. virtual void start_sample_playback(const Ref<AudioSamplePlayback> &p_playback);
  116. virtual void stop_sample_playback(const Ref<AudioSamplePlayback> &p_playback) {}
  117. virtual void set_sample_playback_pause(const Ref<AudioSamplePlayback> &p_playback, bool p_paused) {}
  118. virtual bool is_sample_playback_active(const Ref<AudioSamplePlayback> &p_playback) { return false; }
  119. virtual double get_sample_playback_position(const Ref<AudioSamplePlayback> &p_playback) { return false; }
  120. virtual void update_sample_playback_pitch_scale(const Ref<AudioSamplePlayback> &p_playback, float p_pitch_scale = 0.0f) {}
  121. virtual void set_sample_playback_bus_volumes_linear(const Ref<AudioSamplePlayback> &p_playback, const HashMap<StringName, Vector<AudioFrame>> &p_bus_volumes) {}
  122. virtual void set_sample_bus_count(int p_count) {}
  123. virtual void remove_sample_bus(int p_bus) {}
  124. virtual void add_sample_bus(int p_at_pos = -1) {}
  125. virtual void move_sample_bus(int p_bus, int p_to_pos) {}
  126. virtual void set_sample_bus_send(int p_bus, const StringName &p_send) {}
  127. virtual void set_sample_bus_volume_db(int p_bus, float p_volume_db) {}
  128. virtual void set_sample_bus_solo(int p_bus, bool p_enable) {}
  129. virtual void set_sample_bus_mute(int p_bus, bool p_enable) {}
  130. AudioDriver() {}
  131. virtual ~AudioDriver() {}
  132. };
  133. class AudioDriverManager {
  134. enum {
  135. MAX_DRIVERS = 10
  136. };
  137. static AudioDriver *drivers[MAX_DRIVERS];
  138. static int driver_count;
  139. static AudioDriverDummy dummy_driver;
  140. public:
  141. static const int DEFAULT_MIX_RATE = 44100;
  142. static void add_driver(AudioDriver *p_driver);
  143. static void initialize(int p_driver);
  144. static int get_driver_count();
  145. static AudioDriver *get_driver(int p_driver);
  146. };
  147. class AudioBusLayout;
  148. class AudioServer : public Object {
  149. GDCLASS(AudioServer, Object);
  150. public:
  151. //re-expose this here, as AudioDriver is not exposed to script
  152. enum SpeakerMode {
  153. SPEAKER_MODE_STEREO,
  154. SPEAKER_SURROUND_31,
  155. SPEAKER_SURROUND_51,
  156. SPEAKER_SURROUND_71,
  157. };
  158. enum PlaybackType {
  159. PLAYBACK_TYPE_DEFAULT,
  160. PLAYBACK_TYPE_STREAM,
  161. PLAYBACK_TYPE_SAMPLE,
  162. PLAYBACK_TYPE_MAX
  163. };
  164. enum {
  165. AUDIO_DATA_INVALID_ID = -1,
  166. MAX_CHANNELS_PER_BUS = 4,
  167. MAX_BUSES_PER_PLAYBACK = 6,
  168. LOOKAHEAD_BUFFER_SIZE = 64,
  169. };
  170. typedef void (*AudioCallback)(void *p_userdata);
  171. private:
  172. uint64_t mix_time = 0;
  173. int mix_size = 0;
  174. uint32_t buffer_size = 0;
  175. uint64_t mix_count = 0;
  176. uint64_t mix_frames = 0;
  177. #ifdef DEBUG_ENABLED
  178. SafeNumeric<uint64_t> prof_time;
  179. #endif
  180. float channel_disable_threshold_db = 0.0f;
  181. uint32_t channel_disable_frames = 0;
  182. int channel_count = 0;
  183. int to_mix = 0;
  184. float playback_speed_scale = 1.0f;
  185. bool tag_used_audio_streams = false;
  186. #ifdef DEBUG_ENABLED
  187. bool debug_mute = false;
  188. #endif // DEBUG_ENABLED
  189. struct Bus {
  190. StringName name;
  191. bool solo = false;
  192. bool mute = false;
  193. bool bypass = false;
  194. bool soloed = false;
  195. // Each channel is a stereo pair.
  196. struct Channel {
  197. bool used = false;
  198. bool active = false;
  199. AudioFrame peak_volume = AudioFrame(AUDIO_MIN_PEAK_DB, AUDIO_MIN_PEAK_DB);
  200. Vector<AudioFrame> buffer;
  201. Vector<Ref<AudioEffectInstance>> effect_instances;
  202. uint64_t last_mix_with_audio = 0;
  203. Channel() {}
  204. };
  205. Vector<Channel> channels;
  206. struct Effect {
  207. Ref<AudioEffect> effect;
  208. bool enabled = false;
  209. #ifdef DEBUG_ENABLED
  210. uint64_t prof_time = 0;
  211. #endif
  212. };
  213. Vector<Effect> effects;
  214. float volume_db = 0.0f;
  215. StringName send;
  216. int index_cache = 0;
  217. };
  218. struct AudioStreamPlaybackBusDetails {
  219. bool bus_active[MAX_BUSES_PER_PLAYBACK] = {};
  220. StringName bus[MAX_BUSES_PER_PLAYBACK];
  221. AudioFrame volume[MAX_BUSES_PER_PLAYBACK][MAX_CHANNELS_PER_BUS];
  222. };
  223. struct AudioStreamPlaybackListNode {
  224. // The state machine for audio stream playbacks is as follows:
  225. // 1. The playback is created and added to the playback list in the playing state.
  226. // 2. The playback is (maybe) paused, and the state is set to FADE_OUT_TO_PAUSE.
  227. // 2.1. The playback is mixed after being paused, and the audio server thread atomically sets the state to PAUSED after performing a brief fade-out.
  228. // 3. The playback is (maybe) deleted, and the state is set to FADE_OUT_TO_DELETION.
  229. // 3.1. The playback is mixed after being deleted, and the audio server thread atomically sets the state to AWAITING_DELETION after performing a brief fade-out.
  230. // NOTE: The playback is not deallocated at this time because allocation and deallocation are not realtime-safe.
  231. // 4. The playback is removed and deallocated on the main thread using the SafeList maybe_cleanup method.
  232. enum PlaybackState {
  233. PAUSED = 0, // Paused. Keep this stream playback around though so it can be restarted.
  234. PLAYING = 1, // Playing. Fading may still be necessary if volume changes!
  235. FADE_OUT_TO_PAUSE = 2, // About to pause.
  236. FADE_OUT_TO_DELETION = 3, // About to stop.
  237. AWAITING_DELETION = 4,
  238. };
  239. // If zero or positive, a place in the stream to seek to during the next mix.
  240. SafeNumeric<float> setseek;
  241. SafeNumeric<float> pitch_scale;
  242. SafeNumeric<float> highshelf_gain;
  243. SafeNumeric<float> attenuation_filter_cutoff_hz; // This isn't used unless highshelf_gain is nonzero.
  244. AudioFilterSW::Processor filter_process[8];
  245. // Updating this ref after the list node is created breaks consistency guarantees, don't do it!
  246. Ref<AudioStreamPlayback> stream_playback;
  247. // Playback state determines the fate of a particular AudioStreamListNode during the mix step. Must be atomically replaced.
  248. std::atomic<PlaybackState> state = AWAITING_DELETION;
  249. // This data should only ever be modified by an atomic replacement of the pointer.
  250. std::atomic<AudioStreamPlaybackBusDetails *> bus_details = nullptr;
  251. // Previous bus details should only be accessed on the audio thread.
  252. AudioStreamPlaybackBusDetails *prev_bus_details = nullptr;
  253. // The next few samples are stored here so we have some time to fade audio out if it ends abruptly at the beginning of the next mix.
  254. AudioFrame lookahead[LOOKAHEAD_BUFFER_SIZE];
  255. };
  256. SafeList<AudioStreamPlaybackListNode *> playback_list;
  257. SafeList<AudioStreamPlaybackBusDetails *> bus_details_graveyard;
  258. void _delete_stream_playback(Ref<AudioStreamPlayback> p_playback);
  259. void _delete_stream_playback_list_node(AudioStreamPlaybackListNode *p_node);
  260. // TODO document if this is necessary.
  261. SafeList<AudioStreamPlaybackBusDetails *> bus_details_graveyard_frame_old;
  262. Vector<Vector<AudioFrame>> temp_buffer; //temp_buffer for each level
  263. Vector<AudioFrame> mix_buffer;
  264. Vector<Bus *> buses;
  265. HashMap<StringName, Bus *> bus_map;
  266. void _update_bus_effects(int p_bus);
  267. static AudioServer *singleton;
  268. void init_channels_and_buffers();
  269. void _mix_step();
  270. void _mix_step_for_channel(AudioFrame *p_out_buf, AudioFrame *p_source_buf, AudioFrame p_vol_start, AudioFrame p_vol_final, float p_attenuation_filter_cutoff_hz, float p_highshelf_gain, AudioFilterSW::Processor *p_processor_l, AudioFilterSW::Processor *p_processor_r);
  271. // Should only be called on the main thread.
  272. AudioStreamPlaybackListNode *_find_playback_list_node(Ref<AudioStreamPlayback> p_playback);
  273. struct CallbackItem {
  274. AudioCallback callback;
  275. void *userdata = nullptr;
  276. };
  277. SafeList<CallbackItem *> update_callback_list;
  278. SafeList<CallbackItem *> mix_callback_list;
  279. SafeList<CallbackItem *> listener_changed_callback_list;
  280. friend class AudioDriver;
  281. void _driver_process(int p_frames, int32_t *p_buffer);
  282. LocalVector<Ref<AudioSamplePlayback>> sample_playback_list;
  283. protected:
  284. static void _bind_methods();
  285. public:
  286. _FORCE_INLINE_ int get_channel_count() const {
  287. switch (get_speaker_mode()) {
  288. case SPEAKER_MODE_STEREO:
  289. return 1;
  290. case SPEAKER_SURROUND_31:
  291. return 2;
  292. case SPEAKER_SURROUND_51:
  293. return 3;
  294. case SPEAKER_SURROUND_71:
  295. return 4;
  296. }
  297. ERR_FAIL_V(1);
  298. }
  299. // Do not use from outside audio thread.
  300. bool thread_has_channel_mix_buffer(int p_bus, int p_buffer) const;
  301. AudioFrame *thread_get_channel_mix_buffer(int p_bus, int p_buffer);
  302. int thread_get_mix_buffer_size() const;
  303. int thread_find_bus_index(const StringName &p_name);
  304. #ifdef DEBUG_ENABLED
  305. void set_debug_mute(bool p_mute);
  306. bool get_debug_mute() const;
  307. #endif // DEBUG_ENABLED
  308. void set_bus_count(int p_count);
  309. int get_bus_count() const;
  310. void remove_bus(int p_index);
  311. void add_bus(int p_at_pos = -1);
  312. void move_bus(int p_bus, int p_to_pos);
  313. void set_bus_name(int p_bus, const String &p_name);
  314. String get_bus_name(int p_bus) const;
  315. int get_bus_index(const StringName &p_bus_name) const;
  316. int get_bus_channels(int p_bus) const;
  317. void set_bus_volume_db(int p_bus, float p_volume_db);
  318. float get_bus_volume_db(int p_bus) const;
  319. void set_bus_volume_linear(int p_bus, float p_volume_linear);
  320. float get_bus_volume_linear(int p_bus) const;
  321. void set_bus_send(int p_bus, const StringName &p_send);
  322. StringName get_bus_send(int p_bus) const;
  323. void set_bus_solo(int p_bus, bool p_enable);
  324. bool is_bus_solo(int p_bus) const;
  325. void set_bus_mute(int p_bus, bool p_enable);
  326. bool is_bus_mute(int p_bus) const;
  327. void set_bus_bypass_effects(int p_bus, bool p_enable);
  328. bool is_bus_bypassing_effects(int p_bus) const;
  329. void add_bus_effect(int p_bus, const Ref<AudioEffect> &p_effect, int p_at_pos = -1);
  330. void remove_bus_effect(int p_bus, int p_effect);
  331. int get_bus_effect_count(int p_bus);
  332. Ref<AudioEffect> get_bus_effect(int p_bus, int p_effect);
  333. Ref<AudioEffectInstance> get_bus_effect_instance(int p_bus, int p_effect, int p_channel = 0);
  334. void swap_bus_effects(int p_bus, int p_effect, int p_by_effect);
  335. void set_bus_effect_enabled(int p_bus, int p_effect, bool p_enabled);
  336. bool is_bus_effect_enabled(int p_bus, int p_effect) const;
  337. float get_bus_peak_volume_left_db(int p_bus, int p_channel) const;
  338. float get_bus_peak_volume_right_db(int p_bus, int p_channel) const;
  339. bool is_bus_channel_active(int p_bus, int p_channel) const;
  340. void set_playback_speed_scale(float p_scale);
  341. float get_playback_speed_scale() const;
  342. // Convenience method.
  343. void start_playback_stream(Ref<AudioStreamPlayback> p_playback, const StringName &p_bus, Vector<AudioFrame> p_volume_db_vector, float p_start_time = 0, float p_pitch_scale = 1);
  344. // Expose all parameters.
  345. void start_playback_stream(Ref<AudioStreamPlayback> p_playback, const HashMap<StringName, Vector<AudioFrame>> &p_bus_volumes, float p_start_time = 0, float p_pitch_scale = 1, float p_highshelf_gain = 0, float p_attenuation_cutoff_hz = 0);
  346. void stop_playback_stream(Ref<AudioStreamPlayback> p_playback);
  347. void set_playback_bus_exclusive(Ref<AudioStreamPlayback> p_playback, const StringName &p_bus, Vector<AudioFrame> p_volumes);
  348. void set_playback_bus_volumes_linear(Ref<AudioStreamPlayback> p_playback, const HashMap<StringName, Vector<AudioFrame>> &p_bus_volumes);
  349. void set_playback_all_bus_volumes_linear(Ref<AudioStreamPlayback> p_playback, Vector<AudioFrame> p_volumes);
  350. void set_playback_pitch_scale(Ref<AudioStreamPlayback> p_playback, float p_pitch_scale);
  351. void set_playback_paused(Ref<AudioStreamPlayback> p_playback, bool p_paused);
  352. void set_playback_highshelf_params(Ref<AudioStreamPlayback> p_playback, float p_gain, float p_attenuation_cutoff_hz);
  353. bool is_playback_active(Ref<AudioStreamPlayback> p_playback);
  354. float get_playback_position(Ref<AudioStreamPlayback> p_playback);
  355. bool is_playback_paused(Ref<AudioStreamPlayback> p_playback);
  356. uint64_t get_mix_count() const;
  357. uint64_t get_mixed_frames() const;
  358. String get_driver_name() const;
  359. void notify_listener_changed();
  360. virtual void init();
  361. virtual void finish();
  362. virtual void update();
  363. virtual void load_default_bus_layout();
  364. /* MISC config */
  365. virtual void lock();
  366. virtual void unlock();
  367. virtual SpeakerMode get_speaker_mode() const;
  368. virtual float get_mix_rate() const;
  369. virtual float get_input_mix_rate() const;
  370. virtual float read_output_peak_db() const;
  371. static AudioServer *get_singleton();
  372. virtual double get_output_latency() const;
  373. virtual double get_time_to_next_mix() const;
  374. virtual double get_time_since_last_mix() const;
  375. void add_listener_changed_callback(AudioCallback p_callback, void *p_userdata);
  376. void remove_listener_changed_callback(AudioCallback p_callback, void *p_userdata);
  377. void add_update_callback(AudioCallback p_callback, void *p_userdata);
  378. void remove_update_callback(AudioCallback p_callback, void *p_userdata);
  379. void add_mix_callback(AudioCallback p_callback, void *p_userdata);
  380. void remove_mix_callback(AudioCallback p_callback, void *p_userdata);
  381. void set_bus_layout(const Ref<AudioBusLayout> &p_bus_layout);
  382. Ref<AudioBusLayout> generate_bus_layout() const;
  383. PackedStringArray get_output_device_list();
  384. String get_output_device();
  385. void set_output_device(const String &p_name);
  386. PackedStringArray get_input_device_list();
  387. String get_input_device();
  388. void set_input_device(const String &p_name);
  389. void set_enable_tagging_used_audio_streams(bool p_enable);
  390. #ifdef TOOLS_ENABLED
  391. virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
  392. #endif
  393. PlaybackType get_default_playback_type() const;
  394. bool is_stream_registered_as_sample(const Ref<AudioStream> &p_stream);
  395. void register_stream_as_sample(const Ref<AudioStream> &p_stream);
  396. void unregister_stream_as_sample(const Ref<AudioStream> &p_stream);
  397. void register_sample(const Ref<AudioSample> &p_sample);
  398. void unregister_sample(const Ref<AudioSample> &p_sample);
  399. void start_sample_playback(const Ref<AudioSamplePlayback> &p_playback);
  400. void stop_sample_playback(const Ref<AudioSamplePlayback> &p_playback);
  401. void set_sample_playback_pause(const Ref<AudioSamplePlayback> &p_playback, bool p_paused);
  402. bool is_sample_playback_active(const Ref<AudioSamplePlayback> &p_playback);
  403. double get_sample_playback_position(const Ref<AudioSamplePlayback> &p_playback);
  404. void update_sample_playback_pitch_scale(const Ref<AudioSamplePlayback> &p_playback, float p_pitch_scale = 0.0f);
  405. AudioServer();
  406. virtual ~AudioServer();
  407. };
  408. VARIANT_ENUM_CAST(AudioServer::SpeakerMode)
  409. VARIANT_ENUM_CAST(AudioServer::PlaybackType)
  410. class AudioBusLayout : public Resource {
  411. GDCLASS(AudioBusLayout, Resource);
  412. friend class AudioServer;
  413. struct Bus {
  414. StringName name;
  415. bool solo = false;
  416. bool mute = false;
  417. bool bypass = false;
  418. struct Effect {
  419. Ref<AudioEffect> effect;
  420. bool enabled = false;
  421. };
  422. Vector<Effect> effects;
  423. float volume_db = 0.0f;
  424. StringName send;
  425. Bus() {}
  426. };
  427. Vector<Bus> buses;
  428. protected:
  429. bool _set(const StringName &p_name, const Variant &p_value);
  430. bool _get(const StringName &p_name, Variant &r_ret) const;
  431. void _get_property_list(List<PropertyInfo> *p_list) const;
  432. public:
  433. AudioBusLayout();
  434. };
  435. typedef AudioServer AS;