summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@jmvalin.ca>2012-05-29 17:01:35 -0400
committerJean-Marc Valin <jmvalin@jmvalin.ca>2012-05-30 14:04:51 -0400
commit66ac10210cbae160f225debe1a33c8ad50365a12 (patch)
tree0bcc4938903d60095b5407902c67b449faa46d9a
parentd09dc7c7a2108e7173c4e802ca868327b7a2cab2 (diff)
downloadopus-66ac10210cbae160f225debe1a33c8ad50365a12.tar.gz
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.
-rw-r--r--celt/bands.c11
-rw-r--r--celt/celt.c3
-rw-r--r--celt/pitch.c18
3 files changed, 25 insertions, 7 deletions
diff --git a/celt/bands.c b/celt/bands.c
index ebe04aee..b88513ab 100644
--- a/celt/bands.c
+++ b/celt/bands.c
@@ -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);
diff --git a/celt/celt.c b/celt/celt.c
index 7a4ce77b..1b147272 100644
--- a/celt/celt.c
+++ b/celt/celt.c
@@ -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
diff --git a/celt/pitch.c b/celt/pitch.c
index 37fec8a8..8e906878 100644
--- a/celt/pitch.c
+++ b/celt/pitch.c
@@ -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++)