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 : #include "cnst.h"
40 : #include "prot.h"
41 : #include "wmc_auto.h"
42 :
43 : /*------------------------------------------------------------------*
44 : * vlpc_2st_cod()
45 : *
46 : *
47 : *------------------------------------------------------------------*/
48 :
49 : /*! r: number of allocated bits */
50 111052 : int16_t vlpc_2st_cod(
51 : const float *lsf, /* i : normalized vector to quantize */
52 : float *lsfq, /* i/o: i:1st stage o:1st+2nd stage */
53 : int16_t *indx, /* o : index[] (4 bits per words) */
54 : const int16_t mode, /* i : 0=abs, >0=rel */
55 : const int32_t sr_core /* i : internal sampling rate */
56 : )
57 : {
58 : int16_t i, nbits;
59 : float w[M], x[M], tmp;
60 : int16_t nq, xq[M];
61 111052 : float scale = ( (float) sr_core ) / INT_FS_12k8;
62 111052 : float scaleinv = 1.f / scale;
63 :
64 : /* 0 bit with true weighting: save 0.5 bit */
65 :
66 111052 : lsf_weight_2st( lsf, w, 1, sr_core );
67 :
68 1887884 : for ( i = 0; i < M; i++ )
69 : {
70 1776832 : x[i] = ( lsf[i] - lsfq[i] ) * scaleinv;
71 : }
72 :
73 1887884 : for ( i = 0; i < M; i++ )
74 : {
75 1776832 : x[i] /= w[i];
76 : }
77 :
78 111052 : tmp = 0.0f;
79 :
80 1887884 : for ( i = 0; i < M; i++ )
81 : {
82 1776832 : tmp += x[i] * x[i];
83 : }
84 :
85 111052 : if ( tmp < 8.0f )
86 : {
87 3307 : indx[0] = 0;
88 3307 : indx[1] = 0;
89 :
90 3307 : return ( 10 ); /* 2*(2+3) */
91 : }
92 :
93 : /* weighting from the 1st stage */
94 107745 : lsf_weight_2st( lsfq, w, mode, sr_core );
95 :
96 : /* find lsf residual */
97 :
98 1831665 : for ( i = 0; i < M; i++ )
99 : {
100 1723920 : x[i] = ( lsf[i] - lsfq[i] ) * scaleinv;
101 : }
102 :
103 : /* scale the residual */
104 :
105 1831665 : for ( i = 0; i < M; i++ )
106 : {
107 1723920 : x[i] /= w[i];
108 : }
109 :
110 : /* quantize */
111 107745 : AVQ_cod_lpc( x, xq, indx, 2 );
112 :
113 : /* quantized lsf */
114 :
115 1831665 : for ( i = 0; i < M; i++ )
116 : {
117 1723920 : lsfq[i] += scale * ( w[i] * (float) xq[i] );
118 : }
119 :
120 : /* total number of bits using entropic code to index the quantizer number */
121 107745 : nbits = 0;
122 :
123 323235 : for ( i = 0; i < 2; i++ )
124 : {
125 215490 : nq = indx[i];
126 215490 : nbits += ( 2 + ( nq * 4 ) ); /* 2 bits to specify Q2,Q3,Q4,ext */
127 :
128 215490 : if ( nq > 6 )
129 : {
130 2011 : nbits += nq - 3; /* unary code (Q7=1110, ...) */
131 : }
132 213479 : else if ( nq > 4 )
133 : {
134 49768 : nbits += nq - 4; /* Q5=0, Q6=10 */
135 : }
136 163711 : else if ( nq == 0 )
137 : {
138 8345 : nbits += 3; /* Q0=110 */
139 : }
140 : }
141 :
142 : /* reorder */
143 107745 : v_sort( lsfq, 0, M - 1 );
144 107745 : reorder_lsf( lsfq, LSF_GAP, M, sr_core );
145 :
146 107745 : return ( nbits );
147 : }
|