Revision b9c3e3b6

View differences:

libavcodec/aacsbr.c
698 698
        return -1;
699 699
    }
700 700

  
701
    int abs_bord_lead  =  ch_data->bs_frame_class >= 2 ? ch_data->bs_var_bord[0] : 0;
702
    // frameLengthFlag ? 15 : 16; 960 sample length frames unsupported; this value is numTimeSlots
703
    int abs_bord_trail = (ch_data->bs_frame_class & 1 ? ch_data->bs_var_bord[1] : 0) + 16;
704
    int n_rel_lead;
705

  
706
    if (ch_data->bs_frame_class == FIXFIX) {
707
        n_rel_lead = ch_data->bs_num_env[1] - 1;
708
    } else if (ch_data->bs_frame_class == FIXVAR) {
709
        n_rel_lead = 0;
710
    } else if (ch_data->bs_frame_class < 4) { // VARFIX or VARVAR
711
        n_rel_lead = ch_data->bs_num_rel[0];
712
    } else {
713
        av_log(ac->avccontext, AV_LOG_ERROR,
714
               "Invalid bs_frame_class for SBR: %d\n", ch_data->bs_frame_class);
715
        return -1;
716
    }
717

  
718
    ch_data->t_env_num_env_old = ch_data->t_env[ch_data->bs_num_env[0]];
719
    ch_data->t_env[0]                      = abs_bord_lead;
720
    ch_data->t_env[ch_data->bs_num_env[1]] = abs_bord_trail;
721

  
722
    if (ch_data->bs_frame_class == FIXFIX) {
723
        int temp = (abs_bord_trail + (ch_data->bs_num_env[1] >> 1)) /
724
                   ch_data->bs_num_env[1];
725
        for (i = 0; i < n_rel_lead; i++)
726
            ch_data->t_env[i + 1] = ch_data->t_env[i] + temp;
727
    } else if (ch_data->bs_frame_class > 1) { // VARFIX or VARVAR
728
        for (i = 0; i < n_rel_lead; i++)
729
            ch_data->t_env[i + 1] = ch_data->t_env[i] + ch_data->bs_rel_bord[0][i];
730
    } else { // FIXVAR
731
        for (i = 0; i < n_rel_lead; i++)
732
            ch_data->t_env[i + 1] = abs_bord_lead;
733
    }
734

  
735
    if (ch_data->bs_frame_class & 1) { // FIXVAR or VARVAR
736
        for (i = ch_data->bs_num_env[1] - 1; i > n_rel_lead; i--)
737
            ch_data->t_env[i] = ch_data->t_env[i + 1] -
738
                                ch_data->bs_rel_bord[1][ch_data->bs_num_env[1] - 1 - i];
739
    } else { // FIXFIX or VARFIX
740
        for (i = n_rel_lead; i < ch_data->bs_num_env[1]; i++)
741
            ch_data->t_env[i + 1] = abs_bord_trail;
742
    }
743

  
701 744
    ch_data->bs_num_noise = (ch_data->bs_num_env[1] > 1) + 1;
702 745

  
746
    ch_data->t_q[0] = ch_data->t_env[0];
747
    if (ch_data->bs_num_noise > 1) { // typo in spec bases this on bs_num_env...
748
        unsigned int idx;
749
        if (ch_data->bs_frame_class == FIXFIX) {
750
            idx = ch_data->bs_num_env[1] >> 1;
751
        } else if (ch_data->bs_frame_class & 1) { // FIXVAR or VARVAR
752
            idx = ch_data->bs_num_env[1] - FFMAX(ch_data->bs_pointer - 1, 1);
753
        } else { // VARFIX
754
            if (!ch_data->bs_pointer)
755
                idx = 1;
756
            else if (ch_data->bs_pointer == 1)
757
                idx = ch_data->bs_num_env[1] - 1;
758
            else // bs_pointer > 1
759
                idx = ch_data->bs_pointer - 1;
760
        }
761
        ch_data->t_q[1] = ch_data->t_env[idx];
762
        ch_data->t_q[2] = ch_data->t_env[ch_data->bs_num_env[1]];
763
    } else
764
        ch_data->t_q[1] = ch_data->t_env[ch_data->bs_num_env[1]];
765

  
703 766
    return 0;
704 767
}
705 768

  
......
707 770
    //These variables are saved from the previous frame rather than copied
708 771
    dst->bs_freq_res[0] = dst->bs_freq_res[dst->bs_num_env[1]];
709 772
    dst->bs_num_env[0]  = dst->bs_num_env[1];
773
    dst->t_env_num_env_old = dst->t_env[dst->bs_num_env[0]];
710 774

  
711 775
    //These variables are read from the bitstream and therefore copied
712 776
    memcpy(dst->bs_freq_res+1, src->bs_freq_res+1, sizeof(dst->bs_freq_res)-sizeof(*dst->bs_freq_res));
......
714 778
    memcpy(dst->bs_var_bord,   src->bs_var_bord,   sizeof(dst->bs_var_bord));
715 779
    memcpy(dst->bs_rel_bord,   src->bs_rel_bord,   sizeof(dst->bs_rel_bord));
716 780
    memcpy(dst->bs_num_rel,    src->bs_num_rel,    sizeof(dst->bs_rel_bord));
781
    memcpy(dst->t_env,         src->t_env,         sizeof(dst->t_env));
782
    memcpy(dst->t_q,           src->t_q,           sizeof(dst->t_q));
717 783
    dst->bs_amp_res     = src->bs_amp_res;
718 784
    dst->bs_num_noise   = src->bs_num_noise;
719 785
    dst->bs_pointer     = src->bs_pointer;
......
1030 1096
    return cnt;
1031 1097
}
1032 1098

  
1033
/// Time/frequency Grid (14496-3 sp04 p200)
1034
static int sbr_time_freq_grid(AACContext *ac, SpectralBandReplication *sbr,
1035
                              SBRData *ch_data, int ch)
1036
{
1037
    int abs_bord_lead  =  ch_data->bs_frame_class >= 2 ? ch_data->bs_var_bord[0] : 0;
1038
    // frameLengthFlag ? 15 : 16; 960 sample length frames unsupported; this value is numTimeSlots
1039
    int abs_bord_trail = (ch_data->bs_frame_class & 1 ? ch_data->bs_var_bord[1] : 0) + 16;
1040
    int n_rel_lead;
1041
    int i;
1042

  
1043
    if (ch_data->bs_frame_class == FIXFIX) {
1044
        n_rel_lead = ch_data->bs_num_env[1] - 1;
1045
    } else if (ch_data->bs_frame_class == FIXVAR) {
1046
        n_rel_lead = 0;
1047
    } else if (ch_data->bs_frame_class < 4) { // VARFIX or VARVAR
1048
        n_rel_lead = ch_data->bs_num_rel[0];
1049
    } else {
1050
        av_log(ac->avccontext, AV_LOG_ERROR,
1051
               "Invalid bs_frame_class for SBR: %d\n", ch_data->bs_frame_class);
1052
        return -1;
1053
    }
1054

  
1055
    ch_data->t_env_num_env_old = ch_data->t_env[ch_data->bs_num_env[0]];
1056
    ch_data->t_env[0]                      = abs_bord_lead;
1057
    ch_data->t_env[ch_data->bs_num_env[1]] = abs_bord_trail;
1058

  
1059
    if (ch_data->bs_frame_class == FIXFIX) {
1060
        int temp = (abs_bord_trail + (ch_data->bs_num_env[1] >> 1)) /
1061
                   ch_data->bs_num_env[1];
1062
        for (i = 0; i < n_rel_lead; i++)
1063
            ch_data->t_env[i + 1] = ch_data->t_env[i] + temp;
1064
    } else if (ch_data->bs_frame_class > 1) { // VARFIX or VARVAR
1065
        for (i = 0; i < n_rel_lead; i++)
1066
            ch_data->t_env[i + 1] = ch_data->t_env[i] + ch_data->bs_rel_bord[0][i];
1067
    } else { // FIXVAR
1068
        for (i = 0; i < n_rel_lead; i++)
1069
            ch_data->t_env[i + 1] = abs_bord_lead;
1070
    }
1071

  
1072
    if (ch_data->bs_frame_class & 1) { // FIXVAR or VARVAR
1073
        for (i = ch_data->bs_num_env[1] - 1; i > n_rel_lead; i--)
1074
            ch_data->t_env[i] = ch_data->t_env[i + 1] -
1075
                                ch_data->bs_rel_bord[1][ch_data->bs_num_env[1] - 1 - i];
1076
    } else { // FIXFIX or VARFIX
1077
        for (i = n_rel_lead; i < ch_data->bs_num_env[1]; i++)
1078
            ch_data->t_env[i + 1] = abs_bord_trail;
1079
    }
1080

  
1081
    ch_data->t_q[0] = ch_data->t_env[0];
1082
    if (ch_data->bs_num_noise > 1) { // typo in spec bases this on bs_num_env...
1083
        unsigned int idx;
1084
        if (ch_data->bs_frame_class == FIXFIX) {
1085
            idx = ch_data->bs_num_env[1] >> 1;
1086
        } else if (ch_data->bs_frame_class & 1) { // FIXVAR or VARVAR
1087
            idx = ch_data->bs_num_env[1] - FFMAX(ch_data->bs_pointer - 1, 1);
1088
        } else { // VARFIX
1089
            if (!ch_data->bs_pointer)
1090
                idx = 1;
1091
            else if (ch_data->bs_pointer == 1)
1092
                idx = ch_data->bs_num_env[1] - 1;
1093
            else // bs_pointer > 1
1094
                idx = ch_data->bs_pointer - 1;
1095
        }
1096
        ch_data->t_q[1] = ch_data->t_env[idx];
1097
        ch_data->t_q[2] = ch_data->t_env[ch_data->bs_num_env[1]];
1098
    } else
1099
        ch_data->t_q[1] = ch_data->t_env[ch_data->bs_num_env[1]];
1100

  
1101
    return 0;
1102
}
1103

  
1104 1099
/// Dequantization and stereo decoding (14496-3 sp04 p203)
1105 1100
static void sbr_dequant(SpectralBandReplication *sbr, int id_aac)
1106 1101
{
......
1738 1733

  
1739 1734
void ff_sbr_dequant(AACContext *ac, SpectralBandReplication *sbr, int id_aac)
1740 1735
{
1741
    int ch;
1742

  
1743 1736
    if (sbr->start) {
1744
        for (ch = 0; ch < (id_aac == TYPE_CPE) + 1; ch++) {
1745
            sbr_time_freq_grid(ac, sbr, &sbr->data[ch], ch);
1746
        }
1747 1737
        sbr_dequant(sbr, id_aac);
1748 1738
    }
1749 1739
}

Also available in: Unified diff