Changeset 150 for libmpc/branches/r2d/libmpcdec
- Timestamp:
- 11/24/06 19:18:18 (18 years ago)
- Location:
- libmpc/branches/r2d/libmpcdec
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpc/branches/r2d/libmpcdec/mpc_bits_reader.c
r104 r150 68 68 } 69 69 70 mpc_int32_t mpc_bits_golomb_dec(mpc_bits_reader * r, const mpc_uint_t k) 71 { 72 unsigned int l = 0; 73 unsigned int code = r->buff[0] & ((1 << r->count) - 1); 74 75 while( code == 0 ) { 76 l += r->count; 77 r->buff++; 78 code = r->buff[0]; 79 r->count = 8; 80 } 81 82 while( ((1 << (r->count - 1)) & code) == 0 ) { 83 l++; 84 r->count--; 85 } 86 r->count--; 87 88 while( r->count < k ) { 89 r->buff++; 90 r->count += 8; 91 code = (code << 8) | r->buff[0]; 92 } 93 94 r->count -= k; 95 96 return (l << k) | ((code >> r->count) & ((1 << k) - 1)); 97 } 98 70 99 unsigned int mpc_bits_get_size(mpc_bits_reader * r, mpc_uint64_t * p_size) 71 100 { -
libmpc/branches/r2d/libmpcdec/mpc_demux.c
r149 r150 41 41 mpc_uint32_t mpc_bits_read(mpc_bits_reader * r, const unsigned int nb_bits); 42 42 int mpc_bits_get_block(mpc_bits_reader * r, mpc_block * p_block); 43 mpc_int32_t mpc_bits_golomb_dec(mpc_bits_reader * r, const mpc_uint_t k); 44 unsigned int mpc_bits_get_size(mpc_bits_reader * r, mpc_uint64_t * p_size); 43 45 44 46 // streaminfo.c … … 143 145 { 144 146 return ((d->r->tell(d->r) - d->bytes_total + d->bits_reader.buff - d->buffer) << 3) + 8 - d->bits_reader.count; 147 } 148 149 mpc_status mpc_demux_seek_init(mpc_demux * d) 150 { 151 if (d->seek_table != 0) 152 return MPC_STATUS_OK; 153 154 d->seek_pwr = 6; 155 if (d->si.block_pwr > d->seek_pwr) 156 d->seek_pwr = d->si.block_pwr; 157 d->seek_table = malloc((1 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr)) * sizeof(mpc_uint32_t)); 158 if (d->seek_table == 0) 159 return MPC_STATUS_FILE; 160 d->seek_table[0] = mpc_demux_pos(d); 161 d->seek_table_size = 1; 162 163 return MPC_STATUS_OK; 164 } 165 166 static void mpc_demux_ST(mpc_demux * d) 167 { 168 mpc_uint64_t tmp; 169 mpc_uint32_t * table; 170 mpc_bits_reader r = d->bits_reader; 171 mpc_uint_t i; 172 173 if (d->seek_table != 0) 174 return; 175 176 mpc_bits_get_size(&r, &tmp); 177 d->seek_table_size = tmp; 178 d->seek_pwr = d->si.block_pwr + mpc_bits_read(&r, 4); 179 d->seek_table = malloc((1 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr)) * sizeof(mpc_uint32_t)); 180 181 table = d->seek_table; 182 mpc_bits_get_size(&r, &tmp); 183 table[0] = (tmp + d->si.header_position) * 8; 184 185 if (d->seek_table_size == 1) 186 return; 187 188 mpc_bits_get_size(&r, &tmp); 189 table[1] = (tmp + d->si.header_position) * 8; 190 191 for (i = 2; i < d->seek_table_size; i++) { 192 int code = mpc_bits_golomb_dec(&r, 12); 193 if (code & 1) 194 code = -(code & (-1u << 1)); 195 code <<= 2; 196 table[i] = code + 2 * table[i-1] - table[i-2]; 197 } 198 } 199 200 static void mpc_demux_SP(mpc_demux * d, int size, int block_size) 201 { 202 mpc_size_t cur; 203 mpc_uint64_t ptr; 204 mpc_block b; 205 206 cur = mpc_demux_pos(d); 207 mpc_bits_get_size(&d->bits_reader, &ptr); 208 mpc_demux_seek(d, (ptr - size) * 8 + cur, 11); 209 mpc_bits_get_block(&d->bits_reader, &b); 210 if (memcmp(b.key, "ST", 2) == 0) { 211 mpc_demux_fill(d, b.size, 0); 212 mpc_demux_ST(d); 213 } 214 mpc_demux_seek(d, cur, 11 + block_size); 145 215 } 146 216 … … 189 259 } else if (memcmp(b.key, "EI", 2) == 0) 190 260 streaminfo_encoder_info(&d->si, &d->bits_reader); 261 else if (memcmp(b.key, "SP", 2) == 0) 262 mpc_demux_SP(d, size, b.size); 263 else if (memcmp(b.key, "ST", 2) == 0) 264 mpc_demux_ST(d); 191 265 d->bits_reader.buff += b.size; 192 266 size = mpc_bits_get_block(&d->bits_reader, &b); … … 206 280 p_tmp->r = p_reader; 207 281 mpc_demux_clear_buff(p_tmp); 282 p_tmp->seek_table = 0; 208 283 if (mpc_demux_header(p_tmp) == MPC_STATUS_OK) { 209 p_tmp->seek_pwr = 6; 210 if (p_tmp->si.block_pwr > p_tmp->seek_pwr) 211 p_tmp->seek_pwr = p_tmp->si.block_pwr; 212 p_tmp->seek_table = malloc((1 + p_tmp->si.samples / (MPC_FRAME_LENGTH << p_tmp->seek_pwr)) * sizeof(mpc_uint32_t)); 213 p_tmp->seek_table[0] = mpc_demux_pos(p_tmp); 214 p_tmp->seek_table_size = 1; 284 mpc_demux_seek_init(p_tmp); 215 285 p_tmp->d = mpc_decoder_init(&p_tmp->si); 216 286 } else { -
libmpc/branches/r2d/libmpcdec/streaminfo.c
r149 r150 173 173 mpc_bits_get_size(&r, &si->samples); 174 174 si->is_true_gapless = 1; 175 si->sample_freq = samplefreqs[mpc_bits_read(&r, 4)];175 si->sample_freq = samplefreqs[mpc_bits_read(&r, 3)]; 176 176 si->channels = mpc_bits_read(&r, 4) + 1; 177 177 si->max_band = mpc_bits_read(&r, 5) + 1; 178 178 si->ms = mpc_bits_read(&r, 1); 179 si->block_pwr = mpc_bits_read(&r, 4);179 si->block_pwr = mpc_bits_read(&r, 3) * 2; 180 180 181 181 si->bitrate = 0;
Note: See TracChangeset
for help on using the changeset viewer.