Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : #include <assert.h>
34 : #include <stdint.h>
35 : #include "options.h"
36 : #include "ivas_cnst.h"
37 : #include "ivas_rom_com.h"
38 : #include "prot_fx.h"
39 : #include "cnst.h"
40 : #include "wmc_auto.h"
41 : #include "ivas_prot_fx.h"
42 :
43 : /*-------------------------------------------------------------------------
44 : * stereo_dft_config()
45 : *
46 : * DFT Stereo Configuration function
47 : *------------------------------------------------------------------------*/
48 :
49 28823 : void stereo_dft_config_fx(
50 : STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o : DFT stereo configuration */
51 : const Word32 brate, /* i : IVAS/CPE/nominal total bitrate */
52 : Word16 *bits_frame_nominal, /* o : primary channel nominal bits per frame */
53 : Word16 *bits_frame_nominal_2 /* o : secondary channel nominal bits per frame*/
54 : )
55 : {
56 28823 : IF( hConfig != NULL )
57 : {
58 28453 : hConfig->band_res = STEREO_DFT_BAND_RES_HIGH;
59 28453 : move16();
60 28453 : hConfig->prm_res = 2;
61 28453 : move16();
62 28453 : hConfig->dmx_active = STEREO_DFT_DMX_ACTIVE;
63 28453 : move16();
64 28453 : hConfig->ada_wb_res_cod_mode = 0;
65 28453 : move16();
66 : }
67 :
68 28823 : *bits_frame_nominal_2 = 5000 / FRAMES_PER_SEC;
69 28823 : move16();
70 :
71 : /* ITD, IPD and residual coding is not used in SID/No data */
72 28823 : IF( brate == FRAME_NO_DATA )
73 : {
74 10249 : *bits_frame_nominal = FRAME_NO_DATA;
75 10249 : move16();
76 10249 : IF( hConfig != NULL )
77 : {
78 10249 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_OFF;
79 10249 : move16();
80 10249 : hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
81 10249 : move16();
82 10249 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
83 10249 : move16();
84 : }
85 : }
86 18574 : ELSE IF( EQ_32( brate, IVAS_SID_5k2 ) )
87 : {
88 3070 : *bits_frame_nominal = SID_2k40 / FRAMES_PER_SEC;
89 3070 : move16();
90 3070 : IF( hConfig != NULL )
91 : {
92 3070 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_OFF;
93 3070 : move16();
94 3070 : hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
95 3070 : move16();
96 3070 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
97 3070 : move16();
98 : }
99 : }
100 15504 : ELSE IF( LE_32( brate, IVAS_13k2 ) )
101 : {
102 3925 : *bits_frame_nominal = ACELP_9k60 / FRAMES_PER_SEC;
103 3925 : move16();
104 3925 : IF( hConfig != NULL )
105 : {
106 3925 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_ESF;
107 3925 : move16();
108 3925 : hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
109 3925 : move16();
110 3925 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
111 3925 : move16();
112 : }
113 : }
114 11579 : ELSE IF( LE_32( brate, IVAS_16k4 ) )
115 : {
116 2662 : *bits_frame_nominal = ACELP_13k20 / FRAMES_PER_SEC;
117 2662 : move16();
118 2662 : IF( hConfig != NULL )
119 : {
120 2616 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_ESF;
121 2616 : move16();
122 2616 : hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
123 2616 : move16();
124 2616 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
125 2616 : move16();
126 : }
127 : }
128 8917 : ELSE IF( LE_32( brate, IVAS_24k4 ) )
129 : {
130 5260 : *bits_frame_nominal = ACELP_16k40 / FRAMES_PER_SEC;
131 5260 : move16();
132 5260 : IF( hConfig != NULL )
133 : {
134 5168 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_ESF;
135 5168 : move16();
136 5168 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
137 5168 : move16();
138 : }
139 : }
140 3657 : ELSE IF( LE_32( brate, IVAS_32k ) )
141 : {
142 3644 : *bits_frame_nominal = ACELP_24k40 / FRAMES_PER_SEC;
143 3644 : move16();
144 3644 : IF( hConfig != NULL )
145 : {
146 3412 : hConfig->ada_wb_res_cod_mode = 1;
147 3412 : move16();
148 3412 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_STEFI;
149 3412 : move16();
150 3412 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_1kHz;
151 3412 : move16();
152 : }
153 : }
154 13 : ELSE IF( LE_32( brate, IVAS_48k ) )
155 : {
156 13 : *bits_frame_nominal = ACELP_32k / FRAMES_PER_SEC;
157 13 : move16();
158 13 : IF( hConfig != NULL )
159 : {
160 13 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_STEFI;
161 13 : move16();
162 13 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_1_6kHz;
163 13 : move16();
164 : }
165 : }
166 : ELSE
167 : {
168 0 : assert( 0 && "Bit-rate not supported by DFT stereo." );
169 : }
170 :
171 28823 : test();
172 28823 : IF( hConfig != NULL && hConfig->force_mono_transmission )
173 : {
174 1099 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_OFF;
175 1099 : move16();
176 1099 : hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
177 1099 : move16();
178 1099 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
179 1099 : move16();
180 1099 : hConfig->ada_wb_res_cod_mode = 0;
181 1099 : move16();
182 : }
183 :
184 : /*sanity check*/
185 28823 : IF( hConfig != NULL )
186 : {
187 28453 : assert( LE_16( hConfig->prm_res, STEREO_DFT_NBDIV ) );
188 : /* make sure residual switching and ESF are not active at the same time */
189 28453 : assert( !( EQ_16( hConfig->ada_wb_res_cod_mode, 1 ) && EQ_16( hConfig->res_pred_mode, STEREO_DFT_RESPRED_ESF ) ) );
190 : }
191 :
192 28823 : return;
193 : }
194 :
195 : /*-------------------------------------------------------------------------
196 : * stereo_dft_band_config()
197 : *
198 : * Stereo DFT bands condfiguration
199 : *------------------------------------------------------------------------*/
200 :
201 240397 : Word16 stereo_dft_band_config_fx(
202 : Word16 *band_limits, /* o : DFT band limits */
203 : const Word16 band_res, /* i : DFT band resolution */
204 : const Word16 NFFT, /* i : analysis/synthesis window length */
205 : const Word16 enc_dec /* i : flag to indicate enc vs dec */
206 : )
207 : {
208 : Word16 nbands;
209 :
210 : /*sanity check*/
211 240397 : assert( ( EQ_16( band_res, 1 ) || ( band_res == 0 ) || EQ_16( band_res, 2 ) ) && "stereo DFT: Parameter band resolution not supported!\n" );
212 :
213 240397 : band_limits[0] = 1;
214 240397 : move16();
215 240397 : nbands = 0;
216 240397 : move16();
217 2546859 : WHILE( LT_16( band_limits[nbands], NFFT / 2 ) )
218 : {
219 2306462 : nbands++;
220 2306462 : IF( band_res == 0 )
221 : {
222 0 : assert( 0 && "stereo DFT: band config failed!\n" );
223 : }
224 2306462 : ELSE IF( EQ_16( band_res, 1 ) )
225 : {
226 1799720 : IF( enc_dec == ENC /*0*/ )
227 : {
228 1439134 : band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); // Q0
229 1439134 : move16();
230 : }
231 : ELSE
232 : {
233 360586 : band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); // Q0
234 360586 : move16();
235 : }
236 :
237 1799720 : assert( ( LT_16( nbands, STEREO_DFT_ERB4_BANDS ) ) && "stereo DFT: band config failed!\n" );
238 : }
239 : ELSE
240 : {
241 506742 : IF( enc_dec == ENC )
242 : {
243 314541 : band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); // Q0
244 314541 : move16();
245 : }
246 : ELSE
247 : {
248 192201 : band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); // Q0
249 192201 : move16();
250 : }
251 :
252 506742 : assert( ( LT_16( nbands, STEREO_DFT_ERB8_BANDS ) ) && "stereo DFT: band config failed!\n" );
253 : }
254 : }
255 :
256 240397 : band_limits[nbands] = NFFT / 2; /*Nyquist Freq*/
257 240397 : move16();
258 :
259 240397 : return ( nbands );
260 : }
|