ref: 9faf74088285e6b0b8a125ba606dece8c165f663
parent: a4badac92eb367218c74bbb92c89c632df1bc225
author: Jean-Marc Valin <[email protected]>
date: Sat Dec 4 05:27:22 EST 2010
Keeping the allocation of the intensity-codec bands Also some code to select between constrained and unconstrained VBR
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -925,6 +925,7 @@
ALLOC(lowband_scratch, M*(eBands[m->nbEBands]-eBands[m->nbEBands-1]), celt_norm);
norm = _norm;
norm2 = norm + M*eBands[m->nbEBands];
+#if 0
if (C==2)
{
int j;
@@ -949,7 +950,7 @@
}
}
}
-
+#endif
if (encode)
seed = ((ec_enc*)ec)->rng;
else
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -71,6 +71,7 @@
int start, end;
celt_int32 vbr_rate_norm; /* Target number of 8th bits per frame */
+ int constrained_vbr; /* If zero, VBR can do whatever it likes with the rate */
/* Everything beyond this point gets cleared on a reset */
#define ENCODER_RESET_START frame_max
@@ -142,6 +143,7 @@
st->start = 0;
st->end = st->mode->effEBands;
+ st->constrained_vbr = 1;
st->vbr_rate_norm = 0;
st->vbr_offset = 0;
@@ -1006,7 +1008,10 @@
/* Computes the max bit-rate allowed in VBR more to avoid violating the target rate and buffering */
vbr_bound = vbr_rate;
- max_allowed = IMIN(vbr_rate+vbr_bound-st->vbr_reservoir>>(BITRES+3),nbAvailableBytes);
+ if (st->constrained_vbr)
+ max_allowed = IMIN(vbr_rate+vbr_bound-st->vbr_reservoir>>(BITRES+3),nbAvailableBytes);
+ else
+ max_allowed = nbAvailableBytes;
min_allowed = (tell>>(BITRES+3)) + 2 - nbFilledBytes;
/* In VBR mode the frame size must not be reduced so much that it would result in the encoder running out of bits */
@@ -1021,7 +1026,8 @@
} else
alpha = QCONST16(.001f,15);
/* How many bits have we used in excess of what we're allowed */
- st->vbr_reservoir += target - vbr_rate;
+ if (st->constrained_vbr)
+ st->vbr_reservoir += target - vbr_rate;
/*printf ("%d\n", st->vbr_reservoir);*/
/* Compute the offset we need to apply in order to reach the target */
@@ -1030,7 +1036,7 @@
/*printf ("%d\n", st->vbr_drift);*/
/* We could use any multiple of vbr_rate as bound (depending on the delay) */
- if (st->vbr_reservoir < 0)
+ if (st->constrained_vbr && st->vbr_reservoir < 0)
{
/* We're under the min value -- increase rate */
int adjust = (-st->vbr_reservoir)/(8<<BITRES);