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 "ivas_prot.h" 39 : #include "prot.h" 40 : #include "cnst.h" 41 : #include "wmc_auto.h" 42 : 43 : /*------------------------------------------------------------------------- 44 : * stereo_dft_config() 45 : * 46 : * DFT Stereo Configuration function 47 : *------------------------------------------------------------------------*/ 48 : 49 219620 : void stereo_dft_config( 50 : STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o : DFT stereo configuration */ 51 : const int32_t brate, /* i : IVAS/CPE/nominal total bitrate */ 52 : int16_t *bits_frame_nominal, /* o : primary channel nominal bits per frame */ 53 : int16_t *bits_frame_nominal_2 /* o : secondary channel nominal bits per frame*/ 54 : ) 55 : { 56 219620 : if ( hConfig != NULL ) 57 : { 58 212980 : hConfig->band_res = STEREO_DFT_BAND_RES_HIGH; 59 212980 : hConfig->prm_res = 2; 60 : #ifndef DEBUG_STEREO_DFT_NOSTEREO 61 212980 : hConfig->dmx_active = STEREO_DFT_DMX_ACTIVE; 62 : #else 63 : hConfig->dmx_active = 0; 64 : #endif 65 212980 : hConfig->ada_wb_res_cod_mode = 0; 66 : } 67 : 68 219620 : *bits_frame_nominal_2 = 5000 / FRAMES_PER_SEC; 69 : 70 : /* ITD, IPD and residual coding is not used in SID/No data */ 71 219620 : if ( brate == FRAME_NO_DATA ) 72 : { 73 39817 : *bits_frame_nominal = FRAME_NO_DATA; 74 39817 : if ( hConfig != NULL ) 75 : { 76 : #ifdef DEBUG_MODE_DFT 77 : hConfig->itd_mode = 1; 78 : hConfig->gipd_mode = 1; 79 : #endif 80 39817 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_OFF; 81 39817 : hConfig->band_res = STEREO_DFT_BAND_RES_LOW; 82 39817 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF; 83 : } 84 : } 85 179803 : else if ( brate == IVAS_SID_5k2 ) 86 : { 87 14152 : *bits_frame_nominal = SID_2k40 / FRAMES_PER_SEC; 88 14152 : if ( hConfig != NULL ) 89 : { 90 : #ifdef DEBUG_MODE_DFT 91 : hConfig->itd_mode = 1; 92 : hConfig->gipd_mode = 1; 93 : #endif 94 14152 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_OFF; 95 14152 : hConfig->band_res = STEREO_DFT_BAND_RES_LOW; 96 14152 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF; 97 : } 98 : } 99 165651 : else if ( brate <= IVAS_13k2 ) 100 : { 101 45462 : *bits_frame_nominal = ACELP_9k60 / FRAMES_PER_SEC; 102 45462 : if ( hConfig != NULL ) 103 : { 104 : #ifdef DEBUG_MODE_DFT 105 : hConfig->itd_mode = 1; 106 : hConfig->gipd_mode = 1; 107 : #endif 108 45460 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_ESF; 109 45460 : hConfig->band_res = STEREO_DFT_BAND_RES_LOW; 110 45460 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF; 111 : } 112 : } 113 120189 : else if ( brate <= IVAS_16k4 ) 114 : { 115 27207 : *bits_frame_nominal = ACELP_13k20 / FRAMES_PER_SEC; 116 27207 : if ( hConfig != NULL ) 117 : { 118 : #ifdef DEBUG_MODE_DFT 119 : hConfig->itd_mode = 1; 120 : hConfig->gipd_mode = 1; 121 : #endif 122 27023 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_ESF; 123 27023 : hConfig->band_res = STEREO_DFT_BAND_RES_LOW; 124 27023 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF; 125 : } 126 : } 127 92982 : else if ( brate <= IVAS_24k4 ) 128 : { 129 65796 : *bits_frame_nominal = ACELP_16k40 / FRAMES_PER_SEC; 130 65796 : if ( hConfig != NULL ) 131 : { 132 : #ifdef DEBUG_MODE_DFT 133 : hConfig->itd_mode = 1; 134 : hConfig->gipd_mode = 1; 135 : #endif 136 63660 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_ESF; 137 63660 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF; 138 : } 139 : } 140 27186 : else if ( brate <= IVAS_32k ) 141 : { 142 26571 : *bits_frame_nominal = ACELP_24k40 / FRAMES_PER_SEC; 143 26571 : if ( hConfig != NULL ) 144 : { 145 22253 : hConfig->ada_wb_res_cod_mode = 1; 146 : #ifdef DEBUG_MODE_DFT 147 : hConfig->itd_mode = 1; 148 : hConfig->gipd_mode = 1; 149 : #endif 150 22253 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_STEFI; 151 22253 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_1kHz; 152 : } 153 : } 154 615 : else if ( brate <= IVAS_48k ) 155 : { 156 615 : *bits_frame_nominal = ACELP_32k / FRAMES_PER_SEC; 157 615 : if ( hConfig != NULL ) 158 : { 159 : #ifdef DEBUG_MODE_DFT 160 : hConfig->itd_mode = 1; 161 : hConfig->gipd_mode = 1; 162 : #endif 163 615 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_STEFI; 164 615 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_1_6kHz; 165 : } 166 : } 167 : else 168 : { 169 0 : assert( 0 && "Bit-rate not supported by DFT stereo." ); 170 : } 171 : 172 219620 : if ( hConfig != NULL && hConfig->force_mono_transmission ) 173 : { 174 21297 : hConfig->res_pred_mode = STEREO_DFT_RESPRED_OFF; 175 21297 : hConfig->band_res = STEREO_DFT_BAND_RES_LOW; 176 21297 : hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF; 177 21297 : hConfig->ada_wb_res_cod_mode = 0; 178 : } 179 : 180 : /*sanity check*/ 181 219620 : if ( hConfig != NULL ) 182 : { 183 212980 : assert( hConfig->prm_res <= STEREO_DFT_NBDIV ); 184 : /* make sure residual switching and ESF are not active at the same time */ 185 212980 : assert( !( hConfig->ada_wb_res_cod_mode == 1 && hConfig->res_pred_mode == STEREO_DFT_RESPRED_ESF ) ); 186 : } 187 : 188 219620 : return; 189 : } 190 : 191 : /*------------------------------------------------------------------------- 192 : * stereo_dft_band_config() 193 : * 194 : * Stereo DFT bands condfiguration 195 : *------------------------------------------------------------------------*/ 196 : 197 3341260 : int16_t stereo_dft_band_config( 198 : int16_t *band_limits, /* o : DFT band limits */ 199 : const int16_t band_res, /* i : DFT band resolution */ 200 : const int16_t NFFT, /* i : analysis/synthesis window length */ 201 : const int16_t enc_dec /* i : flag to indicate enc vs dec */ 202 : ) 203 : { 204 : int16_t nbands; 205 : 206 : /*sanity check*/ 207 3341260 : assert( ( band_res == 1 || band_res == 0 || band_res == 2 ) && "stereo DFT: Parameter band resolution not supported!\n" ); 208 : 209 3341260 : band_limits[0] = 1; 210 3341260 : nbands = 0; 211 37007748 : while ( band_limits[nbands++] < NFFT / 2 ) 212 : { 213 33666488 : if ( band_res == 0 ) 214 : { 215 0 : assert( 0 && "stereo DFT: band config failed!\n" ); 216 : } 217 33666488 : else if ( band_res == 1 ) 218 : { 219 27958198 : if ( enc_dec == ENC ) 220 : { 221 20364587 : band_limits[nbands] = (int16_t) round_f( dft_band_limits_erb4[nbands] * ( (float) ( STEREO_DFT_N_NS_ENC ) / STEREO_DFT_N_NS ) ); 222 : } 223 : else 224 : { 225 7593611 : band_limits[nbands] = (int16_t) round_f( dft_band_limits_erb4[nbands] * ( (float) ( STEREO_DFT32MS_N_NS ) / STEREO_DFT_N_NS ) ); 226 : } 227 : 228 27958198 : assert( ( nbands < STEREO_DFT_ERB4_BANDS ) && "stereo DFT: band config failed!\n" ); 229 : } 230 : else 231 : { 232 5708290 : if ( enc_dec == ENC ) 233 : { 234 3539841 : band_limits[nbands] = (int16_t) round_f( dft_band_limits_erb8[nbands] * ( (float) ( STEREO_DFT_N_NS_ENC ) / STEREO_DFT_N_NS ) ); 235 : } 236 : else 237 : { 238 2168449 : band_limits[nbands] = (int16_t) round_f( dft_band_limits_erb8[nbands] * ( (float) ( STEREO_DFT32MS_N_NS ) / STEREO_DFT_N_NS ) ); 239 : } 240 : 241 5708290 : assert( ( nbands < STEREO_DFT_ERB8_BANDS ) && "stereo DFT: band config failed!\n" ); 242 : } 243 : } 244 3341260 : nbands--; 245 3341260 : band_limits[nbands] = NFFT / 2; /*Nyquist Freq*/ 246 : 247 3341260 : return ( nbands ); 248 : }