perf(audio): adjust audio processing presets and limiters

This commit is contained in:
2026-04-06 15:14:01 +02:00
parent 99499ad174
commit bc38742eae
3 changed files with 30 additions and 9 deletions
+25 -4
View File
@@ -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<count;i++) sumSq += buffer[i]*buffer[i];
float rms = sqrtf(sumSq / float(count));
if(rms > 0.8f){
float scale = 0.8f / rms;
for(int i=0;i<count;i++) buffer[i] *= scale;
}
}
// Main processing function - heavily optimized
extern "C" {
@@ -468,6 +486,9 @@ JNIEXPORT void JNICALL Java_com_michatec_radio_helpers_NativeAudioProcessor_proc
if (gBassBoostEnabled) {
gBassL.processNEON(gLeftBuf.data(), numFrames);
gBassR.processNEON(gRightBuf.data(), numFrames);
applyRMSLimit(gLeftBuf.data(), numFrames);
applyRMSLimit(gRightBuf.data(), numFrames);
}
// Reverb
@@ -75,17 +75,17 @@ class NativeAudioProcessor : BaseAudioProcessor() {
// ===== Presets =====
fun setPresetRock() {
enableDrc(true)
setReverb(0.2f)
setReverb(0.10f)
setWidth(1.1f)
setEqAll(floatArrayOf(2f, 1f, 0f, -1f, -1f, 0f, 1f, 2f, 2f, 3f))
enableBassBoost(0.8f)
enableBassBoost(0.6f)
}
fun setPresetPop() {
enableDrc(true)
setReverb(0.15f)
setWidth(1.05f)
setEqAll(floatArrayOf(1f, 1f, 0f, 0f, 0f, 0f, 1f, 2f, 2f, 1f))
setEqAll(floatArrayOf(0f, 1f, 1f, 1f, 0f, 0f, 1f, 2f, 2f, 1f))
enableBassBoost(0.5f)
}
@@ -257,13 +257,13 @@ object PreferencesHelper {
/* Loads Bass Boost gain */
fun loadBassBoost(): Float {
return if (sharedPreferences.getBoolean(Keys.PREF_BASS_BOOST, false)) 0.6f else 0.0f
return if (sharedPreferences.getBoolean(Keys.PREF_BASS_BOOST, false)) 0.4f else 0.0f
}
/* Loads Reverb mix */
fun loadReverb(): Float {
return if (sharedPreferences.getBoolean(Keys.PREF_REVERB, false)) 0.3f else 0.0f
return if (sharedPreferences.getBoolean(Keys.PREF_REVERB, false)) 0.2f else 0.0f
}