Prevent the SILK counter from overflowing after 2 years and 9 months
or "just" 1 year and 4 months for 10-ms frames.
The overflow can eventually cause a divide-by-zero when counter == -16
Thanks to Dmitry Malinin for reporting the bug.
diff --git a/silk/VAD.c b/silk/VAD.c
index 541e505..d0cda52 100644
--- a/silk/VAD.c
+++ b/silk/VAD.c
@@ -312,6 +312,8 @@
/* Initially faster smoothing */
if( psSilk_VAD->counter < 1000 ) { /* 1000 = 20 sec */
min_coef = silk_DIV32_16( silk_int16_MAX, silk_RSHIFT( psSilk_VAD->counter, 4 ) + 1 );
+ /* Increment frame counter */
+ psSilk_VAD->counter++;
} else {
min_coef = 0;
}
@@ -355,7 +357,4 @@
/* Store as part of state */
psSilk_VAD->NL[ k ] = nl;
}
-
- /* Increment frame counter */
- psSilk_VAD->counter++;
}