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