ref: 63fb61f176463809c8ddc553a7501f10392f4719
parent: e8a373fdbd5930636eeb44dbe8a75eaa4934f29b
author: Jean-Marc Valin <[email protected]>
date: Thu Jan 20 17:52:55 EST 2011
Using previous range coder state for PRNG This provides more entropy and allows some more flexibility on the encoder side.
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -605,7 +605,7 @@
static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, celt_norm *Y,
int N, int b, int spread, int B, int intensity, int tf_change, celt_norm *lowband, int resynth, void *ec,
celt_int32 *remaining_bits, int LM, celt_norm *lowband_out, const celt_ener *bandE, int level,
- celt_int32 *seed, celt_word16 gain, celt_norm *lowband_scratch, int fill)
+ celt_uint32 *seed, celt_word16 gain, celt_norm *lowband_scratch, int fill)
{
int q;
int curr_bits;
@@ -992,9 +992,9 @@
/* Finally do the actual quantization */
if (encode)
- cm = alg_quant(X, N, K, spread, B, lowband, resynth, (ec_enc*)ec, seed, gain);
+ cm = alg_quant(X, N, K, spread, B, lowband, resynth, (ec_enc*)ec, gain);
else
- cm = alg_unquant(X, N, K, spread, B, lowband, (ec_dec*)ec, seed, gain);
+ cm = alg_unquant(X, N, K, spread, B, lowband, (ec_dec*)ec, gain);
} else {
/* If there's no pulse, fill the band anyway */
int j;
@@ -1086,7 +1086,7 @@
void quant_all_bands(int encode, const CELTMode *m, int start, int end,
celt_norm *_X, celt_norm *_Y, unsigned char *collapse_masks, const celt_ener *bandE, int *pulses,
int shortBlocks, int spread, int dual_stereo, int intensity, int *tf_res, int resynth,
- int total_bits, void *ec, int LM, int codedBands)
+ int total_bits, void *ec, int LM, int codedBands, ec_uint32 *seed)
{
int i;
celt_int32 balance;
@@ -1097,7 +1097,6 @@
VARDECL(celt_norm, lowband_scratch);
int B;
int M;
- celt_int32 seed;
int lowband_offset;
int update_lowband = 1;
int C = _Y != NULL ? 2 : 1;
@@ -1110,10 +1109,6 @@
norm = _norm;
norm2 = norm + M*eBands[m->nbEBands];
- if (encode)
- seed = ((ec_enc*)ec)->rng;
- else
- seed = ((ec_dec*)ec)->rng;
balance = 0;
lowband_offset = 0;
for (i=start;i<end;i++)
@@ -1201,16 +1196,16 @@
{
x_cm = quant_band(encode, m, i, X, NULL, N, b/2, spread, B, intensity, tf_change,
effective_lowband != -1 ? norm+effective_lowband : NULL, resynth, ec, &remaining_bits, LM,
- norm+M*eBands[i], bandE, 0, &seed, Q15ONE, lowband_scratch, x_cm);
+ norm+M*eBands[i], bandE, 0, seed, Q15ONE, lowband_scratch, x_cm);
y_cm = quant_band(encode, m, i, Y, NULL, N, b/2, spread, B, intensity, tf_change,
effective_lowband != -1 ? norm2+effective_lowband : NULL, resynth, ec, &remaining_bits, LM,
- norm2+M*eBands[i], bandE, 0, &seed, Q15ONE, lowband_scratch, y_cm);
+ norm2+M*eBands[i], bandE, 0, seed, Q15ONE, lowband_scratch, y_cm);
collapse_masks[i*2+0] = (unsigned char)(x_cm&(1<<B)-1);
collapse_masks[i*2+1] = (unsigned char)(y_cm&(1<<B)-1);
} else {
x_cm = quant_band(encode, m, i, X, Y, N, b, spread, B, intensity, tf_change,
effective_lowband != -1 ? norm+effective_lowband : NULL, resynth, ec, &remaining_bits, LM,
- norm+M*eBands[i], bandE, 0, &seed, Q15ONE, lowband_scratch, x_cm|y_cm);
+ norm+M*eBands[i], bandE, 0, seed, Q15ONE, lowband_scratch, x_cm|y_cm);
collapse_masks[i*C+1] = collapse_masks[i*C+0] = (unsigned char)(x_cm&(1<<B)-1);
}
balance += pulses[i] + tell;
--- a/libcelt/bands.h
+++ b/libcelt/bands.h
@@ -88,7 +88,7 @@
void quant_all_bands(int encode, const CELTMode *m, int start, int end,
celt_norm * X, celt_norm * Y, unsigned char *collapse_masks, const celt_ener *bandE, int *pulses,
int time_domain, int fold, int dual_stereo, int intensity, int *tf_res, int resynth,
- int total_bits, void *enc, int M, int codedBands);
+ int total_bits, void *enc, int M, int codedBands, ec_uint32 *seed);
void stereo_decision(const CELTMode *m, celt_norm * restrict X, int *stereo_mode, int len, int M);
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -81,6 +81,7 @@
#define ENCODER_RESET_START frame_max
celt_word32 frame_max;
+ ec_uint32 rng;
int spread_decision;
int delayedIntra;
int tonal_average;
@@ -1293,7 +1294,7 @@
ALLOC(collapse_masks, st->mode->nbEBands, unsigned char);
quant_all_bands(1, st->mode, st->start, st->end, X, C==2 ? X+N : NULL, collapse_masks,
bandE, pulses, shortBlocks, st->spread_decision, dual_stereo, intensity, tf_res, resynth,
- nbCompressedBytes*8, enc, LM, codedBands);
+ nbCompressedBytes*8, enc, LM, codedBands, &st->rng);
if (anti_collapse_rsv > 0)
{
@@ -1317,7 +1318,7 @@
if (anti_collapse_on)
{
anti_collapse(st->mode, X, collapse_masks, LM, C, N,
- st->start, st->end, oldBandE, oldLogE, oldLogE2, pulses, enc->rng);
+ st->start, st->end, oldBandE, oldLogE, oldLogE2, pulses, st->rng);
}
/* Synthesis */
@@ -1388,6 +1389,7 @@
st->consec_transient++;
else
st->consec_transient=0;
+ st->rng = enc->rng;
/* If there's any room left (can only happen for very high rates),
fill it with zeros */
@@ -1598,8 +1600,9 @@
int start, end;
/* Everything beyond this point gets cleared on a reset */
-#define DECODER_RESET_START last_pitch_index
+#define DECODER_RESET_START rng
+ ec_uint32 rng;
int last_pitch_index;
int loss_count;
int postfilter_period;
@@ -2079,7 +2082,7 @@
ALLOC(collapse_masks, st->mode->nbEBands, unsigned char);
quant_all_bands(0, st->mode, st->start, st->end, X, C==2 ? X+N : NULL, collapse_masks,
NULL, pulses, shortBlocks, spread_decision, dual_stereo, intensity, tf_res, 1,
- len*8, dec, LM, codedBands);
+ len*8, dec, LM, codedBands, &st->rng);
if (anti_collapse_rsv > 0)
{
@@ -2091,7 +2094,7 @@
if (anti_collapse_on)
anti_collapse(st->mode, X, collapse_masks, LM, C, N,
- st->start, st->end, oldBandE, oldLogE, oldLogE2, pulses, dec->rng);
+ st->start, st->end, oldBandE, oldLogE, oldLogE2, pulses, st->rng);
log2Amp(st->mode, st->start, st->end, bandE, oldBandE, C);
@@ -2151,6 +2154,7 @@
oldBandE[i]=0;
for (i=0;i<C*st->mode->nbEBands;i++)
oldLogE2[i] = oldLogE[i];
+ st->rng = dec->rng;
deemphasis(out_syn, pcm, N, C, st->mode->preemph, st->preemph_memD);
st->loss_count = 0;
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -176,7 +176,7 @@
}
unsigned alg_quant(celt_norm *X, int N, int K, int spread, int B, celt_norm *lowband,
- int resynth, ec_enc *enc, celt_int32 *seed, celt_word16 gain)
+ int resynth, ec_enc *enc, celt_word16 gain)
{
VARDECL(celt_norm, y);
VARDECL(int, iy);
@@ -340,7 +340,7 @@
/** Decode pulse vector and combine the result with the pitch vector to produce
the final normalised signal in the current band. */
unsigned alg_unquant(celt_norm *X, int N, int K, int spread, int B,
- celt_norm *lowband, ec_dec *dec, celt_int32 *seed, celt_word16 gain)
+ celt_norm *lowband, ec_dec *dec, celt_word16 gain)
{
int i;
celt_word32 Ryy;
--- a/libcelt/vq.h
+++ b/libcelt/vq.h
@@ -53,7 +53,7 @@
* @ret A mask indicating which blocks in the band received pulses
*/
unsigned alg_quant(celt_norm *X, int N, int K, int spread, int B, celt_norm *lowband,
- int resynth, ec_enc *enc, celt_int32 *seed, celt_word16 gain);
+ int resynth, ec_enc *enc, celt_word16 gain);
/** Algebraic pulse decoder
* @param x Decoded normalised spectrum (returned)
@@ -64,7 +64,7 @@
* @ret A mask indicating which blocks in the band received pulses
*/
unsigned alg_unquant(celt_norm *X, int N, int K, int spread, int B,
- celt_norm *lowband, ec_dec *dec, celt_int32 *seed, celt_word16 gain);
+ celt_norm *lowband, ec_dec *dec, celt_word16 gain);
void renormalise_vector(celt_norm *X, int N, celt_word16 gain);