Changeset 81 for libmpcdec/branches/zorg/src/mpc_decoder.c
- Timestamp:
- 10/31/06 11:47:09 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpcdec/branches/zorg/src/mpc_decoder.c
r70 r81 70 70 // forward declarations 71 71 //------------------------------------------------------------------------------ 72 static void mpc_decoder_read_bitstream_sv6(mpc_decoder *d, mpc_bool_t seeking);73 72 static void mpc_decoder_read_bitstream_sv7(mpc_decoder *d, mpc_bool_t seeking); 74 73 static void mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band); … … 77 76 // utility functions 78 77 //------------------------------------------------------------------------------ 79 static mpc_int32_t f_read(mpc_decoder *d, void *ptr, mpc_int32_t size) 80 { 81 return d->r->read(d->r, ptr, size); 82 } 83 84 static mpc_bool_t f_seek(mpc_decoder *d, mpc_int32_t offset) 85 { 86 return d->r->seek(d->r, offset); 87 } 88 89 static mpc_int32_t f_read_dword(mpc_decoder *d, mpc_uint32_t * ptr, mpc_uint32_t count) 78 static mpc_int32_t f_read(mpc_decoder *d, void *ptr, mpc_int32_t size) 79 { 80 return d->r->read(d->r, ptr, size); 81 } 82 83 static mpc_bool_t f_seek(mpc_decoder *d, mpc_int32_t offset) 84 { 85 return d->r->seek(d->r, offset); 86 } 87 88 static mpc_int32_t f_read_dword(mpc_decoder *d, mpc_uint32_t * ptr, mpc_uint32_t count) 90 89 { 91 90 return f_read(d, ptr, count << 2) >> 2; … … 130 129 // resets bitstream decoding 131 130 static void 132 mpc_decoder_reset_bitstream_decode(mpc_decoder *d) 131 mpc_decoder_reset_bitstream_decode(mpc_decoder *d) 133 132 { 134 133 d->dword = 0; … … 140 139 // reports the number of read bits 141 140 static mpc_uint32_t 142 mpc_decoder_bits_read(mpc_decoder *d) 141 mpc_decoder_bits_read(mpc_decoder *d) 143 142 { 144 143 return 32 * d->WordsRead + d->pos; … … 147 146 // read desired number of bits out of the bitstream (max 31) 148 147 static mpc_uint32_t 149 mpc_decoder_bitstream_read(mpc_decoder *d, const mpc_uint32_t bits) 148 mpc_decoder_bitstream_read(mpc_decoder *d, const mpc_uint32_t bits) 150 149 { 151 150 mpc_uint32_t out = d->dword; … … 191 190 } 192 191 193 // decode SCFI-bundle (sv4,5,6) 192 void mpc_decoder_get_block(mpc_decoder *d, mpc_block_t * p_block) 193 { 194 unsigned char tmp; 195 unsigned int size = 2; 196 197 p_block->size = 0; 198 p_block->key[0] = mpc_decoder_bitstream_read(d, 8); 199 p_block->key[1] = mpc_decoder_bitstream_read(d, 8); 200 do { 201 tmp = mpc_decoder_bitstream_read(d, 8); 202 p_block->size = (p_block->size << 7) | (tmp & 0x7F); 203 size++; 204 } while((tmp & 0x80)); 205 206 p_block->size -= size; 207 } 208 194 209 static void 195 mpc_decoder_scfi_bundle_read(mpc_decoder *d, const mpc_huffman* Table, 196 mpc_int32_t* SCFI, mpc_bool_t* DSCF) 197 { 198 mpc_uint32_t value = mpc_decoder_huffman_decode(d, Table, 6); 199 200 *SCFI = value >> 1; 201 *DSCF = value & 1; 202 } 203 204 static void 205 mpc_decoder_reset_v(mpc_decoder *d) 210 mpc_decoder_reset_v(mpc_decoder *d) 206 211 { 207 212 memset(d->V_L, 0, sizeof d->V_L); … … 210 215 211 216 static void 212 mpc_decoder_reset_synthesis(mpc_decoder *d) 217 mpc_decoder_reset_synthesis(mpc_decoder *d) 213 218 { 214 219 mpc_decoder_reset_v(d); … … 216 221 217 222 static void 218 mpc_decoder_reset_y(mpc_decoder *d) 223 mpc_decoder_reset_y(mpc_decoder *d) 219 224 { 220 225 memset(d->Y_L, 0, sizeof d->Y_L); … … 223 228 224 229 static void 225 mpc_decoder_reset_globals(mpc_decoder *d) 230 mpc_decoder_reset_globals(mpc_decoder *d) 226 231 { 227 232 mpc_decoder_reset_bitstream_decode(d); … … 268 273 269 274 static mpc_uint32_t 270 mpc_decoder_decode_internal(mpc_decoder *d, MPC_SAMPLE_FORMAT *buffer) 275 mpc_decoder_decode_internal(mpc_decoder *d, MPC_SAMPLE_FORMAT *buffer) 271 276 { 272 277 mpc_uint32_t output_frame_length = MPC_FRAME_LENGTH; … … 285 290 } 286 291 287 // read jump-info for validity check of frame288 FwdJumpInfo = mpc_decoder_bitstream_read(d, 20);289 290 // decode data and check for validity of frame291 FrameBitCnt = mpc_decoder_bits_read(d);292 292 switch (d->StreamVersion) { 293 293 case 0x07: 294 294 case 0x17: 295 // read jump-info for validity check of frame 296 FwdJumpInfo = mpc_decoder_bitstream_read(d, 20); 297 // decode data and check for validity of frame 298 FrameBitCnt = mpc_decoder_bits_read(d); 295 299 mpc_decoder_read_bitstream_sv7(d, FALSE); 300 d->FrameWasValid = mpc_decoder_bits_read(d) - FrameBitCnt == FwdJumpInfo; 296 301 break; 302 case 0x08: 303 if (d->BlockBits < 8){ 304 mpc_block_t block; 305 // trouver le block 306 mpc_decoder_bitstream_read(d, d->BlockBits); 307 while (1) { 308 mpc_decoder_get_block(d, &block); 309 if (memcmp(block.key, "AD", 2) != 0) 310 mpc_decoder_seek(d, mpc_decoder_bits_read(d) + block.size * 8); 311 else 312 break; 313 } 314 d->BlockBits = block.size * 8; 315 } 316 FrameBitCnt = mpc_decoder_bits_read(d); 317 mpc_decoder_read_bitstream_sv7(d, FALSE); 318 d->BlockBits -= mpc_decoder_bits_read(d) - FrameBitCnt; 319 d->FrameWasValid = 1; 320 break; 297 321 default: 298 322 return (mpc_uint32_t)(-1); 299 323 } 300 d->FrameWasValid = mpc_decoder_bits_read(d) - FrameBitCnt == FwdJumpInfo;301 324 302 325 // synthesize signal … … 307 330 308 331 // cut off first MPC_DECODER_SYNTH_DELAY zero-samples 309 if (d->DecodedFrames == d->OverallFrames && d->StreamVersion >= 6) { 332 if (d->DecodedFrames == d->OverallFrames && d->StreamVersion >= 6) { 310 333 // reconstruct exact filelength 311 334 mpc_int32_t mod_block = mpc_decoder_bitstream_read(d, 11); … … 314 337 if (mod_block == 0) { 315 338 // Encoder bugfix 316 mod_block = 1152; 339 mod_block = 1152; 317 340 } 318 341 FilterDecay = (mod_block + MPC_DECODER_SYNTH_DELAY) % MPC_FRAME_LENGTH; … … 345 368 output_frame_length -= d->samples_to_skip; 346 369 memmove( 347 buffer, 348 buffer + d->samples_to_skip * 2, 370 buffer, 371 buffer + d->samples_to_skip * 2, 349 372 output_frame_length * 2 * sizeof (MPC_SAMPLE_FORMAT)); 350 373 d->samples_to_skip = 0; … … 357 380 mpc_uint32_t mpc_decoder_decode( 358 381 mpc_decoder *d, 359 MPC_SAMPLE_FORMAT *buffer, 360 mpc_uint32_t *vbr_update_acc, 382 MPC_SAMPLE_FORMAT *buffer, 383 mpc_uint32_t *vbr_update_acc, 361 384 mpc_uint32_t *vbr_update_bits) 362 385 { … … 378 401 // error occurred in bitstream 379 402 return (mpc_uint32_t)(-1); 380 } 403 } 381 404 else { 382 405 if (vbr_update_acc && vbr_update_bits) { … … 399 422 400 423 void 401 mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band) 424 mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band) 402 425 { 403 426 mpc_int32_t Band; … … 855 878 d->__r1 = 1; 856 879 d->__r2 = 1; 880 d->BlockBits = 0; 857 881 858 882 d->Max_Band = 0; … … 872 896 case 0x07: 873 897 case 0x17: fpos = 200; break; 898 case 0x08: fpos = 32; break; 874 899 } 875 900 return fpos; … … 892 917 } 893 918 894 mpc_status mpc_decoder_init(mpc_decoder **d, mpc_reader *r, mpc_streaminfo *si) 919 mpc_status mpc_decoder_init(mpc_decoder **d, mpc_reader *r, mpc_streaminfo *si) 895 920 { 896 921 mpc_decoder* p_tmp; 897 922 898 923 p_tmp = malloc(sizeof *p_tmp); 899 924 memset(p_tmp, 0, sizeof *p_tmp); … … 927 952 } 928 953 929 mpc_bool_t mpc_decoder_seek_seconds(mpc_decoder *d, double seconds) 954 mpc_bool_t mpc_decoder_seek_seconds(mpc_decoder *d, double seconds) 930 955 { 931 956 return mpc_decoder_seek_sample(d, (mpc_int64_t)(seconds * (double)d->SampleRate + 0.5)); 932 957 } 933 958 934 mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample) 959 mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample) 935 960 { 936 961 mpc_uint32_t fpos;
Note: See TracChangeset
for help on using the changeset viewer.