ref: 2799c29792ebaa7c01e22457013000fecb18169e
parent: cb8f366af6d80de6815e3375e4d17aee19366607
author: Timothy B. Terriberry <[email protected]>
date: Tue Feb 1 07:53:05 EST 2011
Add assertions for band size restrictions. The way folding is implemented requires two restrictions: 1. The last band must be the largest (so we can use its size to allocate a temporary buffer to handle interleaving/TF changes). 2. No band can be larger than twice the size of the previous band (so that once we have enough data to start folding, we will always have enough data to fold). Mode creation makes a heuristic attempt to satisfy these conditions, but nothing actually guarantees it. This adds some asserts to check them during mode creation. They current pass for all supported custom modes.
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -196,6 +196,14 @@
eBands[++j]=eBands[i+1];
*nbEBands=j;
+ for (i=1;i<*nbEBands;i++)
+ {
+ /* Every band must be smaller than the last band. */
+ celt_assert(eBands[i]-eBands[i-1]<=eBands[*nbEBands]-eBands[*nbEBands-1]);
+ /* Each band must be no larger than twice the size of the previous one. */
+ celt_assert(eBands[i+1]-eBands[i]<=2*(eBands[i]-eBands[i-1]));
+ }
+
/*for (i=0;i<=*nbEBands+1;i++)
printf ("%d ", eBands[i]);
printf ("\n");