Index: webrtc/modules/audio_processing/agc/legacy/digital_agc.c |
diff --git a/webrtc/modules/audio_processing/agc/legacy/digital_agc.c b/webrtc/modules/audio_processing/agc/legacy/digital_agc.c |
index 2ca967a4aae1a0d0a00758b4861a4838b1d11d46..8ad91278b0840e57a9ded287ef517e51f1d9fd25 100644 |
--- a/webrtc/modules/audio_processing/agc/legacy/digital_agc.c |
+++ b/webrtc/modules/audio_processing/agc/legacy/digital_agc.c |
@@ -187,14 +187,12 @@ int32_t WebRtcAgc_CalculateGainTable(int32_t* gainTable, // Q16 |
numFIX -= (int32_t)logApprox * diffGain; // Q14 |
// Calculate ratio |
- // Shift |numFIX| as much as possible. |
- // Ensure we avoid wrap-around in |den| as well. |
- if (numFIX > (den >> 8)) // |den| is Q8. |
minyue-webrtc
2016/05/21 12:33:37
Two problems were with this part
1. if |numFIX| i
|
- { |
- zeros = WebRtcSpl_NormW32(numFIX); |
- } else { |
- zeros = WebRtcSpl_NormW32(den) + 8; |
- } |
+ // 1) Shift |numFIX| as much as possible. Since we later add |den| / 2 to |
+ // |numFIX| before dividing |den| to round the ratio, we use |numFIX| *2 to |
+ // calculate the bit for shifting. |
+ // 2) Ensure we avoid wrap-around in |den| as well. |
+ zeros = WEBRTC_SPL_MIN(WebRtcSpl_NormW32(numFIX * 2), |
peah-webrtc
2016/05/23 04:59:37
The norm computation is on some platforms fairly c
peah-webrtc
2016/05/23 04:59:37
How do you know that numFIX * 2 does not overflow?
minyue-webrtc
2016/05/23 07:40:48
Good question, after a second thought, I see that
|
+ WebRtcSpl_NormW32(den) + 8); |
numFIX *= 1 << zeros; // Q(14+zeros) |
// Shift den so we end up in Qy1 |