audio_server.cpp 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343
  1. /*************************************************************************/
  2. /* audio_server.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2018 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. #include "audio_server.h"
  31. #include "io/resource_loader.h"
  32. #include "os/file_access.h"
  33. #include "os/os.h"
  34. #include "project_settings.h"
  35. #include "servers/audio/audio_driver_dummy.h"
  36. #include "servers/audio/effects/audio_effect_compressor.h"
  37. #ifdef TOOLS_ENABLED
  38. #define MARK_EDITED set_edited(true);
  39. #else
  40. #define MARK_EDITED
  41. #endif
  42. AudioDriver *AudioDriver::singleton = NULL;
  43. AudioDriver *AudioDriver::get_singleton() {
  44. return singleton;
  45. }
  46. void AudioDriver::set_singleton() {
  47. singleton = this;
  48. }
  49. void AudioDriver::audio_server_process(int p_frames, int32_t *p_buffer, bool p_update_mix_time) {
  50. if (p_update_mix_time)
  51. update_mix_time(p_frames);
  52. if (AudioServer::get_singleton())
  53. AudioServer::get_singleton()->_driver_process(p_frames, p_buffer);
  54. }
  55. void AudioDriver::update_mix_time(int p_frames) {
  56. _mix_amount += p_frames;
  57. if (OS::get_singleton())
  58. _last_mix_time = OS::get_singleton()->get_ticks_usec();
  59. }
  60. double AudioDriver::get_mix_time() const {
  61. double total = (OS::get_singleton()->get_ticks_usec() - _last_mix_time) / 1000000.0;
  62. total += _mix_amount / (double)get_mix_rate();
  63. return total;
  64. }
  65. AudioDriver::SpeakerMode AudioDriver::get_speaker_mode_by_total_channels(int p_channels) const {
  66. switch (p_channels) {
  67. case 4: return SPEAKER_SURROUND_31;
  68. case 6: return SPEAKER_SURROUND_51;
  69. case 8: return SPEAKER_SURROUND_71;
  70. }
  71. // Default to STEREO
  72. return SPEAKER_MODE_STEREO;
  73. }
  74. int AudioDriver::get_total_channels_by_speaker_mode(AudioDriver::SpeakerMode p_mode) const {
  75. switch (p_mode) {
  76. case SPEAKER_MODE_STEREO: return 2;
  77. case SPEAKER_SURROUND_31: return 4;
  78. case SPEAKER_SURROUND_51: return 6;
  79. case SPEAKER_SURROUND_71: return 8;
  80. }
  81. ERR_FAIL_V(2);
  82. }
  83. Array AudioDriver::get_device_list() {
  84. Array list;
  85. list.push_back("Default");
  86. return list;
  87. }
  88. String AudioDriver::get_device() {
  89. return "Default";
  90. }
  91. AudioDriver::AudioDriver() {
  92. _last_mix_time = 0;
  93. _mix_amount = 0;
  94. }
  95. AudioDriver *AudioDriverManager::drivers[MAX_DRIVERS];
  96. int AudioDriverManager::driver_count = 0;
  97. AudioDriverDummy AudioDriverManager::dummy_driver;
  98. void AudioDriverManager::add_driver(AudioDriver *p_driver) {
  99. ERR_FAIL_COND(driver_count >= MAX_DRIVERS);
  100. drivers[driver_count++] = p_driver;
  101. }
  102. int AudioDriverManager::get_driver_count() {
  103. return driver_count;
  104. }
  105. void AudioDriverManager::initialize(int p_driver) {
  106. int failed_driver = -1;
  107. // Check if there is a selected driver
  108. if (p_driver >= 0 && p_driver < driver_count) {
  109. if (drivers[p_driver]->init() == OK) {
  110. drivers[p_driver]->set_singleton();
  111. return;
  112. } else {
  113. failed_driver = p_driver;
  114. }
  115. }
  116. // No selected driver, try them all in order
  117. for (int i = 0; i < driver_count; i++) {
  118. // Don't re-init the driver if it failed above
  119. if (i == failed_driver) {
  120. continue;
  121. }
  122. if (drivers[i]->init() == OK) {
  123. drivers[i]->set_singleton();
  124. return;
  125. }
  126. }
  127. // Fallback to our dummy driver
  128. if (dummy_driver.init() == OK) {
  129. ERR_PRINT("AudioDriverManager: all drivers failed, falling back to dummy driver");
  130. dummy_driver.set_singleton();
  131. } else {
  132. ERR_PRINT("AudioDriverManager: dummy driver failed to init()");
  133. }
  134. }
  135. AudioDriver *AudioDriverManager::get_driver(int p_driver) {
  136. ERR_FAIL_INDEX_V(p_driver, driver_count, NULL);
  137. return drivers[p_driver];
  138. }
  139. //////////////////////////////////////////////
  140. //////////////////////////////////////////////
  141. //////////////////////////////////////////////
  142. //////////////////////////////////////////////
  143. void AudioServer::_driver_process(int p_frames, int32_t *p_buffer) {
  144. int todo = p_frames;
  145. if (channel_count != get_channel_count()) {
  146. // Amount of channels changed due to a device change
  147. // reinitialize the buses channels and buffers
  148. init_channels_and_buffers();
  149. }
  150. while (todo) {
  151. if (to_mix == 0) {
  152. _mix_step();
  153. }
  154. int to_copy = MIN(to_mix, todo);
  155. Bus *master = buses[0];
  156. int from = buffer_size - to_mix;
  157. int from_buf = p_frames - todo;
  158. //master master, send to output
  159. int cs = master->channels.size();
  160. for (int k = 0; k < cs; k++) {
  161. if (master->channels[k].active) {
  162. const AudioFrame *buf = master->channels[k].buffer.ptr();
  163. for (int j = 0; j < to_copy; j++) {
  164. float l = CLAMP(buf[from + j].l, -1.0, 1.0);
  165. int32_t vl = l * ((1 << 20) - 1);
  166. p_buffer[(from_buf + j) * (cs * 2) + k * 2 + 0] = vl << 11;
  167. float r = CLAMP(buf[from + j].r, -1.0, 1.0);
  168. int32_t vr = r * ((1 << 20) - 1);
  169. p_buffer[(from_buf + j) * (cs * 2) + k * 2 + 1] = vr << 11;
  170. }
  171. } else {
  172. for (int j = 0; j < to_copy; j++) {
  173. p_buffer[(from_buf + j) * (cs * 2) + k * 2 + 0] = 0;
  174. p_buffer[(from_buf + j) * (cs * 2) + k * 2 + 1] = 0;
  175. }
  176. }
  177. }
  178. todo -= to_copy;
  179. to_mix -= to_copy;
  180. }
  181. #ifdef DEBUG_ENABLED
  182. if (OS::get_singleton() && OS::get_singleton()->is_stdout_verbose()) {
  183. static uint64_t first_ticks = 0;
  184. static uint64_t last_ticks = 0;
  185. static uint64_t ticks = 0;
  186. static int count = 0;
  187. static int total = 0;
  188. ticks = OS::get_singleton()->get_ticks_msec();
  189. if ((ticks - first_ticks) > 10 * 1000 && count > 0) {
  190. print_line("Audio Driver " + String(AudioDriver::get_singleton()->get_name()) + " average latency: " + itos(total / count) + "ms (frame=" + itos(p_frames) + ")");
  191. first_ticks = ticks;
  192. total = 0;
  193. count = 0;
  194. }
  195. total += ticks - last_ticks;
  196. count++;
  197. last_ticks = ticks;
  198. }
  199. #endif
  200. }
  201. void AudioServer::_mix_step() {
  202. bool solo_mode = false;
  203. for (int i = 0; i < buses.size(); i++) {
  204. Bus *bus = buses[i];
  205. bus->index_cache = i; //might be moved around by editor, so..
  206. for (int k = 0; k < bus->channels.size(); k++) {
  207. bus->channels[k].used = false;
  208. }
  209. if (bus->solo) {
  210. //solo chain
  211. solo_mode = true;
  212. bus->soloed = true;
  213. do {
  214. if (bus != buses[0]) {
  215. //everything has a send save for master bus
  216. if (!bus_map.has(bus->send)) {
  217. bus = buses[0]; //send to master
  218. } else {
  219. int prev_index_cache = bus->index_cache;
  220. bus = bus_map[bus->send];
  221. if (prev_index_cache >= bus->index_cache) { //invalid, send to master
  222. bus = buses[0];
  223. }
  224. }
  225. bus->soloed = true;
  226. } else {
  227. bus = NULL;
  228. }
  229. } while (bus);
  230. } else {
  231. bus->soloed = false;
  232. }
  233. }
  234. //make callbacks for mixing the audio
  235. for (Set<CallbackItem>::Element *E = callbacks.front(); E; E = E->next()) {
  236. E->get().callback(E->get().userdata);
  237. }
  238. for (int i = buses.size() - 1; i >= 0; i--) {
  239. //go bus by bus
  240. Bus *bus = buses[i];
  241. for (int k = 0; k < bus->channels.size(); k++) {
  242. if (bus->channels[k].active && !bus->channels[k].used) {
  243. //buffer was not used, but it's still active, so it must be cleaned
  244. AudioFrame *buf = bus->channels[k].buffer.ptrw();
  245. for (uint32_t j = 0; j < buffer_size; j++) {
  246. buf[j] = AudioFrame(0, 0);
  247. }
  248. }
  249. }
  250. //process effects
  251. if (!bus->bypass) {
  252. for (int j = 0; j < bus->effects.size(); j++) {
  253. if (!bus->effects[j].enabled)
  254. continue;
  255. for (int k = 0; k < bus->channels.size(); k++) {
  256. if (!bus->channels[k].active)
  257. continue;
  258. bus->channels[k].effect_instances[j]->process(bus->channels[k].buffer.ptr(), temp_buffer[k].ptrw(), buffer_size);
  259. }
  260. //swap buffers, so internal buffer always has the right data
  261. for (int k = 0; k < bus->channels.size(); k++) {
  262. if (!buses[i]->channels[k].active)
  263. continue;
  264. SWAP(bus->channels[k].buffer, temp_buffer[k]);
  265. }
  266. }
  267. }
  268. //process send
  269. Bus *send = NULL;
  270. if (i > 0) {
  271. //everything has a send save for master bus
  272. if (!bus_map.has(bus->send)) {
  273. send = buses[0];
  274. } else {
  275. send = bus_map[bus->send];
  276. if (send->index_cache >= bus->index_cache) { //invalid, send to master
  277. send = buses[0];
  278. }
  279. }
  280. }
  281. for (int k = 0; k < bus->channels.size(); k++) {
  282. if (!bus->channels[k].active)
  283. continue;
  284. AudioFrame *buf = bus->channels[k].buffer.ptrw();
  285. AudioFrame peak = AudioFrame(0, 0);
  286. float volume = Math::db2linear(bus->volume_db);
  287. if (solo_mode) {
  288. if (!bus->soloed) {
  289. volume = 0.0;
  290. }
  291. } else {
  292. if (bus->mute) {
  293. volume = 0.0;
  294. }
  295. }
  296. //apply volume and compute peak
  297. for (uint32_t j = 0; j < buffer_size; j++) {
  298. buf[j] *= volume;
  299. float l = ABS(buf[j].l);
  300. if (l > peak.l) {
  301. peak.l = l;
  302. }
  303. float r = ABS(buf[j].r);
  304. if (r > peak.r) {
  305. peak.r = r;
  306. }
  307. }
  308. bus->channels[k].peak_volume = AudioFrame(Math::linear2db(peak.l + 0.0000000001), Math::linear2db(peak.r + 0.0000000001));
  309. if (!bus->channels[k].used) {
  310. //see if any audio is contained, because channel was not used
  311. if (MAX(peak.r, peak.l) > Math::db2linear(channel_disable_threshold_db)) {
  312. bus->channels[k].last_mix_with_audio = mix_frames;
  313. } else if (mix_frames - bus->channels[k].last_mix_with_audio > channel_disable_frames) {
  314. bus->channels[k].active = false;
  315. continue; //went inactive, don't mix.
  316. }
  317. }
  318. if (send) {
  319. //if not master bus, send
  320. AudioFrame *target_buf = thread_get_channel_mix_buffer(send->index_cache, k);
  321. for (uint32_t j = 0; j < buffer_size; j++) {
  322. target_buf[j] += buf[j];
  323. }
  324. }
  325. }
  326. }
  327. mix_frames += buffer_size;
  328. to_mix = buffer_size;
  329. }
  330. AudioFrame *AudioServer::thread_get_channel_mix_buffer(int p_bus, int p_buffer) {
  331. ERR_FAIL_INDEX_V(p_bus, buses.size(), NULL);
  332. ERR_FAIL_INDEX_V(p_buffer, buses[p_bus]->channels.size(), NULL);
  333. AudioFrame *data = buses[p_bus]->channels[p_buffer].buffer.ptrw();
  334. if (!buses[p_bus]->channels[p_buffer].used) {
  335. buses[p_bus]->channels[p_buffer].used = true;
  336. buses[p_bus]->channels[p_buffer].active = true;
  337. buses[p_bus]->channels[p_buffer].last_mix_with_audio = mix_frames;
  338. for (uint32_t i = 0; i < buffer_size; i++) {
  339. data[i] = AudioFrame(0, 0);
  340. }
  341. }
  342. return data;
  343. }
  344. int AudioServer::thread_get_mix_buffer_size() const {
  345. return buffer_size;
  346. }
  347. int AudioServer::thread_find_bus_index(const StringName &p_name) {
  348. if (bus_map.has(p_name)) {
  349. return bus_map[p_name]->index_cache;
  350. } else {
  351. return 0;
  352. }
  353. }
  354. void AudioServer::set_bus_count(int p_count) {
  355. ERR_FAIL_COND(p_count < 1);
  356. ERR_FAIL_INDEX(p_count, 256);
  357. MARK_EDITED
  358. lock();
  359. int cb = buses.size();
  360. if (p_count < buses.size()) {
  361. for (int i = p_count; i < buses.size(); i++) {
  362. bus_map.erase(buses[i]->name);
  363. memdelete(buses[i]);
  364. }
  365. }
  366. buses.resize(p_count);
  367. for (int i = cb; i < buses.size(); i++) {
  368. String attempt = "New Bus";
  369. int attempts = 1;
  370. while (true) {
  371. bool name_free = true;
  372. for (int j = 0; j < i; j++) {
  373. if (buses[j]->name == attempt) {
  374. name_free = false;
  375. break;
  376. }
  377. }
  378. if (!name_free) {
  379. attempts++;
  380. attempt = "New Bus " + itos(attempts);
  381. } else {
  382. break;
  383. }
  384. }
  385. buses[i] = memnew(Bus);
  386. buses[i]->channels.resize(channel_count);
  387. for (int j = 0; j < channel_count; j++) {
  388. buses[i]->channels[j].buffer.resize(buffer_size);
  389. }
  390. buses[i]->name = attempt;
  391. buses[i]->solo = false;
  392. buses[i]->mute = false;
  393. buses[i]->bypass = false;
  394. buses[i]->volume_db = 0;
  395. if (i > 0) {
  396. buses[i]->send = "Master";
  397. }
  398. bus_map[attempt] = buses[i];
  399. }
  400. unlock();
  401. emit_signal("bus_layout_changed");
  402. }
  403. void AudioServer::remove_bus(int p_index) {
  404. ERR_FAIL_INDEX(p_index, buses.size());
  405. ERR_FAIL_COND(p_index == 0);
  406. MARK_EDITED
  407. lock();
  408. bus_map.erase(buses[p_index]->name);
  409. memdelete(buses[p_index]);
  410. buses.remove(p_index);
  411. unlock();
  412. emit_signal("bus_layout_changed");
  413. }
  414. void AudioServer::add_bus(int p_at_pos) {
  415. MARK_EDITED
  416. if (p_at_pos >= buses.size()) {
  417. p_at_pos = -1;
  418. } else if (p_at_pos == 0) {
  419. if (buses.size() > 1)
  420. p_at_pos = 1;
  421. else
  422. p_at_pos = -1;
  423. }
  424. String attempt = "New Bus";
  425. int attempts = 1;
  426. while (true) {
  427. bool name_free = true;
  428. for (int j = 0; j < buses.size(); j++) {
  429. if (buses[j]->name == attempt) {
  430. name_free = false;
  431. break;
  432. }
  433. }
  434. if (!name_free) {
  435. attempts++;
  436. attempt = "New Bus " + itos(attempts);
  437. } else {
  438. break;
  439. }
  440. }
  441. Bus *bus = memnew(Bus);
  442. bus->channels.resize(channel_count);
  443. for (int j = 0; j < channel_count; j++) {
  444. bus->channels[j].buffer.resize(buffer_size);
  445. }
  446. bus->name = attempt;
  447. bus->solo = false;
  448. bus->mute = false;
  449. bus->bypass = false;
  450. bus->volume_db = 0;
  451. bus_map[attempt] = bus;
  452. if (p_at_pos == -1)
  453. buses.push_back(bus);
  454. else
  455. buses.insert(p_at_pos, bus);
  456. emit_signal("bus_layout_changed");
  457. }
  458. void AudioServer::move_bus(int p_bus, int p_to_pos) {
  459. ERR_FAIL_COND(p_bus < 1 || p_bus >= buses.size());
  460. ERR_FAIL_COND(p_to_pos != -1 && (p_to_pos < 1 || p_to_pos > buses.size()));
  461. MARK_EDITED
  462. if (p_bus == p_to_pos)
  463. return;
  464. Bus *bus = buses[p_bus];
  465. buses.remove(p_bus);
  466. if (p_to_pos == -1) {
  467. buses.push_back(bus);
  468. } else if (p_to_pos < p_bus) {
  469. buses.insert(p_to_pos, bus);
  470. } else {
  471. buses.insert(p_to_pos - 1, bus);
  472. }
  473. emit_signal("bus_layout_changed");
  474. }
  475. int AudioServer::get_bus_count() const {
  476. return buses.size();
  477. }
  478. void AudioServer::set_bus_name(int p_bus, const String &p_name) {
  479. ERR_FAIL_INDEX(p_bus, buses.size());
  480. if (p_bus == 0 && p_name != "Master")
  481. return; //bus 0 is always master
  482. MARK_EDITED
  483. lock();
  484. if (buses[p_bus]->name == p_name) {
  485. unlock();
  486. return;
  487. }
  488. String attempt = p_name;
  489. int attempts = 1;
  490. while (true) {
  491. bool name_free = true;
  492. for (int i = 0; i < buses.size(); i++) {
  493. if (buses[i]->name == attempt) {
  494. name_free = false;
  495. break;
  496. }
  497. }
  498. if (name_free) {
  499. break;
  500. }
  501. attempts++;
  502. attempt = p_name + " " + itos(attempts);
  503. }
  504. bus_map.erase(buses[p_bus]->name);
  505. buses[p_bus]->name = attempt;
  506. bus_map[attempt] = buses[p_bus];
  507. unlock();
  508. emit_signal("bus_layout_changed");
  509. }
  510. String AudioServer::get_bus_name(int p_bus) const {
  511. ERR_FAIL_INDEX_V(p_bus, buses.size(), String());
  512. return buses[p_bus]->name;
  513. }
  514. int AudioServer::get_bus_index(const StringName &p_bus_name) const {
  515. for (int i = 0; i < buses.size(); ++i) {
  516. if (buses[i]->name == p_bus_name) {
  517. return i;
  518. }
  519. }
  520. return -1;
  521. }
  522. void AudioServer::set_bus_volume_db(int p_bus, float p_volume_db) {
  523. ERR_FAIL_INDEX(p_bus, buses.size());
  524. MARK_EDITED
  525. buses[p_bus]->volume_db = p_volume_db;
  526. }
  527. float AudioServer::get_bus_volume_db(int p_bus) const {
  528. ERR_FAIL_INDEX_V(p_bus, buses.size(), 0);
  529. return buses[p_bus]->volume_db;
  530. }
  531. void AudioServer::set_bus_send(int p_bus, const StringName &p_send) {
  532. ERR_FAIL_INDEX(p_bus, buses.size());
  533. MARK_EDITED
  534. buses[p_bus]->send = p_send;
  535. }
  536. StringName AudioServer::get_bus_send(int p_bus) const {
  537. ERR_FAIL_INDEX_V(p_bus, buses.size(), StringName());
  538. return buses[p_bus]->send;
  539. }
  540. void AudioServer::set_bus_solo(int p_bus, bool p_enable) {
  541. ERR_FAIL_INDEX(p_bus, buses.size());
  542. MARK_EDITED
  543. buses[p_bus]->solo = p_enable;
  544. }
  545. bool AudioServer::is_bus_solo(int p_bus) const {
  546. ERR_FAIL_INDEX_V(p_bus, buses.size(), false);
  547. return buses[p_bus]->solo;
  548. }
  549. void AudioServer::set_bus_mute(int p_bus, bool p_enable) {
  550. ERR_FAIL_INDEX(p_bus, buses.size());
  551. MARK_EDITED
  552. buses[p_bus]->mute = p_enable;
  553. }
  554. bool AudioServer::is_bus_mute(int p_bus) const {
  555. ERR_FAIL_INDEX_V(p_bus, buses.size(), false);
  556. return buses[p_bus]->mute;
  557. }
  558. void AudioServer::set_bus_bypass_effects(int p_bus, bool p_enable) {
  559. ERR_FAIL_INDEX(p_bus, buses.size());
  560. MARK_EDITED
  561. buses[p_bus]->bypass = p_enable;
  562. }
  563. bool AudioServer::is_bus_bypassing_effects(int p_bus) const {
  564. ERR_FAIL_INDEX_V(p_bus, buses.size(), false);
  565. return buses[p_bus]->bypass;
  566. }
  567. void AudioServer::_update_bus_effects(int p_bus) {
  568. for (int i = 0; i < buses[p_bus]->channels.size(); i++) {
  569. buses[p_bus]->channels[i].effect_instances.resize(buses[p_bus]->effects.size());
  570. for (int j = 0; j < buses[p_bus]->effects.size(); j++) {
  571. Ref<AudioEffectInstance> fx = buses[p_bus]->effects[j].effect->instance();
  572. if (Object::cast_to<AudioEffectCompressorInstance>(*fx)) {
  573. Object::cast_to<AudioEffectCompressorInstance>(*fx)->set_current_channel(i);
  574. }
  575. buses[p_bus]->channels[i].effect_instances[j] = fx;
  576. }
  577. }
  578. }
  579. void AudioServer::add_bus_effect(int p_bus, const Ref<AudioEffect> &p_effect, int p_at_pos) {
  580. ERR_FAIL_COND(p_effect.is_null());
  581. ERR_FAIL_INDEX(p_bus, buses.size());
  582. MARK_EDITED
  583. lock();
  584. Bus::Effect fx;
  585. fx.effect = p_effect;
  586. //fx.instance=p_effect->instance();
  587. fx.enabled = true;
  588. if (p_at_pos >= buses[p_bus]->effects.size() || p_at_pos < 0) {
  589. buses[p_bus]->effects.push_back(fx);
  590. } else {
  591. buses[p_bus]->effects.insert(p_at_pos, fx);
  592. }
  593. _update_bus_effects(p_bus);
  594. unlock();
  595. }
  596. void AudioServer::remove_bus_effect(int p_bus, int p_effect) {
  597. ERR_FAIL_INDEX(p_bus, buses.size());
  598. MARK_EDITED
  599. lock();
  600. buses[p_bus]->effects.remove(p_effect);
  601. _update_bus_effects(p_bus);
  602. unlock();
  603. }
  604. int AudioServer::get_bus_effect_count(int p_bus) {
  605. ERR_FAIL_INDEX_V(p_bus, buses.size(), 0);
  606. return buses[p_bus]->effects.size();
  607. }
  608. Ref<AudioEffect> AudioServer::get_bus_effect(int p_bus, int p_effect) {
  609. ERR_FAIL_INDEX_V(p_bus, buses.size(), Ref<AudioEffect>());
  610. ERR_FAIL_INDEX_V(p_effect, buses[p_bus]->effects.size(), Ref<AudioEffect>());
  611. return buses[p_bus]->effects[p_effect].effect;
  612. }
  613. void AudioServer::swap_bus_effects(int p_bus, int p_effect, int p_by_effect) {
  614. ERR_FAIL_INDEX(p_bus, buses.size());
  615. ERR_FAIL_INDEX(p_effect, buses[p_bus]->effects.size());
  616. ERR_FAIL_INDEX(p_by_effect, buses[p_bus]->effects.size());
  617. MARK_EDITED
  618. lock();
  619. SWAP(buses[p_bus]->effects[p_effect], buses[p_bus]->effects[p_by_effect]);
  620. _update_bus_effects(p_bus);
  621. unlock();
  622. }
  623. void AudioServer::set_bus_effect_enabled(int p_bus, int p_effect, bool p_enabled) {
  624. ERR_FAIL_INDEX(p_bus, buses.size());
  625. ERR_FAIL_INDEX(p_effect, buses[p_bus]->effects.size());
  626. MARK_EDITED
  627. buses[p_bus]->effects[p_effect].enabled = p_enabled;
  628. }
  629. bool AudioServer::is_bus_effect_enabled(int p_bus, int p_effect) const {
  630. ERR_FAIL_INDEX_V(p_bus, buses.size(), false);
  631. ERR_FAIL_INDEX_V(p_effect, buses[p_bus]->effects.size(), false);
  632. return buses[p_bus]->effects[p_effect].enabled;
  633. }
  634. float AudioServer::get_bus_peak_volume_left_db(int p_bus, int p_channel) const {
  635. ERR_FAIL_INDEX_V(p_bus, buses.size(), 0);
  636. ERR_FAIL_INDEX_V(p_channel, buses[p_bus]->channels.size(), 0);
  637. return buses[p_bus]->channels[p_channel].peak_volume.l;
  638. }
  639. float AudioServer::get_bus_peak_volume_right_db(int p_bus, int p_channel) const {
  640. ERR_FAIL_INDEX_V(p_bus, buses.size(), 0);
  641. ERR_FAIL_INDEX_V(p_channel, buses[p_bus]->channels.size(), 0);
  642. return buses[p_bus]->channels[p_channel].peak_volume.r;
  643. }
  644. bool AudioServer::is_bus_channel_active(int p_bus, int p_channel) const {
  645. ERR_FAIL_INDEX_V(p_bus, buses.size(), false);
  646. ERR_FAIL_INDEX_V(p_channel, buses[p_bus]->channels.size(), false);
  647. return buses[p_bus]->channels[p_channel].active;
  648. }
  649. void AudioServer::init_channels_and_buffers() {
  650. channel_count = get_channel_count();
  651. temp_buffer.resize(channel_count);
  652. for (int i = 0; i < temp_buffer.size(); i++) {
  653. temp_buffer[i].resize(buffer_size);
  654. }
  655. for (int i = 0; i < buses.size(); i++) {
  656. buses[i]->channels.resize(channel_count);
  657. for (int j = 0; j < channel_count; j++) {
  658. buses[i]->channels[j].buffer.resize(buffer_size);
  659. }
  660. }
  661. }
  662. void AudioServer::init() {
  663. channel_disable_threshold_db = GLOBAL_DEF("audio/channel_disable_threshold_db", -60.0);
  664. channel_disable_frames = float(GLOBAL_DEF("audio/channel_disable_time", 2.0)) * get_mix_rate();
  665. buffer_size = 1024; //hardcoded for now
  666. init_channels_and_buffers();
  667. mix_count = 0;
  668. set_bus_count(1);
  669. set_bus_name(0, "Master");
  670. if (AudioDriver::get_singleton())
  671. AudioDriver::get_singleton()->start();
  672. #ifdef TOOLS_ENABLED
  673. set_edited(false); //avoid editors from thinking this was edited
  674. #endif
  675. GLOBAL_DEF("audio/video_delay_compensation_ms", 0);
  676. }
  677. void AudioServer::load_default_bus_layout() {
  678. if (FileAccess::exists("res://default_bus_layout.tres")) {
  679. Ref<AudioBusLayout> default_layout = ResourceLoader::load("res://default_bus_layout.tres");
  680. if (default_layout.is_valid()) {
  681. set_bus_layout(default_layout);
  682. }
  683. }
  684. }
  685. void AudioServer::finish() {
  686. for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) {
  687. AudioDriverManager::get_driver(i)->finish();
  688. }
  689. for (int i = 0; i < buses.size(); i++) {
  690. memdelete(buses[i]);
  691. }
  692. buses.clear();
  693. }
  694. void AudioServer::update() {
  695. }
  696. /* MISC config */
  697. void AudioServer::lock() {
  698. AudioDriver::get_singleton()->lock();
  699. }
  700. void AudioServer::unlock() {
  701. AudioDriver::get_singleton()->unlock();
  702. }
  703. AudioServer::SpeakerMode AudioServer::get_speaker_mode() const {
  704. return (AudioServer::SpeakerMode)AudioDriver::get_singleton()->get_speaker_mode();
  705. }
  706. float AudioServer::get_mix_rate() const {
  707. return AudioDriver::get_singleton()->get_mix_rate();
  708. }
  709. float AudioServer::read_output_peak_db() const {
  710. return 0;
  711. }
  712. AudioServer *AudioServer::get_singleton() {
  713. return singleton;
  714. }
  715. double AudioServer::get_mix_time() const {
  716. return 0;
  717. }
  718. double AudioServer::get_output_delay() const {
  719. return 0;
  720. }
  721. AudioServer *AudioServer::singleton = NULL;
  722. void *AudioServer::audio_data_alloc(uint32_t p_data_len, const uint8_t *p_from_data) {
  723. void *ad = memalloc(p_data_len);
  724. ERR_FAIL_COND_V(!ad, NULL);
  725. if (p_from_data) {
  726. copymem(ad, p_from_data, p_data_len);
  727. }
  728. audio_data_lock->lock();
  729. audio_data[ad] = p_data_len;
  730. audio_data_total_mem += p_data_len;
  731. audio_data_max_mem = MAX(audio_data_total_mem, audio_data_max_mem);
  732. audio_data_lock->unlock();
  733. return ad;
  734. }
  735. void AudioServer::audio_data_free(void *p_data) {
  736. audio_data_lock->lock();
  737. if (!audio_data.has(p_data)) {
  738. audio_data_lock->unlock();
  739. ERR_FAIL();
  740. }
  741. audio_data_total_mem -= audio_data[p_data];
  742. audio_data.erase(p_data);
  743. memfree(p_data);
  744. audio_data_lock->unlock();
  745. }
  746. size_t AudioServer::audio_data_get_total_memory_usage() const {
  747. return audio_data_total_mem;
  748. }
  749. size_t AudioServer::audio_data_get_max_memory_usage() const {
  750. return audio_data_max_mem;
  751. }
  752. void AudioServer::add_callback(AudioCallback p_callback, void *p_userdata) {
  753. lock();
  754. CallbackItem ci;
  755. ci.callback = p_callback;
  756. ci.userdata = p_userdata;
  757. callbacks.insert(ci);
  758. unlock();
  759. }
  760. void AudioServer::remove_callback(AudioCallback p_callback, void *p_userdata) {
  761. lock();
  762. CallbackItem ci;
  763. ci.callback = p_callback;
  764. ci.userdata = p_userdata;
  765. callbacks.erase(ci);
  766. unlock();
  767. }
  768. void AudioServer::set_bus_layout(const Ref<AudioBusLayout> &p_bus_layout) {
  769. ERR_FAIL_COND(p_bus_layout.is_null() || p_bus_layout->buses.size() == 0);
  770. lock();
  771. for (int i = 0; i < buses.size(); i++) {
  772. memdelete(buses[i]);
  773. }
  774. buses.resize(p_bus_layout->buses.size());
  775. bus_map.clear();
  776. for (int i = 0; i < p_bus_layout->buses.size(); i++) {
  777. Bus *bus = memnew(Bus);
  778. if (i == 0) {
  779. bus->name = "Master";
  780. } else {
  781. bus->name = p_bus_layout->buses[i].name;
  782. bus->send = p_bus_layout->buses[i].send;
  783. }
  784. bus->solo = p_bus_layout->buses[i].solo;
  785. bus->mute = p_bus_layout->buses[i].mute;
  786. bus->bypass = p_bus_layout->buses[i].bypass;
  787. bus->volume_db = p_bus_layout->buses[i].volume_db;
  788. for (int j = 0; j < p_bus_layout->buses[i].effects.size(); j++) {
  789. Ref<AudioEffect> fx = p_bus_layout->buses[i].effects[j].effect;
  790. if (fx.is_valid()) {
  791. Bus::Effect bfx;
  792. bfx.effect = fx;
  793. bfx.enabled = p_bus_layout->buses[i].effects[j].enabled;
  794. bus->effects.push_back(bfx);
  795. }
  796. }
  797. bus_map[bus->name] = bus;
  798. buses[i] = bus;
  799. buses[i]->channels.resize(channel_count);
  800. for (int j = 0; j < channel_count; j++) {
  801. buses[i]->channels[j].buffer.resize(buffer_size);
  802. }
  803. _update_bus_effects(i);
  804. }
  805. #ifdef TOOLS_ENABLED
  806. set_edited(false);
  807. #endif
  808. unlock();
  809. }
  810. Ref<AudioBusLayout> AudioServer::generate_bus_layout() const {
  811. Ref<AudioBusLayout> state;
  812. state.instance();
  813. state->buses.resize(buses.size());
  814. for (int i = 0; i < buses.size(); i++) {
  815. state->buses[i].name = buses[i]->name;
  816. state->buses[i].send = buses[i]->send;
  817. state->buses[i].mute = buses[i]->mute;
  818. state->buses[i].solo = buses[i]->solo;
  819. state->buses[i].bypass = buses[i]->bypass;
  820. state->buses[i].volume_db = buses[i]->volume_db;
  821. for (int j = 0; j < buses[i]->effects.size(); j++) {
  822. AudioBusLayout::Bus::Effect fx;
  823. fx.effect = buses[i]->effects[j].effect;
  824. fx.enabled = buses[i]->effects[j].enabled;
  825. state->buses[i].effects.push_back(fx);
  826. }
  827. }
  828. return state;
  829. }
  830. Array AudioServer::get_device_list() {
  831. return AudioDriver::get_singleton()->get_device_list();
  832. }
  833. String AudioServer::get_device() {
  834. return AudioDriver::get_singleton()->get_device();
  835. }
  836. void AudioServer::set_device(String device) {
  837. AudioDriver::get_singleton()->set_device(device);
  838. }
  839. void AudioServer::_bind_methods() {
  840. ClassDB::bind_method(D_METHOD("set_bus_count", "amount"), &AudioServer::set_bus_count);
  841. ClassDB::bind_method(D_METHOD("get_bus_count"), &AudioServer::get_bus_count);
  842. ClassDB::bind_method(D_METHOD("remove_bus", "index"), &AudioServer::remove_bus);
  843. ClassDB::bind_method(D_METHOD("add_bus", "at_position"), &AudioServer::add_bus, DEFVAL(-1));
  844. ClassDB::bind_method(D_METHOD("move_bus", "index", "to_index"), &AudioServer::move_bus);
  845. ClassDB::bind_method(D_METHOD("set_bus_name", "bus_idx", "name"), &AudioServer::set_bus_name);
  846. ClassDB::bind_method(D_METHOD("get_bus_name", "bus_idx"), &AudioServer::get_bus_name);
  847. ClassDB::bind_method(D_METHOD("get_bus_index", "bus_name"), &AudioServer::get_bus_index);
  848. ClassDB::bind_method(D_METHOD("set_bus_volume_db", "bus_idx", "volume_db"), &AudioServer::set_bus_volume_db);
  849. ClassDB::bind_method(D_METHOD("get_bus_volume_db", "bus_idx"), &AudioServer::get_bus_volume_db);
  850. ClassDB::bind_method(D_METHOD("set_bus_send", "bus_idx", "send"), &AudioServer::set_bus_send);
  851. ClassDB::bind_method(D_METHOD("get_bus_send", "bus_idx"), &AudioServer::get_bus_send);
  852. ClassDB::bind_method(D_METHOD("set_bus_solo", "bus_idx", "enable"), &AudioServer::set_bus_solo);
  853. ClassDB::bind_method(D_METHOD("is_bus_solo", "bus_idx"), &AudioServer::is_bus_solo);
  854. ClassDB::bind_method(D_METHOD("set_bus_mute", "bus_idx", "enable"), &AudioServer::set_bus_mute);
  855. ClassDB::bind_method(D_METHOD("is_bus_mute", "bus_idx"), &AudioServer::is_bus_mute);
  856. ClassDB::bind_method(D_METHOD("set_bus_bypass_effects", "bus_idx", "enable"), &AudioServer::set_bus_bypass_effects);
  857. ClassDB::bind_method(D_METHOD("is_bus_bypassing_effects", "bus_idx"), &AudioServer::is_bus_bypassing_effects);
  858. ClassDB::bind_method(D_METHOD("add_bus_effect", "bus_idx", "effect", "at_position"), &AudioServer::add_bus_effect, DEFVAL(-1));
  859. ClassDB::bind_method(D_METHOD("remove_bus_effect", "bus_idx", "effect_idx"), &AudioServer::remove_bus_effect);
  860. ClassDB::bind_method(D_METHOD("get_bus_effect_count", "bus_idx"), &AudioServer::get_bus_effect_count);
  861. ClassDB::bind_method(D_METHOD("get_bus_effect", "bus_idx", "effect_idx"), &AudioServer::get_bus_effect);
  862. ClassDB::bind_method(D_METHOD("swap_bus_effects", "bus_idx", "effect_idx", "by_effect_idx"), &AudioServer::swap_bus_effects);
  863. ClassDB::bind_method(D_METHOD("set_bus_effect_enabled", "bus_idx", "effect_idx", "enabled"), &AudioServer::set_bus_effect_enabled);
  864. ClassDB::bind_method(D_METHOD("is_bus_effect_enabled", "bus_idx", "effect_idx"), &AudioServer::is_bus_effect_enabled);
  865. ClassDB::bind_method(D_METHOD("get_bus_peak_volume_left_db", "bus_idx", "channel"), &AudioServer::get_bus_peak_volume_left_db);
  866. ClassDB::bind_method(D_METHOD("get_bus_peak_volume_right_db", "bus_idx", "channel"), &AudioServer::get_bus_peak_volume_right_db);
  867. ClassDB::bind_method(D_METHOD("lock"), &AudioServer::lock);
  868. ClassDB::bind_method(D_METHOD("unlock"), &AudioServer::unlock);
  869. ClassDB::bind_method(D_METHOD("get_speaker_mode"), &AudioServer::get_speaker_mode);
  870. ClassDB::bind_method(D_METHOD("get_mix_rate"), &AudioServer::get_mix_rate);
  871. ClassDB::bind_method(D_METHOD("get_device_list"), &AudioServer::get_device_list);
  872. ClassDB::bind_method(D_METHOD("get_device"), &AudioServer::get_device);
  873. ClassDB::bind_method(D_METHOD("set_device"), &AudioServer::set_device);
  874. ClassDB::bind_method(D_METHOD("set_bus_layout", "bus_layout"), &AudioServer::set_bus_layout);
  875. ClassDB::bind_method(D_METHOD("generate_bus_layout"), &AudioServer::generate_bus_layout);
  876. ADD_SIGNAL(MethodInfo("bus_layout_changed"));
  877. BIND_ENUM_CONSTANT(SPEAKER_MODE_STEREO);
  878. BIND_ENUM_CONSTANT(SPEAKER_SURROUND_51);
  879. BIND_ENUM_CONSTANT(SPEAKER_SURROUND_71);
  880. }
  881. AudioServer::AudioServer() {
  882. singleton = this;
  883. audio_data_total_mem = 0;
  884. audio_data_max_mem = 0;
  885. audio_data_lock = Mutex::create();
  886. mix_frames = 0;
  887. channel_count = 0;
  888. to_mix = 0;
  889. }
  890. AudioServer::~AudioServer() {
  891. memdelete(audio_data_lock);
  892. singleton = NULL;
  893. }
  894. /////////////////////////////////
  895. bool AudioBusLayout::_set(const StringName &p_name, const Variant &p_value) {
  896. String s = p_name;
  897. if (s.begins_with("bus/")) {
  898. int index = s.get_slice("/", 1).to_int();
  899. if (buses.size() <= index) {
  900. buses.resize(index + 1);
  901. }
  902. Bus &bus = buses[index];
  903. String what = s.get_slice("/", 2);
  904. if (what == "name") {
  905. bus.name = p_value;
  906. } else if (what == "solo") {
  907. bus.solo = p_value;
  908. } else if (what == "mute") {
  909. bus.mute = p_value;
  910. } else if (what == "bypass_fx") {
  911. bus.bypass = p_value;
  912. } else if (what == "volume_db") {
  913. bus.volume_db = p_value;
  914. } else if (what == "send") {
  915. bus.send = p_value;
  916. } else if (what == "effect") {
  917. int which = s.get_slice("/", 3).to_int();
  918. if (bus.effects.size() <= which) {
  919. bus.effects.resize(which + 1);
  920. }
  921. Bus::Effect &fx = bus.effects[which];
  922. String fxwhat = s.get_slice("/", 4);
  923. if (fxwhat == "effect") {
  924. fx.effect = p_value;
  925. } else if (fxwhat == "enabled") {
  926. fx.enabled = p_value;
  927. } else {
  928. return false;
  929. }
  930. return true;
  931. } else {
  932. return false;
  933. }
  934. return true;
  935. }
  936. return false;
  937. }
  938. bool AudioBusLayout::_get(const StringName &p_name, Variant &r_ret) const {
  939. String s = p_name;
  940. if (s.begins_with("bus/")) {
  941. int index = s.get_slice("/", 1).to_int();
  942. if (index < 0 || index >= buses.size())
  943. return false;
  944. const Bus &bus = buses[index];
  945. String what = s.get_slice("/", 2);
  946. if (what == "name") {
  947. r_ret = bus.name;
  948. } else if (what == "solo") {
  949. r_ret = bus.solo;
  950. } else if (what == "mute") {
  951. r_ret = bus.mute;
  952. } else if (what == "bypass_fx") {
  953. r_ret = bus.bypass;
  954. } else if (what == "volume_db") {
  955. r_ret = bus.volume_db;
  956. } else if (what == "send") {
  957. r_ret = bus.send;
  958. } else if (what == "effect") {
  959. int which = s.get_slice("/", 3).to_int();
  960. if (which < 0 || which >= bus.effects.size()) {
  961. return false;
  962. }
  963. const Bus::Effect &fx = bus.effects[which];
  964. String fxwhat = s.get_slice("/", 4);
  965. if (fxwhat == "effect") {
  966. r_ret = fx.effect;
  967. } else if (fxwhat == "enabled") {
  968. r_ret = fx.enabled;
  969. } else {
  970. return false;
  971. }
  972. return true;
  973. } else {
  974. return false;
  975. }
  976. return true;
  977. }
  978. return false;
  979. }
  980. void AudioBusLayout::_get_property_list(List<PropertyInfo> *p_list) const {
  981. for (int i = 0; i < buses.size(); i++) {
  982. p_list->push_back(PropertyInfo(Variant::STRING, "bus/" + itos(i) + "/name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  983. p_list->push_back(PropertyInfo(Variant::BOOL, "bus/" + itos(i) + "/solo", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  984. p_list->push_back(PropertyInfo(Variant::BOOL, "bus/" + itos(i) + "/mute", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  985. p_list->push_back(PropertyInfo(Variant::BOOL, "bus/" + itos(i) + "/bypass_fx", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  986. p_list->push_back(PropertyInfo(Variant::REAL, "bus/" + itos(i) + "/volume_db", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  987. p_list->push_back(PropertyInfo(Variant::REAL, "bus/" + itos(i) + "/send", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  988. for (int j = 0; j < buses[i].effects.size(); j++) {
  989. p_list->push_back(PropertyInfo(Variant::OBJECT, "bus/" + itos(i) + "/effect/" + itos(j) + "/effect", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  990. p_list->push_back(PropertyInfo(Variant::BOOL, "bus/" + itos(i) + "/effect/" + itos(j) + "/enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  991. }
  992. }
  993. }
  994. AudioBusLayout::AudioBusLayout() {
  995. buses.resize(1);
  996. buses[0].name = "Master";
  997. }