1 /******************************************************************************
2 *
3 * Copyright (C) 2015 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_uni_tables.h"
25 #include "impd_drc_uni_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 WORD32 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 (0);
35 }
36
impd_get_slope_code_tbl_and_size(ia_slope_code_table_struct const ** slope_code_tbl_entry,WORD32 * num_slope_code_tbl_entries)37 void impd_get_slope_code_tbl_and_size(
38 ia_slope_code_table_struct const** slope_code_tbl_entry,
39 WORD32* num_slope_code_tbl_entries) {
40 *slope_code_tbl_entry = &(slopeCodeTableEntryBySize[0]);
41 *num_slope_code_tbl_entries = kNumSlopeValuesTable;
42 }
43
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)44 void impd_get_delta_gain_code_tbl(
45 const WORD32 gain_coding_profile,
46 ia_delta_gain_code_table_struct const** delta_time_code_tbl,
47 WORD32* num_entries) {
48 if (gain_coding_profile == GAIN_CODING_PROFILE_CLIPPING) {
49 *delta_time_code_tbl = deltaGainCodeTableProfile2BySize;
50 *num_entries = kNumDeltaGainValuesTableProfile2;
51 } else {
52 *delta_time_code_tbl = deltaGainCodeTableBySize;
53 *num_entries = kNumDeltaGainValuesTable;
54 }
55 }
56
impd_gen_delta_time_code_tbl(const WORD32 num_gain_max_values,ia_delta_time_code_table_entry_struct * delta_time_code_tbl_item)57 void impd_gen_delta_time_code_tbl(
58 const WORD32 num_gain_max_values,
59 ia_delta_time_code_table_entry_struct* delta_time_code_tbl_item) {
60 WORD32 n, k;
61
62 WORD32 Z = 1;
63 while ((1 << Z) < 2 * num_gain_max_values) {
64 Z++;
65 }
66
67 delta_time_code_tbl_item[0].size = -1;
68 delta_time_code_tbl_item[0].code = -1;
69 delta_time_code_tbl_item[0].value = -1;
70
71 delta_time_code_tbl_item[1].size = 2;
72 delta_time_code_tbl_item[1].code = 0x0;
73 delta_time_code_tbl_item[1].value = 1;
74 for (n = 0; n < 4; n++) {
75 delta_time_code_tbl_item[n + 2].size = 4;
76 delta_time_code_tbl_item[n + 2].code = 0x4 + n;
77 delta_time_code_tbl_item[n + 2].value = n + 2;
78 }
79 for (n = 0; n < 8; n++) {
80 delta_time_code_tbl_item[n + 6].size = 5;
81 delta_time_code_tbl_item[n + 6].code = 0x10 + n;
82 delta_time_code_tbl_item[n + 6].value = n + 6;
83 }
84
85 k = 2 * num_gain_max_values - 14 + 1;
86 for (n = 0; n < k; n++) {
87 delta_time_code_tbl_item[n + 14].size = 2 + Z;
88 delta_time_code_tbl_item[n + 14].code = (0x3 << Z) + n;
89 delta_time_code_tbl_item[n + 14].value = n + 14;
90 }
91 }
92
93 WORD32
impd_get_delta_tmin(const WORD32 sampling_rate)94 impd_get_delta_tmin(const WORD32 sampling_rate) {
95 WORD32 lowerBound = (WORD32)(0.5f + 0.0005f * sampling_rate);
96 WORD32 result = 1;
97 if (sampling_rate < 1000) {
98 return (UNEXPECTED_ERROR);
99 }
100 while (result <= lowerBound) result = result << 1;
101 return result;
102 }
103