Changeset 158 for libmpc/branches/r2d/libmpcdec
- Timestamp:
- 12/10/06 19:42:10 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpc/branches/r2d/libmpcdec/mpc_decoder.c
r151 r158 91 91 { 92 92 memset(d, 0, sizeof *d); 93 mpc_decoder_reset_scf(d); // to be able to decode a cutted stream without big quirks 93 94 94 95 d->__r1 = 1; … … 342 343 static const mpc_int32_t idx51[] = { -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2}; 343 344 344 mpc_int32_t n,k; 345 mpc_int32_t Max_used_Band=0; 346 const mpc_huffman *Table; 347 mpc_int32_t idx; 348 mpc_int32_t *L ,*R; 349 mpc_int32_t *ResL,*ResR; 350 mpc_uint32_t tmp; 345 mpc_int32_t n, idx, Max_used_Band = 0; 351 346 352 347 /***************************** Header *****************************/ 353 ResL = d->Res_L;354 ResR = d->Res_R;355 348 356 349 // first subband 357 *ResL= mpc_bits_read(r, 4);358 *ResR= mpc_bits_read(r, 4);359 if (d->ms && !( *ResL==0 && *ResR==0)) {350 d->Res_L[0] = mpc_bits_read(r, 4); 351 d->Res_R[0] = mpc_bits_read(r, 4); 352 if (d->ms && !(d->Res_L[0] == 0 && d->Res_R[0] == 0)) 360 353 d->MS_Flag[0] = mpc_bits_read(r, 1); 361 }362 354 363 355 // consecutive subbands 364 ++ResL; ++ResR; // increase pointers 365 for (n=1; n <= d->max_band; ++n, ++ResL, ++ResR) 366 { 356 for ( n = 1; n <= d->max_band; n++ ) { 367 357 idx = mpc_bits_huff_dec(r, mpc_table_HuffHdr); 368 *ResL = (idx!=4) ? *(ResL-1)+ idx : (int) mpc_bits_read(r, 4);358 d->Res_L[n] = (idx!=4) ? d->Res_L[n - 1] + idx : (int) mpc_bits_read(r, 4); 369 359 370 360 idx = mpc_bits_huff_dec(r, mpc_table_HuffHdr); 371 *ResR = (idx!=4) ? *(ResR-1) + idx : (int) mpc_bits_read(r, 4); 372 373 if (d->ms && !(*ResL==0 && *ResR==0)) { 374 d->MS_Flag[n] = mpc_bits_read(r, 1); 375 } 376 377 // only perform following procedures up to the maximum non-zero subband 378 if (*ResL!=0 || *ResR!=0) { 379 Max_used_Band = n; 380 } 361 d->Res_R[n] = (idx!=4) ? d->Res_R[n - 1] + idx : (int) mpc_bits_read(r, 4); 362 363 if (!(d->Res_L[n] == 0 && d->Res_R[n] == 0)) { 364 if (d->ms) 365 d->MS_Flag[n] = mpc_bits_read(r, 1); 366 Max_used_Band = n; 367 } 381 368 } 382 369 /****************************** SCFI ******************************/ 383 L = d->SCFI_L; 384 R = d->SCFI_R; 385 ResL = d->Res_L; 386 ResR = d->Res_R; 387 for (n=0; n <= Max_used_Band; ++n, ++L, ++R, ++ResL, ++ResR) { 388 if (*ResL) *L = mpc_bits_huff_dec(r, mpc_table_HuffSCFI); 389 if (*ResR) *R = mpc_bits_huff_dec(r, mpc_table_HuffSCFI); 370 for ( n = 0; n <= Max_used_Band; n++ ) { 371 if (d->Res_L[n]) 372 d->SCFI_L[n] = mpc_bits_huff_dec(r, mpc_table_HuffSCFI); 373 if (d->Res_R[n]) 374 d->SCFI_R[n] = mpc_bits_huff_dec(r, mpc_table_HuffSCFI); 390 375 } 391 376 392 377 /**************************** SCF/DSCF ****************************/ 393 ResL = d->Res_L; 394 ResR = d->Res_R; 395 L = d->SCF_Index_L[0]; 396 R = d->SCF_Index_R[0]; 397 for (n=0; n<=Max_used_Band; ++n, ++ResL, ++ResR, L+=3, R+=3) { 398 if (*ResL) 399 { 400 switch (d->SCFI_L[n]) 401 { 402 case 1: 403 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 404 L[0] = (idx!=8) ? L[2] + idx : (int) mpc_bits_read(r, 6); 405 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 406 L[1] = (idx!=8) ? L[0] + idx : (int) mpc_bits_read(r, 6); 407 L[2] = L[1]; 408 break; 409 case 3: 410 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 411 L[0] = (idx!=8) ? L[2] + idx : (int) mpc_bits_read(r, 6); 412 L[1] = L[0]; 413 L[2] = L[1]; 414 break; 415 case 2: 416 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 417 L[0] = (idx!=8) ? L[2] + idx : (int) mpc_bits_read(r, 6); 418 L[1] = L[0]; 419 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 420 L[2] = (idx!=8) ? L[1] + idx : (int) mpc_bits_read(r, 6); 421 break; 422 case 0: 423 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 424 L[0] = (idx!=8) ? L[2] + idx : (int) mpc_bits_read(r, 6); 425 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 426 L[1] = (idx!=8) ? L[0] + idx : (int) mpc_bits_read(r, 6); 427 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 428 L[2] = (idx!=8) ? L[1] + idx : (int) mpc_bits_read(r, 6); 429 break; 430 default: 431 return; 432 } 433 if (L[0] > 1024) 434 L[0] = 0x8080; 435 if (L[1] > 1024) 436 L[1] = 0x8080; 437 if (L[2] > 1024) 438 L[2] = 0x8080; 439 } 440 if (*ResR) 441 { 442 switch (d->SCFI_R[n]) 443 { 444 case 1: 445 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 446 R[0] = (idx!=8) ? R[2] + idx : (int) mpc_bits_read(r, 6); 447 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 448 R[1] = (idx!=8) ? R[0] + idx : (int) mpc_bits_read(r, 6); 449 R[2] = R[1]; 450 break; 451 case 3: 452 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 453 R[0] = (idx!=8) ? R[2] + idx : (int) mpc_bits_read(r, 6); 454 R[1] = R[0]; 455 R[2] = R[1]; 456 break; 457 case 2: 458 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 459 R[0] = (idx!=8) ? R[2] + idx : (int) mpc_bits_read(r, 6); 460 R[1] = R[0]; 461 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 462 R[2] = (idx!=8) ? R[1] + idx : (int) mpc_bits_read(r, 6); 463 break; 464 case 0: 465 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 466 R[0] = (idx!=8) ? R[2] + idx : (int) mpc_bits_read(r, 6); 467 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 468 R[1] = (idx!=8) ? R[0] + idx : (int) mpc_bits_read(r, 6); 469 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 470 R[2] = (idx!=8) ? R[1] + idx : (int) mpc_bits_read(r, 6); 471 break; 472 default: 473 return; 474 } 475 if (R[0] > 1024) 476 R[0] = 0x8080; 477 if (R[1] > 1024) 478 R[1] = 0x8080; 479 if (R[2] > 1024) 480 R[2] = 0x8080; 481 } 378 for ( n = 0; n <= Max_used_Band; n++ ) { 379 mpc_int32_t * SCF = d->SCF_Index_L[n]; 380 mpc_uint32_t Res = d->Res_L[n], SCFI = d->SCFI_L[n]; 381 do { 382 if (Res) { 383 switch (SCFI) { 384 case 1: 385 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 386 SCF[0] = (idx!=8) ? SCF[2] + idx : (int) mpc_bits_read(r, 6); 387 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 388 SCF[1] = (idx!=8) ? SCF[0] + idx : (int) mpc_bits_read(r, 6); 389 SCF[2] = SCF[1]; 390 break; 391 case 3: 392 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 393 SCF[0] = (idx!=8) ? SCF[2] + idx : (int) mpc_bits_read(r, 6); 394 SCF[1] = SCF[0]; 395 SCF[2] = SCF[1]; 396 break; 397 case 2: 398 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 399 SCF[0] = (idx!=8) ? SCF[2] + idx : (int) mpc_bits_read(r, 6); 400 SCF[1] = SCF[0]; 401 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 402 SCF[2] = (idx!=8) ? SCF[1] + idx : (int) mpc_bits_read(r, 6); 403 break; 404 case 0: 405 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 406 SCF[0] = (idx!=8) ? SCF[2] + idx : (int) mpc_bits_read(r, 6); 407 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 408 SCF[1] = (idx!=8) ? SCF[0] + idx : (int) mpc_bits_read(r, 6); 409 idx = mpc_bits_huff_dec(r, mpc_table_HuffDSCF); 410 SCF[2] = (idx!=8) ? SCF[1] + idx : (int) mpc_bits_read(r, 6); 411 break; 412 default: 413 return; 414 } 415 if (SCF[0] > 1024) 416 SCF[0] = 0x8080; 417 if (SCF[1] > 1024) 418 SCF[1] = 0x8080; 419 if (SCF[2] > 1024) 420 SCF[2] = 0x8080; 421 } 422 Res = d->Res_R[n]; 423 SCFI = d->SCFI_R[n]; 424 } while ( SCF == d->SCF_Index_L[n] && (SCF = d->SCF_Index_R[n])); 482 425 } 483 426 … … 486 429 487 430 /***************************** Samples ****************************/ 488 ResL = d->Res_L; 489 ResR = d->Res_R; 490 L = d->Q[0].L; 491 R = d->Q[0].R; 492 for (n=0; n <= Max_used_Band; ++n, ++ResL, ++ResR, L+=36, R+=36) 493 { 494 /************** links **************/ 495 switch (*ResL) 496 { 497 case -2: case -3: case -4: case -5: case -6: case -7: case -8: case -9: 498 case -10: case -11: case -12: case -13: case -14: case -15: case -16: case -17: 499 L += 36; 500 break; 501 case -1: 502 for (k=0; k<36; k++ ) { 503 tmp = mpc_random_int(d); 504 *L++ = ((tmp >> 24) & 0xFF) + ((tmp >> 16) & 0xFF) + ((tmp >> 8) & 0xFF) + ((tmp >> 0) & 0xFF) - 510; 505 } 506 break; 507 case 0: 508 L += 36;// increase pointer 509 break; 510 case 1: 511 Table = mpc_table_HuffQ[mpc_bits_read(r, 1)][1]; 512 for (k=0; k<12; ++k) 513 { 514 idx = mpc_bits_huff_dec(r, Table); 515 *L++ = idx30[idx]; 516 *L++ = idx31[idx]; 517 *L++ = idx32[idx]; 518 } 519 break; 520 case 2: 521 Table = mpc_table_HuffQ[mpc_bits_read(r, 1)][2]; 522 for (k=0; k<18; ++k) 523 { 524 idx = mpc_bits_huff_dec(r, Table); 525 *L++ = idx50[idx]; 526 *L++ = idx51[idx]; 527 } 528 break; 529 case 3: 530 case 4: 531 Table = mpc_table_HuffQ[mpc_bits_read(r, 1)][*ResL]; 532 for (k=0; k<36; ++k) 533 *L++ = mpc_bits_huff_dec(r, Table); 534 break; 535 case 5: 536 Table = mpc_table_HuffQ[mpc_bits_read(r, 1)][*ResL]; 537 for (k=0; k<36; ++k) 538 *L++ = mpc_bits_huff_dec(r, Table); 539 break; 540 case 6: 541 case 7: 542 Table = mpc_table_HuffQ[mpc_bits_read(r, 1)][*ResL]; 543 for (k=0; k<36; ++k) 544 *L++ = mpc_bits_huff_dec(r, Table); 545 break; 546 case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: 547 tmp = Dc[*ResL]; 548 for (k=0; k<36; ++k) 549 *L++ = (mpc_int32_t)mpc_bits_read(r, Res_bit[*ResL]) - tmp; 550 break; 551 default: 552 return; 553 } 554 /************** rechts **************/ 555 switch (*ResR) 556 { 557 case -2: case -3: case -4: case -5: case -6: case -7: case -8: case -9: 558 case -10: case -11: case -12: case -13: case -14: case -15: case -16: case -17: 559 R += 36; 560 break; 561 case -1: 562 for (k=0; k<36; k++ ) { 563 tmp = mpc_random_int(d); 564 *R++ = ((tmp >> 24) & 0xFF) + ((tmp >> 16) & 0xFF) + ((tmp >> 8) & 0xFF) + ((tmp >> 0) & 0xFF) - 510; 565 } 566 break; 567 case 0: 568 R += 36;// increase pointer 569 break; 570 case 1: 571 Table = mpc_table_HuffQ[mpc_bits_read(r, 1)][1]; 572 for (k=0; k<12; ++k) 573 { 574 idx = mpc_bits_huff_dec(r, Table); 575 *R++ = idx30[idx]; 576 *R++ = idx31[idx]; 577 *R++ = idx32[idx]; 578 } 579 break; 580 case 2: 581 Table = mpc_table_HuffQ[mpc_bits_read(r, 1)][2]; 582 for (k=0; k<18; ++k) 583 { 584 idx = mpc_bits_huff_dec(r, Table); 585 *R++ = idx50[idx]; 586 *R++ = idx51[idx]; 587 } 588 break; 589 case 3: 590 case 4: 591 Table = mpc_table_HuffQ[mpc_bits_read(r, 1)][*ResR]; 592 for (k=0; k<36; ++k) 593 *R++ = mpc_bits_huff_dec(r, Table); 594 break; 595 case 5: 596 Table = mpc_table_HuffQ[mpc_bits_read(r, 1)][*ResR]; 597 for (k=0; k<36; ++k) 598 *R++ = mpc_bits_huff_dec(r, Table); 599 break; 600 case 6: 601 case 7: 602 Table = mpc_table_HuffQ[mpc_bits_read(r, 1)][*ResR]; 603 for (k=0; k<36; ++k) 604 *R++ = mpc_bits_huff_dec(r, Table); 605 break; 606 case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: 607 tmp = Dc[*ResR]; 608 for (k=0; k<36; ++k) 609 *R++ = (mpc_int32_t)mpc_bits_read(r, Res_bit[*ResR]) - tmp; 610 break; 611 default: 612 return; 613 } 431 for ( n = 0; n <= Max_used_Band; n++ ) { 432 mpc_int32_t *q = d->Q[n].L, Res = d->Res_L[n]; 433 do { 434 mpc_int32_t k; 435 const mpc_huffman *Table; 436 switch (Res) { 437 case -2: case -3: case -4: case -5: case -6: case -7: case -8: case -9: 438 case -10: case -11: case -12: case -13: case -14: case -15: case -16: case -17: case 0: 439 break; 440 case -1: 441 for (k=0; k<36; k++ ) { 442 mpc_uint32_t tmp = mpc_random_int(d); 443 q[k] = ((tmp >> 24) & 0xFF) + ((tmp >> 16) & 0xFF) + ((tmp >> 8) & 0xFF) + ((tmp >> 0) & 0xFF) - 510; 444 } 445 break; 446 case 1: 447 Table = mpc_table_HuffQ[mpc_bits_read(r, 1)][1]; 448 for ( k = 0; k < 36; k += 3) { 449 idx = mpc_bits_huff_dec(r, Table); 450 q[k] = idx30[idx]; 451 q[k + 1] = idx31[idx]; 452 q[k + 2] = idx32[idx]; 453 } 454 break; 455 case 2: 456 Table = mpc_table_HuffQ[mpc_bits_read(r, 1)][2]; 457 for ( k = 0; k < 36; k += 2) { 458 idx = mpc_bits_huff_dec(r, Table); 459 q[k] = idx50[idx]; 460 q[k + 1] = idx51[idx]; 461 } 462 break; 463 case 3: 464 case 4: 465 case 5: 466 case 6: 467 case 7: 468 Table = mpc_table_HuffQ[mpc_bits_read(r, 1)][Res]; 469 for ( k = 0; k < 36; k++ ) 470 q[k] = mpc_bits_huff_dec(r, Table); 471 break; 472 case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: 473 for ( k = 0; k < 36; k++ ) 474 q[k] = (mpc_int32_t)mpc_bits_read(r, Res_bit[Res]) - Dc[Res]; 475 break; 476 default: 477 return; 478 } 479 480 Res = d->Res_R[n]; 481 } while (q == d->Q[n].L && (q = d->Q[n].R)); 614 482 } 615 483 }
Note: See TracChangeset
for help on using the changeset viewer.