fix: reduce AGC aggressiveness to prevent noise amplification
Lower maxGain from 8x to 4x (12dB) and target level from 18% to 12%. The previous 8x gain would amplify quiet noise floors by 18dB, transforming room tone and electrical hum into audible static. The compression threshold is raised from 70% to 85% with a gentler 2:1 ratio instead of 3:1, reducing pumping distortion. The soft limiter threshold is relaxed from 0.90 to 0.95 with a 0.2 knee instead of 0.1, providing more headroom before limiting engages. These changes reduce the distortion and unnatural 'processed' sound that other users would hear from barnard clients.
This commit is contained in:
committed by
Brandon McGinty
parent
5c1cd69d65
commit
1bdf15e8e1
+11
-11
@@ -21,16 +21,16 @@ type AGC struct {
|
|||||||
// NewAGC creates a new AGC processor with sensible defaults for voice
|
// NewAGC creates a new AGC processor with sensible defaults for voice
|
||||||
func NewAGC() *AGC {
|
func NewAGC() *AGC {
|
||||||
return &AGC{
|
return &AGC{
|
||||||
targetLevel: 0.18, // Target 18% of max amplitude (balanced level)
|
targetLevel: 0.12, // Target 12% of max amplitude (conservative level)
|
||||||
maxGain: 8.0, // Maximum 8x gain (about 18dB)
|
maxGain: 4.0, // Maximum 4x gain (about 12dB)
|
||||||
minGain: 0.1, // Minimum 0.1x gain (-20dB)
|
minGain: 0.25, // Minimum 0.25x gain (-12dB)
|
||||||
attackTime: 0.005, // Fast attack (5ms)
|
attackTime: 0.008, // Fast attack (8ms)
|
||||||
releaseTime: 0.1, // Slower release (100ms)
|
releaseTime: 0.15, // Slower release (150ms)
|
||||||
currentGain: 1.0, // Start with unity gain
|
currentGain: 1.0, // Start with unity gain
|
||||||
envelope: 0.0, // Start with zero envelope
|
envelope: 0.0, // Start with zero envelope
|
||||||
enabled: true, // Enable by default
|
enabled: true, // Enable by default
|
||||||
compThreshold: 0.7, // Compress signals above 70%
|
compThreshold: 0.85, // Compress signals above 85%
|
||||||
compRatio: 3.0, // 3:1 compression ratio
|
compRatio: 2.0, // 2:1 compression ratio (gentler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,10 +106,10 @@ func (agc *AGC) ProcessSamples(samples []int16) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Soft limiting to prevent clipping
|
// Soft limiting to prevent clipping
|
||||||
if processed > 0.90 {
|
if processed > 0.95 {
|
||||||
processed = 0.90 + (processed-0.90)*0.1
|
processed = 0.95 + (processed-0.95)*0.2
|
||||||
} else if processed < -0.90 {
|
} else if processed < -0.95 {
|
||||||
processed = -0.90 + (processed+0.90)*0.1
|
processed = -0.95 + (processed+0.95)*0.2
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert back to int16
|
// Convert back to int16
|
||||||
|
|||||||
Reference in New Issue
Block a user