Go to the documentation of this file.
25 #define OPUS_RC_BITS 32
27 #define OPUS_RC_CEIL ((1 << OPUS_RC_SYM) - 1)
28 #define OPUS_RC_TOP (1u << 31)
29 #define OPUS_RC_BOT (OPUS_RC_TOP >> OPUS_RC_SYM)
30 #define OPUS_RC_SHIFT (OPUS_RC_BITS - OPUS_RC_SYM - 1)
41 for (; rc->
ext > 0; rc->
ext--)
67 uint32_t low, uint32_t high,
78 uint32_t p_tot,
const int ptwo)
80 uint32_t rscaled, cnd = !!
b;
84 rscaled = rc->
range/p_tot;
86 rc->
range = (!cnd)*(rc->
range - rscaled*(p_tot - p)) + cnd*rscaled*(p -
b);
92 unsigned int k,
scale, total, symbol, low, high;
98 symbol = total -
FFMIN(symbol, total);
100 for (k = 0; cdf[k] <= symbol; k++);
102 low = k ? cdf[k-1] : 0;
191 k = total -
FFMIN(k, total);
214 uint32_t k,
scale, symbol, total = (k0+1)*3 + k0;
217 symbol = total -
FFMIN(symbol, total);
219 k = (symbol < (k0+1)*3) ? symbol/3 : symbol - (k0+1)*2;
222 (k <= k0) ? 3*(k+1) : (k-0-k0) + 3*(k0+1), total);
228 const uint32_t
a =
val <= k0,
b = 2*
a + 1;
236 uint32_t k,
scale, symbol, total, low, center;
238 total = ((qn>>1) + 1) * ((qn>>1) + 1);
241 center = total -
FFMIN(center, total);
243 if (center < total >> 1) {
244 k = (
ff_sqrt(8 * center + 1) - 1) >> 1;
245 low = k * (k + 1) >> 1;
248 k = (2*(qn + 1) -
ff_sqrt(8*(total - center - 1) + 1)) >> 1;
249 low = total - ((qn + 1 - k) * (qn + 2 - k) >> 1);
260 uint32_t symbol, low, total;
262 total = ((qn>>1) + 1) * ((qn>>1) + 1);
265 low = k * (k + 1) >> 1;
268 low = total - ((qn + 1 - k) * (qn + 2 - k) >> 1);
279 uint32_t
scale, low = 0, center;
283 center = (1 << 15) -
FFMIN(center, 1 << 15);
285 if (center >= symbol) {
288 symbol = 1 + ((32768 - 32 - symbol) * (16384-decay) >> 15);
290 while (symbol > 1 && center >= low + 2 * symbol) {
294 symbol = (((symbol - 2) * decay) >> 15) + 1;
303 if (center < low + symbol)
316 uint32_t low = symbol;
322 symbol = ((32768 - 32 - symbol)*(16384 - decay)) >> 15;
323 for (;
i <
val && symbol;
i++) {
324 low += (symbol << 1) + 2;
325 symbol = (symbol*decay) >> 14;
328 low += (++symbol)*
pos;
332 symbol =
FFMIN(1, 32768 - low);
380 if (rc->
rem >= 0 || rc->
ext > 0)
384 memcpy(dst, rc->
buf, rng_bytes);
391 uint8_t *rb_src, *rb_dst;
395 lap = &dst[rng_bytes] - rb_dst;
396 for (
i = 0;
i < lap;
i++)
397 rb_dst[
i] |= rb_src[
i];
398 memcpy(&rb_dst[lap], &rb_src[lap],
FFMAX(rc->
rb.
bytes - lap, 0));
void ff_opus_rc_enc_cdf(OpusRangeCoder *rc, int val, const uint16_t *cdf)
static double cb(void *priv, double x, double y)
uint32_t ff_opus_rc_get_raw(OpusRangeCoder *rc, uint32_t count)
CELT: read 1-25 raw bits at the end of the frame, backwards byte-wise.
void ff_opus_rc_enc_uint(OpusRangeCoder *rc, uint32_t val, uint32_t size)
CELT: write a uniformly distributed integer.
static av_always_inline void opus_rc_enc_carryout(OpusRangeCoder *rc, int cbuf)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static double val(void *priv, double ch)
static av_always_inline float scale(float x, float s)
static av_always_inline void opus_rc_dec_update(OpusRangeCoder *rc, uint32_t scale, uint32_t low, uint32_t high, uint32_t total)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static const uint16_t mask[17]
uint32_t ff_opus_rc_dec_uint(OpusRangeCoder *rc, uint32_t size)
CELT: read a uniform distribution.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void ff_opus_rc_enc_uint_tri(OpusRangeCoder *rc, uint32_t k, int qn)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static av_always_inline void opus_rc_enc_normalize(OpusRangeCoder *rc)
uint32_t ff_opus_rc_dec_uint_tri(OpusRangeCoder *rc, int qn)
void ff_opus_rc_enc_init(OpusRangeCoder *rc)
#define OPUS_MAX_PACKET_SIZE
int ff_opus_rc_dec_init(OpusRangeCoder *rc, const uint8_t *data, int size)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
uint32_t ff_opus_rc_dec_cdf(OpusRangeCoder *rc, const uint16_t *cdf)
void ff_opus_rc_enc_uint_step(OpusRangeCoder *rc, uint32_t val, int k0)
int ff_opus_rc_dec_laplace(OpusRangeCoder *rc, uint32_t symbol, int decay)
#define i(width, name, range_min, range_max)
void ff_opus_rc_enc_laplace(OpusRangeCoder *rc, int *value, uint32_t symbol, int decay)
void ff_opus_rc_put_raw(OpusRangeCoder *rc, uint32_t val, uint32_t count)
CELT: write 0 - 31 bits to the rawbits buffer.
void ff_opus_rc_dec_raw_init(OpusRangeCoder *rc, const uint8_t *rightend, uint32_t bytes)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
uint32_t ff_opus_rc_dec_uint_step(OpusRangeCoder *rc, int k0)
void ff_opus_rc_enc_log(OpusRangeCoder *rc, int val, uint32_t bits)
static av_always_inline void opus_rc_dec_normalize(OpusRangeCoder *rc)
static float distance(float x, float y, int band)
uint32_t ff_opus_rc_dec_log(OpusRangeCoder *rc, uint32_t bits)
static av_always_inline void opus_rc_enc_update(OpusRangeCoder *rc, uint32_t b, uint32_t p, uint32_t p_tot, const int ptwo)
void ff_opus_rc_enc_end(OpusRangeCoder *rc, uint8_t *dst, int size)
uint8_t buf[OPUS_MAX_PACKET_SIZE+12]