• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright (C) 2023 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 #include "ixheaacd_type_def.h"
21 #include "ixheaacd_bitbuffer.h"
22 #include "ixheaacd_cnst.h"
23 #include "ixheaacd_mps_aac_struct.h"
24 #include "ixheaacd_mps_res_rom.h"
25 #include "ixheaacd_basic_op.h"
26 #include "ixheaacd_mps_res.h"
27 
ixheaacd_res_get_sfb_offsets(ia_mps_dec_residual_ics_info_struct * p_ics_info,ia_mps_dec_residual_aac_tables_struct * aac_tables_ptr)28 const WORD16 *ixheaacd_res_get_sfb_offsets(
29     ia_mps_dec_residual_ics_info_struct *p_ics_info,
30     ia_mps_dec_residual_aac_tables_struct *aac_tables_ptr) {
31   if (p_ics_info->window_sequence != EIGHT_SHORT_SEQUENCE) {
32     return aac_tables_ptr->sfb_index_long;
33   } else {
34     return aac_tables_ptr->sfb_index_short;
35   }
36 }
37 
ixheaacd_res_get_sfb_width(ia_mps_dec_residual_ics_info_struct * p_ics_info,ia_mps_dec_residual_aac_tables_struct * aac_tables_ptr)38 const WORD8 *ixheaacd_res_get_sfb_width(ia_mps_dec_residual_ics_info_struct *p_ics_info,
39                                         ia_mps_dec_residual_aac_tables_struct *aac_tables_ptr) {
40   if (p_ics_info->window_sequence != EIGHT_SHORT_SEQUENCE) {
41     return aac_tables_ptr->sfb_index_long_width;
42   } else {
43     return aac_tables_ptr->sfb_index_short_width;
44   }
45 }
46 
ixheaacd_res_ics_read(ia_bit_buf_struct * it_bif_buf,ia_mps_dec_residual_ics_info_struct * p_ics_info,WORD8 tot_sf_bands_ls[2])47 WORD16 ixheaacd_res_ics_read(ia_bit_buf_struct *it_bif_buf,
48                              ia_mps_dec_residual_ics_info_struct *p_ics_info,
49                              WORD8 tot_sf_bands_ls[2]) {
50   WORD i;
51   WORD mask;
52   WORD tmp = 0;
53 
54   tmp = ixheaacd_read_bits_buf(it_bif_buf, 4);
55   p_ics_info->window_sequence = (WORD16)((tmp & 0x6) >> 1);
56 
57   if (p_ics_info->window_sequence != EIGHT_SHORT_SEQUENCE) {
58     p_ics_info->total_sf_bands = tot_sf_bands_ls[0];
59 
60     p_ics_info->window_groups = 1;
61     p_ics_info->window_group_length[0] = 1;
62 
63     tmp = ixheaacd_read_bits_buf(it_bif_buf, 7);
64     p_ics_info->max_sf_bands = (tmp & 0x7E) >> 1;
65 
66     if (tmp & 1) {
67       return (WORD16)((WORD32)AAC_DEC_PREDICTION_NOT_SUPPORTED_IN_LC_AAC);
68     }
69   } else {
70     WORD32 win_grp = 0, tmp2;
71     p_ics_info->total_sf_bands = tot_sf_bands_ls[1];
72 
73     tmp = ixheaacd_read_bits_buf(it_bif_buf, 11);
74     p_ics_info->max_sf_bands = (tmp & 0x780) >> 7;
75 
76     tmp2 = (tmp & 0x7F);
77 
78     for (i = 0; i < 7; i++) {
79       mask = (1 << sub_d(6, i));
80       p_ics_info->window_group_length[i] = 1;
81       if (tmp2 & mask) {
82         p_ics_info->window_group_length[win_grp] =
83             add_d(p_ics_info->window_group_length[win_grp], 1);
84       } else {
85         win_grp = add_d(win_grp, 1);
86       }
87     }
88 
89     p_ics_info->window_group_length[7] = 1;
90     p_ics_info->window_groups = add_d(win_grp, 1);
91   }
92 
93   if (p_ics_info->max_sf_bands > p_ics_info->total_sf_bands)
94     return (WORD16)IA_XHEAAC_DEC_EXE_NONFATAL_EXCEEDS_SFB_TRANSMITTED;
95 
96   return AAC_DEC_OK;
97 }
98