Fixes some cases where MIN/MAX macros result in duplicated function calls

Also enforces an upper bound of 510 kb/s even for frames that are
smaller than 20 ms. This reduces waste for high bitrate VBR.
This commit is contained in:
Jean-Marc Valin 2012-05-29 17:01:35 -04:00
parent d09dc7c7a2
commit 66ac10210c
3 changed files with 25 additions and 7 deletions

View file

@ -212,6 +212,7 @@ void anti_collapse(const CELTMode *m, celt_norm *X_, unsigned char *collapse_mas
int depth;
#ifdef FIXED_POINT
int shift;
opus_val32 thresh32;
#endif
N0 = m->eBands[i+1]-m->eBands[i];
@ -219,7 +220,8 @@ void anti_collapse(const CELTMode *m, celt_norm *X_, unsigned char *collapse_mas
depth = (1+pulses[i])/((m->eBands[i+1]-m->eBands[i])<<LM);
#ifdef FIXED_POINT
thresh = MULT16_32_Q15(QCONST16(0.5f, 15), MIN32(32767,SHR32(celt_exp2(-SHL16(depth, 10-BITRES)),1) ));
thresh32 = SHR32(celt_exp2(-SHL16(depth, 10-BITRES)),1);
thresh = MULT16_32_Q15(QCONST16(0.5f, 15), MIN32(32767,thresh32));
{
opus_val32 t;
t = N0<<LM;
@ -252,9 +254,12 @@ void anti_collapse(const CELTMode *m, celt_norm *X_, unsigned char *collapse_mas
#ifdef FIXED_POINT
if (Ediff < 16384)
r = 2*MIN16(16383,SHR32(celt_exp2(-EXTRACT16(Ediff)),1));
else
{
opus_val32 r32 = SHR32(celt_exp2(-EXTRACT16(Ediff)),1);
r = 2*MIN16(16383,r32);
} else {
r = 0;
}
if (LM==3)
r = MULT16_16_Q14(23170, MIN32(23169, r));
r = SHR16(MIN16(thresh, r),1);

View file

@ -1385,6 +1385,9 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f
opus_int32 min_allowed;
int lm_diff = st->mode->maxLM - LM;
/* Don't attempt to use more than 510 kb/s, even for frames smaller than 20 ms.
The CELT allocator will just not be able to use more than that anyway. */
nbCompressedBytes = IMIN(nbCompressedBytes,1275>>(3-LM));
target = vbr_rate + (st->vbr_offset>>lm_diff) - ((40*C+20)<<BITRES);
/* Shortblocks get a large boost in bitrate, but since they

View file

@ -111,10 +111,17 @@ void pitch_downsample(celt_sig * restrict x[], opus_val16 * restrict x_lp,
opus_val16 lpc[4], mem[4]={0,0,0,0};
#ifdef FIXED_POINT
int shift;
opus_val32 maxabs = MAX32(1, celt_maxabs32(x[0], len));
opus_val32 maxabs = celt_maxabs32(x[0], len);
if (C==2)
maxabs = MAX32(maxabs, celt_maxabs32(x[1], len));
shift = IMAX(0,celt_ilog2(maxabs)-10);
{
opus_val32 maxabs_1 = celt_maxabs32(x[1], len);
maxabs = MAX32(maxabs, maxabs_1);
}
if (maxabs<1)
maxabs=1;
shift = celt_ilog2(maxabs)-10;
if (shift<0)
shift=0;
if (C==2)
shift++;
#endif
@ -173,6 +180,7 @@ void pitch_search(const opus_val16 * restrict x_lp, opus_val16 * restrict y,
VARDECL(opus_val32, xcorr);
#ifdef FIXED_POINT
opus_val32 maxcorr=1;
opus_val16 xmax, ymax;
int shift=0;
#endif
int offset;
@ -194,7 +202,9 @@ void pitch_search(const opus_val16 * restrict x_lp, opus_val16 * restrict y,
y_lp4[j] = y[2*j];
#ifdef FIXED_POINT
shift = celt_ilog2(MAX16(1, MAX16(celt_maxabs16(x_lp4, len>>2), celt_maxabs16(y_lp4, lag>>2))))-11;
xmax = celt_maxabs16(x_lp4, len>>2);
ymax = celt_maxabs16(y_lp4, lag>>2);
shift = celt_ilog2(MAX16(1, MAX16(xmax, ymax)))-11;
if (shift>0)
{
for (j=0;j<len>>2;j++)