Revision ac8d655a libavcodec/aacsbr.c

View differences:

libavcodec/aacsbr.c
619 619
{
620 620
    int i;
621 621
    unsigned bs_pointer;
622
    int abs_bord_lead = 0;
623 622
    // frameLengthFlag ? 15 : 16; 960 sample length frames unsupported; this value is numTimeSlots
624 623
    int abs_bord_trail = 16;
625 624
    int num_rel_lead, num_rel_trail;
626 625
    unsigned bs_num_env_old = ch_data->bs_num_env;
627
    uint8_t bs_rel_bord[2][3];
628 626

  
629 627
    ch_data->bs_freq_res[0] = ch_data->bs_freq_res[ch_data->bs_num_env];
630 628
    ch_data->bs_amp_res = sbr->bs_amp_res_header;
629
    ch_data->t_env_num_env_old = ch_data->t_env[bs_num_env_old];
631 630

  
632 631
    switch (ch_data->bs_frame_class = get_bits(gb, 2)) {
633 632
    case FIXFIX:
......
643 642
            return -1;
644 643
        }
645 644

  
645
        ch_data->t_env[0]                   = 0;
646
        ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail;
647

  
648
        abs_bord_trail = (abs_bord_trail + (ch_data->bs_num_env >> 1)) /
649
                   ch_data->bs_num_env;
650
        for (i = 0; i < num_rel_lead; i++)
651
            ch_data->t_env[i + 1] = ch_data->t_env[i] + abs_bord_trail;
652

  
646 653
        bs_pointer = 0;
647 654

  
648 655
        ch_data->bs_freq_res[1] = get_bits1(gb);
......
654 661
        num_rel_trail           = get_bits(gb, 2);
655 662
        num_rel_lead            = 0;
656 663
        ch_data->bs_num_env     = num_rel_trail + 1;
664
        ch_data->t_env[0]       = 0;
665
        ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail;
657 666

  
658 667
        for (i = 0; i < num_rel_trail; i++)
659
            bs_rel_bord[1][i] = 2 * get_bits(gb, 2) + 2;
668
            ch_data->t_env[ch_data->bs_num_env - 1 - i] = ch_data->t_env[ch_data->bs_num_env - i] - 2 * get_bits(gb, 2) - 2;
660 669

  
661 670
        bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env]);
662 671

  
......
664 673
            ch_data->bs_freq_res[ch_data->bs_num_env - i] = get_bits1(gb);
665 674
        break;
666 675
    case VARFIX:
667
        abs_bord_lead           = get_bits(gb, 2);
676
        ch_data->t_env[0]       = get_bits(gb, 2);
668 677
        num_rel_lead            = get_bits(gb, 2);
669 678
        ch_data->bs_num_env     = num_rel_lead + 1;
679
        ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail;
670 680

  
671 681
        for (i = 0; i < num_rel_lead; i++)
672
            bs_rel_bord[0][i] = 2 * get_bits(gb, 2) + 2;
682
            ch_data->t_env[i + 1] = ch_data->t_env[i] + 2 * get_bits(gb, 2) + 2;
673 683

  
674 684
        bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env]);
675 685

  
676 686
        get_bits1_vector(gb, ch_data->bs_freq_res + 1, ch_data->bs_num_env);
677 687
        break;
678 688
    case VARVAR:
679
        abs_bord_lead           = get_bits(gb, 2);
689
        ch_data->t_env[0]       = get_bits(gb, 2);
680 690
        abs_bord_trail         += get_bits(gb, 2);
681 691
        num_rel_lead            = get_bits(gb, 2);
682 692
        num_rel_trail           = get_bits(gb, 2);
683 693
        ch_data->bs_num_env     = num_rel_lead + num_rel_trail + 1;
694
        ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail;
684 695

  
685 696
        if (ch_data->bs_num_env > 5) {
686 697
            av_log(ac->avccontext, AV_LOG_ERROR,
......
690 701
        }
691 702

  
692 703
        for (i = 0; i < num_rel_lead; i++)
693
            bs_rel_bord[0][i] = 2 * get_bits(gb, 2) + 2;
704
            ch_data->t_env[i + 1] = ch_data->t_env[i] + 2 * get_bits(gb, 2) + 2;
694 705
        for (i = 0; i < num_rel_trail; i++)
695
            bs_rel_bord[1][i] = 2 * get_bits(gb, 2) + 2;
706
            ch_data->t_env[ch_data->bs_num_env - 1 - i] = ch_data->t_env[ch_data->bs_num_env - i] - 2 * get_bits(gb, 2) - 2;
696 707

  
697 708
        bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env]);
698 709

  
......
707 718
        return -1;
708 719
    }
709 720

  
710
    ch_data->t_env_num_env_old = ch_data->t_env[bs_num_env_old];
711
    ch_data->t_env[0]                      = abs_bord_lead;
712
    ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail;
713

  
714
    if (ch_data->bs_frame_class == FIXFIX) {
715
        int temp = (abs_bord_trail + (ch_data->bs_num_env >> 1)) /
716
                   ch_data->bs_num_env;
717
        for (i = 0; i < num_rel_lead; i++)
718
            ch_data->t_env[i + 1] = ch_data->t_env[i] + temp;
719
    } else if (ch_data->bs_frame_class > 1) { // VARFIX or VARVAR
720
        for (i = 0; i < num_rel_lead; i++)
721
            ch_data->t_env[i + 1] = ch_data->t_env[i] + bs_rel_bord[0][i];
722
    }
723

  
724
    if (ch_data->bs_frame_class & 1) { // FIXVAR or VARVAR
725
        for (i = ch_data->bs_num_env - 1; i > num_rel_lead; i--)
726
            ch_data->t_env[i] = ch_data->t_env[i + 1] -
727
                                bs_rel_bord[1][ch_data->bs_num_env - 1 - i];
728
    }
729

  
730 721
    ch_data->bs_num_noise = (ch_data->bs_num_env > 1) + 1;
731 722

  
732 723
    ch_data->t_q[0] = ch_data->t_env[0];

Also available in: Unified diff