1*15dc779aSAndroid Build Coastguard Worker /******************************************************************************
2*15dc779aSAndroid Build Coastguard Worker * *
3*15dc779aSAndroid Build Coastguard Worker * Copyright (C) 2023 The Android Open Source Project
4*15dc779aSAndroid Build Coastguard Worker *
5*15dc779aSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
6*15dc779aSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
7*15dc779aSAndroid Build Coastguard Worker * You may obtain a copy of the License at:
8*15dc779aSAndroid Build Coastguard Worker *
9*15dc779aSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
10*15dc779aSAndroid Build Coastguard Worker *
11*15dc779aSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
12*15dc779aSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
13*15dc779aSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*15dc779aSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
15*15dc779aSAndroid Build Coastguard Worker * limitations under the License.
16*15dc779aSAndroid Build Coastguard Worker *
17*15dc779aSAndroid Build Coastguard Worker *****************************************************************************
18*15dc779aSAndroid Build Coastguard Worker * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19*15dc779aSAndroid Build Coastguard Worker */
20*15dc779aSAndroid Build Coastguard Worker
21*15dc779aSAndroid Build Coastguard Worker #include "ixheaac_error_standards.h"
22*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_error_codes.h"
23*15dc779aSAndroid Build Coastguard Worker #include <string.h>
24*15dc779aSAndroid Build Coastguard Worker #include "ixheaac_type_def.h"
25*15dc779aSAndroid Build Coastguard Worker #include "ixheaac_constants.h"
26*15dc779aSAndroid Build Coastguard Worker #include "impd_drc_common_enc.h"
27*15dc779aSAndroid Build Coastguard Worker #include "impd_drc_uni_drc.h"
28*15dc779aSAndroid Build Coastguard Worker #include "impd_drc_tables.h"
29*15dc779aSAndroid Build Coastguard Worker #include "impd_drc_api.h"
30*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_api.h"
31*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_aac_constants.h"
32*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_psy_const.h"
33*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_tns.h"
34*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_tns_params.h"
35*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_rom.h"
36*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_common_rom.h"
37*15dc779aSAndroid Build Coastguard Worker #include "ixheaace_bitbuffer.h"
38*15dc779aSAndroid Build Coastguard Worker
39*15dc779aSAndroid Build Coastguard Worker 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*15dc779aSAndroid Build Coastguard Worker ia_enhaacplus_enc_get_tns_param(
41*15dc779aSAndroid Build Coastguard Worker ixheaace_temporal_noise_shaping_config_tabulated *pstr_tns_config_tab, WORD32 bit_rate,
42*15dc779aSAndroid Build Coastguard Worker WORD32 channels, WORD32 block_type,
43*15dc779aSAndroid Build Coastguard Worker const ixheaace_temporal_noise_shaping_info_tab *pstr_tns_info_tab, WORD32 size) {
44*15dc779aSAndroid Build Coastguard Worker UWORD32 i;
45*15dc779aSAndroid Build Coastguard Worker
46*15dc779aSAndroid Build Coastguard Worker if (pstr_tns_config_tab == NULL) {
47*15dc779aSAndroid Build Coastguard Worker return IA_EXHEAACE_INIT_FATAL_TNS_CONFIG_INIT_FAILED;
48*15dc779aSAndroid Build Coastguard Worker }
49*15dc779aSAndroid Build Coastguard Worker
50*15dc779aSAndroid Build Coastguard Worker pstr_tns_config_tab->thresh_on = -1;
51*15dc779aSAndroid Build Coastguard Worker
52*15dc779aSAndroid Build Coastguard Worker for (i = 0; i < size / sizeof(ixheaace_temporal_noise_shaping_info_tab); i++) {
53*15dc779aSAndroid Build Coastguard Worker if ((bit_rate >= pstr_tns_info_tab[i].bit_rate_from) &&
54*15dc779aSAndroid Build Coastguard Worker bit_rate <= pstr_tns_info_tab[i].bit_rate_to) {
55*15dc779aSAndroid Build Coastguard Worker switch (block_type) {
56*15dc779aSAndroid Build Coastguard Worker case LONG_WINDOW:
57*15dc779aSAndroid Build Coastguard Worker switch (channels) {
58*15dc779aSAndroid Build Coastguard Worker case NUM_CHANS_MONO:
59*15dc779aSAndroid Build Coastguard Worker
60*15dc779aSAndroid Build Coastguard Worker pstr_tns_config_tab->thresh_on = pstr_tns_info_tab[i].param_mono_long.thresh_on;
61*15dc779aSAndroid Build Coastguard Worker pstr_tns_config_tab->lpc_start_freq =
62*15dc779aSAndroid Build Coastguard Worker pstr_tns_info_tab[i].param_mono_long.lpc_start_freq;
63*15dc779aSAndroid Build Coastguard Worker pstr_tns_config_tab->lpc_stop_freq =
64*15dc779aSAndroid Build Coastguard Worker pstr_tns_info_tab[i].param_mono_long.lpc_stop_freq;
65*15dc779aSAndroid Build Coastguard Worker pstr_tns_config_tab->tns_time_resolution =
66*15dc779aSAndroid Build Coastguard Worker pstr_tns_info_tab[i].param_mono_long.tns_time_resolution;
67*15dc779aSAndroid Build Coastguard Worker
68*15dc779aSAndroid Build Coastguard Worker break;
69*15dc779aSAndroid Build Coastguard Worker case NUM_CHANS_STEREO:
70*15dc779aSAndroid Build Coastguard Worker
71*15dc779aSAndroid Build Coastguard Worker pstr_tns_config_tab->thresh_on = pstr_tns_info_tab[i].param_stereo_long.thresh_on;
72*15dc779aSAndroid Build Coastguard Worker pstr_tns_config_tab->lpc_start_freq =
73*15dc779aSAndroid Build Coastguard Worker pstr_tns_info_tab[i].param_stereo_long.lpc_start_freq;
74*15dc779aSAndroid Build Coastguard Worker pstr_tns_config_tab->lpc_stop_freq =
75*15dc779aSAndroid Build Coastguard Worker pstr_tns_info_tab[i].param_stereo_long.lpc_stop_freq;
76*15dc779aSAndroid Build Coastguard Worker pstr_tns_config_tab->tns_time_resolution =
77*15dc779aSAndroid Build Coastguard Worker pstr_tns_info_tab[i].param_stereo_long.tns_time_resolution;
78*15dc779aSAndroid Build Coastguard Worker
79*15dc779aSAndroid Build Coastguard Worker break;
80*15dc779aSAndroid Build Coastguard Worker }
81*15dc779aSAndroid Build Coastguard Worker break;
82*15dc779aSAndroid Build Coastguard Worker
83*15dc779aSAndroid Build Coastguard Worker case SHORT_WINDOW:
84*15dc779aSAndroid Build Coastguard Worker switch (channels) {
85*15dc779aSAndroid Build Coastguard Worker case NUM_CHANS_MONO:
86*15dc779aSAndroid Build Coastguard Worker
87*15dc779aSAndroid Build Coastguard Worker pstr_tns_config_tab->thresh_on = pstr_tns_info_tab[i].param_mono_short.thresh_on;
88*15dc779aSAndroid Build Coastguard Worker pstr_tns_config_tab->lpc_start_freq =
89*15dc779aSAndroid Build Coastguard Worker pstr_tns_info_tab[i].param_mono_short.lpc_start_freq;
90*15dc779aSAndroid Build Coastguard Worker pstr_tns_config_tab->lpc_stop_freq =
91*15dc779aSAndroid Build Coastguard Worker pstr_tns_info_tab[i].param_mono_short.lpc_stop_freq;
92*15dc779aSAndroid Build Coastguard Worker pstr_tns_config_tab->tns_time_resolution =
93*15dc779aSAndroid Build Coastguard Worker pstr_tns_info_tab[i].param_mono_short.tns_time_resolution;
94*15dc779aSAndroid Build Coastguard Worker break;
95*15dc779aSAndroid Build Coastguard Worker case NUM_CHANS_STEREO:
96*15dc779aSAndroid Build Coastguard Worker
97*15dc779aSAndroid Build Coastguard Worker pstr_tns_config_tab->thresh_on = pstr_tns_info_tab[i].param_stereo_short.thresh_on;
98*15dc779aSAndroid Build Coastguard Worker pstr_tns_config_tab->lpc_start_freq =
99*15dc779aSAndroid Build Coastguard Worker pstr_tns_info_tab[i].param_stereo_short.lpc_start_freq;
100*15dc779aSAndroid Build Coastguard Worker pstr_tns_config_tab->lpc_stop_freq =
101*15dc779aSAndroid Build Coastguard Worker pstr_tns_info_tab[i].param_stereo_short.lpc_stop_freq;
102*15dc779aSAndroid Build Coastguard Worker pstr_tns_config_tab->tns_time_resolution =
103*15dc779aSAndroid Build Coastguard Worker pstr_tns_info_tab[i].param_stereo_short.tns_time_resolution;
104*15dc779aSAndroid Build Coastguard Worker break;
105*15dc779aSAndroid Build Coastguard Worker }
106*15dc779aSAndroid Build Coastguard Worker
107*15dc779aSAndroid Build Coastguard Worker break;
108*15dc779aSAndroid Build Coastguard Worker }
109*15dc779aSAndroid Build Coastguard Worker }
110*15dc779aSAndroid Build Coastguard Worker }
111*15dc779aSAndroid Build Coastguard Worker
112*15dc779aSAndroid Build Coastguard Worker // This check is not being done now
113*15dc779aSAndroid Build Coastguard Worker if (pstr_tns_config_tab->thresh_on == -1) {
114*15dc779aSAndroid Build Coastguard Worker return IA_EXHEAACE_INIT_FATAL_INVALID_TNS_PARAM;
115*15dc779aSAndroid Build Coastguard Worker }
116*15dc779aSAndroid Build Coastguard Worker
117*15dc779aSAndroid Build Coastguard Worker return IA_NO_ERROR;
118*15dc779aSAndroid Build Coastguard Worker }
119*15dc779aSAndroid Build Coastguard Worker
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*15dc779aSAndroid Build Coastguard Worker VOID ia_enhaacplus_enc_get_tns_max_bands(
121*15dc779aSAndroid Build Coastguard Worker WORD32 sampling_rate, WORD32 block_type, WORD32 *tns_max_sfb,
122*15dc779aSAndroid Build Coastguard Worker const ixheaace_temporal_noise_shaping_max_table *pstr_tns_max_bands_tab, WORD32 size,
123*15dc779aSAndroid Build Coastguard Worker WORD32 aot, WORD32 frame_length) {
124*15dc779aSAndroid Build Coastguard Worker UWORD32 i;
125*15dc779aSAndroid Build Coastguard Worker
126*15dc779aSAndroid Build Coastguard Worker *tns_max_sfb = -1;
127*15dc779aSAndroid Build Coastguard Worker
128*15dc779aSAndroid Build Coastguard Worker for (i = 0; i < size / sizeof(ixheaace_temporal_noise_shaping_max_table); i++) {
129*15dc779aSAndroid Build Coastguard Worker if (sampling_rate == pstr_tns_max_bands_tab[i].sampling_rate) {
130*15dc779aSAndroid Build Coastguard Worker if (aot == AOT_AAC_LC || aot == AOT_SBR || aot == AOT_PS) {
131*15dc779aSAndroid Build Coastguard Worker if (block_type == SHORT_WINDOW) {
132*15dc779aSAndroid Build Coastguard Worker *tns_max_sfb = (frame_length == (FRAME_LEN_SHORT_128))
133*15dc779aSAndroid Build Coastguard Worker ? pstr_tns_max_bands_tab[i].max_band_1024_short_lc
134*15dc779aSAndroid Build Coastguard Worker : pstr_tns_max_bands_tab[i].max_band_960_short_lc;
135*15dc779aSAndroid Build Coastguard Worker } else {
136*15dc779aSAndroid Build Coastguard Worker *tns_max_sfb = (frame_length == FRAME_LEN_1024)
137*15dc779aSAndroid Build Coastguard Worker ? pstr_tns_max_bands_tab[i].max_band_1024_long_lc
138*15dc779aSAndroid Build Coastguard Worker : pstr_tns_max_bands_tab[i].max_band_960_long_lc;
139*15dc779aSAndroid Build Coastguard Worker }
140*15dc779aSAndroid Build Coastguard Worker } else if (aot == AOT_AAC_LD || aot == AOT_AAC_ELD) {
141*15dc779aSAndroid Build Coastguard Worker *tns_max_sfb = (frame_length == FRAME_LEN_512)
142*15dc779aSAndroid Build Coastguard Worker ? pstr_tns_max_bands_tab[i].max_band_512_ld
143*15dc779aSAndroid Build Coastguard Worker : pstr_tns_max_bands_tab[i].max_band_480_ld;
144*15dc779aSAndroid Build Coastguard Worker }
145*15dc779aSAndroid Build Coastguard Worker break;
146*15dc779aSAndroid Build Coastguard Worker }
147*15dc779aSAndroid Build Coastguard Worker }
148*15dc779aSAndroid Build Coastguard Worker }
149