ref: 7c673cfcdc18422fdf65eff4c70cde3b7c9df876
parent: 53454f4910d6b580a89c9d7fc03036af24627b2c
author: Gregory Maxwell <[email protected]>
date: Sat Dec 18 21:26:56 EST 2010
Fix for the allocation going negative. (bits[j] >= 0 assert) The modeline-bisection and interpolator have used different criteria for the minimum coding threshold since the introduction of the "backwards done" in 405e6a99. This meant that a lower modeline could be selected which the interpolator was never able to get under the maximum allocation. This patch makes the modeline selection search use the same criteria as the interpolator.
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -403,9 +403,10 @@
hi = m->nbAllocVectors - 2;
do
{
+ int done = 0;
int psum = 0;
int mid = (lo+hi) >> 1;
- for (j=start;j<end;j++)
+ for (j=end;j-->start;)
{
int N = m->eBands[j+1]-m->eBands[j];
bits1[j] = C*N*m->allocVectors[mid*len+j]<<LM>>2;
@@ -412,14 +413,16 @@
if (bits1[j] > 0)
bits1[j] = IMAX(0, bits1[j] + trim_offset[j]);
bits1[j] += offsets[j];
- if (bits1[j] >= thresh[j])
+ if (bits1[j] >= thresh[j] || done)
+ {
+ done = 1;
+ /* Don't allocate more than we can actually use */
psum += IMIN(bits1[j], 64*C<<BITRES<<LM);
- else if (bits1[j] >= C<<BITRES)
- psum += C<<BITRES;
-
- /*printf ("%d ", bits[j]);*/
+ } else {
+ if (bits1[j] >= C<<BITRES)
+ psum += C<<BITRES;
+ }
}
- /*printf ("\n");*/
if (psum > total)
hi = mid - 1;
else