1 /******************************************************************************
2 *
3 * Copyright (C) 2018 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 <stdio.h>
21 #include <math.h>
22
23 #include "impd_type_def.h"
24 #include "impd_drc_extr_delta_coded_info.h"
25 #include "impd_drc_common.h"
26 #include "impd_drc_struct.h"
27 #include "impd_drc_filter_bank.h"
28 #include "impd_drc_rom.h"
29
impd_init_tbls(const WORD32 num_gain_max_values,ia_tables_struct * str_tables)30 VOID impd_init_tbls(const WORD32 num_gain_max_values,
31 ia_tables_struct* str_tables) {
32 impd_gen_delta_time_code_tbl(num_gain_max_values,
33 str_tables->delta_time_code_table);
34 return;
35 }
36
impd_get_delta_gain_code_tbl(const WORD32 gain_coding_profile,ia_delta_gain_code_table_struct const ** delta_time_code_tbl,WORD32 * num_entries)37 void impd_get_delta_gain_code_tbl(
38 const WORD32 gain_coding_profile,
39 ia_delta_gain_code_table_struct const** delta_time_code_tbl,
40 WORD32* num_entries) {
41 if (gain_coding_profile == GAIN_CODING_PROFILE_CLIPPING) {
42 *delta_time_code_tbl = ia_drc_gain_tbls_prof_2;
43 *num_entries = NUM_GAIN_TBL_PROF_2_ENTRIES;
44 } else {
45 *delta_time_code_tbl = ia_drc_gain_tbls_prof_0_1;
46 *num_entries = NUM_GAIN_TBL_PROF_0_1_ENTRIES;
47 }
48 }
49
impd_gen_delta_time_code_tbl(const WORD32 num_gain_max_values,ia_delta_time_code_table_entry_struct * delta_time_code_tbl_item)50 void impd_gen_delta_time_code_tbl(
51 const WORD32 num_gain_max_values,
52 ia_delta_time_code_table_entry_struct* delta_time_code_tbl_item) {
53 WORD32 n, k;
54
55 WORD32 Z = 1;
56 while ((1 << Z) < 2 * num_gain_max_values) {
57 Z++;
58 }
59
60 delta_time_code_tbl_item[0].size = -1;
61 delta_time_code_tbl_item[0].code = -1;
62 delta_time_code_tbl_item[0].value = -1;
63
64 delta_time_code_tbl_item[1].size = 2;
65 delta_time_code_tbl_item[1].code = 0x0;
66 delta_time_code_tbl_item[1].value = 1;
67 for (n = 0; n < 4; n++) {
68 delta_time_code_tbl_item[n + 2].size = 4;
69 delta_time_code_tbl_item[n + 2].code = 0x4 + n;
70 delta_time_code_tbl_item[n + 2].value = n + 2;
71 }
72 for (n = 0; n < 8; n++) {
73 delta_time_code_tbl_item[n + 6].size = 5;
74 delta_time_code_tbl_item[n + 6].code = 0x10 + n;
75 delta_time_code_tbl_item[n + 6].value = n + 6;
76 }
77
78 k = 2 * num_gain_max_values - 14 + 1;
79 for (n = 0; n < k; n++) {
80 delta_time_code_tbl_item[n + 14].size = 2 + Z;
81 delta_time_code_tbl_item[n + 14].code = (0x3 << Z) + n;
82 delta_time_code_tbl_item[n + 14].value = n + 14;
83 }
84 }
85
86 WORD32
impd_get_delta_tmin(const WORD32 sampling_rate)87 impd_get_delta_tmin(const WORD32 sampling_rate) {
88 WORD32 lowerBound = (WORD32)(0.5f + 0.0005f * sampling_rate);
89 WORD32 result = 1;
90 while (result <= lowerBound) result = result << 1;
91 return result;
92 }
93