Changeset 146
- Timestamp:
- 11/18/06 18:46:21 (18 years ago)
- Location:
- libmpc/branches/r2d/libmpcdec
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpc/branches/r2d/libmpcdec/internal.h
r139 r146 69 69 mpc_decoder * d; 70 70 mpc_streaminfo si; 71 72 // buffer 71 73 mpc_uint8_t buffer[DEMUX_BUFFER_SIZE]; 72 mpc_ uint32_t bytes_total;74 mpc_size_t bytes_total; 73 75 mpc_bits_reader bits_reader; 74 76 mpc_uint32_t block_bits; /// bits remaining in current audio block 75 77 mpc_bool_t end; /// end of stream flag 78 79 // seeking 80 mpc_uint32_t * seek_table; 81 mpc_uint_t seek_pwr; /// distance between 2 frames in seek_table = 2^seek_pwr 82 mpc_uint32_t seek_table_size; /// used size in seek_table 76 83 }; 77 84 -
libmpc/branches/r2d/libmpcdec/mpc_demux.c
r143 r146 107 107 /** 108 108 * seek to a bit position in the stream 109 * @param d 109 * @param d demuxer context 110 110 * @param fpos position in the stream in bits from the beginning of mpc datas 111 111 * @param min_bytes number of bytes to load after seeking … … 133 133 d->bits_reader.buff += bit_offset >> 3; 134 134 d->bits_reader.count = 8 - (bit_offset & 7); 135 } 136 137 /** 138 * return the current position in the stream (in bits) 139 * @param d demuxer context 140 * @return current stream position in bits 141 */ 142 static mpc_size_t mpc_demux_pos(mpc_demux * d) 143 { 144 return ((d->r->tell(d->r) - d->bytes_total + d->bits_reader.buff - d->buffer) << 3) + 8 - d->bits_reader.count; 135 145 } 136 146 … … 198 208 p_tmp->r = p_reader; 199 209 mpc_demux_clear_buff(p_tmp); 200 // lire entête201 210 if (mpc_demux_header(p_tmp) == MPC_STATUS_OK) { 202 // initialisation decodeur 211 p_tmp->seek_pwr = 6; 212 if (p_tmp->si.block_pwr > p_tmp->seek_pwr) 213 p_tmp->seek_pwr = p_tmp->si.block_pwr; 214 p_tmp->seek_table = malloc((1 + p_tmp->si.samples / (MPC_FRAME_LENGTH << p_tmp->seek_pwr)) * sizeof(mpc_uint32_t)); 215 p_tmp->seek_table[0] = mpc_demux_pos(p_tmp); 216 p_tmp->seek_table_size = 1; 203 217 p_tmp->d = mpc_decoder_init(&p_tmp->si); 204 218 } else { … … 214 228 { 215 229 mpc_decoder_exit(d->d); 230 free(d->seek_table); 216 231 free(d); 217 232 } … … 222 237 } 223 238 239 #include <stdio.h> 240 224 241 void mpc_demux_decode(mpc_demux * d, mpc_frame_info * i) 225 242 { 243 if (d->d->decoded_samples == (d->seek_table_size << d->seek_pwr) * MPC_FRAME_LENGTH) { 244 d->seek_table[d->seek_table_size] = mpc_demux_pos(d); 245 d->seek_table_size ++; 246 } 247 226 248 if (d->si.stream_version >= 8) { 227 249 mpc_bits_reader r; … … 263 285 mpc_status mpc_demux_seek_sample(mpc_demux * d, mpc_int64_t destsample) 264 286 { 265 mpc_uint32_t fwd, samples_to_skip, fpos = 32, i; 287 mpc_uint32_t fwd, samples_to_skip, fpos, i; 288 mpc_uint32_t block_samples = MPC_FRAME_LENGTH << d->si.block_pwr; 266 289 267 290 if (destsample > d->si.samples) destsample = d->si.samples; 268 fwd = (mpc_uint32_t) (destsample / (MPC_FRAME_LENGTH * d->si.frames_per_block)); 269 samples_to_skip = MPC_DECODER_SYNTH_DELAY + (mpc_uint32_t) 270 (destsample % (MPC_FRAME_LENGTH * d->si.frames_per_block)); 271 272 // FIXME : we start seeking from the beginning of the file, easier but not optimal 273 d->d->decoded_samples = 0; 274 275 if (d->si.stream_version >= 8) { 276 mpc_block b; 277 int size; 278 mpc_demux_seek(d, fpos, 11); 279 size = mpc_bits_get_block(&d->bits_reader, &b); 280 for( i = 0; i < fwd; ){ 281 if (memcmp(b.key, "AD", 2) == 0){ 282 i++; 283 d->d->decoded_samples += MPC_FRAME_LENGTH * d->si.frames_per_block; 284 } 285 fpos += (b.size + size) * 8; 286 mpc_demux_seek(d, fpos, 11); 287 size = mpc_bits_get_block(&d->bits_reader, &b); 288 } 289 d->bits_reader.buff -= size; 290 } else { 291 fwd = (mpc_uint32_t) (destsample / block_samples); 292 samples_to_skip = MPC_DECODER_SYNTH_DELAY + 293 (mpc_uint32_t) (destsample % block_samples); 294 if (d->si.stream_version == 7) { 291 295 if (fwd > 32) { 292 296 fwd -= 32; … … 296 300 fwd = 0; 297 301 } 302 } 303 304 i = fwd >> (d->seek_pwr - d->si.block_pwr); 305 if (i >= d->seek_table_size) 306 i = d->seek_table_size - 1; 307 fpos = d->seek_table[i]; 308 i <<= d->seek_pwr - d->si.block_pwr; 309 d->d->decoded_samples = i * block_samples; 310 311 if (d->si.stream_version >= 8) { 312 mpc_block b; 313 int size; 314 mpc_demux_seek(d, fpos, 11); 315 size = mpc_bits_get_block(&d->bits_reader, &b); 316 while(i < fwd) { 317 if (memcmp(b.key, "AD", 2) == 0) { 318 if (d->d->decoded_samples == (d->seek_table_size << d->seek_pwr) * MPC_FRAME_LENGTH) { 319 d->seek_table[d->seek_table_size] = mpc_demux_pos(d) - 8 * size; 320 d->seek_table_size ++; 321 } 322 d->d->decoded_samples += block_samples; 323 i++; 324 } 325 fpos += (b.size + size) * 8; 326 mpc_demux_seek(d, fpos, 11); 327 size = mpc_bits_get_block(&d->bits_reader, &b); 328 } 329 d->bits_reader.buff -= size; 330 } else { 298 331 mpc_decoder_reset_scf(d->d); 299 fpos += 21 * 8;300 332 mpc_demux_seek(d, fpos, 4); 301 for( i = 0; i < fwd; i++){ 333 for( ; i < fwd; i++){ 334 if (d->d->decoded_samples == (d->seek_table_size << d->seek_pwr) * MPC_FRAME_LENGTH) { 335 d->seek_table[d->seek_table_size] = mpc_demux_pos(d); 336 d->seek_table_size ++; 337 } 338 d->d->decoded_samples += block_samples; 302 339 fpos += mpc_bits_read(&d->bits_reader, 20) + 20; 303 340 mpc_demux_seek(d, fpos, 4); 304 d->d->decoded_samples += MPC_FRAME_LENGTH;305 341 } 306 342 } -
libmpc/branches/r2d/libmpcdec/streaminfo.c
r143 r146 123 123 si->encoder_version = mpc_bits_read(r, 8); 124 124 si->channels = 2; 125 si-> frames_per_block = 1;125 si->block_pwr = 0; 126 126 127 127 mpc_get_encoder_string(si); … … 160 160 si->max_band = mpc_bits_read(&r, 5) + 1; 161 161 si->ms = mpc_bits_read(&r, 1); 162 si-> frames_per_block = 1 <<mpc_bits_read(&r, 4);162 si->block_pwr = mpc_bits_read(&r, 4); 163 163 164 164 si->bitrate = 0;
Note: See TracChangeset
for help on using the changeset viewer.