Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarAudio.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2024-03-25 01:57:55 +1100
committerKae <80987908+Novaenia@users.noreply.github.com>2024-03-25 01:57:55 +1100
commit6b8c4729787daa0c584447f9014bf32320d82789 (patch)
treed450f79ef6757ea96c69a5a4b5cda2d90f37d383 /source/core/StarAudio.cpp
parent5da4b1a4e3493427567583c90c4cbe03c5d3979c (diff)
nicer volume sliders
Diffstat (limited to 'source/core/StarAudio.cpp')
-rw-r--r--source/core/StarAudio.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/source/core/StarAudio.cpp b/source/core/StarAudio.cpp
index 4f07d05..2dfdaee 100644
--- a/source/core/StarAudio.cpp
+++ b/source/core/StarAudio.cpp
@@ -13,6 +13,26 @@
namespace Star {
+float const DefaultPerceptualRangeDb = 40.f;
+float const DefaultPerceptualBoostRangeDb = 6.f;
+// https://github.com/discord/perceptual
+float perceptualToAmplitude(float perceptual, float normalizedMax, float range, float boostRange) {
+ if (perceptual == 0.f) return 0.f;
+ float dB = perceptual > normalizedMax
+ ? ((perceptual - normalizedMax) / normalizedMax) * boostRange
+ : (perceptual / normalizedMax) * range - range;
+ return normalizedMax * pow(10.f, dB / 20.f);
+}
+
+float amplitudeToPerceptual(float amp, float normalizedMax, float range, float boostRange) {
+ if (amp == 0.f) return 0.f;
+ float const dB = 20.f * log10(amp / normalizedMax);
+ float perceptual = dB > 0.f
+ ? dB / boostRange + 1
+ : (range + dB) / range;
+ return normalizedMax * perceptual;
+}
+
namespace {
struct WaveData {
ByteArrayPtr byteArray;