Changeset 219 for libmpc/branches/r2d/libmpcdec/mpc_bits_reader.c
- Timestamp:
- 02/17/07 16:14:53 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpc/branches/r2d/libmpcdec/mpc_bits_reader.c
r195 r219 1 1 /* 2 Copyright (c) 200 5, The Musepack Development Team2 Copyright (c) 2007, The Musepack Development Team 3 3 All rights reserved. 4 4 … … 36 36 #include "internal.h" 37 37 #include "huffman.h" 38 #include "mpc_bits_reader.h" 38 39 39 #define MAX_ENUM 32 40 41 static const mpc_uint32_t Cnk[MAX_ENUM / 2][MAX_ENUM] = 40 const mpc_uint32_t Cnk[MAX_ENUM / 2][MAX_ENUM] = 42 41 { 43 42 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}, … … 59 58 }; 60 59 61 staticconst mpc_uint8_t Cnk_len[MAX_ENUM / 2][MAX_ENUM] =60 const mpc_uint8_t Cnk_len[MAX_ENUM / 2][MAX_ENUM] = 62 61 { 63 62 {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, … … 80 79 }; 81 80 82 staticconst mpc_uint32_t Cnk_lost[MAX_ENUM / 2][MAX_ENUM] =81 const mpc_uint32_t Cnk_lost[MAX_ENUM / 2][MAX_ENUM] = 83 82 { 84 83 {0, 0, 1, 0, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, … … 105 104 static const mpc_uint8_t log2_lost[32] = 106 105 { 0, 1, 0, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31}; 107 108 // FIXME : make it work without 64 bit use for 32 bit output109 mpc_uint32_t mpc_bits_read(mpc_bits_reader * r, const unsigned int nb_bits)110 {111 mpc_uint64_t ret = r->buff[0];112 113 while(nb_bits > r->count){114 r->buff++;115 ret = (ret << 8) | r->buff[0];116 r->count += 8;117 }118 119 r->count -= nb_bits;120 121 return (mpc_uint32_t)((ret >> r->count) & (-1u >> (32 - nb_bits)));122 }123 124 // basic huffman decoding routine125 // works with maximum lengths up to 16126 mpc_int32_t mpc_bits_huff_dec(mpc_bits_reader * r, const mpc_huffman *Table)127 {128 int tmp; mpc_uint32_t code;129 code = ((r->buff[0] << 16) | (r->buff[1] << 8) | r->buff[2])130 << (16 - r->count);131 132 while (code < Table->Code) Table++;133 134 tmp = r->count - Table->Length;135 r->buff -= tmp >> 3;136 r->count = tmp & 0x07;137 138 return Table->Value;139 }140 106 141 107 mpc_int32_t mpc_bits_golomb_dec(mpc_bits_reader * r, const mpc_uint_t k) … … 166 132 167 133 return (l << k) | ((code >> r->count) & ((1 << k) - 1)); 168 }169 170 mpc_uint32_t mpc_bits_enum_dec(mpc_bits_reader * r, mpc_uint_t k, mpc_uint_t n)171 {172 mpc_uint32_t bits = 0;173 mpc_uint32_t code;174 const mpc_uint32_t * C = Cnk[k-1];175 176 code = mpc_bits_read(r, Cnk_len[k-1][n-1] - 1);177 178 if (code >= Cnk_lost[k-1][n-1])179 code = ((code << 1) | mpc_bits_read(r, 1)) - Cnk_lost[k-1][n-1];180 181 do {182 n--;183 if (code >= C[n]) {184 bits |= 1 << n;185 code -= C[n];186 C -= MAX_ENUM;187 k--;188 }189 } while(k > 0);190 191 return bits;192 134 } 193 135
Note: See TracChangeset
for help on using the changeset viewer.