ref: 5e7f02de2c55164d8584362ad384b2d72d1cd62a
parent: 908958cad5fe507219d770cd5ebf95807e826886
author: Jean-Marc Valin <[email protected]>
date: Sun Aug 8 05:48:22 EDT 2010
Moving intra decision to quant_coarse_energy()
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -619,7 +619,6 @@
VARDECL(int, offsets);
VARDECL(int, fine_priority);
VARDECL(int, tf_res);
- int intra_ener = 0;
int shortBlocks=0;
int isTransient=0;
int transient_time, transient_time_quant;
@@ -630,7 +629,6 @@
int mdct_weight_pos=0;
int LM, M;
int tf_select;
- celt_word16 max_decay;
int nbFilledBytes, nbAvailableBytes;
int effEnd;
SAVE_STACK;
@@ -795,28 +793,15 @@
}
ALLOC(tf_res, st->mode->nbEBands, int);
+ /* Needs to be before coarse energy quantization because otherwise the energy gets modified */
tf_select = tf_analysis(bandLogE, st->oldBandE, effEnd, C, isTransient, tf_res, nbAvailableBytes);
for (i=effEnd;i<st->end;i++)
tf_res[i] = tf_res[effEnd-1];
- /* Don't use intra energy when we're operating at low bit-rate */
- intra_ener = st->force_intra || (st->delayedIntra && nbAvailableBytes > st->end);
- if (shortBlocks || intra_decision(bandLogE, st->oldBandE, st->start, effEnd, st->mode->nbEBands, C))
- st->delayedIntra = 1;
- else
- st->delayedIntra = 0;
-
- /* Encode the global flags using a simple probability model
- (first symbols in the stream) */
- ec_enc_bit_prob(enc, intra_ener, 8192);
ALLOC(error, C*st->mode->nbEBands, celt_word16);
-
-#ifdef FIXED_POINT
- max_decay = MIN32(QCONST16(16,DB_SHIFT), SHL32(EXTEND32(nbAvailableBytes),DB_SHIFT-3));
-#else
- max_decay = MIN32(16.f, .125f*nbAvailableBytes);
-#endif
- quant_coarse_energy(st->mode, st->start, st->end, bandLogE, st->oldBandE, nbCompressedBytes*8, intra_ener, st->mode->prob, error, enc, C, LM, max_decay);
+ quant_coarse_energy(st->mode, st->start, st->end, effEnd, bandLogE,
+ st->oldBandE, nbCompressedBytes*8, st->mode->prob,
+ error, enc, C, LM, nbAvailableBytes, st->force_intra, &st->delayedIntra);
ec_enc_bit_prob(enc, shortBlocks!=0, 8192);
--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -66,7 +66,7 @@
static const celt_word16 pred_coef[4] = {29440/32768., 26112/32768., 21248/32768., 16384/32768.};
#endif
-int intra_decision(celt_word16 *eBands, celt_word16 *oldEBands, int start, int end, int len, int C)
+static int intra_decision(const celt_word16 *eBands, celt_word16 *oldEBands, int start, int end, int len, int C)
{
int c, i;
celt_word32 dist = 0;
@@ -106,7 +106,10 @@
celt_free(freq);
}
-void quant_coarse_energy(const CELTMode *m, int start, int end, const celt_word16 *eBands, celt_word16 *oldEBands, int budget, int intra, int *prob, celt_word16 *error, ec_enc *enc, int _C, int LM, celt_word16 max_decay)
+void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd,
+ const celt_word16 *eBands, celt_word16 *oldEBands, int budget,
+ int *prob, celt_word16 *error, ec_enc *enc, int _C, int LM,
+ int nbAvailableBytes, int force_intra, int *delayedIntra)
{
int i, c;
celt_word32 prev[2] = {0,0};
@@ -113,6 +116,24 @@
celt_word16 coef;
celt_word16 beta;
const int C = CHANNELS(_C);
+ int intra;
+ celt_word16 max_decay;
+
+ intra = force_intra || (*delayedIntra && nbAvailableBytes > end);
+ if (/*shortBlocks || */intra_decision(eBands, oldEBands, start, effEnd, m->nbEBands, C))
+ *delayedIntra = 1;
+ else
+ *delayedIntra = 0;
+
+ /* Encode the global flags using a simple probability model
+ (first symbols in the stream) */
+ ec_enc_bit_prob(enc, intra, 8192);
+
+#ifdef FIXED_POINT
+ max_decay = MIN32(QCONST16(16,DB_SHIFT), SHL32(EXTEND32(nbAvailableBytes),DB_SHIFT-3));
+#else
+ max_decay = MIN32(16.f, .125f*nbAvailableBytes);
+#endif
coef = pred_coef[LM];
--- a/libcelt/quant_bands.h
+++ b/libcelt/quant_bands.h
@@ -48,9 +48,10 @@
int *quant_prob_alloc(const CELTMode *m);
void quant_prob_free(int *freq);
-int intra_decision(celt_word16 *eBands, celt_word16 *oldEBands, int start, int end, int len, int C);
-
-void quant_coarse_energy(const CELTMode *m, int start, int end, const celt_word16 *eBands, celt_word16 *oldEBands, int budget, int intra, int *prob, celt_word16 *error, ec_enc *enc, int _C, int LM, celt_word16 max_decay);
+void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd,
+ const celt_word16 *eBands, celt_word16 *oldEBands, int budget,
+ int *prob, celt_word16 *error, ec_enc *enc, int _C, int LM,
+ int nbAvailableBytes, int force_intra, int *delayedIntra);
void quant_fine_energy(const CELTMode *m, int start, int end, celt_ener *eBands, celt_word16 *oldEBands, celt_word16 *error, int *fine_quant, ec_enc *enc, int _C);