diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2021-02-03 10:05:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-03 10:05:34 +0100 |
commit | 3a3af0279b1ed7c3b40136cdd7db1f54e09b88e2 (patch) | |
tree | 4525b1babec36496d19b44f9ef6c2cb217956d3c | |
parent | 0f327f0d65384d635ca9137bd9c7983936027296 (diff) | |
parent | a2b3a73e2d0c2b9e9badeab28fef26565a9ec3f2 (diff) | |
download | redot-engine-3a3af0279b1ed7c3b40136cdd7db1f54e09b88e2.tar.gz |
Merge pull request #45658 from RandomShaper/fix_frozen_peak
Make audio bus channels' peak volume consistent
-rw-r--r-- | core/math/audio_frame.h | 3 | ||||
-rw-r--r-- | servers/audio_server.cpp | 3 | ||||
-rw-r--r-- | servers/audio_server.h | 2 |
3 files changed, 6 insertions, 2 deletions
diff --git a/core/math/audio_frame.h b/core/math/audio_frame.h index 5773da9211..a5616b8d79 100644 --- a/core/math/audio_frame.h +++ b/core/math/audio_frame.h @@ -47,6 +47,9 @@ static inline float undenormalise(volatile float f) { return (v.i & 0x7f800000) < 0x08000000 ? 0.0f : f; } +static const float AUDIO_PEAK_OFFSET = 0.0000000001f; +static const float AUDIO_MIN_PEAK_DB = -200.0f; // linear2db(AUDIO_PEAK_OFFSET) + struct AudioFrame { //left and right samples float l, r; diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp index d4f7876b4b..16c6a26595 100644 --- a/servers/audio_server.cpp +++ b/servers/audio_server.cpp @@ -401,6 +401,7 @@ void AudioServer::_mix_step() { for (int k = 0; k < bus->channels.size(); k++) { if (!bus->channels[k].active) { + bus->channels.write[k].peak_volume = AudioFrame(AUDIO_MIN_PEAK_DB, AUDIO_MIN_PEAK_DB); continue; } @@ -434,7 +435,7 @@ void AudioServer::_mix_step() { } } - bus->channels.write[k].peak_volume = AudioFrame(Math::linear2db(peak.l + 0.0000000001), Math::linear2db(peak.r + 0.0000000001)); + bus->channels.write[k].peak_volume = AudioFrame(Math::linear2db(peak.l + AUDIO_PEAK_OFFSET), Math::linear2db(peak.r + AUDIO_PEAK_OFFSET)); if (!bus->channels[k].used) { //see if any audio is contained, because channel was not used diff --git a/servers/audio_server.h b/servers/audio_server.h index 51fbc59851..a1a373e1ca 100644 --- a/servers/audio_server.h +++ b/servers/audio_server.h @@ -199,7 +199,7 @@ private: last_mix_with_audio = 0; used = false; active = false; - peak_volume = AudioFrame(0, 0); + peak_volume = AudioFrame(AUDIO_MIN_PEAK_DB, AUDIO_MIN_PEAK_DB); } }; |