summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-08-18 18:19:12 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-08-18 18:21:53 -0300
commitcbcf40bd31649d18b24952aec0051cdfbfa78606 (patch)
tree0f2b2f6ddd2e4a2ea119501214090988319ccc6c /servers
parentb044e7d30d1f722d502d9ad564091b2e4a03b390 (diff)
-Volume sliders, mute, solo and fx bypass are functional, closes #9021
-Fixed tree reselect, makes reselecting an audio bux FX work
Diffstat (limited to 'servers')
-rw-r--r--servers/audio_server.cpp74
-rw-r--r--servers/audio_server.h2
2 files changed, 63 insertions, 13 deletions
diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp
index 3547f86eb3..f9fdd9432d 100644
--- a/servers/audio_server.cpp
+++ b/servers/audio_server.cpp
@@ -159,6 +159,8 @@ void AudioServer::_driver_process(int p_frames, int32_t *p_buffer) {
void AudioServer::_mix_step() {
+ bool solo_mode = false;
+
for (int i = 0; i < buses.size(); i++) {
Bus *bus = buses[i];
bus->index_cache = i; //might be moved around by editor, so..
@@ -166,6 +168,33 @@ void AudioServer::_mix_step() {
bus->channels[k].used = false;
}
+
+ 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 {
+ bus = bus_map[bus->send];
+ if (bus->index_cache >= bus->index_cache) { //invalid, send to master
+ bus = buses[0];
+ }
+ }
+
+ bus->soloed = true;
+ } else {
+ bus = NULL;
+ }
+
+ } while (bus);
+ } else {
+ bus->soloed = false;
+ }
}
//make callbacks for mixing the audio
@@ -192,24 +221,26 @@ void AudioServer::_mix_step() {
}
//process effects
- for (int j = 0; j < bus->effects.size(); j++) {
+ if (!bus->bypass) {
+ for (int j = 0; j < bus->effects.size(); j++) {
- if (!bus->effects[j].enabled)
- continue;
+ if (!bus->effects[j].enabled)
+ continue;
- for (int k = 0; k < bus->channels.size(); k++) {
+ for (int k = 0; k < bus->channels.size(); k++) {
- if (!bus->channels[k].active)
- continue;
- bus->channels[k].effect_instances[j]->process(bus->channels[k].buffer.ptr(), temp_buffer[k].ptr(), buffer_size);
- }
+ if (!bus->channels[k].active)
+ continue;
+ bus->channels[k].effect_instances[j]->process(bus->channels[k].buffer.ptr(), temp_buffer[k].ptr(), buffer_size);
+ }
- //swap buffers, so internal buffer always has the right data
- for (int k = 0; k < bus->channels.size(); k++) {
+ //swap buffers, so internal buffer always has the right data
+ for (int k = 0; k < bus->channels.size(); k++) {
- if (!buses[i]->channels[k].active)
- continue;
- SWAP(bus->channels[k].buffer, temp_buffer[k]);
+ if (!buses[i]->channels[k].active)
+ continue;
+ SWAP(bus->channels[k].buffer, temp_buffer[k]);
+ }
}
}
@@ -237,7 +268,24 @@ void AudioServer::_mix_step() {
AudioFrame *buf = bus->channels[k].buffer.ptr();
AudioFrame peak = AudioFrame(0, 0);
+
+ 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
for (uint32_t j = 0; j < buffer_size; j++) {
+
+ buf[j] *= volume;
+
float l = ABS(buf[j].l);
if (l > peak.l) {
peak.l = l;
diff --git a/servers/audio_server.h b/servers/audio_server.h
index caa07891f7..c92ff6d3a0 100644
--- a/servers/audio_server.h
+++ b/servers/audio_server.h
@@ -125,6 +125,8 @@ private:
bool mute;
bool bypass;
+ bool soloed;
+
//Each channel is a stereo pair.
struct Channel {
bool used;