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 <assert.h>
38 : #include <stdint.h>
39 : #include "options.h"
40 : #include "prot_fx.h"
41 : #include "wmc_auto.h"
42 : #include "ivas_prot_fx.h"
43 :
44 :
45 : /*-------------------------------------------------------------------*
46 : * longadd()
47 : *
48 : * long addition: a[] = a[] + b[]
49 : * Addition of unsigned vectors a[] and b[] without saturation.
50 : * All words of b[] are added with carry to the corresponding words in a.
51 : * An assertion failure occurs, if lenb exceeds lena or if overflow occurs.
52 : *--------------------------------------------------------------------*/
53 :
54 0 : void longadd(
55 : UWord16 a[], /* i/o: vector of the length lena */
56 : const UWord16 b[], /* i/o: vector of the length lenb */
57 : const Word16 lena, /* i/o: length of vector a[] */
58 : const Word16 lenb /* i/o: length of vector b[] */
59 : )
60 : {
61 : Word16 h;
62 0 : Word32 carry = 0;
63 :
64 0 : assert( lena >= lenb );
65 0 : for ( h = 0; h < lenb; h++ )
66 : {
67 0 : carry += ( (uint32_t) a[h] ) + ( (uint32_t) b[h] );
68 0 : a[h] = (UWord16) carry;
69 0 : carry = carry >> 16;
70 : }
71 :
72 0 : for ( ; h < lena; h++ )
73 : {
74 0 : carry = ( (uint32_t) a[h] ) + carry;
75 0 : a[h] = (UWord16) carry;
76 0 : carry = carry >> 16;
77 : }
78 :
79 0 : assert( carry == 0 ); /* carry != 0 indicates addition overflow */
80 0 : return;
81 : }
82 :
83 :
84 : /*-------------------------------------------------------------------*
85 : * longshiftright()
86 : *
87 : * long shift right: d[] = a[] >> b
88 : * Logical shift right of unsigned vectors a[] by b bit-positions.
89 : * Vector d[] is filled with leading zeroes, where lend exceeds lena.
90 : * It is allowed to overlay d[] with a[].
91 : *--------------------------------------------------------------------*/
92 :
93 0 : void longshiftright(
94 : UWord16 a[], /* i : vector of the length lena */
95 : const Word16 b, /* i : number of bit positions to shift right */
96 : UWord16 d[], /* o : vector of the length lend */
97 : Word16 lena, /* i : length of vector a[] */
98 : const Word16 lend /* i : length of vector d[] */
99 : )
100 : {
101 : Word16 intb, fracb, fracb_u, k;
102 :
103 0 : intb = b >> 4;
104 :
105 0 : a += intb;
106 0 : lena -= intb;
107 :
108 0 : fracb = b & 0xF;
109 0 : if ( fracb )
110 : {
111 0 : fracb_u = 16 - fracb;
112 0 : for ( k = 0; k < lena - 1; k++ )
113 : {
114 0 : d[k] = ( ( a[k] >> fracb ) | ( a[k + 1] << fracb_u ) ) & 0xFFFF;
115 : }
116 0 : d[k] = ( a[k] >> fracb );
117 0 : k++;
118 : }
119 : else
120 : {
121 0 : for ( k = 0; k < lena; k++ )
122 : {
123 0 : d[k] = a[k];
124 : }
125 : }
126 :
127 : /* fill remaining upper bits with zero */
128 0 : for ( ; k < lend; k++ )
129 : {
130 0 : d[k] = 0;
131 : }
132 :
133 0 : return;
134 : }
135 :
136 146383 : void longshr(
137 : UWord32 a[],
138 : Word16 bits,
139 : Word16 len )
140 : {
141 : Word16 fracb_u, k;
142 :
143 146383 : assert( ( bits > 0 ) && ( bits < 32 ) );
144 :
145 146383 : fracb_u = sub( 32, bits );
146 146383 : len = sub( len, 1 );
147 229708 : FOR( k = 0; k < len; k++ )
148 : {
149 83325 : a[k] = UL_or( (UWord32) W_shr( a[k], bits ), UL_lshl( a[k + 1], fracb_u ) );
150 83325 : move32();
151 : }
152 146383 : a[k] = L_lshr( a[k], bits );
153 146383 : move32();
154 :
155 146383 : return;
156 : }
157 :
158 : /*-------------------------------------------------------------------*
159 : * longshiftleft()
160 : *
161 : * long shift left: d[] = a[] << b
162 : * Logical shift left of unsigned vectors a[] by b bit-positions.
163 : * It is allowed to overlay d[] with a[].
164 : *--------------------------------------------------------------------*/
165 :
166 0 : void longshiftleft(
167 : const UWord16 a[], /* i : vector of the length len */
168 : const Word16 b, /* i : number of bit positions to shift left */
169 : UWord16 d[], /* o : vector of the length len */
170 : const Word16 len /* i : length of vector a[] and d[] */
171 : )
172 : {
173 : Word16 intb; /* integer part of b */
174 : Word16 fracb; /* shift left value for all upper words a[k] */
175 : Word16 fracb_l; /* shift right value for all lower words a[k-1] */
176 0 : Word16 k = len - 1;
177 :
178 0 : intb = b >> 4;
179 0 : fracb = b & 0xF;
180 :
181 0 : if ( fracb )
182 : {
183 0 : fracb_l = 16 - fracb;
184 0 : for ( ; k > intb; k-- )
185 : {
186 0 : d[k] = ( a[k - intb] << fracb ) | ( a[k - intb - 1] >> fracb_l );
187 : }
188 0 : d[k] = ( a[k - intb] << fracb );
189 0 : k--;
190 : }
191 : else
192 : {
193 0 : for ( ; k >= intb; k-- )
194 : {
195 0 : d[k] = a[k - intb];
196 : }
197 : }
198 :
199 0 : for ( ; k >= 0; k-- )
200 : {
201 0 : d[k] = 0;
202 : }
203 :
204 0 : return;
205 : }
|