Commit 1238137c authored by Yushin Cho's avatar Yushin Cho

Change PVQ's generic coder to use dyadic and ec_adapt adaptation

Change-Id: I23b035340ed16b85a12856256d3115f19700dfb3
parent 52168e9d
......@@ -83,22 +83,6 @@ void aom_cdf_adapt_q15(int val, uint16_t *cdf, int n, int *count, int rate) {
OD_ASSERT(cdf[n - 1] == 32768);
}
/** Initializes the cdfs and freq counts for a model.
*
* @param [out] model model being initialized
*/
void generic_model_init(generic_encoder *model) {
int i;
int j;
model->increment = 64;
for (i = 0; i < GENERIC_TABLES; i++) {
for (j = 0; j < 16; j++) {
/* Do flat initialization equivalent to a single symbol in each bin. */
model->cdf[i][j] = (j + 1) * model->increment;
}
}
}
/** Takes the base-2 log of E(x) in Q1.
*
* @param [in] ExQ16 expectation of x in Q16
......@@ -132,23 +116,7 @@ int log_ex(int ex_q16) {
* @param [in] integration integration period of ExQ16 (leaky average over
* 1<<integration samples)
*/
void generic_model_update(generic_encoder *model, int *ex_q16, int x, int xs,
int id, int integration) {
int i;
int xenc;
uint16_t *cdf;
cdf = model->cdf[id];
/* Renormalize if we cannot add increment */
if (cdf[15] + model->increment > 32767) {
for (i = 0; i < 16; i++) {
/* Second term ensures that the pdf is non-null */
cdf[i] = (cdf[i] >> 1) + i + 1;
}
}
/* Update freq count */
xenc = OD_MINI(15, xs);
/* This can be easily vectorized */
for (i = xenc; i < 16; i++) cdf[i] += model->increment;
void generic_model_update(int *ex_q16, int x, int integration) {
/* We could have saturated ExQ16 directly, but this is safe and simpler */
x = OD_MINI(x, 32767);
OD_IIR_DIADIC(*ex_q16, x << 16, integration);
......
......@@ -28,9 +28,7 @@
typedef struct {
/** cdf for multiple expectations of x */
uint16_t cdf[GENERIC_TABLES][16];
/** Frequency increment for learning the cdfs */
int increment;
uint16_t cdf[GENERIC_TABLES][CDF_SIZE(16)];
} generic_encoder;
#define OD_IIR_DIADIC(y, x, shift) ((y) += ((x) - (y)) >> (shift))
......@@ -87,7 +85,6 @@ int generic_decode_(aom_reader *r, generic_encoder *model, int max,
int log_ex(int ex_q16);
void generic_model_update(generic_encoder *model, int *ex_q16, int x, int xs,
int id, int integration);
void generic_model_update(int *ex_q16, int x, int integration);
#endif
......@@ -187,9 +187,9 @@ void od_adapt_pvq_ctx_reset(od_pvq_adapt_ctx *state, int is_keyframe) {
int pli;
int bs;
ctx = &state->pvq_codeword_ctx;
generic_model_init(&state->pvq_param_model[0]);
generic_model_init(&state->pvq_param_model[1]);
generic_model_init(&state->pvq_param_model[2]);
OD_CDFS_INIT(state->pvq_param_model[0].cdf, 0);
OD_CDFS_INIT(state->pvq_param_model[1].cdf, 0);
OD_CDFS_INIT(state->pvq_param_model[2].cdf, 0);
for (i = 0; i < 2*OD_TXSIZES; i++) {
ctx->pvq_adapt[4*i + OD_ADAPT_K_Q8] = 384;
ctx->pvq_adapt[4*i + OD_ADAPT_SUM_EX_Q8] = 256;
......
......@@ -18,7 +18,7 @@ void od_adapt_ctx_reset(od_adapt_ctx *adapt, int is_keyframe) {
OD_CDFS_INIT_Q15(adapt->skip_cdf);
for (pli = 0; pli < OD_NPLANES_MAX; pli++) {
int i;
generic_model_init(&adapt->model_dc[pli]);
OD_CDFS_INIT(adapt->model_dc[pli].cdf, 0);
for (i = 0; i < OD_TXSIZES; i++) {
int j;
adapt->ex_g[pli][i] = 8;
......
......@@ -107,8 +107,8 @@ int generic_decode_(aom_reader *r, generic_encoder *model, int max,
id = OD_MINI(GENERIC_TABLES - 1, lg_q1);
cdf = model->cdf[id];
ms = (max + (1 << shift >> 1)) >> shift;
if (max == -1) xs = aom_read_cdf_unscaled(r, cdf, 16, ACCT_STR_NAME);
else xs = aom_read_cdf_unscaled(r, cdf, OD_MINI(ms + 1, 16), ACCT_STR_NAME);
if (max == -1) xs = aom_read_symbol_pvq(r, cdf, 16, ACCT_STR_NAME);
else xs = aom_read_symbol_pvq(r, cdf, OD_MINI(ms + 1, 16), ACCT_STR_NAME);
if (xs == 15) {
int e;
unsigned decay;
......@@ -132,7 +132,7 @@ int generic_decode_(aom_reader *r, generic_encoder *model, int max,
lsb -= !special << (shift - 1);
}
x = (xs << shift) + lsb;
generic_model_update(model, ex_q16, x, xs, id, integration);
generic_model_update(ex_q16, x, integration);
OD_LOG((OD_LOG_ENTROPY_CODER, OD_LOG_DEBUG,
"dec: %d %d %d %d %d %x", *ex_q16, x, shift, id, xs, dec->rng));
return x;
......
......@@ -105,9 +105,9 @@ void generic_encode(aom_writer *w, generic_encoder *model, int x, int max,
xs = (x + (1 << shift >> 1)) >> shift;
ms = (max + (1 << shift >> 1)) >> shift;
OD_ASSERT(max == -1 || xs <= ms);
if (max == -1) aom_write_cdf_unscaled(w, OD_MINI(15, xs), cdf, 16);
if (max == -1) aom_write_symbol_pvq(w, OD_MINI(15, xs), cdf, 16);
else {
aom_write_cdf_unscaled(w, OD_MINI(15, xs), cdf, OD_MINI(ms + 1, 16));
aom_write_symbol_pvq(w, OD_MINI(15, xs), cdf, OD_MINI(ms + 1, 16));
}
if (xs >= 15) {
int e;
......@@ -132,7 +132,7 @@ void generic_encode(aom_writer *w, generic_encoder *model, int x, int max,
shift - special);
}
}
generic_model_update(model, ex_q16, x, xs, id, integration);
generic_model_update(ex_q16, x, integration);
OD_LOG((OD_LOG_ENTROPY_CODER, OD_LOG_DEBUG,
"enc: %d %d %d %d %d %x", *ex_q16, x, shift, id, xs, enc->rng));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment