2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* audio_server.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2018-01-01 13:40:08 +00:00
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "audio_server.h"
|
2017-01-25 17:30:40 +00:00
|
|
|
#include "io/resource_loader.h"
|
|
|
|
#include "os/file_access.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "os/os.h"
|
2017-07-22 10:47:04 +00:00
|
|
|
#include "project_settings.h"
|
2018-02-27 07:54:56 +00:00
|
|
|
#include "scene/resources/audio_stream_sample.h"
|
2017-09-13 16:34:22 +00:00
|
|
|
#include "servers/audio/audio_driver_dummy.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "servers/audio/effects/audio_effect_compressor.h"
|
2017-01-25 17:30:40 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
|
|
|
#define MARK_EDITED set_edited(true);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define MARK_EDITED
|
|
|
|
|
|
|
|
#endif
|
2017-01-22 23:39:53 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AudioDriver *AudioDriver::singleton = NULL;
|
2017-01-15 19:06:14 +00:00
|
|
|
AudioDriver *AudioDriver::get_singleton() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
return singleton;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDriver::set_singleton() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
singleton = this;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AudioDriver::audio_server_process(int p_frames, int32_t *p_buffer, bool p_update_mix_time) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
if (p_update_mix_time)
|
|
|
|
update_mix_time(p_frames);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
if (AudioServer::get_singleton())
|
2017-03-05 15:44:50 +00:00
|
|
|
AudioServer::get_singleton()->_driver_process(p_frames, p_buffer);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
void AudioDriver::update_mix_time(int p_frames) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_mix_amount += p_frames;
|
2017-08-01 21:09:52 +00:00
|
|
|
if (OS::get_singleton())
|
|
|
|
_last_mix_time = OS::get_singleton()->get_ticks_usec();
|
2017-01-15 19:06:14 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
double AudioDriver::get_mix_time() const {
|
|
|
|
|
|
|
|
double total = (OS::get_singleton()->get_ticks_usec() - _last_mix_time) / 1000000.0;
|
2017-03-05 15:44:50 +00:00
|
|
|
total += _mix_amount / (double)get_mix_rate();
|
2017-01-15 19:06:14 +00:00
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
2017-08-22 21:27:17 +00:00
|
|
|
AudioDriver::SpeakerMode AudioDriver::get_speaker_mode_by_total_channels(int p_channels) const {
|
|
|
|
switch (p_channels) {
|
|
|
|
case 4: return SPEAKER_SURROUND_31;
|
|
|
|
case 6: return SPEAKER_SURROUND_51;
|
|
|
|
case 8: return SPEAKER_SURROUND_71;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default to STEREO
|
|
|
|
return SPEAKER_MODE_STEREO;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AudioDriver::get_total_channels_by_speaker_mode(AudioDriver::SpeakerMode p_mode) const {
|
|
|
|
switch (p_mode) {
|
|
|
|
case SPEAKER_MODE_STEREO: return 2;
|
|
|
|
case SPEAKER_SURROUND_31: return 4;
|
|
|
|
case SPEAKER_SURROUND_51: return 6;
|
|
|
|
case SPEAKER_SURROUND_71: return 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR_FAIL_V(2);
|
|
|
|
}
|
|
|
|
|
2018-07-04 01:08:43 +00:00
|
|
|
Array AudioDriver::get_device_list() {
|
|
|
|
Array list;
|
2018-02-27 07:54:56 +00:00
|
|
|
|
2018-07-04 01:08:43 +00:00
|
|
|
list.push_back("Default");
|
2018-02-27 07:54:56 +00:00
|
|
|
|
2018-07-04 01:08:43 +00:00
|
|
|
return list;
|
2018-02-27 07:54:56 +00:00
|
|
|
}
|
|
|
|
|
2018-07-04 01:08:43 +00:00
|
|
|
String AudioDriver::get_device() {
|
|
|
|
return "Default";
|
2018-02-27 07:54:56 +00:00
|
|
|
}
|
|
|
|
|
2018-07-04 01:08:43 +00:00
|
|
|
Array AudioDriver::capture_get_device_list() {
|
2018-03-25 03:43:51 +00:00
|
|
|
Array list;
|
|
|
|
|
|
|
|
list.push_back("Default");
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
AudioDriver::AudioDriver() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_last_mix_time = 0;
|
|
|
|
_mix_amount = 0;
|
2018-06-21 00:02:02 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
prof_time = 0;
|
|
|
|
#endif
|
2017-01-15 19:06:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AudioDriver *AudioDriverManager::drivers[MAX_DRIVERS];
|
2017-03-05 15:44:50 +00:00
|
|
|
int AudioDriverManager::driver_count = 0;
|
2017-09-13 16:34:22 +00:00
|
|
|
AudioDriverDummy AudioDriverManager::dummy_driver;
|
2017-01-15 19:06:14 +00:00
|
|
|
|
|
|
|
void AudioDriverManager::add_driver(AudioDriver *p_driver) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(driver_count >= MAX_DRIVERS);
|
|
|
|
drivers[driver_count++] = p_driver;
|
2017-01-15 19:06:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int AudioDriverManager::get_driver_count() {
|
|
|
|
|
|
|
|
return driver_count;
|
|
|
|
}
|
2017-09-13 16:34:22 +00:00
|
|
|
|
|
|
|
void AudioDriverManager::initialize(int p_driver) {
|
|
|
|
int failed_driver = -1;
|
|
|
|
|
|
|
|
// Check if there is a selected driver
|
|
|
|
if (p_driver >= 0 && p_driver < driver_count) {
|
|
|
|
if (drivers[p_driver]->init() == OK) {
|
|
|
|
drivers[p_driver]->set_singleton();
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
failed_driver = p_driver;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No selected driver, try them all in order
|
|
|
|
for (int i = 0; i < driver_count; i++) {
|
|
|
|
// Don't re-init the driver if it failed above
|
|
|
|
if (i == failed_driver) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drivers[i]->init() == OK) {
|
|
|
|
drivers[i]->set_singleton();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fallback to our dummy driver
|
|
|
|
if (dummy_driver.init() == OK) {
|
|
|
|
ERR_PRINT("AudioDriverManager: all drivers failed, falling back to dummy driver");
|
|
|
|
dummy_driver.set_singleton();
|
|
|
|
} else {
|
2018-02-21 16:30:55 +00:00
|
|
|
ERR_PRINT("AudioDriverManager: dummy driver failed to init()");
|
2017-09-13 16:34:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
AudioDriver *AudioDriverManager::get_driver(int p_driver) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_driver, driver_count, NULL);
|
2017-01-15 19:06:14 +00:00
|
|
|
return drivers[p_driver];
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AudioServer::_driver_process(int p_frames, int32_t *p_buffer) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int todo = p_frames;
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2018-06-21 00:02:02 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
uint64_t prof_ticks = OS::get_singleton()->get_ticks_usec();
|
|
|
|
#endif
|
|
|
|
|
2018-03-18 01:43:32 +00:00
|
|
|
if (channel_count != get_channel_count()) {
|
|
|
|
// Amount of channels changed due to a device change
|
|
|
|
// reinitialize the buses channels and buffers
|
|
|
|
init_channels_and_buffers();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (todo) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (to_mix == 0) {
|
2017-01-21 22:00:25 +00:00
|
|
|
_mix_step();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int to_copy = MIN(to_mix, todo);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
Bus *master = buses[0];
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int from = buffer_size - to_mix;
|
|
|
|
int from_buf = p_frames - todo;
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
//master master, send to output
|
|
|
|
int cs = master->channels.size();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int k = 0; k < cs; k++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
if (master->channels[k].active) {
|
|
|
|
|
2017-11-25 03:07:54 +00:00
|
|
|
const AudioFrame *buf = master->channels[k].buffer.ptr();
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int j = 0; j < to_copy; j++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float l = CLAMP(buf[from + j].l, -1.0, 1.0);
|
|
|
|
int32_t vl = l * ((1 << 20) - 1);
|
|
|
|
p_buffer[(from_buf + j) * (cs * 2) + k * 2 + 0] = vl << 11;
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float r = CLAMP(buf[from + j].r, -1.0, 1.0);
|
|
|
|
int32_t vr = r * ((1 << 20) - 1);
|
|
|
|
p_buffer[(from_buf + j) * (cs * 2) + k * 2 + 1] = vr << 11;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int j = 0; j < to_copy; j++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
p_buffer[(from_buf + j) * (cs * 2) + k * 2 + 0] = 0;
|
|
|
|
p_buffer[(from_buf + j) * (cs * 2) + k * 2 + 1] = 0;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
todo -= to_copy;
|
|
|
|
to_mix -= to_copy;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
2018-07-17 01:43:47 +00:00
|
|
|
|
|
|
|
// Calculate latency for Performance.AUDIO_OUTPUT_LATENCY
|
|
|
|
if (OS::get_singleton()) {
|
|
|
|
uint64_t ticks = OS::get_singleton()->get_ticks_usec();
|
|
|
|
output_latency = (ticks - output_latency_ticks) / 1000000.f;
|
|
|
|
output_latency_ticks = ticks;
|
|
|
|
}
|
2018-06-21 00:02:02 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
prof_time += OS::get_singleton()->get_ticks_usec() - prof_ticks;
|
|
|
|
#endif
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioServer::_mix_step() {
|
|
|
|
|
2017-08-18 21:19:12 +00:00
|
|
|
bool solo_mode = false;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < buses.size(); i++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
Bus *bus = buses[i];
|
2017-03-05 15:44:50 +00:00
|
|
|
bus->index_cache = i; //might be moved around by editor, so..
|
|
|
|
for (int k = 0; k < bus->channels.size(); k++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
bus->channels.write[k].used = false;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
2017-08-18 21:19:12 +00:00
|
|
|
|
|
|
|
if (bus->solo) {
|
|
|
|
//solo chain
|
|
|
|
solo_mode = true;
|
|
|
|
bus->soloed = true;
|
|
|
|
do {
|
|
|
|
|
|
|
|
if (bus != buses[0]) {
|
|
|
|
//everything has a send save for master bus
|
|
|
|
if (!bus_map.has(bus->send)) {
|
|
|
|
bus = buses[0]; //send to master
|
|
|
|
} else {
|
2017-09-07 19:48:50 +00:00
|
|
|
int prev_index_cache = bus->index_cache;
|
2017-08-18 21:19:12 +00:00
|
|
|
bus = bus_map[bus->send];
|
2017-09-07 19:48:50 +00:00
|
|
|
if (prev_index_cache >= bus->index_cache) { //invalid, send to master
|
2017-08-18 21:19:12 +00:00
|
|
|
bus = buses[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bus->soloed = true;
|
|
|
|
} else {
|
|
|
|
bus = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (bus);
|
|
|
|
} else {
|
|
|
|
bus->soloed = false;
|
|
|
|
}
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//make callbacks for mixing the audio
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Set<CallbackItem>::Element *E = callbacks.front(); E; E = E->next()) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
E->get().callback(E->get().userdata);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = buses.size() - 1; i >= 0; i--) {
|
2017-01-21 22:00:25 +00:00
|
|
|
//go bus by bus
|
|
|
|
Bus *bus = buses[i];
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int k = 0; k < bus->channels.size(); k++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
if (bus->channels[k].active && !bus->channels[k].used) {
|
|
|
|
//buffer was not used, but it's still active, so it must be cleaned
|
2018-07-25 01:11:03 +00:00
|
|
|
AudioFrame *buf = bus->channels.write[k].buffer.ptrw();
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (uint32_t j = 0; j < buffer_size; j++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
buf[j] = AudioFrame(0, 0);
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//process effects
|
2017-08-18 21:19:12 +00:00
|
|
|
if (!bus->bypass) {
|
|
|
|
for (int j = 0; j < bus->effects.size(); j++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-08-18 21:19:12 +00:00
|
|
|
if (!bus->effects[j].enabled)
|
|
|
|
continue;
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2018-06-21 00:02:02 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
uint64_t ticks = OS::get_singleton()->get_ticks_usec();
|
|
|
|
#endif
|
|
|
|
|
2017-08-18 21:19:12 +00:00
|
|
|
for (int k = 0; k < bus->channels.size(); k++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2018-01-18 15:03:53 +00:00
|
|
|
if (!(bus->channels[k].active || bus->channels[k].effect_instances[j]->process_silence()))
|
2017-08-18 21:19:12 +00:00
|
|
|
continue;
|
2018-07-25 01:11:03 +00:00
|
|
|
bus->channels.write[k].effect_instances.write[j]->process(bus->channels[k].buffer.ptr(), temp_buffer.write[k].ptrw(), buffer_size);
|
2017-08-18 21:19:12 +00:00
|
|
|
}
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-08-18 21:19:12 +00:00
|
|
|
//swap buffers, so internal buffer always has the right data
|
|
|
|
for (int k = 0; k < bus->channels.size(); k++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2018-01-18 15:03:53 +00:00
|
|
|
if (!(buses[i]->channels[k].active || bus->channels[k].effect_instances[j]->process_silence()))
|
2017-08-18 21:19:12 +00:00
|
|
|
continue;
|
2018-07-25 01:11:03 +00:00
|
|
|
SWAP(bus->channels.write[k].buffer, temp_buffer.write[k]);
|
2017-08-18 21:19:12 +00:00
|
|
|
}
|
2018-06-21 00:02:02 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_ENABLED
|
2018-07-25 01:11:03 +00:00
|
|
|
bus->effects.write[j].prof_time += OS::get_singleton()->get_ticks_usec() - ticks;
|
2018-06-21 00:02:02 +00:00
|
|
|
#endif
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//process send
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Bus *send = NULL;
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (i > 0) {
|
2017-01-21 22:00:25 +00:00
|
|
|
//everything has a send save for master bus
|
|
|
|
if (!bus_map.has(bus->send)) {
|
2017-03-05 15:44:50 +00:00
|
|
|
send = buses[0];
|
2017-01-21 22:00:25 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
send = bus_map[bus->send];
|
|
|
|
if (send->index_cache >= bus->index_cache) { //invalid, send to master
|
|
|
|
send = buses[0];
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int k = 0; k < bus->channels.size(); k++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
if (!bus->channels[k].active)
|
|
|
|
continue;
|
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
AudioFrame *buf = bus->channels.write[k].buffer.ptrw();
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AudioFrame peak = AudioFrame(0, 0);
|
2017-08-18 21:19:12 +00:00
|
|
|
|
|
|
|
float volume = Math::db2linear(bus->volume_db);
|
|
|
|
|
|
|
|
if (solo_mode) {
|
|
|
|
if (!bus->soloed) {
|
|
|
|
volume = 0.0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (bus->mute) {
|
|
|
|
volume = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//apply volume and compute peak
|
2017-03-05 15:44:50 +00:00
|
|
|
for (uint32_t j = 0; j < buffer_size; j++) {
|
2017-08-18 21:19:12 +00:00
|
|
|
|
|
|
|
buf[j] *= volume;
|
|
|
|
|
2017-01-21 22:00:25 +00:00
|
|
|
float l = ABS(buf[j].l);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (l > peak.l) {
|
|
|
|
peak.l = l;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
float r = ABS(buf[j].r);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (r > peak.r) {
|
|
|
|
peak.r = r;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
bus->channels.write[k].peak_volume = AudioFrame(Math::linear2db(peak.l + 0.0000000001), Math::linear2db(peak.r + 0.0000000001));
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
if (!bus->channels[k].used) {
|
|
|
|
//see if any audio is contained, because channel was not used
|
|
|
|
|
2017-07-08 15:12:18 +00:00
|
|
|
if (MAX(peak.r, peak.l) > Math::db2linear(channel_disable_threshold_db)) {
|
2018-07-25 01:11:03 +00:00
|
|
|
bus->channels.write[k].last_mix_with_audio = mix_frames;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (mix_frames - bus->channels[k].last_mix_with_audio > channel_disable_frames) {
|
2018-07-25 01:11:03 +00:00
|
|
|
bus->channels.write[k].active = false;
|
2017-03-24 20:45:31 +00:00
|
|
|
continue; //went inactive, don't mix.
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (send) {
|
|
|
|
//if not master bus, send
|
2017-03-05 15:44:50 +00:00
|
|
|
AudioFrame *target_buf = thread_get_channel_mix_buffer(send->index_cache, k);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (uint32_t j = 0; j < buffer_size; j++) {
|
|
|
|
target_buf[j] += buf[j];
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
mix_frames += buffer_size;
|
|
|
|
to_mix = buffer_size;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AudioFrame *AudioServer::thread_get_channel_mix_buffer(int p_bus, int p_buffer) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_bus, buses.size(), NULL);
|
|
|
|
ERR_FAIL_INDEX_V(p_buffer, buses[p_bus]->channels.size(), NULL);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
AudioFrame *data = buses.write[p_bus]->channels.write[p_buffer].buffer.ptrw();
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
if (!buses[p_bus]->channels[p_buffer].used) {
|
2018-07-25 01:11:03 +00:00
|
|
|
buses.write[p_bus]->channels.write[p_buffer].used = true;
|
|
|
|
buses.write[p_bus]->channels.write[p_buffer].active = true;
|
|
|
|
buses.write[p_bus]->channels.write[p_buffer].last_mix_with_audio = mix_frames;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (uint32_t i = 0; i < buffer_size; i++) {
|
|
|
|
data[i] = AudioFrame(0, 0);
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AudioServer::thread_get_mix_buffer_size() const {
|
|
|
|
|
|
|
|
return buffer_size;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int AudioServer::thread_find_bus_index(const StringName &p_name) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
if (bus_map.has(p_name)) {
|
|
|
|
return bus_map[p_name]->index_cache;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
void AudioServer::set_bus_count(int p_count) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(p_count < 1);
|
|
|
|
ERR_FAIL_INDEX(p_count, 256);
|
2017-01-25 17:30:40 +00:00
|
|
|
|
|
|
|
MARK_EDITED
|
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
lock();
|
2017-01-21 22:00:25 +00:00
|
|
|
int cb = buses.size();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_count < buses.size()) {
|
|
|
|
for (int i = p_count; i < buses.size(); i++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
bus_map.erase(buses[i]->name);
|
|
|
|
memdelete(buses[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
buses.resize(p_count);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = cb; i < buses.size(); i++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String attempt = "New Bus";
|
|
|
|
int attempts = 1;
|
|
|
|
while (true) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool name_free = true;
|
|
|
|
for (int j = 0; j < i; j++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (buses[j]->name == attempt) {
|
|
|
|
name_free = false;
|
2017-01-21 22:00:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!name_free) {
|
|
|
|
attempts++;
|
2017-03-05 15:44:50 +00:00
|
|
|
attempt = "New Bus " + itos(attempts);
|
2017-01-21 22:00:25 +00:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
buses.write[i] = memnew(Bus);
|
|
|
|
buses.write[i]->channels.resize(channel_count);
|
2018-03-18 01:43:32 +00:00
|
|
|
for (int j = 0; j < channel_count; j++) {
|
2018-07-25 01:11:03 +00:00
|
|
|
buses.write[i]->channels.write[j].buffer.resize(buffer_size);
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
buses[i]->name = attempt;
|
|
|
|
buses[i]->solo = false;
|
|
|
|
buses[i]->mute = false;
|
|
|
|
buses[i]->bypass = false;
|
|
|
|
buses[i]->volume_db = 0;
|
|
|
|
if (i > 0) {
|
|
|
|
buses[i]->send = "Master";
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bus_map[attempt] = buses[i];
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
unlock();
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
emit_signal("bus_layout_changed");
|
2017-01-15 19:06:14 +00:00
|
|
|
}
|
|
|
|
|
2017-01-24 02:12:08 +00:00
|
|
|
void AudioServer::remove_bus(int p_index) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_index, buses.size());
|
|
|
|
ERR_FAIL_COND(p_index == 0);
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
MARK_EDITED
|
|
|
|
|
2017-01-24 02:12:08 +00:00
|
|
|
lock();
|
|
|
|
bus_map.erase(buses[p_index]->name);
|
|
|
|
memdelete(buses[p_index]);
|
|
|
|
buses.remove(p_index);
|
|
|
|
unlock();
|
2018-02-23 22:42:57 +00:00
|
|
|
|
|
|
|
emit_signal("bus_layout_changed");
|
2017-01-24 02:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioServer::add_bus(int p_at_pos) {
|
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
MARK_EDITED
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_at_pos >= buses.size()) {
|
|
|
|
p_at_pos = -1;
|
|
|
|
} else if (p_at_pos == 0) {
|
|
|
|
if (buses.size() > 1)
|
|
|
|
p_at_pos = 1;
|
2017-01-24 02:12:08 +00:00
|
|
|
else
|
2017-03-05 15:44:50 +00:00
|
|
|
p_at_pos = -1;
|
2017-01-24 02:12:08 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String attempt = "New Bus";
|
|
|
|
int attempts = 1;
|
|
|
|
while (true) {
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool name_free = true;
|
|
|
|
for (int j = 0; j < buses.size(); j++) {
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (buses[j]->name == attempt) {
|
|
|
|
name_free = false;
|
2017-01-24 02:12:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!name_free) {
|
|
|
|
attempts++;
|
2017-03-05 15:44:50 +00:00
|
|
|
attempt = "New Bus " + itos(attempts);
|
2017-01-24 02:12:08 +00:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Bus *bus = memnew(Bus);
|
2018-03-18 01:43:32 +00:00
|
|
|
bus->channels.resize(channel_count);
|
|
|
|
for (int j = 0; j < channel_count; j++) {
|
2018-07-25 01:11:03 +00:00
|
|
|
bus->channels.write[j].buffer.resize(buffer_size);
|
2017-01-24 02:12:08 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
bus->name = attempt;
|
|
|
|
bus->solo = false;
|
|
|
|
bus->mute = false;
|
|
|
|
bus->bypass = false;
|
|
|
|
bus->volume_db = 0;
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bus_map[attempt] = bus;
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_at_pos == -1)
|
2017-01-24 02:12:08 +00:00
|
|
|
buses.push_back(bus);
|
|
|
|
else
|
2017-03-05 15:44:50 +00:00
|
|
|
buses.insert(p_at_pos, bus);
|
2018-02-23 22:42:57 +00:00
|
|
|
|
|
|
|
emit_signal("bus_layout_changed");
|
2017-01-24 02:12:08 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AudioServer::move_bus(int p_bus, int p_to_pos) {
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(p_bus < 1 || p_bus >= buses.size());
|
|
|
|
ERR_FAIL_COND(p_to_pos != -1 && (p_to_pos < 1 || p_to_pos > buses.size()));
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
MARK_EDITED
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_bus == p_to_pos)
|
2017-01-24 02:12:08 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
Bus *bus = buses[p_bus];
|
|
|
|
buses.remove(p_bus);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_to_pos == -1) {
|
2017-01-24 02:12:08 +00:00
|
|
|
buses.push_back(bus);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_to_pos < p_bus) {
|
|
|
|
buses.insert(p_to_pos, bus);
|
2017-01-24 02:12:08 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
buses.insert(p_to_pos - 1, bus);
|
2017-01-24 02:12:08 +00:00
|
|
|
}
|
2018-02-23 22:42:57 +00:00
|
|
|
|
|
|
|
emit_signal("bus_layout_changed");
|
2017-01-24 02:12:08 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
int AudioServer::get_bus_count() const {
|
|
|
|
|
|
|
|
return buses.size();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AudioServer::set_bus_name(int p_bus, const String &p_name) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_bus, buses.size());
|
|
|
|
if (p_bus == 0 && p_name != "Master")
|
2017-01-21 22:00:25 +00:00
|
|
|
return; //bus 0 is always master
|
2017-01-25 17:30:40 +00:00
|
|
|
|
|
|
|
MARK_EDITED
|
|
|
|
|
2017-01-21 22:00:25 +00:00
|
|
|
lock();
|
2017-01-15 19:06:14 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (buses[p_bus]->name == p_name) {
|
2017-01-21 22:00:25 +00:00
|
|
|
unlock();
|
|
|
|
return;
|
|
|
|
}
|
2017-01-15 19:06:14 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String attempt = p_name;
|
|
|
|
int attempts = 1;
|
2017-01-15 19:06:14 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (true) {
|
2017-01-15 19:06:14 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool name_free = true;
|
|
|
|
for (int i = 0; i < buses.size(); i++) {
|
2017-01-15 19:06:14 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (buses[i]->name == attempt) {
|
|
|
|
name_free = false;
|
2017-01-21 22:00:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name_free) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
attempts++;
|
2017-03-05 15:44:50 +00:00
|
|
|
attempt = p_name + " " + itos(attempts);
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
bus_map.erase(buses[p_bus]->name);
|
2017-03-05 15:44:50 +00:00
|
|
|
buses[p_bus]->name = attempt;
|
|
|
|
bus_map[attempt] = buses[p_bus];
|
2017-01-21 22:00:25 +00:00
|
|
|
unlock();
|
|
|
|
|
|
|
|
emit_signal("bus_layout_changed");
|
2017-01-15 19:06:14 +00:00
|
|
|
}
|
|
|
|
String AudioServer::get_bus_name(int p_bus) const {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_bus, buses.size(), String());
|
2017-01-21 22:00:25 +00:00
|
|
|
return buses[p_bus]->name;
|
2017-01-15 19:06:14 +00:00
|
|
|
}
|
2016-01-21 13:40:35 +00:00
|
|
|
|
2017-07-10 20:51:29 +00:00
|
|
|
int AudioServer::get_bus_index(const StringName &p_bus_name) const {
|
|
|
|
for (int i = 0; i < buses.size(); ++i) {
|
|
|
|
if (buses[i]->name == p_bus_name) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AudioServer::set_bus_volume_db(int p_bus, float p_volume_db) {
|
2016-01-21 13:40:35 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_bus, buses.size());
|
2017-01-25 17:30:40 +00:00
|
|
|
|
|
|
|
MARK_EDITED
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
buses[p_bus]->volume_db = p_volume_db;
|
2017-01-15 19:06:14 +00:00
|
|
|
}
|
|
|
|
float AudioServer::get_bus_volume_db(int p_bus) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_bus, buses.size(), 0);
|
2017-01-21 22:00:25 +00:00
|
|
|
return buses[p_bus]->volume_db;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AudioServer::set_bus_send(int p_bus, const StringName &p_send) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_bus, buses.size());
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
MARK_EDITED
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
buses[p_bus]->send = p_send;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StringName AudioServer::get_bus_send(int p_bus) const {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_bus, buses.size(), StringName());
|
2017-01-21 22:00:25 +00:00
|
|
|
return buses[p_bus]->send;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AudioServer::set_bus_solo(int p_bus, bool p_enable) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_bus, buses.size());
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
MARK_EDITED
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
buses[p_bus]->solo = p_enable;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool AudioServer::is_bus_solo(int p_bus) const {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_bus, buses.size(), false);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
return buses[p_bus]->solo;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AudioServer::set_bus_mute(int p_bus, bool p_enable) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_bus, buses.size());
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
MARK_EDITED
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
buses[p_bus]->mute = p_enable;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
bool AudioServer::is_bus_mute(int p_bus) const {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_bus, buses.size(), false);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
return buses[p_bus]->mute;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AudioServer::set_bus_bypass_effects(int p_bus, bool p_enable) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_bus, buses.size());
|
2016-01-21 13:40:35 +00:00
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
MARK_EDITED
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
buses[p_bus]->bypass = p_enable;
|
2017-01-15 19:06:14 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
bool AudioServer::is_bus_bypassing_effects(int p_bus) const {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_bus, buses.size(), false);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
return buses[p_bus]->bypass;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioServer::_update_bus_effects(int p_bus) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < buses[p_bus]->channels.size(); i++) {
|
2018-07-25 01:11:03 +00:00
|
|
|
buses.write[p_bus]->channels.write[i].effect_instances.resize(buses[p_bus]->effects.size());
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int j = 0; j < buses[p_bus]->effects.size(); j++) {
|
2018-07-25 01:11:03 +00:00
|
|
|
Ref<AudioEffectInstance> fx = buses.write[p_bus]->effects.write[j].effect->instance();
|
2017-08-24 20:58:51 +00:00
|
|
|
if (Object::cast_to<AudioEffectCompressorInstance>(*fx)) {
|
|
|
|
Object::cast_to<AudioEffectCompressorInstance>(*fx)->set_current_channel(i);
|
2017-01-22 23:39:53 +00:00
|
|
|
}
|
2018-07-25 01:11:03 +00:00
|
|
|
buses.write[p_bus]->channels.write[i].effect_instances.write[j] = fx;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AudioServer::add_bus_effect(int p_bus, const Ref<AudioEffect> &p_effect, int p_at_pos) {
|
2016-01-21 13:40:35 +00:00
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
ERR_FAIL_COND(p_effect.is_null());
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_bus, buses.size());
|
2016-01-21 13:40:35 +00:00
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
MARK_EDITED
|
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
lock();
|
2016-01-21 13:40:35 +00:00
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
Bus::Effect fx;
|
2017-03-05 15:44:50 +00:00
|
|
|
fx.effect = p_effect;
|
2017-01-15 19:06:14 +00:00
|
|
|
//fx.instance=p_effect->instance();
|
2017-03-05 15:44:50 +00:00
|
|
|
fx.enabled = true;
|
2018-06-21 00:02:02 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
fx.prof_time = 0;
|
|
|
|
#endif
|
2016-01-21 13:40:35 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_at_pos >= buses[p_bus]->effects.size() || p_at_pos < 0) {
|
2017-01-21 22:00:25 +00:00
|
|
|
buses[p_bus]->effects.push_back(fx);
|
2017-01-15 19:06:14 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
buses[p_bus]->effects.insert(p_at_pos, fx);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-01-21 22:00:25 +00:00
|
|
|
_update_bus_effects(p_bus);
|
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
unlock();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AudioServer::remove_bus_effect(int p_bus, int p_effect) {
|
2017-01-15 19:06:14 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_bus, buses.size());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
MARK_EDITED
|
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
lock();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-21 22:00:25 +00:00
|
|
|
buses[p_bus]->effects.remove(p_effect);
|
|
|
|
_update_bus_effects(p_bus);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
unlock();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
int AudioServer::get_bus_effect_count(int p_bus) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_bus, buses.size(), 0);
|
2017-01-15 19:06:14 +00:00
|
|
|
|
2017-01-21 22:00:25 +00:00
|
|
|
return buses[p_bus]->effects.size();
|
2017-01-15 19:06:14 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<AudioEffect> AudioServer::get_bus_effect(int p_bus, int p_effect) {
|
2017-01-15 19:06:14 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_bus, buses.size(), Ref<AudioEffect>());
|
|
|
|
ERR_FAIL_INDEX_V(p_effect, buses[p_bus]->effects.size(), Ref<AudioEffect>());
|
2017-01-15 19:06:14 +00:00
|
|
|
|
2017-01-21 22:00:25 +00:00
|
|
|
return buses[p_bus]->effects[p_effect].effect;
|
2017-01-15 19:06:14 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AudioServer::swap_bus_effects(int p_bus, int p_effect, int p_by_effect) {
|
2017-01-15 19:06:14 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_bus, buses.size());
|
|
|
|
ERR_FAIL_INDEX(p_effect, buses[p_bus]->effects.size());
|
|
|
|
ERR_FAIL_INDEX(p_by_effect, buses[p_bus]->effects.size());
|
2017-01-15 19:06:14 +00:00
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
MARK_EDITED
|
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
lock();
|
2018-07-25 01:11:03 +00:00
|
|
|
SWAP(buses.write[p_bus]->effects.write[p_effect], buses.write[p_bus]->effects.write[p_by_effect]);
|
2017-01-21 22:00:25 +00:00
|
|
|
_update_bus_effects(p_bus);
|
2017-01-15 19:06:14 +00:00
|
|
|
unlock();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AudioServer::set_bus_effect_enabled(int p_bus, int p_effect, bool p_enabled) {
|
2017-01-15 19:06:14 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_bus, buses.size());
|
|
|
|
ERR_FAIL_INDEX(p_effect, buses[p_bus]->effects.size());
|
2017-01-25 17:30:40 +00:00
|
|
|
|
|
|
|
MARK_EDITED
|
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
buses.write[p_bus]->effects.write[p_effect].enabled = p_enabled;
|
2017-01-15 19:06:14 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
bool AudioServer::is_bus_effect_enabled(int p_bus, int p_effect) const {
|
2017-01-15 19:06:14 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_bus, buses.size(), false);
|
|
|
|
ERR_FAIL_INDEX_V(p_effect, buses[p_bus]->effects.size(), false);
|
2017-01-21 22:00:25 +00:00
|
|
|
return buses[p_bus]->effects[p_effect].enabled;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float AudioServer::get_bus_peak_volume_left_db(int p_bus, int p_channel) const {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_bus, buses.size(), 0);
|
|
|
|
ERR_FAIL_INDEX_V(p_channel, buses[p_bus]->channels.size(), 0);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
return buses[p_bus]->channels[p_channel].peak_volume.l;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
float AudioServer::get_bus_peak_volume_right_db(int p_bus, int p_channel) const {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_bus, buses.size(), 0);
|
|
|
|
ERR_FAIL_INDEX_V(p_channel, buses[p_bus]->channels.size(), 0);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
return buses[p_bus]->channels[p_channel].peak_volume.r;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool AudioServer::is_bus_channel_active(int p_bus, int p_channel) const {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_bus, buses.size(), false);
|
|
|
|
ERR_FAIL_INDEX_V(p_channel, buses[p_bus]->channels.size(), false);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
return buses[p_bus]->channels[p_channel].active;
|
2017-01-15 19:06:14 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-03-18 01:43:32 +00:00
|
|
|
void AudioServer::init_channels_and_buffers() {
|
|
|
|
channel_count = get_channel_count();
|
|
|
|
temp_buffer.resize(channel_count);
|
|
|
|
|
|
|
|
for (int i = 0; i < temp_buffer.size(); i++) {
|
2018-07-25 01:11:03 +00:00
|
|
|
temp_buffer.write[i].resize(buffer_size);
|
2018-03-18 01:43:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < buses.size(); i++) {
|
|
|
|
buses[i]->channels.resize(channel_count);
|
|
|
|
for (int j = 0; j < channel_count; j++) {
|
2018-07-25 01:11:03 +00:00
|
|
|
buses.write[i]->channels.write[j].buffer.resize(buffer_size);
|
2018-03-18 01:43:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
void AudioServer::init() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-07-19 21:58:15 +00:00
|
|
|
channel_disable_threshold_db = GLOBAL_DEF_RST("audio/channel_disable_threshold_db", -60.0);
|
|
|
|
channel_disable_frames = float(GLOBAL_DEF_RST("audio/channel_disable_time", 2.0)) * get_mix_rate();
|
2018-02-21 16:30:55 +00:00
|
|
|
buffer_size = 1024; //hardcoded for now
|
2017-08-22 21:27:17 +00:00
|
|
|
|
2018-03-18 01:43:32 +00:00
|
|
|
init_channels_and_buffers();
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
mix_count = 0;
|
|
|
|
set_bus_count(1);
|
|
|
|
set_bus_name(0, "Master");
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
if (AudioDriver::get_singleton())
|
|
|
|
AudioDriver::get_singleton()->start();
|
2017-08-22 21:27:17 +00:00
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
set_edited(false); //avoid editors from thinking this was edited
|
|
|
|
#endif
|
2017-09-14 20:45:02 +00:00
|
|
|
|
2018-07-19 21:58:15 +00:00
|
|
|
GLOBAL_DEF_RST("audio/video_delay_compensation_ms", 0);
|
2017-01-15 19:06:14 +00:00
|
|
|
}
|
2017-01-25 17:30:40 +00:00
|
|
|
|
2018-06-21 00:02:02 +00:00
|
|
|
void AudioServer::update() {
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (ScriptDebugger::get_singleton() && ScriptDebugger::get_singleton()->is_profiling()) {
|
|
|
|
|
|
|
|
// Driver time includes server time + effects times
|
|
|
|
// Server time includes effects times
|
|
|
|
uint64_t driver_time = AudioDriver::get_singleton()->get_profiling_time();
|
|
|
|
uint64_t server_time = prof_time;
|
|
|
|
|
|
|
|
// Substract the server time from the driver time
|
|
|
|
if (driver_time > server_time)
|
|
|
|
driver_time -= server_time;
|
|
|
|
|
|
|
|
Array values;
|
|
|
|
|
|
|
|
for (int i = buses.size() - 1; i >= 0; i--) {
|
|
|
|
Bus *bus = buses[i];
|
|
|
|
if (bus->bypass)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (int j = 0; j < bus->effects.size(); j++) {
|
|
|
|
if (!bus->effects[j].enabled)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
values.push_back(String(bus->name) + bus->effects[j].effect->get_name());
|
|
|
|
values.push_back(USEC_TO_SEC(bus->effects[j].prof_time));
|
|
|
|
|
|
|
|
// Substract the effect time from the driver and server times
|
|
|
|
if (driver_time > bus->effects[j].prof_time)
|
|
|
|
driver_time -= bus->effects[j].prof_time;
|
|
|
|
if (server_time > bus->effects[j].prof_time)
|
|
|
|
server_time -= bus->effects[j].prof_time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
values.push_back("audio_server");
|
|
|
|
values.push_back(USEC_TO_SEC(server_time));
|
|
|
|
values.push_back("audio_driver");
|
|
|
|
values.push_back(USEC_TO_SEC(driver_time));
|
|
|
|
|
|
|
|
ScriptDebugger::get_singleton()->add_profiling_frame_data("audio_thread", values);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset profiling times
|
|
|
|
for (int i = buses.size() - 1; i >= 0; i--) {
|
|
|
|
Bus *bus = buses[i];
|
|
|
|
if (bus->bypass)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (int j = 0; j < bus->effects.size(); j++) {
|
|
|
|
if (!bus->effects[j].enabled)
|
|
|
|
continue;
|
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
bus->effects.write[j].prof_time = 0;
|
2018-06-21 00:02:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioDriver::get_singleton()->reset_profiling_time();
|
|
|
|
prof_time = 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
void AudioServer::load_default_bus_layout() {
|
|
|
|
|
|
|
|
if (FileAccess::exists("res://default_bus_layout.tres")) {
|
|
|
|
Ref<AudioBusLayout> default_layout = ResourceLoader::load("res://default_bus_layout.tres");
|
|
|
|
if (default_layout.is_valid()) {
|
|
|
|
set_bus_layout(default_layout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
void AudioServer::finish() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-12-29 10:22:56 +00:00
|
|
|
for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) {
|
|
|
|
AudioDriverManager::get_driver(i)->finish();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < buses.size(); i++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
memdelete(buses[i]);
|
|
|
|
}
|
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
buses.clear();
|
|
|
|
}
|
2017-08-02 14:45:19 +00:00
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
/* MISC config */
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
void AudioServer::lock() {
|
|
|
|
|
|
|
|
AudioDriver::get_singleton()->lock();
|
|
|
|
}
|
|
|
|
void AudioServer::unlock() {
|
|
|
|
|
|
|
|
AudioDriver::get_singleton()->unlock();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AudioServer::SpeakerMode AudioServer::get_speaker_mode() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
return (AudioServer::SpeakerMode)AudioDriver::get_singleton()->get_speaker_mode();
|
|
|
|
}
|
|
|
|
float AudioServer::get_mix_rate() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
return AudioDriver::get_singleton()->get_mix_rate();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
float AudioServer::read_output_peak_db() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
AudioServer *AudioServer::get_singleton() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
return singleton;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
double AudioServer::get_mix_time() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
double AudioServer::get_output_delay() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AudioServer *AudioServer::singleton = NULL;
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void *AudioServer::audio_data_alloc(uint32_t p_data_len, const uint8_t *p_from_data) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void *ad = memalloc(p_data_len);
|
|
|
|
ERR_FAIL_COND_V(!ad, NULL);
|
2017-01-21 22:00:25 +00:00
|
|
|
if (p_from_data) {
|
2017-03-05 15:44:50 +00:00
|
|
|
copymem(ad, p_from_data, p_data_len);
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
audio_data_lock->lock();
|
2017-03-05 15:44:50 +00:00
|
|
|
audio_data[ad] = p_data_len;
|
|
|
|
audio_data_total_mem += p_data_len;
|
|
|
|
audio_data_max_mem = MAX(audio_data_total_mem, audio_data_max_mem);
|
2017-01-21 22:00:25 +00:00
|
|
|
audio_data_lock->unlock();
|
|
|
|
|
|
|
|
return ad;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AudioServer::audio_data_free(void *p_data) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
audio_data_lock->lock();
|
|
|
|
if (!audio_data.has(p_data)) {
|
|
|
|
audio_data_lock->unlock();
|
|
|
|
ERR_FAIL();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
audio_data_total_mem -= audio_data[p_data];
|
2017-01-21 22:00:25 +00:00
|
|
|
audio_data.erase(p_data);
|
|
|
|
memfree(p_data);
|
|
|
|
audio_data_lock->unlock();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
size_t AudioServer::audio_data_get_total_memory_usage() const {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
return audio_data_total_mem;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
size_t AudioServer::audio_data_get_max_memory_usage() const {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
return audio_data_max_mem;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AudioServer::add_callback(AudioCallback p_callback, void *p_userdata) {
|
2017-01-21 22:00:25 +00:00
|
|
|
lock();
|
|
|
|
CallbackItem ci;
|
2017-03-05 15:44:50 +00:00
|
|
|
ci.callback = p_callback;
|
|
|
|
ci.userdata = p_userdata;
|
2017-01-21 22:00:25 +00:00
|
|
|
callbacks.insert(ci);
|
|
|
|
unlock();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AudioServer::remove_callback(AudioCallback p_callback, void *p_userdata) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
lock();
|
|
|
|
CallbackItem ci;
|
2017-03-05 15:44:50 +00:00
|
|
|
ci.callback = p_callback;
|
|
|
|
ci.userdata = p_userdata;
|
2017-01-21 22:00:25 +00:00
|
|
|
callbacks.erase(ci);
|
|
|
|
unlock();
|
|
|
|
}
|
|
|
|
|
2017-03-13 15:45:27 +00:00
|
|
|
void AudioServer::set_bus_layout(const Ref<AudioBusLayout> &p_bus_layout) {
|
2017-01-25 17:30:40 +00:00
|
|
|
|
2017-03-13 15:45:27 +00:00
|
|
|
ERR_FAIL_COND(p_bus_layout.is_null() || p_bus_layout->buses.size() == 0);
|
2017-01-25 17:30:40 +00:00
|
|
|
|
|
|
|
lock();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < buses.size(); i++) {
|
2017-01-25 17:30:40 +00:00
|
|
|
memdelete(buses[i]);
|
|
|
|
}
|
2017-03-13 15:45:27 +00:00
|
|
|
buses.resize(p_bus_layout->buses.size());
|
2017-01-25 17:30:40 +00:00
|
|
|
bus_map.clear();
|
2017-03-13 15:45:27 +00:00
|
|
|
for (int i = 0; i < p_bus_layout->buses.size(); i++) {
|
2017-03-05 15:44:50 +00:00
|
|
|
Bus *bus = memnew(Bus);
|
|
|
|
if (i == 0) {
|
|
|
|
bus->name = "Master";
|
2017-01-25 17:30:40 +00:00
|
|
|
} else {
|
2017-03-13 15:45:27 +00:00
|
|
|
bus->name = p_bus_layout->buses[i].name;
|
|
|
|
bus->send = p_bus_layout->buses[i].send;
|
2017-01-25 17:30:40 +00:00
|
|
|
}
|
|
|
|
|
2017-03-13 15:45:27 +00:00
|
|
|
bus->solo = p_bus_layout->buses[i].solo;
|
|
|
|
bus->mute = p_bus_layout->buses[i].mute;
|
|
|
|
bus->bypass = p_bus_layout->buses[i].bypass;
|
|
|
|
bus->volume_db = p_bus_layout->buses[i].volume_db;
|
2017-01-25 17:30:40 +00:00
|
|
|
|
2017-03-13 15:45:27 +00:00
|
|
|
for (int j = 0; j < p_bus_layout->buses[i].effects.size(); j++) {
|
2017-01-25 17:30:40 +00:00
|
|
|
|
2017-03-13 15:45:27 +00:00
|
|
|
Ref<AudioEffect> fx = p_bus_layout->buses[i].effects[j].effect;
|
2017-01-25 17:30:40 +00:00
|
|
|
|
|
|
|
if (fx.is_valid()) {
|
|
|
|
|
|
|
|
Bus::Effect bfx;
|
2017-03-05 15:44:50 +00:00
|
|
|
bfx.effect = fx;
|
2017-03-13 15:45:27 +00:00
|
|
|
bfx.enabled = p_bus_layout->buses[i].effects[j].enabled;
|
2017-01-25 17:30:40 +00:00
|
|
|
bus->effects.push_back(bfx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bus_map[bus->name] = bus;
|
2018-07-25 01:11:03 +00:00
|
|
|
buses.write[i] = bus;
|
2017-01-25 17:30:40 +00:00
|
|
|
|
2018-03-18 01:43:32 +00:00
|
|
|
buses[i]->channels.resize(channel_count);
|
|
|
|
for (int j = 0; j < channel_count; j++) {
|
2018-07-25 01:11:03 +00:00
|
|
|
buses.write[i]->channels.write[j].buffer.resize(buffer_size);
|
2017-01-25 17:30:40 +00:00
|
|
|
}
|
|
|
|
_update_bus_effects(i);
|
|
|
|
}
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
set_edited(false);
|
|
|
|
#endif
|
|
|
|
unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<AudioBusLayout> AudioServer::generate_bus_layout() const {
|
|
|
|
|
|
|
|
Ref<AudioBusLayout> state;
|
|
|
|
state.instance();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
state->buses.resize(buses.size());
|
2017-01-25 17:30:40 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < buses.size(); i++) {
|
2017-01-25 17:30:40 +00:00
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
state->buses.write[i].name = buses[i]->name;
|
|
|
|
state->buses.write[i].send = buses[i]->send;
|
|
|
|
state->buses.write[i].mute = buses[i]->mute;
|
|
|
|
state->buses.write[i].solo = buses[i]->solo;
|
|
|
|
state->buses.write[i].bypass = buses[i]->bypass;
|
|
|
|
state->buses.write[i].volume_db = buses[i]->volume_db;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int j = 0; j < buses[i]->effects.size(); j++) {
|
2017-01-25 17:30:40 +00:00
|
|
|
AudioBusLayout::Bus::Effect fx;
|
2017-03-05 15:44:50 +00:00
|
|
|
fx.effect = buses[i]->effects[j].effect;
|
|
|
|
fx.enabled = buses[i]->effects[j].enabled;
|
2018-07-25 01:11:03 +00:00
|
|
|
state->buses.write[i].effects.push_back(fx);
|
2017-01-25 17:30:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2018-03-25 03:43:51 +00:00
|
|
|
Array AudioServer::get_device_list() {
|
|
|
|
|
|
|
|
return AudioDriver::get_singleton()->get_device_list();
|
|
|
|
}
|
|
|
|
|
|
|
|
String AudioServer::get_device() {
|
|
|
|
|
|
|
|
return AudioDriver::get_singleton()->get_device();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioServer::set_device(String device) {
|
|
|
|
|
|
|
|
AudioDriver::get_singleton()->set_device(device);
|
|
|
|
}
|
|
|
|
|
2018-07-04 01:08:43 +00:00
|
|
|
Array AudioServer::capture_get_device_list() {
|
2018-02-27 07:54:56 +00:00
|
|
|
|
2018-07-04 01:08:43 +00:00
|
|
|
return AudioDriver::get_singleton()->capture_get_device_list();
|
2018-02-27 07:54:56 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 18:35:52 +00:00
|
|
|
String AudioServer::capture_get_device() {
|
2018-02-27 07:54:56 +00:00
|
|
|
|
2018-07-04 01:08:43 +00:00
|
|
|
return AudioDriver::get_singleton()->capture_get_device();
|
2018-02-27 07:54:56 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 18:35:52 +00:00
|
|
|
void AudioServer::capture_set_device(const String &p_name) {
|
2018-02-27 07:54:56 +00:00
|
|
|
|
2018-07-25 18:35:52 +00:00
|
|
|
AudioDriver::get_singleton()->capture_set_device(p_name);
|
2018-02-27 07:54:56 +00:00
|
|
|
}
|
|
|
|
|
2017-01-21 22:00:25 +00:00
|
|
|
void AudioServer::_bind_methods() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_bus_count", "amount"), &AudioServer::set_bus_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bus_count"), &AudioServer::get_bus_count);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("remove_bus", "index"), &AudioServer::remove_bus);
|
2017-09-10 13:37:49 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("add_bus", "at_position"), &AudioServer::add_bus, DEFVAL(-1));
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("move_bus", "index", "to_index"), &AudioServer::move_bus);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_bus_name", "bus_idx", "name"), &AudioServer::set_bus_name);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bus_name", "bus_idx"), &AudioServer::get_bus_name);
|
2017-07-10 20:51:29 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_bus_index", "bus_name"), &AudioServer::get_bus_index);
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_bus_volume_db", "bus_idx", "volume_db"), &AudioServer::set_bus_volume_db);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bus_volume_db", "bus_idx"), &AudioServer::get_bus_volume_db);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_bus_send", "bus_idx", "send"), &AudioServer::set_bus_send);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bus_send", "bus_idx"), &AudioServer::get_bus_send);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_bus_solo", "bus_idx", "enable"), &AudioServer::set_bus_solo);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_bus_solo", "bus_idx"), &AudioServer::is_bus_solo);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_bus_mute", "bus_idx", "enable"), &AudioServer::set_bus_mute);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_bus_mute", "bus_idx"), &AudioServer::is_bus_mute);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_bus_bypass_effects", "bus_idx", "enable"), &AudioServer::set_bus_bypass_effects);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_bus_bypassing_effects", "bus_idx"), &AudioServer::is_bus_bypassing_effects);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-09-10 13:37:49 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("add_bus_effect", "bus_idx", "effect", "at_position"), &AudioServer::add_bus_effect, DEFVAL(-1));
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("remove_bus_effect", "bus_idx", "effect_idx"), &AudioServer::remove_bus_effect);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-07-18 19:03:34 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_bus_effect_count", "bus_idx"), &AudioServer::get_bus_effect_count);
|
2017-08-09 11:19:41 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_bus_effect", "bus_idx", "effect_idx"), &AudioServer::get_bus_effect);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("swap_bus_effects", "bus_idx", "effect_idx", "by_effect_idx"), &AudioServer::swap_bus_effects);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_bus_effect_enabled", "bus_idx", "effect_idx", "enabled"), &AudioServer::set_bus_effect_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_bus_effect_enabled", "bus_idx", "effect_idx"), &AudioServer::is_bus_effect_enabled);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_bus_peak_volume_left_db", "bus_idx", "channel"), &AudioServer::get_bus_peak_volume_left_db);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bus_peak_volume_right_db", "bus_idx", "channel"), &AudioServer::get_bus_peak_volume_right_db);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("lock"), &AudioServer::lock);
|
|
|
|
ClassDB::bind_method(D_METHOD("unlock"), &AudioServer::unlock);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_speaker_mode"), &AudioServer::get_speaker_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_mix_rate"), &AudioServer::get_mix_rate);
|
2018-03-25 03:43:51 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_device_list"), &AudioServer::get_device_list);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_device"), &AudioServer::get_device);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_device"), &AudioServer::set_device);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2018-07-25 18:35:52 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("capture_get_device_list"), &AudioServer::capture_get_device_list);
|
|
|
|
ClassDB::bind_method(D_METHOD("capture_get_device"), &AudioServer::capture_get_device);
|
|
|
|
ClassDB::bind_method(D_METHOD("capture_set_device"), &AudioServer::capture_set_device);
|
|
|
|
|
2017-08-09 11:19:41 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_bus_layout", "bus_layout"), &AudioServer::set_bus_layout);
|
|
|
|
ClassDB::bind_method(D_METHOD("generate_bus_layout"), &AudioServer::generate_bus_layout);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("bus_layout_changed"));
|
2017-09-12 19:09:06 +00:00
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(SPEAKER_MODE_STEREO);
|
|
|
|
BIND_ENUM_CONSTANT(SPEAKER_SURROUND_51);
|
|
|
|
BIND_ENUM_CONSTANT(SPEAKER_SURROUND_71);
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
2017-01-15 19:06:14 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
AudioServer::AudioServer() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
singleton = this;
|
|
|
|
audio_data_total_mem = 0;
|
|
|
|
audio_data_max_mem = 0;
|
|
|
|
audio_data_lock = Mutex::create();
|
|
|
|
mix_frames = 0;
|
2018-03-18 01:43:32 +00:00
|
|
|
channel_count = 0;
|
2017-03-05 15:44:50 +00:00
|
|
|
to_mix = 0;
|
2018-07-17 01:43:47 +00:00
|
|
|
output_latency = 0;
|
|
|
|
output_latency_ticks = 0;
|
2018-06-21 00:02:02 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
prof_time = 0;
|
|
|
|
#endif
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AudioServer::~AudioServer() {
|
|
|
|
|
2017-01-21 22:00:25 +00:00
|
|
|
memdelete(audio_data_lock);
|
2017-04-27 19:36:35 +00:00
|
|
|
singleton = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-01-15 19:06:14 +00:00
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
/////////////////////////////////
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool AudioBusLayout::_set(const StringName &p_name, const Variant &p_value) {
|
2017-01-25 17:30:40 +00:00
|
|
|
|
|
|
|
String s = p_name;
|
|
|
|
if (s.begins_with("bus/")) {
|
2017-03-05 15:44:50 +00:00
|
|
|
int index = s.get_slice("/", 1).to_int();
|
|
|
|
if (buses.size() <= index) {
|
|
|
|
buses.resize(index + 1);
|
2017-01-25 17:30:40 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
Bus &bus = buses.write[index];
|
2017-01-25 17:30:40 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String what = s.get_slice("/", 2);
|
|
|
|
|
|
|
|
if (what == "name") {
|
|
|
|
bus.name = p_value;
|
|
|
|
} else if (what == "solo") {
|
|
|
|
bus.solo = p_value;
|
|
|
|
} else if (what == "mute") {
|
|
|
|
bus.mute = p_value;
|
|
|
|
} else if (what == "bypass_fx") {
|
|
|
|
bus.bypass = p_value;
|
|
|
|
} else if (what == "volume_db") {
|
|
|
|
bus.volume_db = p_value;
|
|
|
|
} else if (what == "send") {
|
|
|
|
bus.send = p_value;
|
|
|
|
} else if (what == "effect") {
|
|
|
|
int which = s.get_slice("/", 3).to_int();
|
|
|
|
if (bus.effects.size() <= which) {
|
|
|
|
bus.effects.resize(which + 1);
|
2017-01-25 17:30:40 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
Bus::Effect &fx = bus.effects.write[which];
|
2017-01-25 17:30:40 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String fxwhat = s.get_slice("/", 4);
|
|
|
|
if (fxwhat == "effect") {
|
|
|
|
fx.effect = p_value;
|
|
|
|
} else if (fxwhat == "enabled") {
|
|
|
|
fx.enabled = p_value;
|
2017-01-25 17:30:40 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool AudioBusLayout::_get(const StringName &p_name, Variant &r_ret) const {
|
2017-01-25 17:30:40 +00:00
|
|
|
|
|
|
|
String s = p_name;
|
|
|
|
if (s.begins_with("bus/")) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int index = s.get_slice("/", 1).to_int();
|
|
|
|
if (index < 0 || index >= buses.size())
|
2017-01-25 17:30:40 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
const Bus &bus = buses[index];
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String what = s.get_slice("/", 2);
|
|
|
|
|
|
|
|
if (what == "name") {
|
|
|
|
r_ret = bus.name;
|
|
|
|
} else if (what == "solo") {
|
|
|
|
r_ret = bus.solo;
|
|
|
|
} else if (what == "mute") {
|
|
|
|
r_ret = bus.mute;
|
|
|
|
} else if (what == "bypass_fx") {
|
|
|
|
r_ret = bus.bypass;
|
|
|
|
} else if (what == "volume_db") {
|
|
|
|
r_ret = bus.volume_db;
|
|
|
|
} else if (what == "send") {
|
|
|
|
r_ret = bus.send;
|
|
|
|
} else if (what == "effect") {
|
|
|
|
int which = s.get_slice("/", 3).to_int();
|
|
|
|
if (which < 0 || which >= bus.effects.size()) {
|
2017-01-25 17:30:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Bus::Effect &fx = bus.effects[which];
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String fxwhat = s.get_slice("/", 4);
|
|
|
|
if (fxwhat == "effect") {
|
|
|
|
r_ret = fx.effect;
|
|
|
|
} else if (fxwhat == "enabled") {
|
|
|
|
r_ret = fx.enabled;
|
2017-01-25 17:30:40 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void AudioBusLayout::_get_property_list(List<PropertyInfo> *p_list) const {
|
2017-01-25 17:30:40 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < buses.size(); i++) {
|
2018-01-11 22:35:12 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, "bus/" + itos(i) + "/name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "bus/" + itos(i) + "/solo", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "bus/" + itos(i) + "/mute", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "bus/" + itos(i) + "/bypass_fx", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "bus/" + itos(i) + "/volume_db", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "bus/" + itos(i) + "/send", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
2017-01-25 17:30:40 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int j = 0; j < buses[i].effects.size(); j++) {
|
2018-01-11 22:35:12 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, "bus/" + itos(i) + "/effect/" + itos(j) + "/effect", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "bus/" + itos(i) + "/effect/" + itos(j) + "/enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
2017-01-25 17:30:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioBusLayout::AudioBusLayout() {
|
|
|
|
|
|
|
|
buses.resize(1);
|
2018-07-25 01:11:03 +00:00
|
|
|
buses.write[0].name = "Master";
|
2017-01-25 17:30:40 +00:00
|
|
|
}
|