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 28494 : 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 28494 : IF( hConfig != NULL )
57 : {
58 28112 : hConfig->band_res = STEREO_DFT_BAND_RES_HIGH;
59 28112 : move16();
60 28112 : hConfig->prm_res = 2;
61 28112 : move16();
62 28112 : hConfig->dmx_active = STEREO_DFT_DMX_ACTIVE;
63 28112 : move16();
64 28112 : hConfig->ada_wb_res_cod_mode = 0;
65 28112 : move16();
66 : }
67 :
68 28494 : *bits_frame_nominal_2 = 5000 / FRAMES_PER_SEC;
69 28494 : move16();
70 :
71 : /* ITD, IPD and residual coding is not used in SID/No data */
72 28494 : IF( brate == FRAME_NO_DATA )
73 : {
74 10151 : *bits_frame_nominal = FRAME_NO_DATA;
75 10151 : move16();
76 10151 : IF( hConfig != NULL )
77 : {
78 10151 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_OFF;
79 10151 : move16();
80 10151 : hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
81 10151 : move16();
82 10151 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
83 10151 : move16();
84 : }
85 : }
86 18343 : ELSE IF( EQ_32( brate, IVAS_SID_5k2 ) )
87 : {
88 3046 : *bits_frame_nominal = SID_2k40 / FRAMES_PER_SEC;
89 3046 : move16();
90 3046 : IF( hConfig != NULL )
91 : {
92 3046 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_OFF;
93 3046 : move16();
94 3046 : hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
95 3046 : move16();
96 3046 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
97 3046 : move16();
98 : }
99 : }
100 15297 : ELSE IF( LE_32( brate, IVAS_13k2 ) )
101 : {
102 3869 : *bits_frame_nominal = ACELP_9k60 / FRAMES_PER_SEC;
103 3869 : move16();
104 3869 : IF( hConfig != NULL )
105 : {
106 3869 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_ESF;
107 3869 : move16();
108 3869 : hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
109 3869 : move16();
110 3869 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
111 3869 : move16();
112 : }
113 : }
114 11428 : ELSE IF( LE_32( brate, IVAS_16k4 ) )
115 : {
116 2610 : *bits_frame_nominal = ACELP_13k20 / FRAMES_PER_SEC;
117 2610 : move16();
118 2610 : IF( hConfig != NULL )
119 : {
120 2565 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_ESF;
121 2565 : move16();
122 2565 : hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
123 2565 : move16();
124 2565 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
125 2565 : move16();
126 : }
127 : }
128 8818 : ELSE IF( LE_32( brate, IVAS_24k4 ) )
129 : {
130 5213 : *bits_frame_nominal = ACELP_16k40 / FRAMES_PER_SEC;
131 5213 : move16();
132 5213 : IF( hConfig != NULL )
133 : {
134 5127 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_ESF;
135 5127 : move16();
136 5127 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
137 5127 : move16();
138 : }
139 : }
140 3605 : ELSE IF( LE_32( brate, IVAS_32k ) )
141 : {
142 3592 : *bits_frame_nominal = ACELP_24k40 / FRAMES_PER_SEC;
143 3592 : move16();
144 3592 : IF( hConfig != NULL )
145 : {
146 3341 : hConfig->ada_wb_res_cod_mode = 1;
147 3341 : move16();
148 3341 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_STEFI;
149 3341 : move16();
150 3341 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_1kHz;
151 3341 : 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 28494 : test();
172 28494 : IF( hConfig != NULL && hConfig->force_mono_transmission )
173 : {
174 1090 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_OFF;
175 1090 : move16();
176 1090 : hConfig->band_res = STEREO_DFT_BAND_RES_LOW;
177 1090 : move16();
178 1090 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF;
179 1090 : move16();
180 1090 : hConfig->ada_wb_res_cod_mode = 0;
181 1090 : move16();
182 : }
183 :
184 : /*sanity check*/
185 28494 : IF( hConfig != NULL )
186 : {
187 28112 : assert( LE_16( hConfig->prm_res, STEREO_DFT_NBDIV ) );
188 : /* make sure residual switching and ESF are not active at the same time */
189 28112 : assert( !( EQ_16( hConfig->ada_wb_res_cod_mode, 1 ) && EQ_16( hConfig->res_pred_mode, STEREO_DFT_RESPRED_ESF ) ) );
190 : }
191 :
192 28494 : return;
193 : }
194 :
195 : /*-------------------------------------------------------------------------
196 : * stereo_dft_band_config()
197 : *
198 : * Stereo DFT bands condfiguration
199 : *------------------------------------------------------------------------*/
200 :
201 239785 : 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 239785 : assert( ( EQ_16( band_res, 1 ) || ( band_res == 0 ) || EQ_16( band_res, 2 ) ) && "stereo DFT: Parameter band resolution not supported!\n" );
212 :
213 239785 : band_limits[0] = 1;
214 239785 : move16();
215 239785 : nbands = 0;
216 239785 : move16();
217 2541128 : WHILE( LT_16( band_limits[nbands], NFFT / 2 ) )
218 : {
219 2301343 : nbands++;
220 2301343 : IF( band_res == 0 )
221 : {
222 0 : assert( 0 && "stereo DFT: band config failed!\n" );
223 : }
224 2301343 : ELSE IF( EQ_16( band_res, 1 ) )
225 : {
226 1796579 : IF( enc_dec == ENC /*0*/ )
227 : {
228 1439699 : band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); // Q0
229 1439699 : move16();
230 : }
231 : ELSE
232 : {
233 356880 : band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); // Q0
234 356880 : move16();
235 : }
236 :
237 1796579 : assert( ( LT_16( nbands, STEREO_DFT_ERB4_BANDS ) ) && "stereo DFT: band config failed!\n" );
238 : }
239 : ELSE
240 : {
241 504764 : IF( enc_dec == ENC )
242 : {
243 314170 : band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); // Q0
244 314170 : move16();
245 : }
246 : ELSE
247 : {
248 190594 : band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); // Q0
249 190594 : move16();
250 : }
251 :
252 504764 : assert( ( LT_16( nbands, STEREO_DFT_ERB8_BANDS ) ) && "stereo DFT: band config failed!\n" );
253 : }
254 : }
255 :
256 239785 : band_limits[nbands] = NFFT / 2; /*Nyquist Freq*/
257 239785 : move16();
258 :
259 239785 : return ( nbands );
260 : }
|