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 "ixheaac_error_standards.h"
22 #include "ixheaace_error_codes.h"
23 #include <string.h>
24 #include "ixheaac_type_def.h"
25 #include "ixheaac_constants.h"
26 #include "impd_drc_common_enc.h"
27 #include "impd_drc_uni_drc.h"
28 #include "impd_drc_tables.h"
29 #include "impd_drc_api.h"
30 #include "ixheaace_api.h"
31 #include "ixheaace_aac_constants.h"
32 #include "ixheaace_psy_const.h"
33 #include "ixheaace_tns.h"
34 #include "ixheaace_tns_params.h"
35 #include "ixheaace_rom.h"
36 #include "ixheaace_common_rom.h"
37 #include "ixheaace_bitbuffer.h"
38
39 IA_ERRORCODE
ia_enhaacplus_enc_get_tns_param(ixheaace_temporal_noise_shaping_config_tabulated * pstr_tns_config_tab,WORD32 bit_rate,WORD32 channels,WORD32 block_type,const ixheaace_temporal_noise_shaping_info_tab * pstr_tns_info_tab,WORD32 size)40 ia_enhaacplus_enc_get_tns_param(
41 ixheaace_temporal_noise_shaping_config_tabulated *pstr_tns_config_tab, WORD32 bit_rate,
42 WORD32 channels, WORD32 block_type,
43 const ixheaace_temporal_noise_shaping_info_tab *pstr_tns_info_tab, WORD32 size) {
44 UWORD32 i;
45
46 if (pstr_tns_config_tab == NULL) {
47 return IA_EXHEAACE_INIT_FATAL_TNS_CONFIG_INIT_FAILED;
48 }
49
50 pstr_tns_config_tab->thresh_on = -1;
51
52 for (i = 0; i < size / sizeof(ixheaace_temporal_noise_shaping_info_tab); i++) {
53 if ((bit_rate >= pstr_tns_info_tab[i].bit_rate_from) &&
54 bit_rate <= pstr_tns_info_tab[i].bit_rate_to) {
55 switch (block_type) {
56 case LONG_WINDOW:
57 switch (channels) {
58 case NUM_CHANS_MONO:
59
60 pstr_tns_config_tab->thresh_on = pstr_tns_info_tab[i].param_mono_long.thresh_on;
61 pstr_tns_config_tab->lpc_start_freq =
62 pstr_tns_info_tab[i].param_mono_long.lpc_start_freq;
63 pstr_tns_config_tab->lpc_stop_freq =
64 pstr_tns_info_tab[i].param_mono_long.lpc_stop_freq;
65 pstr_tns_config_tab->tns_time_resolution =
66 pstr_tns_info_tab[i].param_mono_long.tns_time_resolution;
67
68 break;
69 case NUM_CHANS_STEREO:
70
71 pstr_tns_config_tab->thresh_on = pstr_tns_info_tab[i].param_stereo_long.thresh_on;
72 pstr_tns_config_tab->lpc_start_freq =
73 pstr_tns_info_tab[i].param_stereo_long.lpc_start_freq;
74 pstr_tns_config_tab->lpc_stop_freq =
75 pstr_tns_info_tab[i].param_stereo_long.lpc_stop_freq;
76 pstr_tns_config_tab->tns_time_resolution =
77 pstr_tns_info_tab[i].param_stereo_long.tns_time_resolution;
78
79 break;
80 }
81 break;
82
83 case SHORT_WINDOW:
84 switch (channels) {
85 case NUM_CHANS_MONO:
86
87 pstr_tns_config_tab->thresh_on = pstr_tns_info_tab[i].param_mono_short.thresh_on;
88 pstr_tns_config_tab->lpc_start_freq =
89 pstr_tns_info_tab[i].param_mono_short.lpc_start_freq;
90 pstr_tns_config_tab->lpc_stop_freq =
91 pstr_tns_info_tab[i].param_mono_short.lpc_stop_freq;
92 pstr_tns_config_tab->tns_time_resolution =
93 pstr_tns_info_tab[i].param_mono_short.tns_time_resolution;
94 break;
95 case NUM_CHANS_STEREO:
96
97 pstr_tns_config_tab->thresh_on = pstr_tns_info_tab[i].param_stereo_short.thresh_on;
98 pstr_tns_config_tab->lpc_start_freq =
99 pstr_tns_info_tab[i].param_stereo_short.lpc_start_freq;
100 pstr_tns_config_tab->lpc_stop_freq =
101 pstr_tns_info_tab[i].param_stereo_short.lpc_stop_freq;
102 pstr_tns_config_tab->tns_time_resolution =
103 pstr_tns_info_tab[i].param_stereo_short.tns_time_resolution;
104 break;
105 }
106
107 break;
108 }
109 }
110 }
111
112 // This check is not being done now
113 if (pstr_tns_config_tab->thresh_on == -1) {
114 return IA_EXHEAACE_INIT_FATAL_INVALID_TNS_PARAM;
115 }
116
117 return IA_NO_ERROR;
118 }
119
ia_enhaacplus_enc_get_tns_max_bands(WORD32 sampling_rate,WORD32 block_type,WORD32 * tns_max_sfb,const ixheaace_temporal_noise_shaping_max_table * pstr_tns_max_bands_tab,WORD32 size,WORD32 aot,WORD32 frame_length)120 VOID ia_enhaacplus_enc_get_tns_max_bands(
121 WORD32 sampling_rate, WORD32 block_type, WORD32 *tns_max_sfb,
122 const ixheaace_temporal_noise_shaping_max_table *pstr_tns_max_bands_tab, WORD32 size,
123 WORD32 aot, WORD32 frame_length) {
124 UWORD32 i;
125
126 *tns_max_sfb = -1;
127
128 for (i = 0; i < size / sizeof(ixheaace_temporal_noise_shaping_max_table); i++) {
129 if (sampling_rate == pstr_tns_max_bands_tab[i].sampling_rate) {
130 if (aot == AOT_AAC_LC || aot == AOT_SBR || aot == AOT_PS) {
131 if (block_type == SHORT_WINDOW) {
132 *tns_max_sfb = (frame_length == (FRAME_LEN_SHORT_128))
133 ? pstr_tns_max_bands_tab[i].max_band_1024_short_lc
134 : pstr_tns_max_bands_tab[i].max_band_960_short_lc;
135 } else {
136 *tns_max_sfb = (frame_length == FRAME_LEN_1024)
137 ? pstr_tns_max_bands_tab[i].max_band_1024_long_lc
138 : pstr_tns_max_bands_tab[i].max_band_960_long_lc;
139 }
140 } else if (aot == AOT_AAC_LD || aot == AOT_AAC_ELD) {
141 *tns_max_sfb = (frame_length == FRAME_LEN_512)
142 ? pstr_tns_max_bands_tab[i].max_band_512_ld
143 : pstr_tns_max_bands_tab[i].max_band_480_ld;
144 }
145 break;
146 }
147 }
148 }
149