| 199 | } |
| 200 | |
| 201 | void ArithmeticEncoder::encodeBit(ArithmeticBitModel* m, U32 sym) |
| 202 | { |
| 203 | assert(m && (sym <= 1)); |
| 204 | |
| 205 | U32 x = m->bit_0_prob * (length >> BM__LengthShift); // product l x p0 |
| 206 | // update interval |
| 207 | if (sym == 0) { |
| 208 | length = x; |
| 209 | ++m->bit_0_count; |
| 210 | } |
| 211 | else { |
| 212 | U32 init_base = base; |
| 213 | base += x; |
| 214 | length -= x; |
| 215 | if (init_base > base) propagate_carry(); // overflow = carry |
| 216 | } |
| 217 | |
| 218 | if (length < AC__MinLength) renorm_enc_interval(); // renormalization |
| 219 | if (--m->bits_until_update == 0) m->update(); // periodic model update |
| 220 | } |
| 221 | |
| 222 | void ArithmeticEncoder::encodeSymbol(ArithmeticModel* m, U32 sym) |
| 223 | { |