ref: 6bf04627b09f63ce903fdaaee11754712b6e6c88
parent: 4a11daa233b2afad1770a42492ccc3dc96087a9a
author: Jean-Marc Valin <[email protected]>
date: Thu Sep 30 06:16:22 EDT 2010
Allowing to change the allocation dynamically. Uses a scaling factor that gets applied to the allocation matrix. Conflicts: libcelt/celt.c libcelt/rate.c libcelt/rate.h
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -65,6 +65,9 @@
0.8695045f, 0.9251086f, 0.9662361f, 0.9914865f};
#endif
+static const int trim_cdf[7] = {0, 4, 10, 23, 119, 125, 128};
+static const int trim_coef[6] = {4, 6, 7, 8, 10, 12};
+
/** Encoder state
@brief Encoder state
*/
@@ -895,8 +898,18 @@
offsets[i] *= (6<<BITRES);
}
bits = nbCompressedBytes*8 - ec_enc_tell(enc, 0) - 1;
- codedBands = compute_allocation(st->mode, st->start, st->end, offsets, bits, pulses, fine_quant, fine_priority, C, LM);
+ {
+ int alloc_trim;
+ int trim_index = 3;
+ /*if (isTransient)
+ trim_index = 2;
+ if (has_fold==0)
+ trim_index = 2;*/
+ alloc_trim = trim_coef[trim_index];
+ ec_encode_bin(enc, trim_cdf[trim_index], trim_cdf[trim_index+1], 7);
+ codedBands = compute_allocation(st->mode, st->start, st->end, offsets, alloc_trim, bits, pulses, fine_quant, fine_priority, C, LM);
+ }
quant_fine_energy(st->mode, st->start, st->end, bandE, oldBandE, error, fine_quant, enc, C);
#ifdef MEASURE_NORM_MSE
@@ -1580,7 +1593,16 @@
bits = len*8 - ec_dec_tell(dec, 0) - 1;
ALLOC(fine_quant, st->mode->nbEBands, int);
- codedBands = compute_allocation(st->mode, st->start, st->end, offsets, bits, pulses, fine_quant, fine_priority, C, LM);
+ {
+ int fl, alloc_trim;
+ int trim_index=0;
+ fl = ec_decode_bin(dec, 7);
+ while (trim_cdf[trim_index+1] <= fl)
+ trim_index++;
+ ec_dec_update(dec, trim_cdf[trim_index], trim_cdf[trim_index+1], 128);
+ alloc_trim = trim_coef[trim_index];
+ codedBands = compute_allocation(st->mode, st->start, st->end, offsets, alloc_trim, bits, pulses, fine_quant, fine_priority, C, LM);
+ }
/*bits = ec_dec_tell(dec, 0);
compute_fine_allocation(st->mode, fine_quant, (20*C+len*8/5-(ec_dec_tell(dec, 0)-bits))/C);*/
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -257,7 +257,8 @@
return codedBands;
}
-int compute_allocation(const CELTMode *m, int start, int end, int *offsets, int total, int *pulses, int *ebits, int *fine_priority, int _C, int LM)
+int compute_allocation(const CELTMode *m, int start, int end, int *offsets, int alloc_trim,
+ int total, int *pulses, int *ebits, int *fine_priority, int _C, int LM)
{
int lo, hi, len, j;
const int C = CHANNELS(_C);
@@ -279,7 +280,7 @@
for (j=start;j<end;j++)
{
int N = m->eBands[j+1]-m->eBands[j];
- bits1[j] = ((C*N*m->allocVectors[mid*len+j]<<LM>>2) + offsets[j]);
+ bits1[j] = ((alloc_trim*C*N*m->allocVectors[mid*len+j]<<LM>>5) + offsets[j]);
psum += bits1[j];
/*printf ("%d ", bits[j]);*/
}
@@ -294,8 +295,8 @@
for (j=start;j<end;j++)
{
int N = m->eBands[j+1]-m->eBands[j];
- bits1[j] = (C*N*m->allocVectors[lo*len+j]<<LM>>2);
- bits2[j] = (C*N*m->allocVectors[hi*len+j]<<LM>>2) - bits1[j];
+ bits1[j] = (alloc_trim*C*N*m->allocVectors[lo*len+j]<<LM>>5);
+ bits2[j] = (alloc_trim*C*N*m->allocVectors[hi*len+j]<<LM>>5) - bits1[j];
bits1[j] += offsets[j];
}
codedBands = interp_bits2pulses(m, start, end, bits1, bits2, total, pulses, ebits, fine_priority, len, C, LM);
--- a/libcelt/rate.h
+++ b/libcelt/rate.h
@@ -104,7 +104,8 @@
@param pulses Number of pulses per band (returned)
@return Total number of bits allocated
*/
-int compute_allocation(const CELTMode *m, int start, int end, int *offsets, int total, int *pulses, int *ebits, int *fine_priority, int _C, int LM);
+int compute_allocation(const CELTMode *m, int start, int end, int *offsets, int alloc_trim,
+ int total, int *pulses, int *ebits, int *fine_priority, int _C, int LM);
#endif