/src/libxaac/encoder/ixheaace_tns_params.c
Line | Count | Source |
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 |
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 | 9.51k | const ixheaace_temporal_noise_shaping_info_tab *pstr_tns_info_tab, WORD32 size) { |
44 | 9.51k | UWORD32 i; |
45 | | |
46 | 9.51k | if (pstr_tns_config_tab == NULL) { |
47 | 0 | return IA_EXHEAACE_INIT_FATAL_TNS_CONFIG_INIT_FAILED; |
48 | 0 | } |
49 | | |
50 | 9.51k | pstr_tns_config_tab->thresh_on = -1; |
51 | | |
52 | 57.0k | for (i = 0; i < size / sizeof(ixheaace_temporal_noise_shaping_info_tab); i++) { |
53 | 47.5k | if ((bit_rate >= pstr_tns_info_tab[i].bit_rate_from) && |
54 | 25.5k | bit_rate <= pstr_tns_info_tab[i].bit_rate_to) { |
55 | 9.51k | switch (block_type) { |
56 | 5.82k | case LONG_WINDOW: |
57 | 5.82k | switch (channels) { |
58 | 3.17k | case NUM_CHANS_MONO: |
59 | | |
60 | 3.17k | pstr_tns_config_tab->thresh_on = pstr_tns_info_tab[i].param_mono_long.thresh_on; |
61 | 3.17k | pstr_tns_config_tab->lpc_start_freq = |
62 | 3.17k | pstr_tns_info_tab[i].param_mono_long.lpc_start_freq; |
63 | 3.17k | pstr_tns_config_tab->lpc_stop_freq = |
64 | 3.17k | pstr_tns_info_tab[i].param_mono_long.lpc_stop_freq; |
65 | 3.17k | pstr_tns_config_tab->tns_time_resolution = |
66 | 3.17k | pstr_tns_info_tab[i].param_mono_long.tns_time_resolution; |
67 | | |
68 | 3.17k | break; |
69 | 2.64k | case NUM_CHANS_STEREO: |
70 | | |
71 | 2.64k | pstr_tns_config_tab->thresh_on = pstr_tns_info_tab[i].param_stereo_long.thresh_on; |
72 | 2.64k | pstr_tns_config_tab->lpc_start_freq = |
73 | 2.64k | pstr_tns_info_tab[i].param_stereo_long.lpc_start_freq; |
74 | 2.64k | pstr_tns_config_tab->lpc_stop_freq = |
75 | 2.64k | pstr_tns_info_tab[i].param_stereo_long.lpc_stop_freq; |
76 | 2.64k | pstr_tns_config_tab->tns_time_resolution = |
77 | 2.64k | pstr_tns_info_tab[i].param_stereo_long.tns_time_resolution; |
78 | | |
79 | 2.64k | break; |
80 | 5.82k | } |
81 | 5.82k | break; |
82 | | |
83 | 5.82k | case SHORT_WINDOW: |
84 | 3.68k | switch (channels) { |
85 | 1.99k | case NUM_CHANS_MONO: |
86 | | |
87 | 1.99k | pstr_tns_config_tab->thresh_on = pstr_tns_info_tab[i].param_mono_short.thresh_on; |
88 | 1.99k | pstr_tns_config_tab->lpc_start_freq = |
89 | 1.99k | pstr_tns_info_tab[i].param_mono_short.lpc_start_freq; |
90 | 1.99k | pstr_tns_config_tab->lpc_stop_freq = |
91 | 1.99k | pstr_tns_info_tab[i].param_mono_short.lpc_stop_freq; |
92 | 1.99k | pstr_tns_config_tab->tns_time_resolution = |
93 | 1.99k | pstr_tns_info_tab[i].param_mono_short.tns_time_resolution; |
94 | 1.99k | break; |
95 | 1.69k | case NUM_CHANS_STEREO: |
96 | | |
97 | 1.69k | pstr_tns_config_tab->thresh_on = pstr_tns_info_tab[i].param_stereo_short.thresh_on; |
98 | 1.69k | pstr_tns_config_tab->lpc_start_freq = |
99 | 1.69k | pstr_tns_info_tab[i].param_stereo_short.lpc_start_freq; |
100 | 1.69k | pstr_tns_config_tab->lpc_stop_freq = |
101 | 1.69k | pstr_tns_info_tab[i].param_stereo_short.lpc_stop_freq; |
102 | 1.69k | pstr_tns_config_tab->tns_time_resolution = |
103 | 1.69k | pstr_tns_info_tab[i].param_stereo_short.tns_time_resolution; |
104 | 1.69k | break; |
105 | 3.68k | } |
106 | | |
107 | 3.68k | break; |
108 | 9.51k | } |
109 | 9.51k | } |
110 | 47.5k | } |
111 | | |
112 | | // This check is not being done now |
113 | 9.51k | if (pstr_tns_config_tab->thresh_on == -1) { |
114 | 0 | return IA_EXHEAACE_INIT_FATAL_INVALID_TNS_PARAM; |
115 | 0 | } |
116 | | |
117 | 9.51k | return IA_NO_ERROR; |
118 | 9.51k | } |
119 | | |
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 | 9.51k | WORD32 aot, WORD32 frame_length) { |
124 | 9.51k | UWORD32 i; |
125 | | |
126 | 9.51k | *tns_max_sfb = -1; |
127 | | |
128 | 71.9k | for (i = 0; i < size / sizeof(ixheaace_temporal_noise_shaping_max_table); i++) { |
129 | 71.9k | if (sampling_rate == pstr_tns_max_bands_tab[i].sampling_rate) { |
130 | 9.51k | if (aot == AOT_AAC_LC || aot == AOT_SBR || aot == AOT_PS) { |
131 | 7.37k | if (block_type == SHORT_WINDOW) { |
132 | 3.68k | *tns_max_sfb = (frame_length == (FRAME_LEN_SHORT_128)) |
133 | 3.68k | ? pstr_tns_max_bands_tab[i].max_band_1024_short_lc |
134 | 3.68k | : pstr_tns_max_bands_tab[i].max_band_960_short_lc; |
135 | 3.68k | } else { |
136 | 3.68k | *tns_max_sfb = (frame_length == FRAME_LEN_1024) |
137 | 3.68k | ? pstr_tns_max_bands_tab[i].max_band_1024_long_lc |
138 | 3.68k | : pstr_tns_max_bands_tab[i].max_band_960_long_lc; |
139 | 3.68k | } |
140 | 7.37k | } else if (aot == AOT_AAC_LD || aot == AOT_AAC_ELD) { |
141 | 2.13k | *tns_max_sfb = (frame_length == FRAME_LEN_512) |
142 | 2.13k | ? pstr_tns_max_bands_tab[i].max_band_512_ld |
143 | 2.13k | : pstr_tns_max_bands_tab[i].max_band_480_ld; |
144 | 2.13k | } |
145 | 9.51k | break; |
146 | 9.51k | } |
147 | 71.9k | } |
148 | 9.51k | } |