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 : /*==================================================================================== 34 : EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 35 : ====================================================================================*/ 36 : 37 : #include <stdint.h> 38 : #include "options.h" 39 : #ifdef DEBUGGING 40 : #include "debug.h" 41 : #endif 42 : #include <math.h> 43 : #include "prot.h" 44 : #include "rom_com.h" 45 : #include "wmc_auto.h" 46 : 47 : /*-------------------------------------------------------------------* 48 : * Function pvq_decode() * 49 : * * 50 : * PVQ subvector decoding algorithm * 51 : *-------------------------------------------------------------------*/ 52 : 53 885486 : void pvq_decode( 54 : Decoder_State *st, /* i/o: Decoder state */ 55 : PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ 56 : float *xq, /* o : decoded vector (scaled float) */ 57 : int16_t *y, /* o : decoded vector (non-scaled short)*/ 58 : const int16_t k_val, /* i : number of allocated pulses */ 59 : const int16_t dim, /* i : Length of vector */ 60 : const float gain /* i : Gain */ 61 : ) 62 : { 63 : int16_t i; 64 : float gain_fac; 65 : float yy; 66 : int16_t output[PVQ_MAX_BAND_SIZE]; /* short interface as in STL-FIP */ 67 : uint32_t h_mem[1 + KMAX_NON_DIRECT + 1]; /* allocate max offset memory for dim 6 */ 68 : PvqEntry entry; 69 : 70 885486 : entry = get_size_mpvq_calc_offset( dim, k_val, h_mem ); /* get size & prepare H(adaptive table for entry.size=N_MPVQ(dim,k_val) */ 71 : 72 885486 : if ( dim != 1 ) 73 : { 74 885360 : entry.lead_sign_ind = (int16_t) rc_dec_bits( st, hPVQ, 1 ); 75 885360 : entry.index = rc_dec_uniform( st, hPVQ, entry.size ); /* NB so far no PVQ-size wc is exactly 2^32-1 */ 76 : 77 : /* safety check in case of bit errors */ 78 885360 : if ( st->hHQ_core != NULL ) 79 : { 80 884979 : if ( entry.index >= entry.size || st->hHQ_core->ber_occured_in_pvq != 0 ) 81 : { 82 0 : st->hHQ_core->ber_occured_in_pvq = 1; 83 0 : st->BER_detect = 1; 84 0 : entry.index = 0; /* a zero index will essentially disable PVQ index decompostion complexity */ 85 : } 86 : } 87 : } 88 : else 89 : { 90 126 : entry.lead_sign_ind = (int16_t) rc_dec_bits( st, hPVQ, 1 ); /* always a single sign bit */ 91 126 : entry.index = 0; 92 : } 93 885486 : mpvq_decode_vec( &entry, h_mem, output ); 94 : 95 885486 : mvs2s( output, y, dim ); 96 : 97 : /* Find decoded vector energy */ 98 885486 : yy = 0; 99 12213090 : for ( i = 0; i < dim; i++ ) 100 : { 101 11327604 : yy += y[i] * y[i]; 102 : } 103 : 104 : /* Apply scaling, always energy in yy */ 105 885486 : gain_fac = gain * 1.0f / (float) sqrt( yy ); 106 12213090 : for ( i = 0; i < dim; i++ ) 107 : { 108 11327604 : xq[i] = y[i] * gain_fac; 109 : } 110 : 111 885486 : return; 112 : }