Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/servers/audio/audio_server.cpp
20849 views
1
/**************************************************************************/
2
/* audio_server.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "audio_server.h"
32
33
#include "core/config/project_settings.h"
34
#include "core/debugger/engine_debugger.h"
35
#include "core/error/error_macros.h"
36
#include "core/io/resource_loader.h"
37
#include "core/math/audio_frame.h"
38
#include "core/os/os.h"
39
#include "core/string/string_name.h"
40
#include "core/templates/pair.h"
41
#include "scene/scene_string_names.h"
42
#include "servers/audio/audio_driver_dummy.h"
43
#include "servers/audio/audio_stream.h"
44
#include "servers/audio/effects/audio_effect_compressor.h"
45
46
#ifdef TOOLS_ENABLED
47
#define MARK_EDITED set_edited(true);
48
#else
49
#define MARK_EDITED
50
#endif
51
52
AudioDriver *AudioDriver::singleton = nullptr;
53
AudioDriver *AudioDriver::get_singleton() {
54
return singleton;
55
}
56
57
void AudioDriver::set_singleton() {
58
singleton = this;
59
}
60
61
void AudioDriver::audio_server_process(int p_frames, int32_t *p_buffer, bool p_update_mix_time) {
62
if (p_update_mix_time) {
63
update_mix_time(p_frames);
64
}
65
66
if (AudioServer::get_singleton()) {
67
AudioServer::get_singleton()->_driver_process(p_frames, p_buffer);
68
}
69
}
70
71
void AudioDriver::update_mix_time(int p_frames) {
72
_last_mix_frames = p_frames;
73
if (OS::get_singleton()) {
74
_last_mix_time = OS::get_singleton()->get_ticks_usec();
75
}
76
}
77
78
double AudioDriver::get_time_since_last_mix() {
79
lock();
80
uint64_t last_mix_time = _last_mix_time;
81
unlock();
82
return (OS::get_singleton()->get_ticks_usec() - last_mix_time) / 1000000.0;
83
}
84
85
double AudioDriver::get_time_to_next_mix() {
86
lock();
87
uint64_t last_mix_time = _last_mix_time;
88
uint64_t last_mix_frames = _last_mix_frames;
89
unlock();
90
double total = (OS::get_singleton()->get_ticks_usec() - last_mix_time) / 1000000.0;
91
double mix_buffer = last_mix_frames / (double)get_mix_rate();
92
return mix_buffer - total;
93
}
94
95
void AudioDriver::input_buffer_init(int driver_buffer_frames) {
96
const int input_buffer_channels = 2;
97
input_buffer.resize(driver_buffer_frames * input_buffer_channels * 4);
98
input_position = 0;
99
input_size = 0;
100
}
101
102
void AudioDriver::input_buffer_write(int32_t sample) {
103
if ((int)input_position < input_buffer.size()) {
104
input_buffer.write[input_position++] = sample;
105
if ((int)input_position >= input_buffer.size()) {
106
input_position = 0;
107
}
108
if ((int)input_size < input_buffer.size()) {
109
input_size++;
110
}
111
} else {
112
// This protection was added in GH-26505 due to a "possible crash".
113
// This cannot have happened unless two non-locked threads entered function simultaneously, which was possible when multiple calls to
114
// `AudioDriver::input_start()` did not raise an error condition.
115
WARN_PRINT("input_buffer_write: Invalid input_position=" + itos(input_position) + " input_buffer.size()=" + itos(input_buffer.size()));
116
}
117
}
118
119
int AudioDriver::_get_configured_mix_rate() {
120
StringName audio_driver_setting = "audio/driver/mix_rate";
121
int mix_rate = GLOBAL_GET(audio_driver_setting);
122
123
#ifdef WEB_ENABLED
124
// `0` is an acceptable value (resorts to the browser's default).
125
return MAX(0, mix_rate);
126
#else // !WEB_ENABLED
127
// In the case of invalid mix rate, let's default to a sensible value..
128
if (mix_rate <= 0) {
129
WARN_PRINT(vformat("Invalid mix rate of %d, consider reassigning setting \'%s\'. \nDefaulting mix rate to value %d.",
130
mix_rate, audio_driver_setting, AudioDriverManager::DEFAULT_MIX_RATE));
131
mix_rate = AudioDriverManager::DEFAULT_MIX_RATE;
132
}
133
return mix_rate;
134
#endif
135
}
136
137
AudioDriver::SpeakerMode AudioDriver::get_speaker_mode_by_total_channels(int p_channels) const {
138
switch (p_channels) {
139
case 4:
140
return SPEAKER_SURROUND_31;
141
case 6:
142
return SPEAKER_SURROUND_51;
143
case 8:
144
return SPEAKER_SURROUND_71;
145
}
146
147
// Default to STEREO
148
return SPEAKER_MODE_STEREO;
149
}
150
151
int AudioDriver::get_total_channels_by_speaker_mode(AudioDriver::SpeakerMode p_mode) const {
152
switch (p_mode) {
153
case SPEAKER_MODE_STEREO:
154
return 2;
155
case SPEAKER_SURROUND_31:
156
return 4;
157
case SPEAKER_SURROUND_51:
158
return 6;
159
case SPEAKER_SURROUND_71:
160
return 8;
161
}
162
163
ERR_FAIL_V(2);
164
}
165
166
PackedStringArray AudioDriver::get_output_device_list() {
167
PackedStringArray list;
168
169
list.push_back("Default");
170
171
return list;
172
}
173
174
String AudioDriver::get_output_device() {
175
return "Default";
176
}
177
178
PackedStringArray AudioDriver::get_input_device_list() {
179
PackedStringArray list;
180
181
list.push_back("Default");
182
183
return list;
184
}
185
186
void AudioDriver::start_sample_playback(const Ref<AudioSamplePlayback> &p_playback) {
187
if (p_playback.is_valid()) {
188
if (p_playback->stream.is_valid()) {
189
WARN_PRINT_ED(vformat(R"(Trying to play stream (%s) as a sample (%s), but the driver doesn't support sample playback.)", p_playback->get_instance_id(), p_playback->stream->get_instance_id()));
190
} else {
191
WARN_PRINT_ED(vformat(R"(Trying to play stream (%s) as a null sample, but the driver doesn't support sample playback.)", p_playback->get_instance_id()));
192
}
193
} else {
194
WARN_PRINT_ED("Trying to play a null sample playback from a driver that don't support sample playback.");
195
}
196
}
197
198
AudioDriverDummy AudioDriverManager::dummy_driver;
199
AudioDriver *AudioDriverManager::drivers[MAX_DRIVERS] = {
200
&AudioDriverManager::dummy_driver,
201
};
202
int AudioDriverManager::driver_count = 1;
203
204
void AudioDriverManager::add_driver(AudioDriver *p_driver) {
205
ERR_FAIL_COND(driver_count >= MAX_DRIVERS);
206
drivers[driver_count - 1] = p_driver;
207
208
// Last driver is always our dummy driver
209
drivers[driver_count++] = &AudioDriverManager::dummy_driver;
210
}
211
212
int AudioDriverManager::get_driver_count() {
213
return driver_count;
214
}
215
216
void AudioDriverManager::initialize(int p_driver) {
217
GLOBAL_DEF_RST("audio/driver/enable_input", false);
218
GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "audio/driver/mix_rate", PROPERTY_HINT_RANGE, "11025,192000,1,or_greater,suffix:Hz"), DEFAULT_MIX_RATE);
219
GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "audio/driver/mix_rate.web", PROPERTY_HINT_RANGE, "0,192000,1,or_greater,suffix:Hz"), 0); // Safer default output_latency for web (use browser default).
220
221
int failed_driver = -1;
222
223
// Check if there is a selected driver
224
if (p_driver >= 0 && p_driver < driver_count) {
225
if (drivers[p_driver]->init() == OK) {
226
drivers[p_driver]->set_singleton();
227
return;
228
} else {
229
failed_driver = p_driver;
230
}
231
}
232
233
// No selected driver, try them all in order
234
for (int i = 0; i < driver_count; i++) {
235
// Don't re-init the driver if it failed above
236
if (i == failed_driver) {
237
continue;
238
}
239
240
if (drivers[i]->init() == OK) {
241
drivers[i]->set_singleton();
242
break;
243
}
244
}
245
246
if (driver_count > 1 && String(AudioDriver::get_singleton()->get_name()) == "Dummy") {
247
WARN_PRINT("All audio drivers failed, falling back to the dummy driver.");
248
}
249
}
250
251
AudioDriver *AudioDriverManager::get_driver(int p_driver) {
252
ERR_FAIL_INDEX_V(p_driver, driver_count, nullptr);
253
return drivers[p_driver];
254
}
255
256
//////////////////////////////////////////////
257
//////////////////////////////////////////////
258
//////////////////////////////////////////////
259
//////////////////////////////////////////////
260
261
void AudioServer::_driver_process(int p_frames, int32_t *p_buffer) {
262
mix_count++;
263
int todo = p_frames;
264
265
#ifdef DEBUG_ENABLED
266
uint64_t prof_ticks = OS::get_singleton()->get_ticks_usec();
267
#endif
268
269
if (channel_count != get_channel_count()) {
270
// Amount of channels changed due to a output_device change
271
// reinitialize the buses channels and buffers
272
init_channels_and_buffers();
273
}
274
275
ERR_FAIL_COND_MSG(buses.is_empty() && todo, "AudioServer bus count is less than 1.");
276
while (todo) {
277
if (to_mix == 0) {
278
_mix_step();
279
}
280
281
int to_copy = MIN(to_mix, todo);
282
283
Bus *master = buses[0];
284
285
int from = buffer_size - to_mix;
286
int from_buf = p_frames - todo;
287
288
//master master, send to output
289
int cs = master->channels.size();
290
291
// Take away 1 from the stride, as we are manually incrementing by 1 for stereo.
292
uintptr_t stride_minus_one = (cs * 2) - 1;
293
294
for (int k = 0; k < cs; k++) {
295
// The destination start for data will be the same in all cases.
296
int32_t *dest = &p_buffer[from_buf * (cs * 2) + (k * 2)];
297
298
#ifdef DEBUG_ENABLED
299
if (!debug_mute && master->channels[k].active) {
300
#else
301
if (master->channels[k].active) {
302
#endif // DEBUG_ENABLED
303
const AudioFrame *buf = master->channels[k].buffer.ptr();
304
305
for (int j = 0; j < to_copy; j++) {
306
float l = CLAMP(buf[from + j].left, -1.0, 1.0);
307
int32_t vl = l * ((1 << 20) - 1);
308
int32_t vl2 = (vl < 0 ? -1 : 1) * (Math::abs(vl) << 11);
309
*dest = vl2;
310
dest++;
311
312
float r = CLAMP(buf[from + j].right, -1.0, 1.0);
313
int32_t vr = r * ((1 << 20) - 1);
314
int32_t vr2 = (vr < 0 ? -1 : 1) * (Math::abs(vr) << 11);
315
*dest = vr2;
316
dest += stride_minus_one;
317
}
318
319
} else {
320
// Bizarrely, profiling indicates that detecting the common case of cs == 1,
321
// k == 0, and using memset is SLOWER than setting them individually.
322
// Perhaps it gets optimized to a faster instruction than memset.
323
for (int j = 0; j < to_copy; j++) {
324
*dest = 0;
325
dest++;
326
*dest = 0;
327
dest += stride_minus_one;
328
}
329
}
330
}
331
332
todo -= to_copy;
333
to_mix -= to_copy;
334
}
335
336
#ifdef DEBUG_ENABLED
337
prof_time.add(OS::get_singleton()->get_ticks_usec() - prof_ticks);
338
#endif
339
}
340
341
void AudioServer::_mix_step() {
342
bool solo_mode = false;
343
344
for (int i = 0; i < buses.size(); i++) {
345
Bus *bus = buses[i];
346
bus->index_cache = i; //might be moved around by editor, so..
347
for (int k = 0; k < bus->channels.size(); k++) {
348
bus->channels.write[k].used = false;
349
}
350
351
if (bus->solo) {
352
//solo chain
353
solo_mode = true;
354
bus->soloed = true;
355
do {
356
if (bus != buses[0]) {
357
//everything has a send save for master bus
358
if (!bus_map.has(bus->send)) {
359
bus = buses[0]; //send to master
360
} else {
361
int prev_index_cache = bus->index_cache;
362
bus = bus_map[bus->send];
363
if (prev_index_cache >= bus->index_cache) { //invalid, send to master
364
bus = buses[0];
365
}
366
}
367
368
bus->soloed = true;
369
} else {
370
bus = nullptr;
371
}
372
373
} while (bus);
374
} else {
375
bus->soloed = false;
376
}
377
}
378
// This is legacy code from 3.x that allows video players and other audio sources that do not implement AudioStreamPlayback to output audio.
379
for (CallbackItem *ci : mix_callback_list) {
380
ci->callback(ci->userdata);
381
}
382
383
// Main mixing loop for audio streams.
384
// The basic idea here is to copy the samples returned by the AudioStreamPlayback's mix function into the audio buffers,
385
// while always maintaining a lookahead buffer of size LOOKAHEAD_BUFFER_SIZE to allow fade-outs for sudden stoppages.
386
for (AudioStreamPlaybackListNode *playback : playback_list) {
387
// Paused streams are no-ops. Don't even mix audio from the stream playback.
388
if (playback->state.load() == AudioStreamPlaybackListNode::PAUSED) {
389
continue;
390
}
391
392
if (playback->stream_playback->get_is_sample()) {
393
continue;
394
}
395
396
// If `fading_out` is true, we're in the process of fading out the stream playback.
397
// TODO: Currently this sets the volume of the stream to 0 which creates a linear interpolation between its previous volume and silence.
398
// A more punchy option for fading out could be to just use the lookahead buffer.
399
bool fading_out = playback->state.load() == AudioStreamPlaybackListNode::FADE_OUT_TO_DELETION || playback->state.load() == AudioStreamPlaybackListNode::FADE_OUT_TO_PAUSE;
400
401
AudioFrame *buf = mix_buffer.ptrw();
402
403
// Copy the old contents of the lookahead buffer into the beginning of the mix buffer.
404
for (int i = 0; i < LOOKAHEAD_BUFFER_SIZE; i++) {
405
buf[i] = playback->lookahead[i];
406
}
407
408
// Mix the audio stream.
409
unsigned int mixed_frames = playback->stream_playback->mix(&buf[LOOKAHEAD_BUFFER_SIZE], playback->pitch_scale.get(), buffer_size);
410
411
if (tag_used_audio_streams && playback->stream_playback->is_playing()) {
412
playback->stream_playback->tag_used_streams();
413
}
414
415
// Check to see if the stream has run out of samples.
416
if (mixed_frames != buffer_size) {
417
// We know we have at least the size of our lookahead buffer for fade-out purposes.
418
419
float fadeout_base = 0.94;
420
float fadeout_coefficient = 1;
421
static_assert(LOOKAHEAD_BUFFER_SIZE == 64, "Update fadeout_base and comment here if you change LOOKAHEAD_BUFFER_SIZE.");
422
// 0.94 ^ 64 = 0.01906. There might still be a pop but it'll be way better than if we didn't do this.
423
for (unsigned int idx = mixed_frames; idx < buffer_size; idx++) {
424
fadeout_coefficient *= fadeout_base;
425
buf[idx] *= fadeout_coefficient;
426
}
427
AudioStreamPlaybackListNode::PlaybackState new_state;
428
new_state = AudioStreamPlaybackListNode::AWAITING_DELETION;
429
playback->state.store(new_state);
430
} else {
431
// Move the last little bit of what we just mixed into our lookahead buffer for the next call to _mix_step.
432
for (int i = 0; i < LOOKAHEAD_BUFFER_SIZE; i++) {
433
playback->lookahead[i] = buf[buffer_size + i];
434
}
435
}
436
437
// Get the bus details for this playback. This contains information about which buses the playback is assigned to and the volume of the playback on each bus.
438
AudioStreamPlaybackBusDetails *bus_details_ptr = playback->bus_details.load();
439
ERR_FAIL_NULL(bus_details_ptr);
440
// Make a copy of the bus details so we can modify it without worrying about other threads.
441
AudioStreamPlaybackBusDetails bus_details = *bus_details_ptr;
442
443
// Mix to any active buses.
444
for (int idx = 0; idx < MAX_BUSES_PER_PLAYBACK; idx++) {
445
if (!bus_details.bus_active[idx]) {
446
continue;
447
}
448
// This is the AudioServer-internal index of the bus we're mixing to in this step of the loop. Not to be confused with `idx` which is an index into `AudioStreamPlaybackBusDetails` member var arrays.
449
int bus_idx = thread_find_bus_index(bus_details.bus[idx]);
450
451
// It's important to know whether or not this bus was active in the previous mix step of this stream. If it was, we need to perform volume interpolation to avoid pops.
452
int prev_bus_idx = -1;
453
for (int search_idx = 0; search_idx < MAX_BUSES_PER_PLAYBACK; search_idx++) {
454
if (!playback->prev_bus_details->bus_active[search_idx]) {
455
continue;
456
}
457
// If the StringNames of the buses match, we've found the previous bus index. This indicates that this playback mixed to `prev_bus_details->bus[prev_bus_index]` in the previous mix step, which gives us a way to look up the playback's previous volume.
458
if (playback->prev_bus_details->bus[search_idx].hash() == bus_details.bus[idx].hash()) {
459
prev_bus_idx = search_idx;
460
break;
461
}
462
}
463
464
// It's now time to mix to the bus. We do this by going through each channel of the bus and mixing to it.
465
// The channels correspond to output channels of the audio device, e.g. stereo or 5.1. To reduce needless nesting, this is done with a helper method named `_mix_step_for_channel`.
466
for (int channel_idx = 0; channel_idx < channel_count; channel_idx++) {
467
AudioFrame *channel_buf = thread_get_channel_mix_buffer(bus_idx, channel_idx);
468
// TODO: This `fading_out` check could be replaced with with an exponential fadeout of the samples from the lookahead buffer for more punchy results.
469
if (fading_out) {
470
bus_details.volume[idx][channel_idx] = AudioFrame(0, 0);
471
}
472
AudioFrame channel_vol = bus_details.volume[idx][channel_idx];
473
474
// If this bus was not active in the previous mix step, we want to start playback at the full volume to avoid crushing transients.
475
AudioFrame prev_channel_vol = channel_vol;
476
// If this bus was active in the previous mix step, we need to interpolate between the previous volume and the current volume to avoid pops. Set `prev_channel_volume` accordingly.
477
if (prev_bus_idx != -1) {
478
prev_channel_vol = playback->prev_bus_details->volume[prev_bus_idx][channel_idx];
479
}
480
_mix_step_for_channel(channel_buf, buf, prev_channel_vol, channel_vol, playback->attenuation_filter_cutoff_hz.get(), playback->highshelf_gain.get(), &playback->filter_process[channel_idx * 2], &playback->filter_process[channel_idx * 2 + 1]);
481
}
482
}
483
484
// Now go through and fade-out any buses that were being played to previously that we missed by going through current data.
485
for (int idx = 0; idx < MAX_BUSES_PER_PLAYBACK; idx++) {
486
if (!playback->prev_bus_details->bus_active[idx]) {
487
continue;
488
}
489
int bus_idx = thread_find_bus_index(playback->prev_bus_details->bus[idx]);
490
491
int current_bus_idx = -1;
492
for (int search_idx = 0; search_idx < MAX_BUSES_PER_PLAYBACK; search_idx++) {
493
if (bus_details.bus[search_idx] == playback->prev_bus_details->bus[idx]) {
494
current_bus_idx = search_idx;
495
}
496
}
497
if (current_bus_idx != -1) {
498
// If we found a corresponding bus in the current bus assignments, we've already mixed to this bus.
499
continue;
500
}
501
502
for (int channel_idx = 0; channel_idx < channel_count; channel_idx++) {
503
AudioFrame *channel_buf = thread_get_channel_mix_buffer(bus_idx, channel_idx);
504
AudioFrame prev_channel_vol = playback->prev_bus_details->volume[idx][channel_idx];
505
// Fade out to silence. This could be replaced with an exponential fadeout of the samples from the lookahead buffer for more punchy results.
506
_mix_step_for_channel(channel_buf, buf, prev_channel_vol, AudioFrame(0, 0), playback->attenuation_filter_cutoff_hz.get(), playback->highshelf_gain.get(), &playback->filter_process[channel_idx * 2], &playback->filter_process[channel_idx * 2 + 1]);
507
}
508
}
509
510
// Copy the bus details we mixed with to the previous bus details to maintain volume ramps.
511
for (int i = 0; i < MAX_BUSES_PER_PLAYBACK; i++) {
512
playback->prev_bus_details->bus_active[i] = bus_details.bus_active[i];
513
}
514
for (int i = 0; i < MAX_BUSES_PER_PLAYBACK; i++) {
515
playback->prev_bus_details->bus[i] = bus_details.bus[i];
516
}
517
for (int i = 0; i < MAX_BUSES_PER_PLAYBACK; i++) {
518
for (int j = 0; j < MAX_CHANNELS_PER_BUS; j++) {
519
playback->prev_bus_details->volume[i][j] = bus_details.volume[i][j];
520
}
521
}
522
523
switch (playback->state.load()) {
524
case AudioStreamPlaybackListNode::AWAITING_DELETION:
525
case AudioStreamPlaybackListNode::FADE_OUT_TO_DELETION:
526
// Remove the playback from the list.
527
_delete_stream_playback_list_node(playback);
528
break;
529
case AudioStreamPlaybackListNode::FADE_OUT_TO_PAUSE: {
530
// Pause the stream.
531
playback->state.store(AudioStreamPlaybackListNode::PAUSED);
532
} break;
533
case AudioStreamPlaybackListNode::PLAYING:
534
case AudioStreamPlaybackListNode::PAUSED:
535
// No-op!
536
break;
537
}
538
}
539
540
// Now that all of the buses have their audio sources mixed into them, we can process the effects and bus sends.
541
for (int i = buses.size() - 1; i >= 0; i--) {
542
Bus *bus = buses[i];
543
544
for (int k = 0; k < bus->channels.size(); k++) {
545
if (bus->channels[k].active && !bus->channels[k].used) {
546
// Buffer was not used, but it's still active, so it must be cleaned.
547
AudioFrame *buf = bus->channels.write[k].buffer.ptrw();
548
549
for (uint32_t j = 0; j < buffer_size; j++) {
550
buf[j] = AudioFrame(0, 0);
551
}
552
}
553
}
554
555
// Process effects.
556
if (!bus->bypass) {
557
for (int j = 0; j < bus->effects.size(); j++) {
558
if (!bus->effects[j].enabled) {
559
continue;
560
}
561
562
#ifdef DEBUG_ENABLED
563
uint64_t ticks = OS::get_singleton()->get_ticks_usec();
564
#endif
565
566
for (int k = 0; k < bus->channels.size(); k++) {
567
if (!(bus->channels[k].active || bus->channels[k].effect_instances[j]->process_silence())) {
568
continue;
569
}
570
bus->channels.write[k].effect_instances.write[j]->process(bus->channels[k].buffer.ptr(), temp_buffer.write[k].ptrw(), buffer_size);
571
}
572
573
// Swap buffers, so internal buffer always has the right data.
574
for (int k = 0; k < bus->channels.size(); k++) {
575
if (!(buses[i]->channels[k].active || bus->channels[k].effect_instances[j]->process_silence())) {
576
continue;
577
}
578
SWAP(bus->channels.write[k].buffer, temp_buffer.write[k]);
579
}
580
581
#ifdef DEBUG_ENABLED
582
bus->effects.write[j].prof_time += OS::get_singleton()->get_ticks_usec() - ticks;
583
#endif
584
}
585
}
586
587
// Process send.
588
589
Bus *send = nullptr;
590
591
if (i > 0) {
592
// Everything has a send except for the master bus.
593
if (!bus_map.has(bus->send)) {
594
send = buses[0];
595
} else {
596
send = bus_map[bus->send];
597
if (send->index_cache >= bus->index_cache) { // Invalid, send to master.
598
send = buses[0];
599
}
600
}
601
}
602
603
for (int k = 0; k < bus->channels.size(); k++) {
604
if (!bus->channels[k].active) {
605
bus->channels.write[k].peak_volume = AudioFrame(AUDIO_MIN_PEAK_DB, AUDIO_MIN_PEAK_DB);
606
continue;
607
}
608
609
AudioFrame *buf = bus->channels.write[k].buffer.ptrw();
610
611
AudioFrame peak = AudioFrame(0, 0);
612
613
float volume = Math::db_to_linear(bus->volume_db);
614
615
if (solo_mode) {
616
if (!bus->soloed) {
617
volume = 0.0;
618
}
619
} else {
620
if (bus->mute) {
621
volume = 0.0;
622
}
623
}
624
625
// Apply volume and compute peak.
626
for (uint32_t j = 0; j < buffer_size; j++) {
627
buf[j] *= volume;
628
629
float l = Math::abs(buf[j].left);
630
if (l > peak.left) {
631
peak.left = l;
632
}
633
float r = Math::abs(buf[j].right);
634
if (r > peak.right) {
635
peak.right = r;
636
}
637
}
638
639
bus->channels.write[k].peak_volume = AudioFrame(Math::linear_to_db(peak.left + AUDIO_PEAK_OFFSET), Math::linear_to_db(peak.right + AUDIO_PEAK_OFFSET));
640
641
if (!bus->channels[k].used) {
642
// See if any audio is contained, because channel was not used.
643
644
if (MAX(peak.right, peak.left) > Math::db_to_linear(channel_disable_threshold_db)) {
645
bus->channels.write[k].last_mix_with_audio = mix_frames;
646
} else if (mix_frames - bus->channels[k].last_mix_with_audio > channel_disable_frames) {
647
bus->channels.write[k].active = false;
648
continue; //went inactive, don't mix.
649
}
650
}
651
652
if (send) {
653
// If not master bus, send.
654
AudioFrame *target_buf = thread_get_channel_mix_buffer(send->index_cache, k);
655
656
for (uint32_t j = 0; j < buffer_size; j++) {
657
target_buf[j] += buf[j];
658
}
659
}
660
}
661
}
662
663
mix_frames += buffer_size;
664
to_mix = buffer_size;
665
}
666
667
void AudioServer::_mix_step_for_channel(AudioFrame *p_out_buf, AudioFrame *p_source_buf, AudioFrame p_vol_start, AudioFrame p_vol_final, float p_attenuation_filter_cutoff_hz, float p_highshelf_gain, AudioFilterSW::Processor *p_processor_l, AudioFilterSW::Processor *p_processor_r) {
668
// TODO: In the future it could be nice to replace all of these hardcoded effects with something a bit cleaner and more flexible, but for now this is what we do to support 3D audio players.
669
if (p_highshelf_gain != 0) {
670
AudioFilterSW filter;
671
filter.set_mode(AudioFilterSW::HIGHSHELF);
672
filter.set_sampling_rate(AudioServer::get_singleton()->get_mix_rate());
673
filter.set_cutoff(p_attenuation_filter_cutoff_hz);
674
filter.set_resonance(1);
675
filter.set_stages(1);
676
filter.set_gain(p_highshelf_gain);
677
678
ERR_FAIL_NULL(p_processor_l);
679
ERR_FAIL_NULL(p_processor_r);
680
681
bool is_just_started = p_vol_start.left == 0 && p_vol_start.right == 0;
682
p_processor_l->set_filter(&filter, /* clear_history= */ is_just_started);
683
p_processor_l->update_coeffs(buffer_size);
684
p_processor_r->set_filter(&filter, /* clear_history= */ is_just_started);
685
p_processor_r->update_coeffs(buffer_size);
686
687
for (unsigned int frame_idx = 0; frame_idx < buffer_size; frame_idx++) {
688
// TODO: Make lerp speed buffer-size-invariant if buffer_size ever becomes a project setting to avoid very small buffer sizes causing pops due to too-fast lerps.
689
float lerp_param = (float)frame_idx / buffer_size;
690
AudioFrame vol = p_vol_final * lerp_param + (1 - lerp_param) * p_vol_start;
691
AudioFrame mixed = vol * p_source_buf[frame_idx];
692
p_processor_l->process_one_interp(mixed.left);
693
p_processor_r->process_one_interp(mixed.right);
694
p_out_buf[frame_idx] += mixed;
695
}
696
697
} else {
698
for (unsigned int frame_idx = 0; frame_idx < buffer_size; frame_idx++) {
699
// TODO: Make lerp speed buffer-size-invariant if buffer_size ever becomes a project setting to avoid very small buffer sizes causing pops due to too-fast lerps.
700
float lerp_param = (float)frame_idx / buffer_size;
701
p_out_buf[frame_idx] += (p_vol_final * lerp_param + (1 - lerp_param) * p_vol_start) * p_source_buf[frame_idx];
702
}
703
}
704
}
705
706
AudioServer::AudioStreamPlaybackListNode *AudioServer::_find_playback_list_node(Ref<AudioStreamPlayback> p_playback) {
707
for (AudioStreamPlaybackListNode *playback_list_node : playback_list) {
708
if (playback_list_node->stream_playback == p_playback) {
709
return playback_list_node;
710
}
711
}
712
return nullptr;
713
}
714
715
void AudioServer::_delete_stream_playback(Ref<AudioStreamPlayback> p_playback) {
716
ERR_FAIL_COND(p_playback.is_null());
717
AudioStreamPlaybackListNode *playback_node = _find_playback_list_node(p_playback);
718
if (playback_node) {
719
_delete_stream_playback_list_node(playback_node);
720
}
721
}
722
723
void AudioServer::_delete_stream_playback_list_node(AudioStreamPlaybackListNode *p_playback_node) {
724
// Remove the playback from the list, registering a destructor to be run on the main thread.
725
playback_list.erase(p_playback_node, [](AudioStreamPlaybackListNode *p) {
726
delete p->prev_bus_details;
727
delete p->bus_details.load();
728
p->stream_playback.unref();
729
delete p;
730
});
731
}
732
733
bool AudioServer::thread_has_channel_mix_buffer(int p_bus, int p_buffer) const {
734
if (p_bus < 0 || p_bus >= buses.size()) {
735
return false;
736
}
737
if (p_buffer < 0 || p_buffer >= buses[p_bus]->channels.size()) {
738
return false;
739
}
740
return true;
741
}
742
743
AudioFrame *AudioServer::thread_get_channel_mix_buffer(int p_bus, int p_buffer) {
744
ERR_FAIL_INDEX_V(p_bus, buses.size(), nullptr);
745
ERR_FAIL_INDEX_V(p_buffer, buses[p_bus]->channels.size(), nullptr);
746
747
AudioFrame *data = buses.write[p_bus]->channels.write[p_buffer].buffer.ptrw();
748
749
if (!buses[p_bus]->channels[p_buffer].used) {
750
buses.write[p_bus]->channels.write[p_buffer].used = true;
751
buses.write[p_bus]->channels.write[p_buffer].active = true;
752
buses.write[p_bus]->channels.write[p_buffer].last_mix_with_audio = mix_frames;
753
for (uint32_t i = 0; i < buffer_size; i++) {
754
data[i] = AudioFrame(0, 0);
755
}
756
}
757
758
return data;
759
}
760
761
int AudioServer::thread_get_mix_buffer_size() const {
762
return buffer_size;
763
}
764
765
int AudioServer::thread_find_bus_index(const StringName &p_name) {
766
if (bus_map.has(p_name)) {
767
return bus_map[p_name]->index_cache;
768
} else {
769
return 0;
770
}
771
}
772
773
#ifdef DEBUG_ENABLED
774
void AudioServer::set_debug_mute(bool p_mute) {
775
debug_mute = p_mute;
776
}
777
778
bool AudioServer::get_debug_mute() const {
779
return debug_mute;
780
}
781
#endif // DEBUG_ENABLED
782
783
void AudioServer::set_bus_count(int p_count) {
784
ERR_FAIL_COND(p_count < 1);
785
ERR_FAIL_INDEX(p_count, 256);
786
787
MARK_EDITED
788
789
lock();
790
int cb = buses.size();
791
792
if (p_count < buses.size()) {
793
for (int i = p_count; i < buses.size(); i++) {
794
bus_map.erase(buses[i]->name);
795
memdelete(buses[i]);
796
}
797
}
798
799
buses.resize(p_count);
800
801
for (int i = cb; i < buses.size(); i++) {
802
String attempt = "New Bus";
803
int attempts = 1;
804
while (true) {
805
bool name_free = true;
806
for (int j = 0; j < i; j++) {
807
if (buses[j]->name == attempt) {
808
name_free = false;
809
break;
810
}
811
}
812
813
if (!name_free) {
814
attempts++;
815
attempt = "New Bus " + itos(attempts);
816
} else {
817
break;
818
}
819
}
820
821
buses.write[i] = memnew(Bus);
822
buses.write[i]->channels.resize(channel_count);
823
for (int j = 0; j < channel_count; j++) {
824
buses.write[i]->channels.write[j].buffer.resize(buffer_size);
825
}
826
buses[i]->name = attempt;
827
buses[i]->solo = false;
828
buses[i]->mute = false;
829
buses[i]->bypass = false;
830
buses[i]->volume_db = 0;
831
if (i > 0) {
832
buses[i]->send = SceneStringName(Master);
833
}
834
835
bus_map[attempt] = buses[i];
836
}
837
838
unlock();
839
840
AudioDriver::get_singleton()->set_sample_bus_count(p_count);
841
842
emit_signal(SNAME("bus_layout_changed"));
843
}
844
845
void AudioServer::remove_bus(int p_index) {
846
ERR_FAIL_INDEX(p_index, buses.size());
847
ERR_FAIL_COND(p_index == 0);
848
849
MARK_EDITED
850
851
lock();
852
bus_map.erase(buses[p_index]->name);
853
memdelete(buses[p_index]);
854
buses.remove_at(p_index);
855
unlock();
856
857
AudioDriver::get_singleton()->remove_sample_bus(p_index);
858
859
emit_signal(SNAME("bus_layout_changed"));
860
}
861
862
void AudioServer::add_bus(int p_at_pos) {
863
MARK_EDITED
864
865
if (p_at_pos >= buses.size()) {
866
p_at_pos = -1;
867
} else if (p_at_pos == 0) {
868
if (buses.size() > 1) {
869
p_at_pos = 1;
870
} else {
871
p_at_pos = -1;
872
}
873
}
874
875
String attempt = "New Bus";
876
int attempts = 1;
877
while (true) {
878
bool name_free = true;
879
for (int j = 0; j < buses.size(); j++) {
880
if (buses[j]->name == attempt) {
881
name_free = false;
882
break;
883
}
884
}
885
886
if (!name_free) {
887
attempts++;
888
attempt = "New Bus " + itos(attempts);
889
} else {
890
break;
891
}
892
}
893
894
Bus *bus = memnew(Bus);
895
bus->channels.resize(channel_count);
896
for (int j = 0; j < channel_count; j++) {
897
bus->channels.write[j].buffer.resize(buffer_size);
898
}
899
bus->name = attempt;
900
bus->solo = false;
901
bus->mute = false;
902
bus->bypass = false;
903
bus->volume_db = 0;
904
905
bus_map[attempt] = bus;
906
907
if (p_at_pos == -1) {
908
buses.push_back(bus);
909
} else {
910
buses.insert(p_at_pos, bus);
911
}
912
913
AudioDriver::get_singleton()->add_sample_bus(p_at_pos);
914
915
emit_signal(SNAME("bus_layout_changed"));
916
}
917
918
void AudioServer::move_bus(int p_bus, int p_to_pos) {
919
ERR_FAIL_COND(p_bus < 1 || p_bus >= buses.size());
920
ERR_FAIL_COND(p_to_pos != -1 && (p_to_pos < 1 || p_to_pos > buses.size()));
921
922
MARK_EDITED
923
924
if (p_bus == p_to_pos) {
925
return;
926
}
927
928
Bus *bus = buses[p_bus];
929
buses.remove_at(p_bus);
930
931
if (p_to_pos == -1) {
932
buses.push_back(bus);
933
} else if (p_to_pos < p_bus) {
934
buses.insert(p_to_pos, bus);
935
} else {
936
buses.insert(p_to_pos - 1, bus);
937
}
938
939
AudioDriver::get_singleton()->move_sample_bus(p_bus, p_to_pos);
940
941
emit_signal(SNAME("bus_layout_changed"));
942
}
943
944
int AudioServer::get_bus_count() const {
945
return buses.size();
946
}
947
948
void AudioServer::set_bus_name(int p_bus, const String &p_name) {
949
ERR_FAIL_INDEX(p_bus, buses.size());
950
if (p_bus == 0 && p_name != "Master") {
951
return; // Bus 0 is always "Master".
952
}
953
954
MARK_EDITED
955
956
lock();
957
958
StringName old_name = buses[p_bus]->name;
959
960
if (old_name == p_name) {
961
unlock();
962
return;
963
}
964
965
String attempt = p_name;
966
int attempts = 1;
967
968
while (true) {
969
bool name_free = true;
970
for (int i = 0; i < buses.size(); i++) {
971
if (buses[i]->name == attempt) {
972
name_free = false;
973
break;
974
}
975
}
976
977
if (name_free) {
978
break;
979
}
980
981
attempts++;
982
attempt = p_name + " " + itos(attempts);
983
}
984
bus_map.erase(old_name);
985
buses[p_bus]->name = attempt;
986
bus_map[attempt] = buses[p_bus];
987
unlock();
988
989
emit_signal(SNAME("bus_renamed"), p_bus, old_name, attempt);
990
}
991
992
String AudioServer::get_bus_name(int p_bus) const {
993
ERR_FAIL_INDEX_V(p_bus, buses.size(), String());
994
return buses[p_bus]->name;
995
}
996
997
int AudioServer::get_bus_index(const StringName &p_bus_name) const {
998
for (int i = 0; i < buses.size(); ++i) {
999
if (buses[i]->name == p_bus_name) {
1000
return i;
1001
}
1002
}
1003
return -1;
1004
}
1005
1006
void AudioServer::set_bus_volume_db(int p_bus, float p_volume_db) {
1007
ERR_FAIL_INDEX(p_bus, buses.size());
1008
1009
MARK_EDITED
1010
1011
buses[p_bus]->volume_db = p_volume_db;
1012
1013
AudioDriver::get_singleton()->set_sample_bus_volume_db(p_bus, p_volume_db);
1014
}
1015
1016
float AudioServer::get_bus_volume_db(int p_bus) const {
1017
ERR_FAIL_INDEX_V(p_bus, buses.size(), 0);
1018
return buses[p_bus]->volume_db;
1019
}
1020
1021
void AudioServer::set_bus_volume_linear(int p_bus, float p_volume_linear) {
1022
set_bus_volume_db(p_bus, Math::linear_to_db(p_volume_linear));
1023
}
1024
1025
float AudioServer::get_bus_volume_linear(int p_bus) const {
1026
return Math::db_to_linear(get_bus_volume_db(p_bus));
1027
}
1028
1029
int AudioServer::get_bus_channels(int p_bus) const {
1030
ERR_FAIL_INDEX_V(p_bus, buses.size(), 0);
1031
return buses[p_bus]->channels.size();
1032
}
1033
1034
void AudioServer::set_bus_send(int p_bus, const StringName &p_send) {
1035
ERR_FAIL_INDEX(p_bus, buses.size());
1036
1037
MARK_EDITED
1038
1039
buses[p_bus]->send = p_send;
1040
1041
AudioDriver::get_singleton()->set_sample_bus_send(p_bus, p_send);
1042
}
1043
1044
StringName AudioServer::get_bus_send(int p_bus) const {
1045
ERR_FAIL_INDEX_V(p_bus, buses.size(), StringName());
1046
return buses[p_bus]->send;
1047
}
1048
1049
void AudioServer::set_bus_solo(int p_bus, bool p_enable) {
1050
ERR_FAIL_INDEX(p_bus, buses.size());
1051
1052
MARK_EDITED
1053
1054
buses[p_bus]->solo = p_enable;
1055
1056
AudioDriver::get_singleton()->set_sample_bus_solo(p_bus, p_enable);
1057
}
1058
1059
bool AudioServer::is_bus_solo(int p_bus) const {
1060
ERR_FAIL_INDEX_V(p_bus, buses.size(), false);
1061
1062
return buses[p_bus]->solo;
1063
}
1064
1065
void AudioServer::set_bus_mute(int p_bus, bool p_enable) {
1066
ERR_FAIL_INDEX(p_bus, buses.size());
1067
1068
MARK_EDITED
1069
1070
buses[p_bus]->mute = p_enable;
1071
1072
AudioDriver::get_singleton()->set_sample_bus_mute(p_bus, p_enable);
1073
}
1074
1075
bool AudioServer::is_bus_mute(int p_bus) const {
1076
ERR_FAIL_INDEX_V(p_bus, buses.size(), false);
1077
1078
return buses[p_bus]->mute;
1079
}
1080
1081
void AudioServer::set_bus_bypass_effects(int p_bus, bool p_enable) {
1082
ERR_FAIL_INDEX(p_bus, buses.size());
1083
1084
MARK_EDITED
1085
1086
buses[p_bus]->bypass = p_enable;
1087
}
1088
1089
bool AudioServer::is_bus_bypassing_effects(int p_bus) const {
1090
ERR_FAIL_INDEX_V(p_bus, buses.size(), false);
1091
1092
return buses[p_bus]->bypass;
1093
}
1094
1095
void AudioServer::_update_bus_effects(int p_bus) {
1096
for (int i = 0; i < buses[p_bus]->channels.size(); i++) {
1097
buses.write[p_bus]->channels.write[i].effect_instances.resize(buses[p_bus]->effects.size());
1098
for (int j = 0; j < buses[p_bus]->effects.size(); j++) {
1099
Ref<AudioEffectInstance> fx = buses.write[p_bus]->effects.write[j].effect->instantiate();
1100
if (Object::cast_to<AudioEffectCompressorInstance>(*fx)) {
1101
Object::cast_to<AudioEffectCompressorInstance>(*fx)->set_current_channel(i);
1102
}
1103
buses.write[p_bus]->channels.write[i].effect_instances.write[j] = fx;
1104
}
1105
}
1106
}
1107
1108
void AudioServer::add_bus_effect(int p_bus, const Ref<AudioEffect> &p_effect, int p_at_pos) {
1109
ERR_FAIL_COND(p_effect.is_null());
1110
ERR_FAIL_INDEX(p_bus, buses.size());
1111
1112
MARK_EDITED
1113
1114
lock();
1115
1116
Bus::Effect fx;
1117
fx.effect = p_effect;
1118
//fx.instance=p_effect->instantiate();
1119
fx.enabled = true;
1120
#ifdef DEBUG_ENABLED
1121
fx.prof_time = 0;
1122
#endif
1123
1124
if (p_at_pos >= buses[p_bus]->effects.size() || p_at_pos < 0) {
1125
buses[p_bus]->effects.push_back(fx);
1126
} else {
1127
buses[p_bus]->effects.insert(p_at_pos, fx);
1128
}
1129
1130
_update_bus_effects(p_bus);
1131
1132
unlock();
1133
}
1134
1135
void AudioServer::remove_bus_effect(int p_bus, int p_effect) {
1136
ERR_FAIL_INDEX(p_bus, buses.size());
1137
1138
MARK_EDITED
1139
1140
lock();
1141
1142
buses[p_bus]->effects.remove_at(p_effect);
1143
_update_bus_effects(p_bus);
1144
1145
unlock();
1146
}
1147
1148
int AudioServer::get_bus_effect_count(int p_bus) {
1149
ERR_FAIL_INDEX_V(p_bus, buses.size(), 0);
1150
1151
return buses[p_bus]->effects.size();
1152
}
1153
1154
Ref<AudioEffectInstance> AudioServer::get_bus_effect_instance(int p_bus, int p_effect, int p_channel) {
1155
ERR_FAIL_INDEX_V(p_bus, buses.size(), Ref<AudioEffectInstance>());
1156
ERR_FAIL_INDEX_V(p_effect, buses[p_bus]->effects.size(), Ref<AudioEffectInstance>());
1157
ERR_FAIL_INDEX_V(p_channel, buses[p_bus]->channels.size(), Ref<AudioEffectInstance>());
1158
1159
return buses[p_bus]->channels[p_channel].effect_instances[p_effect];
1160
}
1161
1162
Ref<AudioEffect> AudioServer::get_bus_effect(int p_bus, int p_effect) {
1163
ERR_FAIL_INDEX_V(p_bus, buses.size(), Ref<AudioEffect>());
1164
ERR_FAIL_INDEX_V(p_effect, buses[p_bus]->effects.size(), Ref<AudioEffect>());
1165
1166
return buses[p_bus]->effects[p_effect].effect;
1167
}
1168
1169
void AudioServer::swap_bus_effects(int p_bus, int p_effect, int p_by_effect) {
1170
ERR_FAIL_INDEX(p_bus, buses.size());
1171
ERR_FAIL_INDEX(p_effect, buses[p_bus]->effects.size());
1172
ERR_FAIL_INDEX(p_by_effect, buses[p_bus]->effects.size());
1173
1174
MARK_EDITED
1175
1176
lock();
1177
SWAP(buses.write[p_bus]->effects.write[p_effect], buses.write[p_bus]->effects.write[p_by_effect]);
1178
_update_bus_effects(p_bus);
1179
unlock();
1180
}
1181
1182
void AudioServer::set_bus_effect_enabled(int p_bus, int p_effect, bool p_enabled) {
1183
ERR_FAIL_INDEX(p_bus, buses.size());
1184
ERR_FAIL_INDEX(p_effect, buses[p_bus]->effects.size());
1185
1186
MARK_EDITED
1187
1188
buses.write[p_bus]->effects.write[p_effect].enabled = p_enabled;
1189
}
1190
1191
bool AudioServer::is_bus_effect_enabled(int p_bus, int p_effect) const {
1192
ERR_FAIL_INDEX_V(p_bus, buses.size(), false);
1193
ERR_FAIL_INDEX_V(p_effect, buses[p_bus]->effects.size(), false);
1194
return buses[p_bus]->effects[p_effect].enabled;
1195
}
1196
1197
float AudioServer::get_bus_peak_volume_left_db(int p_bus, int p_channel) const {
1198
ERR_FAIL_INDEX_V(p_bus, buses.size(), 0);
1199
ERR_FAIL_INDEX_V(p_channel, buses[p_bus]->channels.size(), 0);
1200
1201
return buses[p_bus]->channels[p_channel].peak_volume.left;
1202
}
1203
1204
float AudioServer::get_bus_peak_volume_right_db(int p_bus, int p_channel) const {
1205
ERR_FAIL_INDEX_V(p_bus, buses.size(), 0);
1206
ERR_FAIL_INDEX_V(p_channel, buses[p_bus]->channels.size(), 0);
1207
1208
return buses[p_bus]->channels[p_channel].peak_volume.right;
1209
}
1210
1211
bool AudioServer::is_bus_channel_active(int p_bus, int p_channel) const {
1212
ERR_FAIL_INDEX_V(p_bus, buses.size(), false);
1213
ERR_FAIL_INDEX_V(p_channel, buses[p_bus]->channels.size(), false);
1214
1215
return buses[p_bus]->channels[p_channel].active;
1216
}
1217
1218
void AudioServer::set_playback_speed_scale(float p_scale) {
1219
ERR_FAIL_COND(p_scale <= 0);
1220
1221
playback_speed_scale = p_scale;
1222
}
1223
1224
float AudioServer::get_playback_speed_scale() const {
1225
return playback_speed_scale;
1226
}
1227
1228
void AudioServer::start_playback_stream(Ref<AudioStreamPlayback> p_playback, const StringName &p_bus, Vector<AudioFrame> p_volume_db_vector, float p_start_time, float p_pitch_scale) {
1229
ERR_FAIL_COND(p_playback.is_null());
1230
1231
HashMap<StringName, Vector<AudioFrame>> map;
1232
map[p_bus] = p_volume_db_vector;
1233
1234
start_playback_stream(p_playback, map, p_start_time, p_pitch_scale);
1235
}
1236
1237
void AudioServer::start_playback_stream(Ref<AudioStreamPlayback> p_playback, const HashMap<StringName, Vector<AudioFrame>> &p_bus_volumes, float p_start_time, float p_pitch_scale, float p_highshelf_gain, float p_attenuation_cutoff_hz) {
1238
ERR_FAIL_COND(p_playback.is_null());
1239
1240
AudioStreamPlaybackListNode *playback_node = new AudioStreamPlaybackListNode();
1241
playback_node->stream_playback = p_playback;
1242
playback_node->stream_playback->start(p_start_time);
1243
1244
AudioStreamPlaybackBusDetails *new_bus_details = new AudioStreamPlaybackBusDetails();
1245
int idx = 0;
1246
for (KeyValue<StringName, Vector<AudioFrame>> pair : p_bus_volumes) {
1247
if (pair.value.size() < channel_count || pair.value.size() != MAX_CHANNELS_PER_BUS) {
1248
delete playback_node;
1249
delete new_bus_details;
1250
ERR_FAIL();
1251
}
1252
1253
new_bus_details->bus_active[idx] = true;
1254
new_bus_details->bus[idx] = pair.key;
1255
for (int channel_idx = 0; channel_idx < MAX_CHANNELS_PER_BUS; channel_idx++) {
1256
new_bus_details->volume[idx][channel_idx] = pair.value[channel_idx];
1257
}
1258
idx++;
1259
}
1260
playback_node->bus_details.store(new_bus_details);
1261
playback_node->prev_bus_details = new AudioStreamPlaybackBusDetails();
1262
1263
playback_node->pitch_scale.set(p_pitch_scale);
1264
playback_node->highshelf_gain.set(p_highshelf_gain);
1265
playback_node->attenuation_filter_cutoff_hz.set(p_attenuation_cutoff_hz);
1266
1267
memset(playback_node->prev_bus_details->volume, 0, sizeof(playback_node->prev_bus_details->volume));
1268
1269
for (AudioFrame &frame : playback_node->lookahead) {
1270
frame = AudioFrame(0, 0);
1271
}
1272
1273
playback_node->state.store(AudioStreamPlaybackListNode::PLAYING);
1274
1275
playback_list.insert(playback_node);
1276
}
1277
1278
void AudioServer::stop_playback_stream(Ref<AudioStreamPlayback> p_playback) {
1279
ERR_FAIL_COND(p_playback.is_null());
1280
1281
// Handle sample playback.
1282
if (p_playback->get_is_sample()) {
1283
if (p_playback->get_sample_playback().is_valid()) {
1284
AudioServer::get_singleton()->stop_sample_playback(p_playback->get_sample_playback());
1285
} else {
1286
_delete_stream_playback(p_playback);
1287
}
1288
return;
1289
}
1290
1291
if (!p_playback->is_playing()) {
1292
p_playback->stop();
1293
}
1294
1295
AudioStreamPlaybackListNode *playback_node = _find_playback_list_node(p_playback);
1296
if (!playback_node) {
1297
return;
1298
}
1299
1300
AudioStreamPlaybackListNode::PlaybackState new_state, old_state;
1301
do {
1302
old_state = playback_node->state.load();
1303
if (old_state == AudioStreamPlaybackListNode::AWAITING_DELETION) {
1304
break; // Don't fade out again.
1305
}
1306
new_state = AudioStreamPlaybackListNode::FADE_OUT_TO_DELETION;
1307
1308
} while (!playback_node->state.compare_exchange_strong(old_state, new_state));
1309
}
1310
1311
void AudioServer::set_playback_bus_exclusive(Ref<AudioStreamPlayback> p_playback, const StringName &p_bus, Vector<AudioFrame> p_volumes) {
1312
ERR_FAIL_COND(p_volumes.size() != MAX_CHANNELS_PER_BUS);
1313
1314
HashMap<StringName, Vector<AudioFrame>> map;
1315
map[p_bus] = p_volumes;
1316
1317
set_playback_bus_volumes_linear(p_playback, map);
1318
}
1319
1320
void AudioServer::set_playback_bus_volumes_linear(Ref<AudioStreamPlayback> p_playback, const HashMap<StringName, Vector<AudioFrame>> &p_bus_volumes) {
1321
ERR_FAIL_COND(p_bus_volumes.size() > MAX_BUSES_PER_PLAYBACK);
1322
1323
// Samples.
1324
if (p_playback->get_is_sample() && p_playback->get_sample_playback().is_valid()) {
1325
Ref<AudioSamplePlayback> sample_playback = p_playback->get_sample_playback();
1326
AudioDriver::get_singleton()->set_sample_playback_bus_volumes_linear(sample_playback, p_bus_volumes);
1327
return;
1328
}
1329
1330
AudioStreamPlaybackListNode *playback_node = _find_playback_list_node(p_playback);
1331
if (!playback_node) {
1332
return;
1333
}
1334
AudioStreamPlaybackBusDetails *old_bus_details, *new_bus_details = new AudioStreamPlaybackBusDetails();
1335
1336
int idx = 0;
1337
for (KeyValue<StringName, Vector<AudioFrame>> pair : p_bus_volumes) {
1338
if (idx >= MAX_BUSES_PER_PLAYBACK) {
1339
break;
1340
}
1341
if (pair.value.size() < channel_count || pair.value.size() != MAX_CHANNELS_PER_BUS) {
1342
delete new_bus_details;
1343
ERR_FAIL();
1344
}
1345
1346
new_bus_details->bus_active[idx] = true;
1347
new_bus_details->bus[idx] = pair.key;
1348
for (int channel_idx = 0; channel_idx < MAX_CHANNELS_PER_BUS; channel_idx++) {
1349
new_bus_details->volume[idx][channel_idx] = pair.value[channel_idx];
1350
}
1351
idx++;
1352
}
1353
1354
do {
1355
old_bus_details = playback_node->bus_details.load();
1356
} while (!playback_node->bus_details.compare_exchange_strong(old_bus_details, new_bus_details));
1357
1358
bus_details_graveyard.insert(old_bus_details);
1359
}
1360
1361
void AudioServer::set_playback_all_bus_volumes_linear(Ref<AudioStreamPlayback> p_playback, Vector<AudioFrame> p_volumes) {
1362
ERR_FAIL_COND(p_playback.is_null());
1363
ERR_FAIL_COND(p_volumes.size() != MAX_CHANNELS_PER_BUS);
1364
1365
HashMap<StringName, Vector<AudioFrame>> map;
1366
1367
AudioStreamPlaybackListNode *playback_node = _find_playback_list_node(p_playback);
1368
if (!playback_node) {
1369
return;
1370
}
1371
for (int bus_idx = 0; bus_idx < MAX_BUSES_PER_PLAYBACK; bus_idx++) {
1372
if (playback_node->bus_details.load()->bus_active[bus_idx]) {
1373
map[playback_node->bus_details.load()->bus[bus_idx]] = p_volumes;
1374
}
1375
}
1376
1377
set_playback_bus_volumes_linear(p_playback, map);
1378
}
1379
1380
void AudioServer::set_playback_pitch_scale(Ref<AudioStreamPlayback> p_playback, float p_pitch_scale) {
1381
ERR_FAIL_COND(p_playback.is_null());
1382
1383
// Samples.
1384
if (p_playback->get_is_sample() && p_playback->get_sample_playback().is_valid()) {
1385
Ref<AudioSamplePlayback> sample_playback = p_playback->get_sample_playback();
1386
AudioServer::get_singleton()->update_sample_playback_pitch_scale(sample_playback, p_pitch_scale);
1387
return;
1388
}
1389
1390
AudioStreamPlaybackListNode *playback_node = _find_playback_list_node(p_playback);
1391
if (!playback_node) {
1392
return;
1393
}
1394
1395
playback_node->pitch_scale.set(p_pitch_scale);
1396
}
1397
1398
void AudioServer::set_playback_paused(Ref<AudioStreamPlayback> p_playback, bool p_paused) {
1399
ERR_FAIL_COND(p_playback.is_null());
1400
1401
AudioStreamPlaybackListNode *playback_node = _find_playback_list_node(p_playback);
1402
if (!playback_node) {
1403
return;
1404
}
1405
1406
AudioStreamPlaybackListNode::PlaybackState new_state, old_state;
1407
do {
1408
old_state = playback_node->state.load();
1409
new_state = p_paused ? AudioStreamPlaybackListNode::FADE_OUT_TO_PAUSE : AudioStreamPlaybackListNode::PLAYING;
1410
if (!p_paused && old_state == AudioStreamPlaybackListNode::PLAYING) {
1411
return; // No-op.
1412
}
1413
if (p_paused && (old_state == AudioStreamPlaybackListNode::PAUSED || old_state == AudioStreamPlaybackListNode::FADE_OUT_TO_PAUSE)) {
1414
return; // No-op.
1415
}
1416
1417
} while (!playback_node->state.compare_exchange_strong(old_state, new_state));
1418
}
1419
1420
void AudioServer::set_playback_highshelf_params(Ref<AudioStreamPlayback> p_playback, float p_gain, float p_attenuation_cutoff_hz) {
1421
ERR_FAIL_COND(p_playback.is_null());
1422
1423
AudioStreamPlaybackListNode *playback_node = _find_playback_list_node(p_playback);
1424
if (!playback_node) {
1425
return;
1426
}
1427
1428
playback_node->attenuation_filter_cutoff_hz.set(p_attenuation_cutoff_hz);
1429
playback_node->highshelf_gain.set(p_gain);
1430
}
1431
1432
bool AudioServer::is_playback_active(Ref<AudioStreamPlayback> p_playback) {
1433
ERR_FAIL_COND_V(p_playback.is_null(), false);
1434
1435
if (p_playback->get_is_sample()) {
1436
if (p_playback->get_sample_playback().is_valid()) {
1437
return sample_playback_list.has(p_playback->get_sample_playback());
1438
} else {
1439
return false;
1440
}
1441
}
1442
1443
AudioStreamPlaybackListNode *playback_node = _find_playback_list_node(p_playback);
1444
if (!playback_node) {
1445
return false;
1446
}
1447
1448
return playback_node->state.load() == AudioStreamPlaybackListNode::PLAYING;
1449
}
1450
1451
float AudioServer::get_playback_position(Ref<AudioStreamPlayback> p_playback) {
1452
ERR_FAIL_COND_V(p_playback.is_null(), 0);
1453
1454
// Samples.
1455
if (p_playback->get_is_sample() && p_playback->get_sample_playback().is_valid()) {
1456
Ref<AudioSamplePlayback> sample_playback = p_playback->get_sample_playback();
1457
return AudioServer::get_singleton()->get_sample_playback_position(sample_playback);
1458
}
1459
1460
AudioStreamPlaybackListNode *playback_node = _find_playback_list_node(p_playback);
1461
if (!playback_node) {
1462
return 0;
1463
}
1464
1465
return playback_node->stream_playback->get_playback_position();
1466
}
1467
1468
bool AudioServer::is_playback_paused(Ref<AudioStreamPlayback> p_playback) {
1469
ERR_FAIL_COND_V(p_playback.is_null(), false);
1470
1471
AudioStreamPlaybackListNode *playback_node = _find_playback_list_node(p_playback);
1472
if (!playback_node) {
1473
return false;
1474
}
1475
1476
return playback_node->state.load() == AudioStreamPlaybackListNode::PAUSED || playback_node->state.load() == AudioStreamPlaybackListNode::FADE_OUT_TO_PAUSE;
1477
}
1478
1479
uint64_t AudioServer::get_mix_count() const {
1480
return mix_count;
1481
}
1482
1483
uint64_t AudioServer::get_mixed_frames() const {
1484
return mix_frames;
1485
}
1486
1487
String AudioServer::get_driver_name() const {
1488
return AudioDriver::get_singleton()->get_name();
1489
}
1490
1491
void AudioServer::notify_listener_changed() {
1492
for (CallbackItem *ci : listener_changed_callback_list) {
1493
ci->callback(ci->userdata);
1494
}
1495
}
1496
1497
void AudioServer::init_channels_and_buffers() {
1498
channel_count = get_channel_count();
1499
temp_buffer.resize(channel_count);
1500
mix_buffer.resize(buffer_size + LOOKAHEAD_BUFFER_SIZE);
1501
1502
for (int i = 0; i < temp_buffer.size(); i++) {
1503
temp_buffer.write[i].resize(buffer_size);
1504
}
1505
1506
for (int i = 0; i < buses.size(); i++) {
1507
buses[i]->channels.resize(channel_count);
1508
for (int j = 0; j < channel_count; j++) {
1509
buses.write[i]->channels.write[j].buffer.resize(buffer_size);
1510
}
1511
_update_bus_effects(i);
1512
}
1513
}
1514
1515
void AudioServer::init() {
1516
channel_disable_threshold_db = GLOBAL_DEF_RST(PropertyInfo(Variant::FLOAT, "audio/buses/channel_disable_threshold_db", PROPERTY_HINT_RANGE, "-80,0,0.1,suffix:dB"), -60.0);
1517
channel_disable_frames = float(GLOBAL_DEF_RST(PropertyInfo(Variant::FLOAT, "audio/buses/channel_disable_time", PROPERTY_HINT_RANGE, "0,5,0.01,or_greater"), 2.0)) * get_mix_rate();
1518
// TODO: Buffer size is hardcoded for now. This would be really nice to have as a project setting because currently it limits audio latency to an absolute minimum of 11ms with default mix rate, but there's some additional work required to make that happen. See TODOs in `_mix_step_for_channel`.
1519
// When this becomes a project setting, it should be specified in milliseconds rather than raw sample count, because 512 samples at 192khz is shorter than it is at 48khz, for example.
1520
buffer_size = 512;
1521
1522
init_channels_and_buffers();
1523
1524
mix_count = 0;
1525
set_bus_count(1);
1526
set_bus_name(0, "Master");
1527
1528
if (AudioDriver::get_singleton()) {
1529
AudioDriver::get_singleton()->start();
1530
AudioDriver::get_singleton()->set_sample_bus_count(1);
1531
}
1532
1533
#ifdef TOOLS_ENABLED
1534
set_edited(false); //avoid editors from thinking this was edited
1535
#endif
1536
1537
GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "audio/video/video_delay_compensation_ms", PROPERTY_HINT_RANGE, "-1000,1000,1,suffix:ms"), 0);
1538
}
1539
1540
void AudioServer::update() {
1541
#ifdef DEBUG_ENABLED
1542
if (EngineDebugger::is_profiling(SNAME("servers"))) {
1543
// Driver time includes server time + effects times
1544
// Server time includes effects times
1545
uint64_t driver_time = AudioDriver::get_singleton()->get_profiling_time();
1546
uint64_t server_time = prof_time.get();
1547
1548
// Subtract the server time from the driver time
1549
if (driver_time > server_time) {
1550
driver_time -= server_time;
1551
}
1552
1553
Array values;
1554
1555
for (int i = buses.size() - 1; i >= 0; i--) {
1556
Bus *bus = buses[i];
1557
if (bus->bypass) {
1558
continue;
1559
}
1560
1561
for (int j = 0; j < bus->effects.size(); j++) {
1562
if (!bus->effects[j].enabled) {
1563
continue;
1564
}
1565
1566
values.push_back(String(bus->name) + bus->effects[j].effect->get_name());
1567
values.push_back(USEC_TO_SEC(bus->effects[j].prof_time));
1568
1569
// Subtract the effect time from the driver and server times
1570
if (driver_time > bus->effects[j].prof_time) {
1571
driver_time -= bus->effects[j].prof_time;
1572
}
1573
if (server_time > bus->effects[j].prof_time) {
1574
server_time -= bus->effects[j].prof_time;
1575
}
1576
}
1577
}
1578
1579
values.push_back("audio_server");
1580
values.push_back(USEC_TO_SEC(server_time));
1581
values.push_back("audio_driver");
1582
values.push_back(USEC_TO_SEC(driver_time));
1583
1584
values.push_front("audio_thread");
1585
EngineDebugger::profiler_add_frame_data("servers", values);
1586
}
1587
1588
// Reset profiling times
1589
for (int i = buses.size() - 1; i >= 0; i--) {
1590
Bus *bus = buses[i];
1591
if (bus->bypass) {
1592
continue;
1593
}
1594
1595
for (int j = 0; j < bus->effects.size(); j++) {
1596
if (!bus->effects[j].enabled) {
1597
continue;
1598
}
1599
1600
bus->effects.write[j].prof_time = 0;
1601
}
1602
}
1603
1604
AudioDriver::get_singleton()->reset_profiling_time();
1605
prof_time.set(0);
1606
#endif
1607
1608
for (CallbackItem *ci : update_callback_list) {
1609
ci->callback(ci->userdata);
1610
}
1611
mix_callback_list.maybe_cleanup();
1612
update_callback_list.maybe_cleanup();
1613
listener_changed_callback_list.maybe_cleanup();
1614
playback_list.maybe_cleanup();
1615
for (AudioStreamPlaybackBusDetails *bus_details : bus_details_graveyard_frame_old) {
1616
bus_details_graveyard_frame_old.erase(bus_details, [](AudioStreamPlaybackBusDetails *d) { delete d; });
1617
}
1618
for (AudioStreamPlaybackBusDetails *bus_details : bus_details_graveyard) {
1619
bus_details_graveyard_frame_old.insert(bus_details);
1620
bus_details_graveyard.erase(bus_details);
1621
}
1622
bus_details_graveyard.maybe_cleanup();
1623
bus_details_graveyard_frame_old.maybe_cleanup();
1624
}
1625
1626
void AudioServer::load_default_bus_layout() {
1627
String layout_path = GLOBAL_GET("audio/buses/default_bus_layout");
1628
1629
if (ResourceLoader::exists(layout_path)) {
1630
Ref<AudioBusLayout> default_layout = ResourceLoader::load(layout_path);
1631
if (default_layout.is_valid()) {
1632
set_bus_layout(default_layout);
1633
}
1634
}
1635
}
1636
1637
void AudioServer::finish() {
1638
for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) {
1639
AudioDriverManager::get_driver(i)->finish();
1640
}
1641
1642
for (int i = 0; i < buses.size(); i++) {
1643
memdelete(buses[i]);
1644
}
1645
1646
buses.clear();
1647
}
1648
1649
/* MISC config */
1650
1651
void AudioServer::lock() {
1652
AudioDriver::get_singleton()->lock();
1653
}
1654
1655
void AudioServer::unlock() {
1656
AudioDriver::get_singleton()->unlock();
1657
}
1658
1659
AudioServer::SpeakerMode AudioServer::get_speaker_mode() const {
1660
return (AudioServer::SpeakerMode)AudioDriver::get_singleton()->get_speaker_mode();
1661
}
1662
1663
float AudioServer::get_mix_rate() const {
1664
return AudioDriver::get_singleton()->get_mix_rate();
1665
}
1666
1667
float AudioServer::get_input_mix_rate() const {
1668
return AudioDriver::get_singleton()->get_input_mix_rate();
1669
}
1670
1671
float AudioServer::read_output_peak_db() const {
1672
return 0;
1673
}
1674
1675
AudioServer *AudioServer::get_singleton() {
1676
return singleton;
1677
}
1678
1679
double AudioServer::get_output_latency() const {
1680
return AudioDriver::get_singleton()->get_latency();
1681
}
1682
1683
double AudioServer::get_time_to_next_mix() const {
1684
return AudioDriver::get_singleton()->get_time_to_next_mix();
1685
}
1686
1687
double AudioServer::get_time_since_last_mix() const {
1688
return AudioDriver::get_singleton()->get_time_since_last_mix();
1689
}
1690
1691
AudioServer *AudioServer::singleton = nullptr;
1692
1693
void AudioServer::add_update_callback(AudioCallback p_callback, void *p_userdata) {
1694
CallbackItem *ci = new CallbackItem();
1695
ci->callback = p_callback;
1696
ci->userdata = p_userdata;
1697
update_callback_list.insert(ci);
1698
}
1699
1700
void AudioServer::remove_update_callback(AudioCallback p_callback, void *p_userdata) {
1701
for (CallbackItem *ci : update_callback_list) {
1702
if (ci->callback == p_callback && ci->userdata == p_userdata) {
1703
update_callback_list.erase(ci, [](CallbackItem *c) { delete c; });
1704
}
1705
}
1706
}
1707
1708
void AudioServer::add_mix_callback(AudioCallback p_callback, void *p_userdata) {
1709
CallbackItem *ci = new CallbackItem();
1710
ci->callback = p_callback;
1711
ci->userdata = p_userdata;
1712
mix_callback_list.insert(ci);
1713
}
1714
1715
void AudioServer::remove_mix_callback(AudioCallback p_callback, void *p_userdata) {
1716
for (CallbackItem *ci : mix_callback_list) {
1717
if (ci->callback == p_callback && ci->userdata == p_userdata) {
1718
mix_callback_list.erase(ci, [](CallbackItem *c) { delete c; });
1719
}
1720
}
1721
}
1722
1723
void AudioServer::add_listener_changed_callback(AudioCallback p_callback, void *p_userdata) {
1724
CallbackItem *ci = new CallbackItem();
1725
ci->callback = p_callback;
1726
ci->userdata = p_userdata;
1727
listener_changed_callback_list.insert(ci);
1728
}
1729
1730
void AudioServer::remove_listener_changed_callback(AudioCallback p_callback, void *p_userdata) {
1731
for (CallbackItem *ci : listener_changed_callback_list) {
1732
if (ci->callback == p_callback && ci->userdata == p_userdata) {
1733
listener_changed_callback_list.erase(ci, [](CallbackItem *c) { delete c; });
1734
}
1735
}
1736
}
1737
1738
void AudioServer::set_bus_layout(const Ref<AudioBusLayout> &p_bus_layout) {
1739
ERR_FAIL_COND(p_bus_layout.is_null() || p_bus_layout->buses.is_empty());
1740
1741
lock();
1742
for (int i = 0; i < buses.size(); i++) {
1743
memdelete(buses[i]);
1744
}
1745
buses.resize(p_bus_layout->buses.size());
1746
bus_map.clear();
1747
1748
AudioDriver::get_singleton()->set_sample_bus_count(buses.size());
1749
1750
for (int i = 0; i < p_bus_layout->buses.size(); i++) {
1751
Bus *bus = memnew(Bus);
1752
if (i == 0) {
1753
bus->name = SceneStringName(Master);
1754
} else {
1755
bus->name = p_bus_layout->buses[i].name;
1756
bus->send = p_bus_layout->buses[i].send;
1757
AudioDriver::get_singleton()->set_sample_bus_send(i, bus->send);
1758
}
1759
1760
bus->solo = p_bus_layout->buses[i].solo;
1761
bus->mute = p_bus_layout->buses[i].mute;
1762
bus->bypass = p_bus_layout->buses[i].bypass;
1763
bus->volume_db = p_bus_layout->buses[i].volume_db;
1764
1765
AudioDriver::get_singleton()->set_sample_bus_solo(i, bus->solo);
1766
AudioDriver::get_singleton()->set_sample_bus_mute(i, bus->mute);
1767
AudioDriver::get_singleton()->set_sample_bus_volume_db(i, bus->volume_db);
1768
1769
for (int j = 0; j < p_bus_layout->buses[i].effects.size(); j++) {
1770
Ref<AudioEffect> fx = p_bus_layout->buses[i].effects[j].effect;
1771
1772
if (fx.is_valid()) {
1773
Bus::Effect bfx;
1774
bfx.effect = fx;
1775
bfx.enabled = p_bus_layout->buses[i].effects[j].enabled;
1776
#ifdef DEBUG_ENABLED
1777
bfx.prof_time = 0;
1778
#endif
1779
bus->effects.push_back(bfx);
1780
}
1781
}
1782
1783
bus_map[bus->name] = bus;
1784
buses.write[i] = bus;
1785
1786
buses[i]->channels.resize(channel_count);
1787
for (int j = 0; j < channel_count; j++) {
1788
buses.write[i]->channels.write[j].buffer.resize(buffer_size);
1789
}
1790
_update_bus_effects(i);
1791
}
1792
#ifdef TOOLS_ENABLED
1793
set_edited(false);
1794
#endif
1795
unlock();
1796
1797
// Samples bus sync.
1798
}
1799
1800
Ref<AudioBusLayout> AudioServer::generate_bus_layout() const {
1801
Ref<AudioBusLayout> state;
1802
state.instantiate();
1803
1804
state->buses.resize(buses.size());
1805
1806
for (int i = 0; i < buses.size(); i++) {
1807
state->buses.write[i].name = buses[i]->name;
1808
state->buses.write[i].send = buses[i]->send;
1809
state->buses.write[i].mute = buses[i]->mute;
1810
state->buses.write[i].solo = buses[i]->solo;
1811
state->buses.write[i].bypass = buses[i]->bypass;
1812
state->buses.write[i].volume_db = buses[i]->volume_db;
1813
for (int j = 0; j < buses[i]->effects.size(); j++) {
1814
AudioBusLayout::Bus::Effect fx;
1815
fx.effect = buses[i]->effects[j].effect;
1816
fx.enabled = buses[i]->effects[j].enabled;
1817
state->buses.write[i].effects.push_back(fx);
1818
}
1819
}
1820
1821
return state;
1822
}
1823
1824
PackedStringArray AudioServer::get_output_device_list() {
1825
return AudioDriver::get_singleton()->get_output_device_list();
1826
}
1827
1828
String AudioServer::get_output_device() {
1829
return AudioDriver::get_singleton()->get_output_device();
1830
}
1831
1832
void AudioServer::set_output_device(const String &p_name) {
1833
AudioDriver::get_singleton()->set_output_device(p_name);
1834
}
1835
1836
PackedStringArray AudioServer::get_input_device_list() {
1837
return AudioDriver::get_singleton()->get_input_device_list();
1838
}
1839
1840
String AudioServer::get_input_device() {
1841
return AudioDriver::get_singleton()->get_input_device();
1842
}
1843
1844
void AudioServer::set_input_device(const String &p_name) {
1845
AudioDriver::get_singleton()->set_input_device(p_name);
1846
}
1847
1848
Error AudioServer::set_input_device_active(bool p_is_active) {
1849
if (input_device_active == p_is_active) {
1850
return OK;
1851
}
1852
if (p_is_active) {
1853
if (!GLOBAL_GET("audio/driver/enable_input")) {
1854
WARN_PRINT("You must enable the project setting \"audio/driver/enable_input\" to use audio capture.");
1855
return FAILED;
1856
}
1857
1858
input_buffer_ofs = 0;
1859
input_device_active = true;
1860
return AudioDriver::get_singleton()->input_start();
1861
} else {
1862
input_device_active = false;
1863
return AudioDriver::get_singleton()->input_stop();
1864
}
1865
}
1866
1867
int AudioServer::get_input_frames_available() {
1868
AudioDriver *ad = AudioDriver::get_singleton();
1869
ad->lock();
1870
int64_t input_position = ad->get_input_position();
1871
if (input_position < input_buffer_ofs) {
1872
input_position += ad->get_input_buffer().size();
1873
}
1874
ad->unlock();
1875
return (int)((input_position - input_buffer_ofs) / 2); // Buffer is stereo.
1876
}
1877
1878
int AudioServer::get_input_buffer_length_frames() {
1879
AudioDriver *ad = AudioDriver::get_singleton();
1880
ad->lock();
1881
int buffsize = ad->get_input_buffer().size();
1882
ad->unlock();
1883
return buffsize / 2;
1884
}
1885
1886
PackedVector2Array AudioServer::get_input_frames(int p_frames) {
1887
PackedVector2Array ret;
1888
AudioDriver *ad = AudioDriver::get_singleton();
1889
ad->lock();
1890
int input_position = ad->get_input_position();
1891
Vector<int32_t> buf = ad->get_input_buffer();
1892
if (input_position < input_buffer_ofs) {
1893
input_position += buf.size();
1894
}
1895
if ((input_buffer_ofs + p_frames * 2 <= input_position) && (p_frames >= 0)) {
1896
ret.resize(p_frames);
1897
for (int i = 0; i < p_frames; i++) {
1898
float l = (buf[input_buffer_ofs++] >> 16) / 32768.f;
1899
if (input_buffer_ofs >= buf.size()) {
1900
input_buffer_ofs = 0;
1901
}
1902
float r = (buf[input_buffer_ofs++] >> 16) / 32768.f;
1903
if (input_buffer_ofs >= buf.size()) {
1904
input_buffer_ofs = 0;
1905
}
1906
ret.write[i] = Vector2(l, r);
1907
}
1908
}
1909
ad->unlock();
1910
return ret;
1911
}
1912
1913
void AudioServer::set_enable_tagging_used_audio_streams(bool p_enable) {
1914
tag_used_audio_streams = p_enable;
1915
}
1916
1917
#ifdef TOOLS_ENABLED
1918
void AudioServer::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
1919
const String pf = p_function;
1920
if ((p_idx == 0 && pf == "get_bus_index") || (p_idx == 1 && pf == "set_bus_send")) {
1921
for (const AudioServer::Bus *E : buses) {
1922
r_options->push_back(String(E->name).quote());
1923
}
1924
}
1925
1926
Object::get_argument_options(p_function, p_idx, r_options);
1927
}
1928
#endif
1929
1930
AudioServer::PlaybackType AudioServer::get_default_playback_type() const {
1931
int playback_type = GLOBAL_GET_CACHED(int, "audio/general/default_playback_type");
1932
ERR_FAIL_COND_V_MSG(
1933
playback_type < 0 || playback_type >= PlaybackType::PLAYBACK_TYPE_MAX,
1934
PlaybackType::PLAYBACK_TYPE_STREAM,
1935
vformat(R"(Project settings value (%s) for "audio/general/default_playback_type" is not supported)", playback_type));
1936
1937
switch (playback_type) {
1938
case 1: {
1939
return PlaybackType::PLAYBACK_TYPE_SAMPLE;
1940
} break;
1941
1942
case 0:
1943
default: {
1944
return PlaybackType::PLAYBACK_TYPE_STREAM;
1945
} break;
1946
}
1947
}
1948
1949
bool AudioServer::is_stream_registered_as_sample(const Ref<AudioStream> &p_stream) {
1950
ERR_FAIL_COND_V_MSG(p_stream.is_null(), false, "Parameter p_stream is null.");
1951
return AudioDriver::get_singleton()->is_stream_registered_as_sample(p_stream);
1952
}
1953
1954
void AudioServer::register_stream_as_sample(const Ref<AudioStream> &p_stream) {
1955
ERR_FAIL_COND_MSG(p_stream.is_null(), "Parameter p_stream is null.");
1956
ERR_FAIL_COND_MSG(!(p_stream->can_be_sampled()), "Parameter p_stream cannot be sampled.");
1957
Ref<AudioSample> sample = p_stream->generate_sample();
1958
register_sample(sample);
1959
}
1960
1961
void AudioServer::unregister_stream_as_sample(const Ref<AudioStream> &p_stream) {
1962
ERR_FAIL_COND_MSG(p_stream.is_null(), "Parameter p_stream is null.");
1963
ERR_FAIL_COND_MSG(!(p_stream->can_be_sampled()), "Parameter p_stream cannot be sampled.");
1964
Ref<AudioSample> sample = p_stream->generate_sample();
1965
unregister_sample(sample);
1966
}
1967
1968
void AudioServer::register_sample(const Ref<AudioSample> &p_sample) {
1969
ERR_FAIL_COND_MSG(p_sample.is_null(), "Parameter p_sample is null.");
1970
ERR_FAIL_COND_MSG(p_sample->stream.is_null(), "Parameter p_sample->stream is null.");
1971
ERR_FAIL_COND_MSG(!(p_sample->stream->can_be_sampled()), "Parameter p_stream cannot be sampled.");
1972
AudioDriver::get_singleton()->register_sample(p_sample);
1973
}
1974
1975
void AudioServer::unregister_sample(const Ref<AudioSample> &p_sample) {
1976
ERR_FAIL_COND_MSG(p_sample.is_null(), "Parameter p_sample is null.");
1977
ERR_FAIL_COND_MSG(p_sample->stream.is_null(), "Parameter p_sample->stream is null.");
1978
AudioDriver::get_singleton()->unregister_sample(p_sample);
1979
}
1980
1981
void AudioServer::start_sample_playback(const Ref<AudioSamplePlayback> &p_playback) {
1982
ERR_FAIL_COND_MSG(p_playback.is_null(), "Parameter p_playback is null.");
1983
AudioDriver::get_singleton()->start_sample_playback(p_playback);
1984
sample_playback_list.ordered_insert(p_playback);
1985
}
1986
1987
void AudioServer::stop_sample_playback(const Ref<AudioSamplePlayback> &p_playback) {
1988
ERR_FAIL_COND_MSG(p_playback.is_null(), "Parameter p_playback is null.");
1989
if (!sample_playback_list.has(p_playback)) {
1990
return;
1991
}
1992
sample_playback_list.erase(p_playback);
1993
AudioDriver::get_singleton()->stop_sample_playback(p_playback);
1994
p_playback->stream_playback->set_sample_playback(nullptr);
1995
stop_playback_stream(p_playback->stream_playback);
1996
}
1997
1998
void AudioServer::set_sample_playback_pause(const Ref<AudioSamplePlayback> &p_playback, bool p_paused) {
1999
ERR_FAIL_COND_MSG(p_playback.is_null(), "Parameter p_playback is null.");
2000
AudioDriver::get_singleton()->set_sample_playback_pause(p_playback, p_paused);
2001
}
2002
2003
bool AudioServer::is_sample_playback_active(const Ref<AudioSamplePlayback> &p_playback) {
2004
ERR_FAIL_COND_V_MSG(p_playback.is_null(), false, "Parameter p_playback is null.");
2005
return sample_playback_list.has(p_playback);
2006
}
2007
2008
double AudioServer::get_sample_playback_position(const Ref<AudioSamplePlayback> &p_playback) {
2009
ERR_FAIL_COND_V_MSG(p_playback.is_null(), false, "Parameter p_playback is null.");
2010
return AudioDriver::get_singleton()->get_sample_playback_position(p_playback);
2011
}
2012
2013
void AudioServer::update_sample_playback_pitch_scale(const Ref<AudioSamplePlayback> &p_playback, float p_pitch_scale) {
2014
ERR_FAIL_COND_MSG(p_playback.is_null(), "Parameter p_playback is null.");
2015
return AudioDriver::get_singleton()->update_sample_playback_pitch_scale(p_playback, p_pitch_scale);
2016
}
2017
2018
void AudioServer::_bind_methods() {
2019
ClassDB::bind_method(D_METHOD("set_bus_count", "amount"), &AudioServer::set_bus_count);
2020
ClassDB::bind_method(D_METHOD("get_bus_count"), &AudioServer::get_bus_count);
2021
2022
ClassDB::bind_method(D_METHOD("remove_bus", "index"), &AudioServer::remove_bus);
2023
ClassDB::bind_method(D_METHOD("add_bus", "at_position"), &AudioServer::add_bus, DEFVAL(-1));
2024
ClassDB::bind_method(D_METHOD("move_bus", "index", "to_index"), &AudioServer::move_bus);
2025
2026
ClassDB::bind_method(D_METHOD("set_bus_name", "bus_idx", "name"), &AudioServer::set_bus_name);
2027
ClassDB::bind_method(D_METHOD("get_bus_name", "bus_idx"), &AudioServer::get_bus_name);
2028
ClassDB::bind_method(D_METHOD("get_bus_index", "bus_name"), &AudioServer::get_bus_index);
2029
2030
ClassDB::bind_method(D_METHOD("get_bus_channels", "bus_idx"), &AudioServer::get_bus_channels);
2031
2032
ClassDB::bind_method(D_METHOD("set_bus_volume_db", "bus_idx", "volume_db"), &AudioServer::set_bus_volume_db);
2033
ClassDB::bind_method(D_METHOD("get_bus_volume_db", "bus_idx"), &AudioServer::get_bus_volume_db);
2034
2035
ClassDB::bind_method(D_METHOD("set_bus_volume_linear", "bus_idx", "volume_linear"), &AudioServer::set_bus_volume_linear);
2036
ClassDB::bind_method(D_METHOD("get_bus_volume_linear", "bus_idx"), &AudioServer::get_bus_volume_linear);
2037
2038
ClassDB::bind_method(D_METHOD("set_bus_send", "bus_idx", "send"), &AudioServer::set_bus_send);
2039
ClassDB::bind_method(D_METHOD("get_bus_send", "bus_idx"), &AudioServer::get_bus_send);
2040
2041
ClassDB::bind_method(D_METHOD("set_bus_solo", "bus_idx", "enable"), &AudioServer::set_bus_solo);
2042
ClassDB::bind_method(D_METHOD("is_bus_solo", "bus_idx"), &AudioServer::is_bus_solo);
2043
2044
ClassDB::bind_method(D_METHOD("set_bus_mute", "bus_idx", "enable"), &AudioServer::set_bus_mute);
2045
ClassDB::bind_method(D_METHOD("is_bus_mute", "bus_idx"), &AudioServer::is_bus_mute);
2046
2047
ClassDB::bind_method(D_METHOD("set_bus_bypass_effects", "bus_idx", "enable"), &AudioServer::set_bus_bypass_effects);
2048
ClassDB::bind_method(D_METHOD("is_bus_bypassing_effects", "bus_idx"), &AudioServer::is_bus_bypassing_effects);
2049
2050
ClassDB::bind_method(D_METHOD("add_bus_effect", "bus_idx", "effect", "at_position"), &AudioServer::add_bus_effect, DEFVAL(-1));
2051
ClassDB::bind_method(D_METHOD("remove_bus_effect", "bus_idx", "effect_idx"), &AudioServer::remove_bus_effect);
2052
2053
ClassDB::bind_method(D_METHOD("get_bus_effect_count", "bus_idx"), &AudioServer::get_bus_effect_count);
2054
ClassDB::bind_method(D_METHOD("get_bus_effect", "bus_idx", "effect_idx"), &AudioServer::get_bus_effect);
2055
ClassDB::bind_method(D_METHOD("get_bus_effect_instance", "bus_idx", "effect_idx", "channel"), &AudioServer::get_bus_effect_instance, DEFVAL(0));
2056
ClassDB::bind_method(D_METHOD("swap_bus_effects", "bus_idx", "effect_idx", "by_effect_idx"), &AudioServer::swap_bus_effects);
2057
2058
ClassDB::bind_method(D_METHOD("set_bus_effect_enabled", "bus_idx", "effect_idx", "enabled"), &AudioServer::set_bus_effect_enabled);
2059
ClassDB::bind_method(D_METHOD("is_bus_effect_enabled", "bus_idx", "effect_idx"), &AudioServer::is_bus_effect_enabled);
2060
2061
ClassDB::bind_method(D_METHOD("get_bus_peak_volume_left_db", "bus_idx", "channel"), &AudioServer::get_bus_peak_volume_left_db);
2062
ClassDB::bind_method(D_METHOD("get_bus_peak_volume_right_db", "bus_idx", "channel"), &AudioServer::get_bus_peak_volume_right_db);
2063
2064
ClassDB::bind_method(D_METHOD("set_playback_speed_scale", "scale"), &AudioServer::set_playback_speed_scale);
2065
ClassDB::bind_method(D_METHOD("get_playback_speed_scale"), &AudioServer::get_playback_speed_scale);
2066
2067
ClassDB::bind_method(D_METHOD("lock"), &AudioServer::lock);
2068
ClassDB::bind_method(D_METHOD("unlock"), &AudioServer::unlock);
2069
2070
ClassDB::bind_method(D_METHOD("get_speaker_mode"), &AudioServer::get_speaker_mode);
2071
ClassDB::bind_method(D_METHOD("get_mix_rate"), &AudioServer::get_mix_rate);
2072
ClassDB::bind_method(D_METHOD("get_input_mix_rate"), &AudioServer::get_input_mix_rate);
2073
2074
ClassDB::bind_method(D_METHOD("get_driver_name"), &AudioServer::get_driver_name);
2075
2076
ClassDB::bind_method(D_METHOD("get_output_device_list"), &AudioServer::get_output_device_list);
2077
ClassDB::bind_method(D_METHOD("get_output_device"), &AudioServer::get_output_device);
2078
ClassDB::bind_method(D_METHOD("set_output_device", "name"), &AudioServer::set_output_device);
2079
2080
ClassDB::bind_method(D_METHOD("get_time_to_next_mix"), &AudioServer::get_time_to_next_mix);
2081
ClassDB::bind_method(D_METHOD("get_time_since_last_mix"), &AudioServer::get_time_since_last_mix);
2082
ClassDB::bind_method(D_METHOD("get_output_latency"), &AudioServer::get_output_latency);
2083
2084
ClassDB::bind_method(D_METHOD("get_input_device_list"), &AudioServer::get_input_device_list);
2085
ClassDB::bind_method(D_METHOD("get_input_device"), &AudioServer::get_input_device);
2086
ClassDB::bind_method(D_METHOD("set_input_device", "name"), &AudioServer::set_input_device);
2087
ClassDB::bind_method(D_METHOD("set_input_device_active", "active"), &AudioServer::set_input_device_active);
2088
ClassDB::bind_method(D_METHOD("get_input_frames_available"), &AudioServer::get_input_frames_available);
2089
ClassDB::bind_method(D_METHOD("get_input_buffer_length_frames"), &AudioServer::get_input_buffer_length_frames);
2090
ClassDB::bind_method(D_METHOD("get_input_frames", "frames"), &AudioServer::get_input_frames);
2091
2092
ClassDB::bind_method(D_METHOD("set_bus_layout", "bus_layout"), &AudioServer::set_bus_layout);
2093
ClassDB::bind_method(D_METHOD("generate_bus_layout"), &AudioServer::generate_bus_layout);
2094
2095
ClassDB::bind_method(D_METHOD("set_enable_tagging_used_audio_streams", "enable"), &AudioServer::set_enable_tagging_used_audio_streams);
2096
2097
ClassDB::bind_method(D_METHOD("is_stream_registered_as_sample", "stream"), &AudioServer::is_stream_registered_as_sample);
2098
ClassDB::bind_method(D_METHOD("register_stream_as_sample", "stream"), &AudioServer::register_stream_as_sample);
2099
2100
ADD_PROPERTY(PropertyInfo(Variant::INT, "bus_count"), "set_bus_count", "get_bus_count");
2101
ADD_PROPERTY(PropertyInfo(Variant::STRING, "output_device"), "set_output_device", "get_output_device");
2102
ADD_PROPERTY(PropertyInfo(Variant::STRING, "input_device"), "set_input_device", "get_input_device");
2103
// The default value may be set to an empty string by the platform-specific audio driver.
2104
// Override for class reference generation purposes.
2105
ADD_PROPERTY_DEFAULT("input_device", "Default");
2106
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "playback_speed_scale"), "set_playback_speed_scale", "get_playback_speed_scale");
2107
2108
ADD_SIGNAL(MethodInfo("bus_layout_changed"));
2109
ADD_SIGNAL(MethodInfo("bus_renamed", PropertyInfo(Variant::INT, "bus_index"), PropertyInfo(Variant::STRING_NAME, "old_name"), PropertyInfo(Variant::STRING_NAME, "new_name")));
2110
2111
BIND_ENUM_CONSTANT(SPEAKER_MODE_STEREO);
2112
BIND_ENUM_CONSTANT(SPEAKER_SURROUND_31);
2113
BIND_ENUM_CONSTANT(SPEAKER_SURROUND_51);
2114
BIND_ENUM_CONSTANT(SPEAKER_SURROUND_71);
2115
2116
BIND_ENUM_CONSTANT(PLAYBACK_TYPE_DEFAULT);
2117
BIND_ENUM_CONSTANT(PLAYBACK_TYPE_STREAM);
2118
BIND_ENUM_CONSTANT(PLAYBACK_TYPE_SAMPLE);
2119
BIND_ENUM_CONSTANT(PLAYBACK_TYPE_MAX);
2120
}
2121
2122
AudioServer::AudioServer() {
2123
singleton = this;
2124
}
2125
2126
AudioServer::~AudioServer() {
2127
singleton = nullptr;
2128
}
2129
2130
/////////////////////////////////
2131
2132
bool AudioBusLayout::_set(const StringName &p_name, const Variant &p_value) {
2133
String s = p_name;
2134
if (s.begins_with("bus/")) {
2135
int index = s.get_slicec('/', 1).to_int();
2136
if (buses.size() <= index) {
2137
buses.resize(index + 1);
2138
}
2139
2140
Bus &bus = buses.write[index];
2141
2142
String what = s.get_slicec('/', 2);
2143
2144
if (what == "name") {
2145
bus.name = p_value;
2146
} else if (what == "solo") {
2147
bus.solo = p_value;
2148
} else if (what == "mute") {
2149
bus.mute = p_value;
2150
} else if (what == "bypass_fx") {
2151
bus.bypass = p_value;
2152
} else if (what == "volume_db") {
2153
bus.volume_db = p_value;
2154
} else if (what == "send") {
2155
bus.send = p_value;
2156
} else if (what == "effect") {
2157
int which = s.get_slicec('/', 3).to_int();
2158
if (bus.effects.size() <= which) {
2159
bus.effects.resize(which + 1);
2160
}
2161
2162
Bus::Effect &fx = bus.effects.write[which];
2163
2164
String fxwhat = s.get_slicec('/', 4);
2165
if (fxwhat == "effect") {
2166
fx.effect = p_value;
2167
} else if (fxwhat == "enabled") {
2168
fx.enabled = p_value;
2169
} else {
2170
return false;
2171
}
2172
2173
return true;
2174
} else {
2175
return false;
2176
}
2177
2178
return true;
2179
}
2180
2181
return false;
2182
}
2183
2184
bool AudioBusLayout::_get(const StringName &p_name, Variant &r_ret) const {
2185
String s = p_name;
2186
if (s.begins_with("bus/")) {
2187
int index = s.get_slicec('/', 1).to_int();
2188
if (index < 0 || index >= buses.size()) {
2189
return false;
2190
}
2191
2192
const Bus &bus = buses[index];
2193
2194
String what = s.get_slicec('/', 2);
2195
2196
if (what == "name") {
2197
r_ret = bus.name;
2198
} else if (what == "solo") {
2199
r_ret = bus.solo;
2200
} else if (what == "mute") {
2201
r_ret = bus.mute;
2202
} else if (what == "bypass_fx") {
2203
r_ret = bus.bypass;
2204
} else if (what == "volume_db") {
2205
r_ret = bus.volume_db;
2206
} else if (what == "send") {
2207
r_ret = bus.send;
2208
} else if (what == "effect") {
2209
int which = s.get_slicec('/', 3).to_int();
2210
if (which < 0 || which >= bus.effects.size()) {
2211
return false;
2212
}
2213
2214
const Bus::Effect &fx = bus.effects[which];
2215
2216
String fxwhat = s.get_slicec('/', 4);
2217
if (fxwhat == "effect") {
2218
r_ret = fx.effect;
2219
} else if (fxwhat == "enabled") {
2220
r_ret = fx.enabled;
2221
} else {
2222
return false;
2223
}
2224
2225
return true;
2226
} else {
2227
return false;
2228
}
2229
2230
return true;
2231
}
2232
2233
return false;
2234
}
2235
2236
void AudioBusLayout::_get_property_list(List<PropertyInfo> *p_list) const {
2237
for (int i = 0; i < buses.size(); i++) {
2238
p_list->push_back(PropertyInfo(Variant::STRING, "bus/" + itos(i) + "/name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
2239
p_list->push_back(PropertyInfo(Variant::BOOL, "bus/" + itos(i) + "/solo", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
2240
p_list->push_back(PropertyInfo(Variant::BOOL, "bus/" + itos(i) + "/mute", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
2241
p_list->push_back(PropertyInfo(Variant::BOOL, "bus/" + itos(i) + "/bypass_fx", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
2242
p_list->push_back(PropertyInfo(Variant::FLOAT, "bus/" + itos(i) + "/volume_db", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
2243
p_list->push_back(PropertyInfo(Variant::FLOAT, "bus/" + itos(i) + "/send", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
2244
2245
for (int j = 0; j < buses[i].effects.size(); j++) {
2246
p_list->push_back(PropertyInfo(Variant::OBJECT, "bus/" + itos(i) + "/effect/" + itos(j) + "/effect", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
2247
p_list->push_back(PropertyInfo(Variant::BOOL, "bus/" + itos(i) + "/effect/" + itos(j) + "/enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
2248
}
2249
}
2250
}
2251
2252
AudioBusLayout::AudioBusLayout() {
2253
buses.resize(1);
2254
buses.write[0].name = SceneStringName(Master);
2255
}
2256
2257