- value = get_bits(&alac->gb, readsamplesize);
-
- /* mask value to readsamplesize size */
- if (readsamplesize != 32)
- value &= (0xffffffff >> (32 - readsamplesize));
-
- x = value;
- } else {
- /* standard rice encoding */
- int extrabits;
- int k; /* size of extra bits */
-
- /* read k, that is bits as is */
- k = 31 - rice_kmodifier - count_leading_zeros((history >> 9) + 3);
-
- if (k < 0)
- k += rice_kmodifier;
- else
- k = rice_kmodifier;
-
- if (k != 1) {
- extrabits = show_bits(&alac->gb, k);
-
- /* multiply x by 2^k - 1, as part of their strange algorithm */
- x = (x << k) - x;
-
- if (extrabits > 1) {
- x += extrabits - 1;
- skip_bits(&alac->gb, k);
- } else
- skip_bits(&alac->gb, k - 1);
- }
- }
+ /* read k, that is bits as is */
+ k = av_log2((history >> 9) + 3);
+ x= decode_scalar(&alac->gb, k, rice_kmodifier, readsamplesize);