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 <stdint.h>
34 : #include "options.h"
35 : #include "ivas_prot.h"
36 : #include "ivas_prot_rend.h"
37 : #include "prot.h"
38 : #ifdef DEBUGGING
39 : #include "debug.h"
40 : #endif
41 : #include "wmc_auto.h"
42 :
43 :
44 : /*-----------------------------------------------------------------------------------------*
45 : * Function ivas_rev_delay_line_init()
46 : *
47 : * Initialize the delay line
48 : *-----------------------------------------------------------------------------------------*/
49 :
50 3645 : void ivas_rev_delay_line_init(
51 : ivas_rev_delay_line_t *pDelay, /* o : the delay line to initialize */
52 : float *memory_buffer, /* i : the memory buffer to use for the delay line */
53 : const uint16_t delay, /* i : the delay */
54 : const uint16_t maxdelay /* i : maximum delay to be supported */
55 : )
56 : {
57 3645 : pDelay->MaxDelay = maxdelay;
58 :
59 3645 : if ( delay <= pDelay->MaxDelay )
60 : {
61 3645 : pDelay->Delay = delay;
62 : }
63 : else
64 : {
65 0 : pDelay->Delay = pDelay->MaxDelay;
66 : }
67 :
68 3645 : pDelay->pBuffer = memory_buffer;
69 3645 : set_f( pDelay->pBuffer, 0, pDelay->MaxDelay );
70 3645 : pDelay->BufferPos = 0;
71 3645 : pDelay->Gain = 1.0f;
72 :
73 3645 : return;
74 : }
75 :
76 :
77 : /*-----------------------------------------------------------------------------------------*
78 : * Function ivas_rev_delay_line_feed_sample()
79 : *
80 : * Feed sample into delay line; NOTE: get a sample out of the line before feeding the next
81 : *-----------------------------------------------------------------------------------------*/
82 :
83 0 : void ivas_rev_delay_line_feed_sample(
84 : ivas_rev_delay_line_t *pDelay, /* i : the delay line */
85 : float input /* i : the sample to feed */
86 : )
87 : {
88 0 : pDelay->pBuffer[pDelay->BufferPos++] = input;
89 :
90 0 : if ( pDelay->BufferPos >= pDelay->Delay )
91 : {
92 0 : pDelay->BufferPos = 0;
93 : }
94 :
95 0 : return;
96 : }
97 :
98 :
99 : /*-----------------------------------------------------------------------------------------*
100 : * Function ivas_rev_delay_line_feed_sample_blk()
101 : *
102 : * Feed sample block into delay line; NOTE: get samples out of the line before feeding the next block
103 : *-----------------------------------------------------------------------------------------*/
104 :
105 22729860 : void ivas_rev_delay_line_feed_sample_blk(
106 : ivas_rev_delay_line_t *pDelay, /* i/o: the delay line */
107 : const uint16_t blk_size, /* i : number of samples in the input data block */
108 : float *input /* i : the samples to feed */
109 : )
110 : {
111 : float *pDst, *pSrc;
112 : uint16_t i, pos;
113 :
114 22729860 : pos = (uint16_t) pDelay->BufferPos;
115 :
116 22729860 : if ( pos + blk_size > (uint16_t) pDelay->Delay ) /* splitting block in 2 if it exceeds buffer end limit */
117 : {
118 : uint16_t blk_size_1; /* 1st block up to the end of the buffer */
119 : uint16_t blk_size_2; /* 2nd block at the beginning of the buffer */
120 :
121 5072784 : blk_size_1 = (uint16_t) pDelay->Delay - pos;
122 5072784 : blk_size_2 = blk_size - blk_size_1;
123 5072784 : pDst = &pDelay->pBuffer[pos];
124 145820715 : for ( i = 0; i < blk_size_1; i++ )
125 : {
126 140747931 : pDst[i] = input[i];
127 : }
128 5072784 : pDst = &pDelay->pBuffer[0];
129 5072784 : pSrc = &input[blk_size_1];
130 145872481 : for ( i = 0; i < blk_size_2; i++ )
131 : {
132 140799697 : pDst[i] = pSrc[i];
133 : }
134 5072784 : pos = blk_size_2;
135 : }
136 : else /* copy only 1 data block directly if it fits in the buffer */
137 : {
138 17657076 : pDst = &pDelay->pBuffer[pos];
139 1424052248 : for ( i = 0; i < blk_size; i++ )
140 : {
141 1406395172 : pDst[i] = input[i];
142 : }
143 17657076 : pos += blk_size;
144 : }
145 22729860 : pDelay->BufferPos = pos;
146 :
147 22729860 : if ( pDelay->BufferPos >= pDelay->Delay )
148 : {
149 166384 : pDelay->BufferPos = 0;
150 : }
151 :
152 22729860 : return;
153 : }
154 :
155 :
156 : /*-----------------------------------------------------------------------------------------*
157 : * Function ivas_rev_delay_line_get_sample()
158 : *
159 : * Get sample out of delay line, amplified by set gain
160 : * NOTE: get a sample out of the line before feeding the next
161 : *-----------------------------------------------------------------------------------------*/
162 :
163 : /*! r: sample gotten out of delay line, and amplified by set gain */
164 0 : float ivas_rev_delay_line_get_sample(
165 : ivas_rev_delay_line_t *pDelay /* i/o: the delay line */
166 : )
167 : {
168 0 : if ( pDelay->Gain == 1.0f )
169 : {
170 :
171 0 : return pDelay->pBuffer[pDelay->BufferPos];
172 : }
173 : else
174 : {
175 :
176 0 : return pDelay->Gain * pDelay->pBuffer[pDelay->BufferPos];
177 : }
178 : }
179 :
180 :
181 : /*-----------------------------------------------------------------------------------------*
182 : * Function ivas_rev_delay_line_get_sample_blk()
183 : *
184 : * Get a block samples out of delay line, amplified by set gain
185 : *-----------------------------------------------------------------------------------------*/
186 :
187 22729860 : void ivas_rev_delay_line_get_sample_blk(
188 : ivas_rev_delay_line_t *pDelay, /* i : the delay line */
189 : const uint16_t blk_size, /* i : number of samples in the data block */
190 : float *output /* i/o: amples gotten out of delay line, and amplified by set gainin */
191 : )
192 : {
193 : float *pDst, *pSrc;
194 : uint16_t i, pos;
195 : float gain;
196 :
197 22729860 : pos = (uint16_t) pDelay->BufferPos;
198 22729860 : gain = pDelay->Gain;
199 :
200 22729860 : if ( pos + blk_size > (uint16_t) pDelay->Delay ) /* splitting block in 2 if it exceeds buffer end limit */
201 : {
202 : uint16_t blk_size_1; /* 1st block up to the end of the buffer */
203 : uint16_t blk_size_2; /* 2nd block at the beginning of the buffer */
204 :
205 5072784 : blk_size_1 = (uint16_t) pDelay->Delay - pos;
206 5072784 : blk_size_2 = blk_size - blk_size_1;
207 5072784 : pSrc = &pDelay->pBuffer[pos];
208 5072784 : if ( gain == 1.0f )
209 : {
210 145820715 : for ( i = 0; i < blk_size_1; i++ )
211 : {
212 140747931 : output[i] = pSrc[i];
213 : }
214 5072784 : pSrc = &pDelay->pBuffer[0];
215 5072784 : pDst = &output[blk_size_1];
216 145872481 : for ( i = 0; i < blk_size_2; i++ )
217 : {
218 140799697 : pDst[i] = pSrc[i];
219 : }
220 : }
221 : else
222 : {
223 0 : for ( i = 0; i < blk_size_1; i++ )
224 : {
225 0 : output[i] = gain * pSrc[i];
226 : }
227 0 : pSrc = &pDelay->pBuffer[0];
228 0 : pDst = &output[blk_size_1];
229 0 : for ( i = 0; i < blk_size_2; i++ )
230 : {
231 0 : pDst[i] = gain * pSrc[i];
232 : }
233 : }
234 : }
235 : else /* copy only 1 data block directly if it fits in the buffer */
236 : {
237 17657076 : pSrc = &pDelay->pBuffer[pos];
238 :
239 17657076 : if ( gain == 1.0f )
240 : {
241 1424052248 : for ( i = 0; i < blk_size; i++ )
242 : {
243 1406395172 : output[i] = pSrc[i];
244 : }
245 : }
246 : else
247 : {
248 0 : for ( i = 0; i < blk_size; i++ )
249 : {
250 0 : output[i] = gain * pSrc[i];
251 : }
252 : }
253 : }
254 :
255 22729860 : return;
256 : }
|