From bc38742eae830442b5dd286ebb56830de56e3755 Mon Sep 17 00:00:00 2001 From: Michatec Date: Mon, 6 Apr 2026 15:14:01 +0200 Subject: [PATCH] perf(audio): adjust audio processing presets and limiters --- app/src/main/cpp/radio.cpp | 29 ++++++++++++++++--- .../radio/helpers/NativeAudioProcessor.kt | 6 ++-- .../radio/helpers/PreferencesHelper.kt | 4 +-- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/app/src/main/cpp/radio.cpp b/app/src/main/cpp/radio.cpp index 5bbe574..cc551d2 100644 --- a/app/src/main/cpp/radio.cpp +++ b/app/src/main/cpp/radio.cpp @@ -110,8 +110,9 @@ struct alignas(16) BassFilter { float y = x * a0 + z1; z1 = x * a1 + z2 - b1 * y + DENORMAL_OFFSET; z2 = x * a2 - b2 * y; - if(y>1.2f) y=1.2f; - else if(y<-1.2f) y=-1.2f; + y = bassSafeClip(y); + if(y > 1.2f) y = 1.2f; + else if(y < -1.2f) y = -1.2f; return y; } @@ -139,6 +140,13 @@ struct alignas(16) BassFilter { #endif } + static inline float bassSafeClip(float x) { + const float maxGain = 1.0f; + if (x > maxGain) return maxGain - (maxGain - x) * 0.5f; + if (x < -maxGain) return -maxGain - (-maxGain - x) * 0.5f; + return x; + } + void setLowShelf(float sr,float f,float g,float q){ active=std::abs(g)>0.01f; if(!active) return; @@ -232,8 +240,8 @@ class CompressorOptimized { public: float threshold = 0.3f; float ratio = 4.0f; - float attack = 0.01f; - float release = 0.2f; + float attack = 0.08f; + float release = 0.8f; float sampleRate = 44100.0f; private: @@ -385,6 +393,16 @@ inline void applyAutoGain(float* buffer, int count){ } } +inline void applyRMSLimit(float* buffer, int count){ + float sumSq = 0.0f; + for(int i=0;i 0.8f){ + float scale = 0.8f / rms; + for(int i=0;i