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 "ixheaac_type_def.h"
21 #include "ixheaacd_bitbuffer.h"
22 #include "ixheaacd_mps_aac_struct.h"
23 #include "ixheaacd_mps_res_rom.h"
24 #include "ixheaacd_error_codes.h"
25
ixheaacd_res_c_pulse_data_read(ia_bit_buf_struct * it_bit_buf,ia_mps_dec_residual_pulse_data_struct * pulse_data,ia_mps_dec_residual_aac_tables_struct * aac_tables_ptr)26 WORD32 ixheaacd_res_c_pulse_data_read(ia_bit_buf_struct *it_bit_buf,
27 ia_mps_dec_residual_pulse_data_struct *pulse_data,
28 ia_mps_dec_residual_aac_tables_struct *aac_tables_ptr) {
29 WORD32 i, k;
30 WORD32 error = 0;
31 pulse_data->pulse_data_present = (FLAG)ixheaacd_read_bits_buf(it_bit_buf, 1);
32 if (pulse_data->pulse_data_present) {
33 WORD32 tmp = ixheaacd_read_bits_buf(it_bit_buf, 8);
34 pulse_data->number_pulse = tmp >> 6;
35 pulse_data->pulse_start_band = tmp & 0x3F;
36
37 if (pulse_data->pulse_start_band >= 52) {
38 return (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_PULSEDATA_ERROR;
39 }
40
41 k = aac_tables_ptr->sfb_index_long[pulse_data->pulse_start_band];
42
43 for (i = 0; i <= pulse_data->number_pulse; i++) {
44 WORD32 tmp = ixheaacd_read_bits_buf(it_bit_buf, 9);
45 pulse_data->pulse_offset[i] = tmp >> 4;
46 pulse_data->pulse_amp[i] = tmp & 0xF;
47
48 k += pulse_data->pulse_offset[i];
49 if (k >= 1024) error = (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_PULSEDATA_ERROR;
50 }
51 }
52
53 return error;
54 }
55