Commit 9fb690fa authored by David Michael Barr's avatar David Michael Barr

Match style for update_cdf and remove nsymbs2speed

We can simplify as cdfs have at least 2 symbols.
parent aeb5a5ef
......@@ -140,24 +140,17 @@ int msac_decode_uniform(MsacContext *const c, const unsigned n) {
return v < m ? v : (v << 1) - m + msac_decode_bool(c, EC_BOOL_EPROB);
}
void update_cdf(uint16_t *cdf, unsigned val, unsigned nsymbs) {
int rate;
void msac_update_cdf(uint16_t *const cdf, const unsigned val,
const unsigned n_symbols)
{
const int rate = 4 + (cdf[n_symbols] > 15) + (cdf[n_symbols] > 31) +
(n_symbols > 3);
unsigned i;
static const int nsymbs2speed[17] = {
0, 0, 1, 1, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2
};
assert(nsymbs < 17);
rate = 3 + (cdf[nsymbs] > 15) + (cdf[nsymbs] > 31) + nsymbs2speed[nsymbs];
for (i = 0; i < val; ++i)
cdf[i] += (32768 - cdf[i]) >> rate;
for (i = val; i < nsymbs - 1; i++)
for (i = val; i < n_symbols - 1; i++)
cdf[i] -= cdf[i] >> rate;
cdf[nsymbs] += (cdf[nsymbs] < 32);
cdf[n_symbols] += (cdf[n_symbols] < 32);
}
void msac_init(MsacContext *const s, const uint8_t *const data,
......
......@@ -52,14 +52,14 @@ unsigned msac_decode_bool(MsacContext *s, unsigned f);
unsigned msac_decode_bools(MsacContext *c, unsigned l);
int msac_decode_subexp(MsacContext *c, int ref, int n, unsigned k);
int msac_decode_uniform(MsacContext *c, unsigned n);
void update_cdf(uint16_t *cdf, unsigned val, unsigned nsymbs);
void msac_update_cdf(uint16_t *cdf, unsigned val, unsigned n_symbols);
static inline unsigned msac_decode_symbol_adapt(MsacContext *const c,
uint16_t *const cdf,
const unsigned n_symbols)
{
const unsigned val = msac_decode_symbol(c, cdf, n_symbols);
update_cdf(cdf, val, n_symbols);
msac_update_cdf(cdf, val, n_symbols);
return val;
}
......@@ -68,7 +68,7 @@ static inline unsigned msac_decode_bool_adapt(MsacContext *const c,
{
const unsigned bit = msac_decode_bool(c, *cdf >> EC_PROB_SHIFT);
uint16_t bak_cdf[3] = { cdf[0], 0, cdf[1] };
update_cdf(bak_cdf, bit, 2);
msac_update_cdf(bak_cdf, bit, 2);
cdf[0] = bak_cdf[0];
cdf[1] = bak_cdf[2];
return bit;
......
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