xref: /aosp_15_r20/external/libxaac/encoder/ixheaace_mps_static_gain.c (revision 15dc779a375ca8b5125643b829a8aa4b70d7f451)
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 
21 #include <math.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include "ixheaac_type_def.h"
25 #include "ixheaac_error_standards.h"
26 #include "ixheaace_error_codes.h"
27 #include "ixheaace_mps_common_fix.h"
28 #include "ixheaace_mps_defines.h"
29 #include "ixheaace_mps_common_define.h"
30 #include "ixheaace_bitbuffer.h"
31 
32 #include "ixheaace_mps_static_gain.h"
33 #include "ixheaace_mps_bitstream.h"
34 #include "ixheaace_mps_struct_def.h"
35 #include "ixheaace_mps_sac_polyphase.h"
36 #include "ixheaace_mps_sac_nlc_enc.h"
37 #include "ixheaace_mps_sac_hybfilter.h"
38 #include "ixheaace_mps_spatial_bitstream.h"
39 #include "ixheaace_mps_param_extract.h"
40 #include "ixheaace_mps_tree.h"
41 #include "ixheaace_mps_rom.h"
42 
ixheaace_mps_212_static_gain_init(ixheaace_mps_pstr_static_gain pstr_static_gain,const ixheaace_mps_pstr_static_gain_config pstr_static_gain_config)43 IA_ERRORCODE ixheaace_mps_212_static_gain_init(
44     ixheaace_mps_pstr_static_gain pstr_static_gain,
45     const ixheaace_mps_pstr_static_gain_config pstr_static_gain_config) {
46   IA_ERRORCODE error = IA_NO_ERROR;
47   FLOAT32 pre_gain_factor;
48   pstr_static_gain->fixed_gain_dmx = pstr_static_gain_config->fixed_gain_dmx;
49   pstr_static_gain->pre_gain_factor_db = pstr_static_gain_config->pre_gain_factor_db;
50 
51   if ((pstr_static_gain->pre_gain_factor_db < -20) ||
52       (pstr_static_gain->pre_gain_factor_db > 20)) {
53     return IA_EXHEAACE_CONFIG_NONFATAL_MPS_INVALID_CONFIG;
54   }
55 
56   if (pstr_static_gain->pre_gain_factor_db) {
57     pre_gain_factor = pre_gain_factor_table_flt_new[pstr_static_gain->pre_gain_factor_db + 20];
58   } else {
59     pre_gain_factor = 1.0f;
60   }
61 
62   if (pstr_static_gain->fixed_gain_dmx) {
63     pstr_static_gain->post_gain = dmx_gain_table_flt[pstr_static_gain->fixed_gain_dmx - 1];
64   } else {
65     pstr_static_gain->post_gain = 1.0f;
66   }
67 
68   memset(pstr_static_gain->pre_gain, 0, sizeof(pstr_static_gain->pre_gain));
69 
70   pstr_static_gain->pre_gain[0] = pre_gain_factor;
71   pstr_static_gain->pre_gain[1] = pre_gain_factor;
72 
73   return error;
74 }
75