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.
This commit is contained in:
Alex P 2025-10-06 22:23:23 +03:00
parent 5158c89103
commit 04dd37f58f
1 changed files with 4 additions and 3 deletions

View File

@ -496,11 +496,12 @@ retry_read:
if (abs_val > peak) peak = abs_val; 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 // 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; 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 // Apply gain with NEON and saturation
float32x4_t vgain = vdupq_n_f32(gain); float32x4_t vgain = vdupq_n_f32(gain);