From 04dd37f58f7d556f807a9f3accfcc342c8e7a60b Mon Sep 17 00:00:00 2001 From: Alex P Date: Mon, 6 Oct 2025 22:23:23 +0300 Subject: [PATCH] fix: Add noise gate to prevent amplifying silence artifacts Add noise gate threshold at peak > 256 (-42dB) to prevent dynamic gain from amplifying quantization noise and hardware noise floor. This fixes crackling, buzzing, and static-like noise when HDMI audio is at very low volume or during silence. Without the gate, signals below -42dB (peak < 256) would get 8x gain applied, amplifying noise floor to audible levels. Now these signals pass through unmodified, eliminating the artifacts. --- internal/audio/c/audio.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/audio/c/audio.c b/internal/audio/c/audio.c index 32db0b6b..a3ce3a95 100644 --- a/internal/audio/c/audio.c +++ b/internal/audio/c/audio.c @@ -496,11 +496,12 @@ retry_read: if (abs_val > peak) peak = abs_val; } - // Apply gain if signal is weak (below -18dB = 4096) for best quality + // Apply gain if signal is weak (below -18dB = 4096) but above noise floor + // Noise gate: only apply gain if peak > 256 (below this is likely just noise) // Target: boost to ~50% of range (16384) to improve SNR - if (peak > 0 && peak < 4096) { + if (peak > 256 && peak < 4096) { float gain = 16384.0f / peak; - if (gain > 8.0f) gain = 8.0f; // Max 18dB boost for best quality + if (gain > 8.0f) gain = 8.0f; // Max 18dB boost // Apply gain with NEON and saturation float32x4_t vgain = vdupq_n_f32(gain);