Reworked the allocation trim to be absolute (in bits/sample) rather relative
Also making use of alloc_trim_analysis() again because the effect of inter-channel correlation on the bitstream is really in terms of absolute number of bits/samples.
This commit is contained in:
parent
fd54a99e2d
commit
c40addcb04
2 changed files with 37 additions and 21 deletions
|
@ -54,7 +54,6 @@
|
||||||
#include "plc.h"
|
#include "plc.h"
|
||||||
|
|
||||||
static const int trim_cdf[7] = {0, 4, 10, 23, 119, 125, 128};
|
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
|
/** Encoder state
|
||||||
@brief Encoder state
|
@brief Encoder state
|
||||||
|
@ -569,12 +568,12 @@ static int alloc_trim_analysis(const CELTMode *m, const celt_norm *X,
|
||||||
}
|
}
|
||||||
sum = MULT16_16_Q15(QCONST16(1.f/8, 15), sum);
|
sum = MULT16_16_Q15(QCONST16(1.f/8, 15), sum);
|
||||||
/*printf ("%f\n", sum);*/
|
/*printf ("%f\n", sum);*/
|
||||||
if (sum > QCONST16(.95,10))
|
if (sum > QCONST16(.995,10))
|
||||||
trim_index-=3;
|
trim_index-=3;
|
||||||
else if (sum > QCONST16(.75,10))
|
else if (sum > QCONST16(.92,10))
|
||||||
trim_index-=2;
|
trim_index-=2;
|
||||||
else if (sum > QCONST16(.5,10))
|
else if (sum > QCONST16(.75,10))
|
||||||
trim_index--;
|
trim_index-=1;
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
float diff=0;
|
float diff=0;
|
||||||
|
@ -788,13 +787,8 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, c
|
||||||
}
|
}
|
||||||
offsets[i] *= (6<<BITRES);
|
offsets[i] *= (6<<BITRES);
|
||||||
}
|
}
|
||||||
{
|
alloc_trim = alloc_trim_analysis(st->mode, X, bandLogE, st->mode->nbEBands, LM, C, N);
|
||||||
int trim_index;
|
ec_encode_bin(enc, trim_cdf[alloc_trim], trim_cdf[alloc_trim+1], 7);
|
||||||
/*trim_index = alloc_trim_analysis(st->mode, X, bandLogE, st->mode->nbEBands, LM, C, N);*/
|
|
||||||
trim_index = 3;
|
|
||||||
alloc_trim = trim_coef[trim_index];
|
|
||||||
ec_encode_bin(enc, trim_cdf[trim_index], trim_cdf[trim_index+1], 7);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Variable bitrate */
|
/* Variable bitrate */
|
||||||
if (st->vbr_rate_norm>0)
|
if (st->vbr_rate_norm>0)
|
||||||
|
@ -1529,12 +1523,11 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
|
||||||
ALLOC(fine_quant, st->mode->nbEBands, int);
|
ALLOC(fine_quant, st->mode->nbEBands, int);
|
||||||
{
|
{
|
||||||
int fl;
|
int fl;
|
||||||
int trim_index=0;
|
alloc_trim = 0;
|
||||||
fl = ec_decode_bin(dec, 7);
|
fl = ec_decode_bin(dec, 7);
|
||||||
while (trim_cdf[trim_index+1] <= fl)
|
while (trim_cdf[alloc_trim+1] <= fl)
|
||||||
trim_index++;
|
alloc_trim++;
|
||||||
ec_dec_update(dec, trim_cdf[trim_index], trim_cdf[trim_index+1], 128);
|
ec_dec_update(dec, trim_cdf[alloc_trim], trim_cdf[alloc_trim+1], 128);
|
||||||
alloc_trim = trim_coef[trim_index];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bits = len*8 - ec_dec_tell(dec, 0) - 1;
|
bits = len*8 - ec_dec_tell(dec, 0) - 1;
|
||||||
|
|
|
@ -268,11 +268,21 @@ int compute_allocation(const CELTMode *m, int start, int end, int *offsets, int
|
||||||
int codedBands;
|
int codedBands;
|
||||||
VARDECL(int, bits1);
|
VARDECL(int, bits1);
|
||||||
VARDECL(int, bits2);
|
VARDECL(int, bits2);
|
||||||
|
VARDECL(int, thresh);
|
||||||
|
VARDECL(int, trim_offset);
|
||||||
SAVE_STACK;
|
SAVE_STACK;
|
||||||
|
|
||||||
len = m->nbEBands;
|
len = m->nbEBands;
|
||||||
ALLOC(bits1, len, int);
|
ALLOC(bits1, len, int);
|
||||||
ALLOC(bits2, len, int);
|
ALLOC(bits2, len, int);
|
||||||
|
ALLOC(thresh, len, int);
|
||||||
|
ALLOC(trim_offset, len, int);
|
||||||
|
|
||||||
|
for (j=start;j<end;j++)
|
||||||
|
thresh[j] = 3*(C*(m->eBands[j+1]-m->eBands[j])<<LM<<BITRES)>>3;
|
||||||
|
for (j=start;j<end;j++)
|
||||||
|
trim_offset[j] = C*(m->eBands[j+1]-m->eBands[j])*(alloc_trim-3)*(m->nbEBands-j-1)
|
||||||
|
<<(LM+BITRES)>>5;
|
||||||
|
|
||||||
lo = 0;
|
lo = 0;
|
||||||
hi = m->nbAllocVectors - 1;
|
hi = m->nbAllocVectors - 1;
|
||||||
|
@ -283,8 +293,17 @@ int compute_allocation(const CELTMode *m, int start, int end, int *offsets, int
|
||||||
for (j=start;j<end;j++)
|
for (j=start;j<end;j++)
|
||||||
{
|
{
|
||||||
int N = m->eBands[j+1]-m->eBands[j];
|
int N = m->eBands[j+1]-m->eBands[j];
|
||||||
bits1[j] = ((alloc_trim*C*N*m->allocVectors[mid*len+j]<<LM>>5) + offsets[j]);
|
bits1[j] = C*N*m->allocVectors[mid*len+j]<<LM>>2;
|
||||||
psum += bits1[j];
|
if (bits1[j] > 0)
|
||||||
|
bits1[j] += trim_offset[j];
|
||||||
|
if (bits1[j] < 0)
|
||||||
|
bits1[j] = 0;
|
||||||
|
bits1[j] += offsets[j];
|
||||||
|
if (bits1[j] >= thresh[j])
|
||||||
|
psum += bits1[j];
|
||||||
|
else if (bits1[j] >= 1<<BITRES)
|
||||||
|
psum += 1<<BITRES;
|
||||||
|
|
||||||
/*printf ("%d ", bits[j]);*/
|
/*printf ("%d ", bits[j]);*/
|
||||||
}
|
}
|
||||||
/*printf ("\n");*/
|
/*printf ("\n");*/
|
||||||
|
@ -298,8 +317,12 @@ int compute_allocation(const CELTMode *m, int start, int end, int *offsets, int
|
||||||
for (j=start;j<end;j++)
|
for (j=start;j<end;j++)
|
||||||
{
|
{
|
||||||
int N = m->eBands[j+1]-m->eBands[j];
|
int N = m->eBands[j+1]-m->eBands[j];
|
||||||
bits1[j] = (alloc_trim*C*N*m->allocVectors[lo*len+j]<<LM>>5);
|
bits1[j] = (C*N*m->allocVectors[lo*len+j]<<LM>>2);
|
||||||
bits2[j] = (alloc_trim*C*N*m->allocVectors[hi*len+j]<<LM>>5) - bits1[j];
|
bits2[j] = (C*N*m->allocVectors[hi*len+j]<<LM>>2) - bits1[j];
|
||||||
|
if (bits1[j] > 0)
|
||||||
|
bits1[j] += trim_offset[j];
|
||||||
|
if (bits1[j] < 0)
|
||||||
|
bits1[j] = 0;
|
||||||
bits1[j] += offsets[j];
|
bits1[j] += offsets[j];
|
||||||
}
|
}
|
||||||
codedBands = interp_bits2pulses(m, start, end, bits1, bits2, total, pulses, ebits, fine_priority, len, C, LM);
|
codedBands = interp_bits2pulses(m, start, end, bits1, bits2, total, pulses, ebits, fine_priority, len, C, LM);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue