comparison alac.c @ 5357:07c6fa478918 libavcodec

Remove code duplication. Based on a patch by Matthieu Castet.
author vitor
date Tue, 17 Jul 2007 22:05:33 +0000
parents e00f7048c50c
children f3a26c190f9a
comparison
equal deleted inserted replaced
5356:ed7d84e0164d 5357:07c6fa478918
628 uint8_t interlacing_shift; 628 uint8_t interlacing_shift;
629 uint8_t interlacing_leftweight; 629 uint8_t interlacing_leftweight;
630 630
631 if (!isnotcompressed) { 631 if (!isnotcompressed) {
632 /* compressed */ 632 /* compressed */
633 int16_t predictor_coef_table_a[32]; 633 int16_t predictor_coef_table[channels][32];
634 int predictor_coef_num_a; 634 int predictor_coef_num[channels];
635 int prediction_type_a; 635 int prediction_type[channels];
636 int prediction_quantitization_a; 636 int prediction_quantitization[channels];
637 int ricemodifier_a; 637 int ricemodifier[channels];
638 638
639 int16_t predictor_coef_table_b[32]; 639 int i, chan;
640 int predictor_coef_num_b;
641 int prediction_type_b;
642 int prediction_quantitization_b;
643 int ricemodifier_b;
644
645 int i;
646 640
647 interlacing_shift = get_bits(&alac->gb, 8); 641 interlacing_shift = get_bits(&alac->gb, 8);
648 interlacing_leftweight = get_bits(&alac->gb, 8); 642 interlacing_leftweight = get_bits(&alac->gb, 8);
649 643
650 /******** channel 1 ***********/ 644 for (chan = 0; chan < channels; chan++) {
651 prediction_type_a = get_bits(&alac->gb, 4); 645 prediction_type[chan] = get_bits(&alac->gb, 4);
652 prediction_quantitization_a = get_bits(&alac->gb, 4); 646 prediction_quantitization[chan] = get_bits(&alac->gb, 4);
653 647
654 ricemodifier_a = get_bits(&alac->gb, 3); 648 ricemodifier[chan] = get_bits(&alac->gb, 3);
655 predictor_coef_num_a = get_bits(&alac->gb, 5); 649 predictor_coef_num[chan] = get_bits(&alac->gb, 5);
656 650
657 /* read the predictor table */ 651 /* read the predictor table */
658 for (i = 0; i < predictor_coef_num_a; i++) { 652 for (i = 0; i < predictor_coef_num[chan]; i++) {
659 predictor_coef_table_a[i] = (int16_t)get_bits(&alac->gb, 16); 653 predictor_coef_table[chan][i] = (int16_t)get_bits(&alac->gb, 16);
660 } 654 }
661 655 }
662 /******** channel 2 *********/ 656
663 prediction_type_b = get_bits(&alac->gb, 4);
664 prediction_quantitization_b = get_bits(&alac->gb, 4);
665
666 ricemodifier_b = get_bits(&alac->gb, 3);
667 predictor_coef_num_b = get_bits(&alac->gb, 5);
668
669 /* read the predictor table */
670 for (i = 0; i < predictor_coef_num_b; i++) {
671 predictor_coef_table_b[i] = (int16_t)get_bits(&alac->gb, 16);
672 }
673
674 /*********************/
675 if (wasted_bytes) { 657 if (wasted_bytes) {
676 /* see mono case */ 658 /* see mono case */
677 av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented, unhandling of wasted_bytes\n"); 659 av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented, unhandling of wasted_bytes\n");
678 } 660 }
679 661
680 /* channel 1 */ 662 for (chan = 0; chan < channels; chan++) {
681 bastardized_rice_decompress(alac, 663 bastardized_rice_decompress(alac,
682 alac->predicterror_buffer[0], 664 alac->predicterror_buffer[chan],
683 outputsamples, 665 outputsamples,
684 readsamplesize, 666 readsamplesize,
685 alac->setinfo_rice_initialhistory, 667 alac->setinfo_rice_initialhistory,
686 alac->setinfo_rice_kmodifier, 668 alac->setinfo_rice_kmodifier,
687 ricemodifier_a * alac->setinfo_rice_historymult / 4, 669 ricemodifier[chan] * alac->setinfo_rice_historymult / 4,
688 (1 << alac->setinfo_rice_kmodifier) - 1); 670 (1 << alac->setinfo_rice_kmodifier) - 1);
689 671
690 if (prediction_type_a == 0) { 672 if (prediction_type[chan] == 0) {
691 /* adaptive fir */ 673 /* adaptive fir */
692 predictor_decompress_fir_adapt(alac->predicterror_buffer[0], 674 predictor_decompress_fir_adapt(alac->predicterror_buffer[chan],
693 alac->outputsamples_buffer[0], 675 alac->outputsamples_buffer[chan],
694 outputsamples, 676 outputsamples,
695 readsamplesize, 677 readsamplesize,
696 predictor_coef_table_a, 678 predictor_coef_table[chan],
697 predictor_coef_num_a, 679 predictor_coef_num[chan],
698 prediction_quantitization_a); 680 prediction_quantitization[chan]);
699 } else { 681 } else {
700 /* see mono case */ 682 /* see mono case */
701 av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\n", prediction_type_a); 683 av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\n", prediction_type[chan]);
702 } 684 }
703 685 }
704 /* channel 2 */
705 bastardized_rice_decompress(alac,
706 alac->predicterror_buffer[1],
707 outputsamples,
708 readsamplesize,
709 alac->setinfo_rice_initialhistory,
710 alac->setinfo_rice_kmodifier,
711 ricemodifier_b * alac->setinfo_rice_historymult / 4,
712 (1 << alac->setinfo_rice_kmodifier) - 1);
713
714 if (prediction_type_b == 0) {
715 /* adaptive fir */
716 predictor_decompress_fir_adapt(alac->predicterror_buffer[1],
717 alac->outputsamples_buffer[1],
718 outputsamples,
719 readsamplesize,
720 predictor_coef_table_b,
721 predictor_coef_num_b,
722 prediction_quantitization_b);
723 } else {
724 av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\n", prediction_type_b);
725 }
726 } else { 686 } else {
727 /* not compressed, easy case */ 687 /* not compressed, easy case */
728 if (alac->setinfo_sample_size <= 16) { 688 if (alac->setinfo_sample_size <= 16) {
729 int i; 689 int i, chan;
690 for (chan = 0; chan < channels; chan++) {
730 for (i = 0; i < outputsamples; i++) { 691 for (i = 0; i < outputsamples; i++) {
731 int32_t audiobits_a, audiobits_b; 692 int32_t audiobits;
732 693
733 audiobits_a = get_bits(&alac->gb, alac->setinfo_sample_size); 694 audiobits = get_bits(&alac->gb, alac->setinfo_sample_size);
734 audiobits_b = get_bits(&alac->gb, alac->setinfo_sample_size); 695 audiobits = SIGN_EXTENDED32(audiobits, alac->setinfo_sample_size);
735 696 alac->outputsamples_buffer[chan][i] = audiobits;
736 audiobits_a = SIGN_EXTENDED32(audiobits_a, alac->setinfo_sample_size);
737 audiobits_b = SIGN_EXTENDED32(audiobits_b, alac->setinfo_sample_size);
738
739 alac->outputsamples_buffer[0][i] = audiobits_a;
740 alac->outputsamples_buffer[1][i] = audiobits_b;
741 } 697 }
698 }
742 } else { 699 } else {
743 int i; 700 int i, chan;
701 for (chan = 0; chan < channels; chan++) {
744 for (i = 0; i < outputsamples; i++) { 702 for (i = 0; i < outputsamples; i++) {
745 int32_t audiobits_a, audiobits_b; 703 int32_t audiobits;
746 704
747 audiobits_a = get_bits(&alac->gb, 16); 705 audiobits = get_bits(&alac->gb, 16);
748 audiobits_a = audiobits_a << 16; 706 audiobits = audiobits << 16;
749 audiobits_a = audiobits_a >> (32 - alac->setinfo_sample_size); 707 audiobits = audiobits >> (32 - alac->setinfo_sample_size);
750 audiobits_a |= get_bits(&alac->gb, alac->setinfo_sample_size - 16); 708 audiobits |= get_bits(&alac->gb, alac->setinfo_sample_size - 16);
751 709
752 audiobits_b = get_bits(&alac->gb, 16); 710 alac->outputsamples_buffer[chan][i] = audiobits;
753 audiobits_b = audiobits_b << 16;
754 audiobits_b = audiobits_b >> (32 - alac->setinfo_sample_size);
755 audiobits_b |= get_bits(&alac->gb, alac->setinfo_sample_size - 16);
756
757 alac->outputsamples_buffer[0][i] = audiobits_a;
758 alac->outputsamples_buffer[1][i] = audiobits_b;
759 } 711 }
712 }
760 } 713 }
761 /* wasted_bytes = 0; */ 714 /* wasted_bytes = 0; */
762 interlacing_shift = 0; 715 interlacing_shift = 0;
763 interlacing_leftweight = 0; 716 interlacing_leftweight = 0;
764 } 717 }