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 "prot.h"
36 : #include "ivas_prot.h"
37 : #include "ivas_prot_rend.h"
38 : #include "ivas_cnst.h"
39 : #include "ivas_rom_rend.h"
40 : #include <math.h>
41 : #include "ivas_rom_binaural_crend_head.h"
42 : #include "ivas_stat_rend.h"
43 : #include "lib_rend.h"
44 : #ifdef DEBUGGING
45 : #include "debug.h"
46 : #endif
47 : #include "wmc_auto.h"
48 :
49 :
50 : /*-------------------------------------------------------------------------
51 : * ivas_Crend_hrtf_init()
52 : *
53 : * Initialize hHrtf handle
54 : *------------------------------------------------------------------------*/
55 :
56 7694 : ivas_error ivas_Crend_hrtf_init(
57 : HRTFS_CREND_DATA *hHrtf /* i/o: HRTF handle */
58 : )
59 : {
60 : int16_t i, j;
61 :
62 7694 : if ( hHrtf == NULL )
63 : {
64 0 : return IVAS_ERR_WRONG_PARAMS;
65 : }
66 :
67 7694 : hHrtf->latency_s = 0;
68 7694 : hHrtf->gain_lfe = 0;
69 7694 : hHrtf->max_num_ir = 0;
70 7694 : hHrtf->max_num_iterations = 0;
71 7694 : hHrtf->index_frequency_max_diffuse = 0;
72 7694 : hHrtf->same_inv_diffuse_weight = 1;
73 :
74 130798 : for ( i = 0; i < MAX_INTERN_CHANNELS; i++ )
75 : {
76 369312 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
77 : {
78 246208 : hHrtf->inv_diffuse_weight[j][i] = 0;
79 246208 : hHrtf->num_iterations[i][j] = 0;
80 246208 : hHrtf->pIndex_frequency_max[i][j] = NULL;
81 246208 : hHrtf->pOut_to_bin_re[i][j] = NULL;
82 246208 : hHrtf->pOut_to_bin_im[i][j] = NULL;
83 246208 : hHrtf->pOut_to_bin_re_dyn[i][j] = NULL;
84 246208 : hHrtf->pOut_to_bin_im_dyn[i][j] = NULL;
85 246208 : hHrtf->pIndex_frequency_max_dyn[i][j] = NULL;
86 : }
87 : }
88 :
89 23082 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
90 : {
91 15388 : hHrtf->num_iterations_diffuse[j] = 0;
92 15388 : hHrtf->pIndex_frequency_max_diffuse[j] = NULL;
93 15388 : hHrtf->pOut_to_bin_diffuse_re[j] = NULL;
94 15388 : hHrtf->pOut_to_bin_diffuse_im[j] = NULL;
95 15388 : hHrtf->pIndex_frequency_max_diffuse_dyn[j] = NULL;
96 15388 : hHrtf->pOut_to_bin_diffuse_re_dyn[j] = NULL;
97 15388 : hHrtf->pOut_to_bin_diffuse_im_dyn[j] = NULL;
98 : }
99 :
100 7694 : hHrtf->init_from_rom = 1;
101 :
102 7694 : return IVAS_ERR_OK;
103 : }
104 :
105 :
106 : /*-------------------------------------------------------------------------
107 : * ivas_hrtf_open()
108 : *
109 : * Open hHrtf handle for Crend renderer
110 : *------------------------------------------------------------------------*/
111 :
112 6841 : static ivas_error ivas_hrtf_open(
113 : HRTFS_CREND_HANDLE *hHrtf_out /* o : HRTF handle */
114 : )
115 : {
116 : HRTFS_CREND_HANDLE hHrtf;
117 : ivas_error error;
118 :
119 6841 : if ( *hHrtf_out == NULL )
120 : {
121 6841 : if ( ( hHrtf = (HRTFS_CREND_HANDLE) malloc( sizeof( HRTFS_CREND_DATA ) ) ) == NULL )
122 : {
123 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend HRTFS Handle\n" );
124 : }
125 :
126 6841 : if ( ( error = ivas_Crend_hrtf_init( hHrtf ) ) != IVAS_ERR_OK )
127 : {
128 0 : return error;
129 : }
130 :
131 6841 : *hHrtf_out = hHrtf;
132 : }
133 : else
134 : {
135 0 : return IVAS_ERR_INTERNAL;
136 : }
137 :
138 6841 : return IVAS_ERR_OK;
139 : }
140 :
141 :
142 : /*-------------------------------------------------------------------------
143 : * ivas_hrtf_close()
144 : *
145 : * Close hHrtf handle
146 : *------------------------------------------------------------------------*/
147 :
148 6841 : static void ivas_hrtf_close(
149 : HRTFS_CREND_HANDLE *hHrtf /* i/o: Crend HRTF handle */
150 : )
151 : {
152 6841 : if ( hHrtf == NULL || *hHrtf == NULL )
153 : {
154 0 : return;
155 : }
156 :
157 6841 : free( *hHrtf );
158 6841 : *hHrtf = NULL;
159 :
160 6841 : return;
161 : }
162 :
163 :
164 : /*-------------------------------------------------------------------------
165 : * ivas_rend_initCrend()
166 : *
167 : * Allocate and initialize crend renderer handle
168 : *------------------------------------------------------------------------*/
169 :
170 7694 : static ivas_error ivas_rend_initCrend(
171 : CREND_WRAPPER *pCrend,
172 : const AUDIO_CONFIG inConfig,
173 : const AUDIO_CONFIG outConfig,
174 : HRTFS_CREND_HANDLE hHrtfCrend,
175 : const int16_t ext_rend_flag,
176 : const int32_t output_Fs )
177 : {
178 : int16_t i, j, tmp, tmp2;
179 : int16_t nchan_in;
180 : IVAS_REND_AudioConfigType inConfigType;
181 : HRTFS_CREND_HANDLE hHrtf;
182 : ivas_error error;
183 :
184 7694 : inConfigType = getAudioConfigType( inConfig );
185 7694 : hHrtf = pCrend->hHrtfCrend;
186 :
187 : /* Do all error checks up front so that the nested if later is easier */
188 7694 : if ( inConfigType != IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED && inConfigType != IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS )
189 : {
190 0 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Encountered unsupported input config in Crend" );
191 : }
192 :
193 7694 : if ( outConfig != IVAS_AUDIO_CONFIG_BINAURAL && outConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && outConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB && outConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && outConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
194 : {
195 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Encountered unsupported output type in Crend" );
196 : }
197 :
198 7694 : if ( hHrtf == NULL )
199 : {
200 7694 : if ( hHrtfCrend != NULL && ext_rend_flag == 0 )
201 : {
202 : /* HRTF set loaded from binary file */
203 853 : hHrtf = hHrtfCrend;
204 853 : hHrtf->init_from_rom = 0;
205 : }
206 : else
207 : {
208 : /* create new handle when HRTF is loaded from ROM, or external renderer is used */
209 6841 : if ( ( error = ivas_hrtf_open( &hHrtf ) ) != IVAS_ERR_OK )
210 : {
211 0 : return error;
212 : }
213 :
214 6841 : hHrtf->init_from_rom = 1;
215 6841 : if ( hHrtfCrend != NULL )
216 : {
217 0 : hHrtf->init_from_rom = 0;
218 : }
219 : }
220 : }
221 :
222 7694 : if ( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ) != IVAS_ERR_OK )
223 : {
224 0 : return error;
225 : }
226 7694 : hHrtf->max_num_ir = nchan_in;
227 :
228 7694 : if ( hHrtf->max_num_ir <= 0 )
229 : {
230 0 : return IVAS_ERR_INTERNAL_FATAL;
231 : }
232 :
233 7694 : if ( hHrtf->init_from_rom )
234 : {
235 6841 : if ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED )
236 : {
237 5240 : hHrtf->max_num_ir -= 1; /* subtract LFE */
238 5240 : hHrtf->gain_lfe = GAIN_LFE;
239 :
240 5240 : if ( output_Fs == 48000 )
241 : {
242 2144 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
243 : {
244 1528 : hHrtf->latency_s = CRendBin_Combined_BRIR_latency_s;
245 1528 : hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_48kHz;
246 1528 : hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_48kHz;
247 : }
248 : else
249 : {
250 616 : hHrtf->latency_s = CRendBin_Combined_HRIR_latency_s;
251 616 : hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_48kHz;
252 616 : hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_48kHz;
253 : }
254 :
255 6432 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
256 : {
257 4288 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
258 : {
259 3056 : hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_48kHz[j];
260 3056 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_48kHz[j];
261 3056 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_48kHz[j];
262 3056 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_48kHz[j];
263 : }
264 : else
265 : {
266 1232 : hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_48kHz[j];
267 1232 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_48kHz[j];
268 1232 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_48kHz[j];
269 1232 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_48kHz[j];
270 : }
271 : }
272 : }
273 3096 : else if ( output_Fs == 32000 )
274 : {
275 1563 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
276 : {
277 1283 : hHrtf->latency_s = CRendBin_Combined_BRIR_latency_s;
278 1283 : hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_32kHz;
279 1283 : hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_32kHz;
280 : }
281 : else
282 : {
283 280 : hHrtf->latency_s = CRendBin_Combined_HRIR_latency_s;
284 280 : hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_32kHz;
285 280 : hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_32kHz;
286 : }
287 :
288 4689 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
289 : {
290 3126 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
291 : {
292 2566 : hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_32kHz[j];
293 2566 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_32kHz[j];
294 2566 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_32kHz[j];
295 2566 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_32kHz[j];
296 : }
297 : else
298 : {
299 560 : hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_32kHz[j];
300 560 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_32kHz[j];
301 560 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_32kHz[j];
302 560 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_32kHz[j];
303 : }
304 : }
305 : }
306 1533 : else if ( output_Fs == 16000 )
307 : {
308 1533 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
309 : {
310 1070 : hHrtf->latency_s = CRendBin_Combined_BRIR_latency_s;
311 :
312 1070 : hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_16kHz;
313 1070 : hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_16kHz;
314 : }
315 : else
316 : {
317 463 : hHrtf->latency_s = CRendBin_Combined_HRIR_latency_s;
318 463 : hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_16kHz;
319 463 : hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_16kHz;
320 : }
321 :
322 4599 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
323 : {
324 3066 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
325 : {
326 2140 : hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_16kHz[j];
327 2140 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_16kHz[j];
328 2140 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_16kHz[j];
329 2140 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_16kHz[j];
330 : }
331 : else
332 : {
333 926 : hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_16kHz[j];
334 926 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_16kHz[j];
335 926 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_16kHz[j];
336 926 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_16kHz[j];
337 : }
338 : }
339 : }
340 : else
341 : {
342 0 : return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Encountered Unsupported sampling rate in Crend" );
343 : }
344 :
345 55316 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
346 : {
347 50076 : if ( inConfig == IVAS_AUDIO_CONFIG_5_1 )
348 : {
349 4360 : tmp = channelIndex_CICP6[i];
350 : }
351 45716 : else if ( inConfig == IVAS_AUDIO_CONFIG_7_1 )
352 : {
353 1505 : tmp = channelIndex_CICP12[i];
354 : }
355 44211 : else if ( inConfig == IVAS_AUDIO_CONFIG_5_1_2 )
356 : {
357 1778 : tmp = channelIndex_CICP14[i];
358 : }
359 42433 : else if ( inConfig == IVAS_AUDIO_CONFIG_5_1_4 )
360 : {
361 2052 : tmp = channelIndex_CICP16[i];
362 : }
363 40381 : else if ( inConfig == IVAS_AUDIO_CONFIG_7_1_4 )
364 : {
365 40381 : tmp = channelIndex_CICP19[i];
366 : }
367 : else
368 : {
369 0 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Channel configuration not specified!\n\n" );
370 : }
371 :
372 50076 : if ( output_Fs == 48000 )
373 : {
374 58650 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
375 : {
376 39100 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
377 : {
378 30492 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_Combined_BRIR_inv_diffuse_weight_48kHz[j][tmp];
379 30492 : hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_48kHz[tmp][j];
380 30492 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_48kHz[tmp][j];
381 30492 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_Combined_BRIR_coeff_re_48kHz[tmp][j];
382 30492 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_Combined_BRIR_coeff_im_48kHz[tmp][j];
383 : }
384 : else
385 : {
386 8608 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_Combined_HRIR_inv_diffuse_weight_48kHz[j][tmp];
387 8608 : hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_48kHz[tmp][j];
388 8608 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_48kHz[tmp][j];
389 8608 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_Combined_HRIR_coeff_re_48kHz[tmp][j];
390 8608 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_Combined_HRIR_coeff_im_48kHz[tmp][j];
391 : }
392 : }
393 : }
394 30526 : else if ( output_Fs == 32000 )
395 : {
396 48003 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
397 : {
398 32002 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
399 : {
400 27506 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_Combined_BRIR_inv_diffuse_weight_32kHz[j][tmp];
401 27506 : hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_32kHz[tmp][j];
402 27506 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_32kHz[tmp][j];
403 27506 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_Combined_BRIR_coeff_re_32kHz[tmp][j];
404 27506 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_Combined_BRIR_coeff_im_32kHz[tmp][j];
405 : }
406 : else
407 : {
408 4496 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_Combined_HRIR_inv_diffuse_weight_32kHz[j][tmp];
409 4496 : hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_32kHz[tmp][j];
410 4496 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_32kHz[tmp][j];
411 4496 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_Combined_HRIR_coeff_re_32kHz[tmp][j];
412 4496 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_Combined_HRIR_coeff_im_32kHz[tmp][j];
413 : }
414 : }
415 : }
416 14525 : else if ( output_Fs == 16000 )
417 : {
418 43575 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
419 : {
420 29050 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
421 : {
422 22724 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_Combined_BRIR_inv_diffuse_weight_16kHz[j][tmp];
423 22724 : hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_16kHz[tmp][j];
424 22724 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_16kHz[tmp][j];
425 22724 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_Combined_BRIR_coeff_re_16kHz[tmp][j];
426 22724 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_Combined_BRIR_coeff_im_16kHz[tmp][j];
427 : }
428 : else
429 : {
430 6326 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_Combined_HRIR_inv_diffuse_weight_16kHz[j][tmp];
431 6326 : hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_16kHz[tmp][j];
432 6326 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_16kHz[tmp][j];
433 6326 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_Combined_HRIR_coeff_re_16kHz[tmp][j];
434 6326 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_Combined_HRIR_coeff_im_16kHz[tmp][j];
435 : }
436 : }
437 : }
438 : else
439 : {
440 0 : return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Encountered Unsupported sampling rate in Crend" );
441 : }
442 : }
443 : }
444 1601 : else if ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS )
445 : {
446 1601 : if ( inConfig == IVAS_AUDIO_CONFIG_HOA3 )
447 : {
448 635 : if ( output_Fs == 48000 )
449 : {
450 355 : hHrtf->latency_s = CRendBin_HOA3_HRIR_latency_s;
451 355 : hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_48kHz;
452 355 : hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_48kHz;
453 :
454 6035 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
455 : {
456 17040 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
457 : {
458 11360 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_48kHz[j][i];
459 11360 : hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_48kHz[i][j];
460 11360 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_48kHz[i][j];
461 11360 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_HOA3_HRIR_coeff_re_48kHz[i][j];
462 11360 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_HOA3_HRIR_coeff_im_48kHz[i][j];
463 : }
464 : }
465 1065 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
466 : {
467 710 : hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_48kHz[j];
468 710 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_48kHz[j];
469 710 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_48kHz[j];
470 710 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_48kHz[j];
471 : }
472 : }
473 280 : else if ( output_Fs == 32000 )
474 : {
475 140 : hHrtf->latency_s = CRendBin_HOA3_HRIR_latency_s;
476 140 : hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_32kHz;
477 140 : hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_32kHz;
478 :
479 2380 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
480 : {
481 6720 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
482 : {
483 4480 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_32kHz[j][i];
484 4480 : hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_32kHz[i][j];
485 4480 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_32kHz[i][j];
486 4480 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_HOA3_HRIR_coeff_re_32kHz[i][j];
487 4480 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_HOA3_HRIR_coeff_im_32kHz[i][j];
488 : }
489 : }
490 :
491 420 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
492 : {
493 280 : hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_32kHz[j];
494 280 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_32kHz[j];
495 280 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_32kHz[j];
496 280 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_32kHz[j];
497 : }
498 : }
499 140 : else if ( output_Fs == 16000 )
500 : {
501 140 : hHrtf->latency_s = CRendBin_HOA3_HRIR_latency_s;
502 140 : hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_16kHz;
503 140 : hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_16kHz;
504 :
505 2380 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
506 : {
507 6720 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
508 : {
509 4480 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_16kHz[j][i];
510 4480 : hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_16kHz[i][j];
511 4480 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_16kHz[i][j];
512 4480 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_HOA3_HRIR_coeff_re_16kHz[i][j];
513 4480 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_HOA3_HRIR_coeff_im_16kHz[i][j];
514 : }
515 : }
516 :
517 420 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
518 : {
519 280 : hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_16kHz[j];
520 280 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_16kHz[j];
521 280 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_16kHz[j];
522 280 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_16kHz[j];
523 : }
524 : }
525 : else
526 : {
527 0 : return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Encountered Unsupported sampling rate in Crend" );
528 : }
529 : }
530 966 : else if ( inConfig == IVAS_AUDIO_CONFIG_HOA2 )
531 : {
532 448 : if ( output_Fs == 48000 )
533 : {
534 168 : hHrtf->latency_s = CRendBin_HOA2_HRIR_latency_s;
535 168 : hHrtf->max_num_iterations = CRendBin_HOA2_HRIR_max_num_iterations_48kHz;
536 168 : hHrtf->index_frequency_max_diffuse = CRendBin_HOA2_HRIR_index_frequency_max_diffuse_48kHz;
537 :
538 1680 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
539 : {
540 4536 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
541 : {
542 3024 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_48kHz[j][i];
543 3024 : hHrtf->num_iterations[i][j] = CRendBin_HOA2_HRIR_num_iterations_48kHz[i][j];
544 3024 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_48kHz[i][j];
545 3024 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_HOA2_HRIR_coeff_re_48kHz[i][j];
546 3024 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_HOA2_HRIR_coeff_im_48kHz[i][j];
547 : }
548 : }
549 504 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
550 : {
551 336 : hHrtf->num_iterations_diffuse[j] = CRendBin_HOA2_HRIR_num_iterations_diffuse_48kHz[j];
552 336 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_48kHz[j];
553 336 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_48kHz[j];
554 336 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_48kHz[j];
555 : }
556 : }
557 280 : else if ( output_Fs == 32000 )
558 : {
559 140 : hHrtf->latency_s = CRendBin_HOA2_HRIR_latency_s;
560 140 : hHrtf->max_num_iterations = CRendBin_HOA2_HRIR_max_num_iterations_32kHz;
561 140 : hHrtf->index_frequency_max_diffuse = CRendBin_HOA2_HRIR_index_frequency_max_diffuse_32kHz;
562 :
563 1400 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
564 : {
565 3780 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
566 : {
567 2520 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_32kHz[j][i];
568 2520 : hHrtf->num_iterations[i][j] = CRendBin_HOA2_HRIR_num_iterations_32kHz[i][j];
569 2520 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_32kHz[i][j];
570 2520 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_HOA2_HRIR_coeff_re_32kHz[i][j];
571 2520 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_HOA2_HRIR_coeff_im_32kHz[i][j];
572 : }
573 : }
574 :
575 420 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
576 : {
577 280 : hHrtf->num_iterations_diffuse[j] = CRendBin_HOA2_HRIR_num_iterations_diffuse_32kHz[j];
578 280 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_32kHz[j];
579 280 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_32kHz[j];
580 280 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_32kHz[j];
581 : }
582 : }
583 140 : else if ( output_Fs == 16000 )
584 : {
585 140 : hHrtf->latency_s = CRendBin_HOA2_HRIR_latency_s;
586 140 : hHrtf->max_num_iterations = CRendBin_HOA2_HRIR_max_num_iterations_16kHz;
587 140 : hHrtf->index_frequency_max_diffuse = CRendBin_HOA2_HRIR_index_frequency_max_diffuse_16kHz;
588 :
589 1400 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
590 : {
591 3780 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
592 : {
593 2520 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_16kHz[j][i];
594 2520 : hHrtf->num_iterations[i][j] = CRendBin_HOA2_HRIR_num_iterations_16kHz[i][j];
595 2520 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_16kHz[i][j];
596 2520 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_HOA2_HRIR_coeff_re_16kHz[i][j];
597 2520 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_HOA2_HRIR_coeff_im_16kHz[i][j];
598 : }
599 : }
600 :
601 420 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
602 : {
603 280 : hHrtf->num_iterations_diffuse[j] = CRendBin_HOA2_HRIR_num_iterations_diffuse_16kHz[j];
604 280 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_16kHz[j];
605 280 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_16kHz[j];
606 280 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_16kHz[j];
607 : }
608 : }
609 : else
610 : {
611 0 : return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Encountered Unsupported sampling rate in Crend" );
612 : }
613 : }
614 518 : else if ( inConfig == IVAS_AUDIO_CONFIG_FOA )
615 : {
616 518 : if ( output_Fs == 48000 )
617 : {
618 238 : hHrtf->latency_s = CRendBin_FOA_HRIR_latency_s;
619 238 : hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_48kHz;
620 238 : hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_48kHz;
621 :
622 1190 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
623 : {
624 2856 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
625 : {
626 1904 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_FOA_HRIR_inv_diffuse_weight_48kHz[j][i];
627 1904 : hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_48kHz[i][j];
628 1904 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_48kHz[i][j];
629 1904 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_FOA_HRIR_coeff_re_48kHz[i][j];
630 1904 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_FOA_HRIR_coeff_im_48kHz[i][j];
631 : }
632 : }
633 714 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
634 : {
635 476 : hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_48kHz[j];
636 476 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_48kHz[j];
637 476 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_48kHz[j];
638 476 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_48kHz[j];
639 : }
640 : }
641 280 : else if ( output_Fs == 32000 )
642 : {
643 140 : hHrtf->latency_s = CRendBin_FOA_HRIR_latency_s;
644 140 : hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_32kHz;
645 140 : hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_32kHz;
646 :
647 700 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
648 : {
649 1680 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
650 : {
651 1120 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_FOA_HRIR_inv_diffuse_weight_32kHz[j][i];
652 1120 : hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_32kHz[i][j];
653 1120 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_32kHz[i][j];
654 1120 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_FOA_HRIR_coeff_re_32kHz[i][j];
655 1120 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_FOA_HRIR_coeff_im_32kHz[i][j];
656 : }
657 : }
658 :
659 420 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
660 : {
661 280 : hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_32kHz[j];
662 280 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_32kHz[j];
663 280 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_32kHz[j];
664 280 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_32kHz[j];
665 : }
666 : }
667 140 : else if ( output_Fs == 16000 )
668 : {
669 140 : hHrtf->latency_s = CRendBin_FOA_HRIR_latency_s;
670 140 : hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_16kHz;
671 140 : hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_16kHz;
672 :
673 700 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
674 : {
675 1680 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
676 : {
677 1120 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_FOA_HRIR_inv_diffuse_weight_16kHz[j][i];
678 1120 : hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_16kHz[i][j];
679 1120 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_16kHz[i][j];
680 1120 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_FOA_HRIR_coeff_re_16kHz[i][j];
681 1120 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_FOA_HRIR_coeff_im_16kHz[i][j];
682 : }
683 : }
684 :
685 420 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
686 : {
687 280 : hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_16kHz[j];
688 280 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_16kHz[j];
689 280 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_16kHz[j];
690 280 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_16kHz[j];
691 : }
692 : }
693 : else
694 : {
695 0 : return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Encountered Unsupported sampling rate in Crend" );
696 : }
697 : }
698 : else
699 : {
700 0 : return IVAS_ERROR( IVAS_ERR_INVALID_INPUT_FORMAT, "Encountered unsupported input config in Crend" );
701 : }
702 : }
703 : else
704 : {
705 0 : return IVAS_ERROR( IVAS_ERR_INTERNAL, "Unsupported renderer type in Crend" );
706 : }
707 : }
708 : else
709 : {
710 853 : if ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED )
711 : {
712 853 : hHrtf->max_num_ir -= 1; /* subtract LFE */
713 853 : hHrtf->gain_lfe = GAIN_LFE;
714 : }
715 :
716 853 : if ( ext_rend_flag == 1 )
717 : {
718 0 : if ( hHrtfCrend == NULL )
719 : {
720 0 : return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "Invalid function parameters " );
721 : }
722 0 : hHrtf->latency_s = hHrtfCrend->latency_s;
723 0 : hHrtf->max_num_iterations = hHrtfCrend->max_num_iterations;
724 0 : hHrtf->index_frequency_max_diffuse = hHrtfCrend->index_frequency_max_diffuse;
725 :
726 0 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
727 : {
728 0 : hHrtf->num_iterations_diffuse[j] = hHrtfCrend->num_iterations_diffuse[j];
729 0 : hHrtf->pIndex_frequency_max_diffuse[j] = hHrtfCrend->pIndex_frequency_max_diffuse[j];
730 0 : hHrtf->pOut_to_bin_diffuse_re[j] = hHrtfCrend->pOut_to_bin_diffuse_re[j];
731 0 : hHrtf->pOut_to_bin_diffuse_im[j] = hHrtfCrend->pOut_to_bin_diffuse_im[j];
732 : }
733 : }
734 :
735 853 : if ( inConfig == IVAS_AUDIO_CONFIG_7_1 && ext_rend_flag == 0 )
736 : {
737 : /* hack to enable pointers swapping - needed when indexes of 'channelIndex_CICPx[]' are not in increasing order */
738 189 : for ( i = 5; i < hHrtf->max_num_ir; i++ )
739 : {
740 126 : tmp = channelIndex_CICP12[i];
741 126 : tmp2 = channelIndex_CICP14[i];
742 :
743 378 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
744 : {
745 252 : hHrtf->inv_diffuse_weight[j][tmp2] = hHrtfCrend->inv_diffuse_weight[j][tmp];
746 252 : hHrtf->num_iterations[tmp2][j] = hHrtfCrend->num_iterations[tmp][j];
747 252 : hHrtf->pIndex_frequency_max[tmp2][j] = hHrtfCrend->pIndex_frequency_max[tmp][j];
748 252 : hHrtf->pOut_to_bin_re[tmp2][j] = hHrtfCrend->pOut_to_bin_re[tmp][j];
749 252 : hHrtf->pOut_to_bin_im[tmp2][j] = hHrtfCrend->pOut_to_bin_im[tmp][j];
750 : }
751 : }
752 : }
753 :
754 9180 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
755 : {
756 8327 : if ( inConfig == IVAS_AUDIO_CONFIG_5_1 )
757 : {
758 360 : tmp = channelIndex_CICP6[i];
759 : }
760 7967 : else if ( inConfig == IVAS_AUDIO_CONFIG_7_1 )
761 : {
762 441 : if ( ext_rend_flag == 0 )
763 : {
764 441 : tmp = channelIndex_CICP14[i];
765 : }
766 : else
767 : {
768 0 : tmp = channelIndex_CICP12[i];
769 : }
770 : }
771 7526 : else if ( inConfig == IVAS_AUDIO_CONFIG_5_1_2 )
772 : {
773 441 : tmp = channelIndex_CICP14[i];
774 : }
775 7085 : else if ( inConfig == IVAS_AUDIO_CONFIG_5_1_4 )
776 : {
777 540 : tmp = channelIndex_CICP16[i];
778 : }
779 6545 : else if ( inConfig == IVAS_AUDIO_CONFIG_7_1_4 )
780 : {
781 6545 : tmp = channelIndex_CICP19[i];
782 : }
783 0 : else if ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS )
784 : {
785 0 : tmp = i;
786 : }
787 : else
788 : {
789 0 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Channel configuration not specified!\n\n" );
790 : }
791 :
792 24981 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
793 : {
794 16654 : hHrtf->inv_diffuse_weight[j][i] = hHrtfCrend->inv_diffuse_weight[j][tmp];
795 16654 : hHrtf->num_iterations[i][j] = hHrtfCrend->num_iterations[tmp][j];
796 :
797 16654 : if ( ext_rend_flag == 0 )
798 : {
799 : /* in case of HRTF handle reuse, swap the pointers for correct deallocation at the exit */
800 : #define WMC_TOOL_SKIP
801 16654 : swap( hHrtf->pIndex_frequency_max[i][j], hHrtf->pIndex_frequency_max[tmp][j], const uint16_t * );
802 : MOVE( 3 );
803 16654 : swap( hHrtf->pOut_to_bin_re[i][j], hHrtf->pOut_to_bin_re[tmp][j], const float * );
804 : MOVE( 3 );
805 16654 : swap( hHrtf->pOut_to_bin_im[i][j], hHrtf->pOut_to_bin_im[tmp][j], const float * );
806 : MOVE( 3 );
807 : #undef WMC_TOOL_SKIP
808 : }
809 : else
810 : {
811 0 : hHrtf->pIndex_frequency_max[i][j] = hHrtfCrend->pIndex_frequency_max[tmp][j];
812 0 : hHrtf->pOut_to_bin_re[i][j] = hHrtfCrend->pOut_to_bin_re[tmp][j];
813 0 : hHrtf->pOut_to_bin_im[i][j] = hHrtfCrend->pOut_to_bin_im[tmp][j];
814 : }
815 : }
816 : }
817 : }
818 :
819 7694 : hHrtf->same_inv_diffuse_weight = 1;
820 82361 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
821 : {
822 74667 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
823 : {
824 46948 : if ( hHrtf->inv_diffuse_weight[0][i] != hHrtf->inv_diffuse_weight[1][i] )
825 : {
826 0 : hHrtf->same_inv_diffuse_weight = 0;
827 0 : break;
828 : }
829 : }
830 : }
831 :
832 7694 : pCrend->hHrtfCrend = hHrtf;
833 :
834 7694 : return IVAS_ERR_OK;
835 : }
836 :
837 :
838 : /*-------------------------------------------------------------------------
839 : * ivas_shoebox_data_init()
840 : *
841 : * Initialize shoebox_data_t handle
842 : *------------------------------------------------------------------------*/
843 :
844 816 : static ivas_error ivas_shoebox_data_init(
845 : shoebox_data_t *hShoeboxData /* i/o: shoebox_data_t handle */
846 : )
847 : {
848 : int16_t i;
849 :
850 816 : if ( hShoeboxData == NULL )
851 : {
852 0 : return IVAS_ERR_WRONG_PARAMS;
853 : }
854 :
855 123216 : for ( i = 0; i < 150; i++ )
856 : {
857 122400 : hShoeboxData->data[i] = 0.0f;
858 : }
859 1632 : for ( i = 0; i < 1; i++ )
860 : {
861 816 : hShoeboxData->size[i] = 0;
862 : }
863 :
864 816 : return IVAS_ERR_OK;
865 : }
866 :
867 :
868 : /*-------------------------------------------------------------------------
869 : * ivas_shoebox_output_init()
870 : *
871 : * Initialize shoebox_output_t handle
872 : *------------------------------------------------------------------------*/
873 :
874 204 : static ivas_error ivas_shoebox_output_init(
875 : shoebox_output_t *hShoeboxOutput /* i/o: shoebox_output_t handle */
876 : )
877 : {
878 : ivas_error error;
879 :
880 204 : if ( hShoeboxOutput == NULL )
881 : {
882 0 : return IVAS_ERR_WRONG_PARAMS;
883 : }
884 :
885 204 : hShoeboxOutput->n_sources = 0;
886 204 : hShoeboxOutput->n_ref = 0;
887 :
888 204 : if ( ( error = ivas_shoebox_data_init( &hShoeboxOutput->times ) ) != IVAS_ERR_OK )
889 : {
890 0 : return error;
891 : }
892 :
893 204 : if ( ( error = ivas_shoebox_data_init( &hShoeboxOutput->gains ) ) != IVAS_ERR_OK )
894 : {
895 0 : return error;
896 : }
897 :
898 204 : if ( ( error = ivas_shoebox_data_init( &hShoeboxOutput->az_angle ) ) != IVAS_ERR_OK )
899 : {
900 0 : return error;
901 : }
902 :
903 204 : if ( ( error = ivas_shoebox_data_init( &hShoeboxOutput->el_angle ) ) != IVAS_ERR_OK )
904 : {
905 0 : return error;
906 : }
907 :
908 204 : return IVAS_ERR_OK;
909 : }
910 :
911 :
912 : /*-------------------------------------------------------------------------
913 : * ivas_shoebox_config_init()
914 : *
915 : * Initialize shoebox_config_t handle
916 : *------------------------------------------------------------------------*/
917 :
918 204 : static ivas_error ivas_shoebox_config_init_params(
919 : shoebox_config_t *hShoeboxConfig /* i/o: shoebox_config_t handle */
920 : )
921 : {
922 : int16_t i;
923 :
924 204 : if ( hShoeboxConfig == NULL )
925 : {
926 0 : return IVAS_ERR_WRONG_PARAMS;
927 : }
928 :
929 204 : hShoeboxConfig->room_L = 0.0f;
930 204 : hShoeboxConfig->room_W = 0.0f;
931 204 : hShoeboxConfig->room_H = 0.0f;
932 :
933 1428 : for ( i = 0; i < IVAS_ROOM_ABS_COEFF; i++ )
934 : {
935 1224 : hShoeboxConfig->abs_coeff[i] = 0.0f;
936 : }
937 816 : for ( i = 0; i < 3; i++ )
938 : {
939 612 : hShoeboxConfig->list_orig[i] = 0.0f;
940 : }
941 :
942 204 : return IVAS_ERR_OK;
943 : }
944 :
945 :
946 : /*-------------------------------------------------------------------------
947 : * ivas_shoebox_obj_init()
948 : *
949 : * Initialize shoebox_obj_t handle
950 : *------------------------------------------------------------------------*/
951 :
952 204 : static ivas_error ivas_shoebox_obj_init(
953 : shoebox_obj_t *hShoeboxObj /* i/o: shoebox_obj_t handle */
954 : )
955 : {
956 : int16_t i;
957 : ivas_error error;
958 :
959 204 : if ( hShoeboxObj == NULL )
960 : {
961 0 : return IVAS_ERR_WRONG_PARAMS;
962 : }
963 :
964 204 : hShoeboxObj->isCartesian = 0;
965 204 : hShoeboxObj->isRelative = 0;
966 204 : hShoeboxObj->isZHeight = 0;
967 204 : hShoeboxObj->isRadians = 0;
968 204 : hShoeboxObj->MAX_SOURCES = 0;
969 204 : hShoeboxObj->max_bands = 0;
970 204 : hShoeboxObj->REF_ORDER = 0;
971 :
972 15504 : for ( i = 0; i < 75; i++ )
973 : {
974 15300 : hShoeboxObj->src_pos[i] = 0.0f;
975 : }
976 5304 : for ( i = 0; i < 25; i++ )
977 : {
978 5100 : hShoeboxObj->src_dist[i] = 0.0f;
979 : }
980 816 : for ( i = 0; i < 3; i++ )
981 : {
982 612 : hShoeboxObj->list_pos[i] = 0.0f;
983 : }
984 :
985 204 : hShoeboxObj->nSrc = 0;
986 204 : hShoeboxObj->radius = 0.0f;
987 204 : hShoeboxObj->min_wall_dist = 0.0f;
988 204 : hShoeboxObj->soundspeed = 0.0f;
989 204 : hShoeboxObj->air_coeff = 0.0f;
990 :
991 204 : if ( ( error = ivas_shoebox_config_init_params( &hShoeboxObj->cal ) ) != IVAS_ERR_OK )
992 : {
993 0 : return error;
994 : }
995 :
996 204 : return IVAS_ERR_OK;
997 : }
998 :
999 :
1000 : /*-------------------------------------------------------------------------
1001 : * ivas_er_init_handle()
1002 : *
1003 : * Initialize early reflections handle
1004 : *------------------------------------------------------------------------*/
1005 :
1006 204 : static ivas_error ivas_er_init_handle(
1007 : er_struct_t *reflections /* i/o: early reflections handle */
1008 : )
1009 : {
1010 : int16_t i;
1011 : ivas_error error;
1012 :
1013 204 : if ( reflections == NULL )
1014 : {
1015 0 : return IVAS_ERR_WRONG_PARAMS;
1016 : }
1017 :
1018 204 : reflections->audio_config = IVAS_AUDIO_CONFIG_INVALID;
1019 204 : reflections->use_er = 0;
1020 204 : reflections->is_ready = 0;
1021 204 : reflections->circ_len = 0;
1022 204 : reflections->circ_insert = 0;
1023 204 : reflections->n_total_reflections = 0;
1024 204 : reflections->is_cartesian = 0;
1025 204 : reflections->is_relative = 0;
1026 204 : reflections->max_frame_size = 0;
1027 204 : reflections->output_Fs = 0.0f;
1028 :
1029 15504 : for ( i = 0; i < 75; i++ )
1030 : {
1031 15300 : reflections->source_positions[i] = 0.0f;
1032 : }
1033 816 : for ( i = 0; i < 3; i++ )
1034 : {
1035 612 : reflections->user_origin[i] = 0.0f;
1036 612 : if ( i == 2 )
1037 : {
1038 204 : reflections->user_origin[i] = ER_LIST_HEIGHT;
1039 : }
1040 : }
1041 :
1042 204 : reflections->circ_buffers = NULL;
1043 204 : reflections->closest_ch_idx = NULL;
1044 :
1045 204 : if ( ( error = ivas_shoebox_output_init( &reflections->shoebox_data ) ) != IVAS_ERR_OK )
1046 : {
1047 0 : return error;
1048 : }
1049 :
1050 204 : if ( ( error = ivas_shoebox_obj_init( &reflections->shoebox_lib ) ) != IVAS_ERR_OK )
1051 : {
1052 0 : return error;
1053 : }
1054 :
1055 204 : return IVAS_ERR_OK;
1056 : }
1057 :
1058 :
1059 : /*-------------------------------------------------------------------------
1060 : * ivas_rend_initCrendWrapper()
1061 : *
1062 : * Allocate and initialize crend renderer handle
1063 : *------------------------------------------------------------------------*/
1064 :
1065 7694 : ivas_error ivas_rend_initCrendWrapper(
1066 : CREND_WRAPPER_HANDLE *pCrend,
1067 : const int16_t num_poses )
1068 : {
1069 : int16_t i;
1070 : CREND_HANDLE hCrend;
1071 : int16_t pos_idx;
1072 :
1073 7694 : if ( pCrend == NULL )
1074 : {
1075 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for renderer handle" );
1076 : }
1077 :
1078 7694 : if ( ( *pCrend = (CREND_WRAPPER_HANDLE) malloc( sizeof( CREND_WRAPPER ) ) ) == NULL )
1079 : {
1080 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend Wrapper\n" );
1081 : }
1082 :
1083 7694 : ( *pCrend )->binaural_latency_ns = 0;
1084 7694 : ( *pCrend )->hHrtfCrend = NULL;
1085 :
1086 69246 : for ( pos_idx = 0; pos_idx < MAX_HEAD_ROT_POSES; pos_idx++ )
1087 : {
1088 61552 : ( *pCrend )->hCrend[pos_idx] = NULL;
1089 : }
1090 :
1091 16312 : for ( pos_idx = 0; pos_idx < num_poses; pos_idx++ )
1092 : {
1093 8618 : hCrend = NULL;
1094 8618 : if ( ( hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL )
1095 : {
1096 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for renderer handle" );
1097 : }
1098 :
1099 8618 : hCrend->lfe_delay_line = NULL;
1100 :
1101 146506 : for ( i = 0; i < MAX_INTERN_CHANNELS; i++ )
1102 : {
1103 137888 : hCrend->freq_buffer_re[i] = NULL;
1104 137888 : hCrend->freq_buffer_im[i] = NULL;
1105 : }
1106 :
1107 25854 : for ( i = 0; i < BINAURAL_CHANNELS; i++ )
1108 : {
1109 17236 : hCrend->prev_out_buffer[i] = NULL;
1110 : }
1111 :
1112 8618 : hCrend->freq_buffer_re_diffuse[0] = NULL;
1113 8618 : hCrend->freq_buffer_re_diffuse[1] = NULL;
1114 8618 : hCrend->freq_buffer_im_diffuse[0] = NULL;
1115 8618 : hCrend->freq_buffer_im_diffuse[1] = NULL;
1116 8618 : hCrend->hReverb = NULL;
1117 8618 : hCrend->reflections = NULL;
1118 8618 : hCrend->delay_line_rw_index = 0;
1119 8618 : hCrend->diffuse_delay_line_rw_index = 0;
1120 8618 : hCrend->hTrack = NULL;
1121 8618 : hCrend->m_fYaw = 0;
1122 8618 : hCrend->m_fPitch = 0;
1123 8618 : hCrend->m_fRoll = 0;
1124 :
1125 8618 : ( *pCrend )->hCrend[pos_idx] = hCrend;
1126 : }
1127 :
1128 7694 : return IVAS_ERR_OK;
1129 : }
1130 :
1131 :
1132 : /*-------------------------------------------------------------------------
1133 : * ivas_rend_openMultiBinCrend()
1134 : *
1135 : * Allocate and initialize crend renderer handle
1136 : *------------------------------------------------------------------------*/
1137 :
1138 170 : ivas_error ivas_rend_openMultiBinCrend(
1139 : CREND_WRAPPER_HANDLE *pCrend,
1140 : const AUDIO_CONFIG inConfig,
1141 : const AUDIO_CONFIG outConfig,
1142 : const MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData,
1143 : const int32_t output_Fs )
1144 : {
1145 170 : return ivas_rend_openCrend( pCrend, inConfig, outConfig, NULL /*hRendCfg*/, NULL, NULL /* hHrtfStatistics */, output_Fs, 0, pMultiBinPoseData->num_poses );
1146 : }
1147 :
1148 :
1149 : /*-------------------------------------------------------------------------
1150 : * ivas_rend_openCrend()
1151 : *
1152 : * Allocate and initialize crend renderer handle
1153 : *------------------------------------------------------------------------*/
1154 :
1155 7694 : ivas_error ivas_rend_openCrend(
1156 : CREND_WRAPPER_HANDLE *pCrend,
1157 : const AUDIO_CONFIG inConfig,
1158 : const AUDIO_CONFIG outConfig,
1159 : RENDER_CONFIG_DATA *hRendCfg,
1160 : HRTFS_CREND_HANDLE hHrtfCrend,
1161 : HRTFS_STATISTICS_HANDLE hHrtfStatistics,
1162 : const int32_t output_Fs,
1163 : const int16_t ext_rend_flag,
1164 : const int16_t num_poses )
1165 : {
1166 : int16_t i, subframe_length;
1167 : int32_t max_total_ir_len;
1168 : HRTFS_CREND_HANDLE hHrtf;
1169 : CREND_HANDLE hCrend;
1170 : ivas_error error;
1171 : int16_t pos_idx;
1172 :
1173 7694 : if ( ( error = ivas_rend_initCrendWrapper( pCrend, num_poses ) ) != IVAS_ERR_OK )
1174 : {
1175 0 : return error;
1176 : }
1177 :
1178 7694 : subframe_length = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES;
1179 :
1180 7694 : if ( ( *pCrend )->hHrtfCrend == NULL )
1181 : {
1182 7694 : if ( ( error = ivas_rend_initCrend( *pCrend, inConfig, outConfig, hHrtfCrend, ext_rend_flag, output_Fs ) ) != IVAS_ERR_OK )
1183 : {
1184 0 : return error;
1185 : }
1186 : }
1187 :
1188 16312 : for ( pos_idx = 0; pos_idx < num_poses; pos_idx++ )
1189 : {
1190 8618 : hCrend = ( *pCrend )->hCrend[pos_idx];
1191 8618 : hHrtf = ( *pCrend )->hHrtfCrend;
1192 :
1193 8618 : if ( hHrtf != NULL )
1194 : {
1195 8618 : max_total_ir_len = hHrtf->max_num_iterations * subframe_length;
1196 :
1197 94909 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
1198 : {
1199 86291 : if ( ( hCrend->freq_buffer_re[i] = (float *) malloc( sizeof( float ) * max_total_ir_len ) ) == NULL )
1200 : {
1201 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
1202 : }
1203 86291 : set_zero_l( hCrend->freq_buffer_re[i], max_total_ir_len );
1204 :
1205 86291 : if ( ( hCrend->freq_buffer_im[i] = (float *) malloc( sizeof( float ) * max_total_ir_len ) ) == NULL )
1206 : {
1207 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
1208 : }
1209 86291 : set_zero_l( hCrend->freq_buffer_im[i], max_total_ir_len );
1210 : }
1211 :
1212 25854 : for ( i = 0; i < BINAURAL_CHANNELS; i++ )
1213 : {
1214 17236 : if ( ( hCrend->prev_out_buffer[i] = (float *) malloc( sizeof( float ) * subframe_length ) ) == NULL )
1215 : {
1216 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
1217 : }
1218 17236 : set_zero_l( hCrend->prev_out_buffer[i], subframe_length );
1219 : }
1220 :
1221 8618 : max_total_ir_len = hHrtf->num_iterations_diffuse[0] * subframe_length;
1222 :
1223 8618 : if ( max_total_ir_len > 0 )
1224 : {
1225 4512 : if ( ( hCrend->freq_buffer_re_diffuse[0] = (float *) malloc( sizeof( float ) * max_total_ir_len ) ) == NULL )
1226 : {
1227 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
1228 : }
1229 4512 : if ( hHrtf->same_inv_diffuse_weight == 0 )
1230 : {
1231 0 : if ( ( hCrend->freq_buffer_re_diffuse[1] = (float *) malloc( sizeof( float ) * max_total_ir_len ) ) == NULL )
1232 : {
1233 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
1234 : }
1235 : }
1236 : else
1237 : {
1238 4512 : hCrend->freq_buffer_re_diffuse[1] = NULL;
1239 : }
1240 4512 : set_zero_l( hCrend->freq_buffer_re_diffuse[0], max_total_ir_len );
1241 4512 : if ( hCrend->freq_buffer_re_diffuse[1] != NULL )
1242 : {
1243 0 : set_zero_l( hCrend->freq_buffer_re_diffuse[1], max_total_ir_len );
1244 : }
1245 :
1246 4512 : if ( ( hCrend->freq_buffer_im_diffuse[0] = (float *) malloc( sizeof( float ) * max_total_ir_len ) ) == NULL )
1247 : {
1248 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
1249 : }
1250 4512 : if ( hHrtf->same_inv_diffuse_weight == 0 )
1251 : {
1252 0 : if ( ( hCrend->freq_buffer_im_diffuse[1] = (float *) malloc( sizeof( float ) * max_total_ir_len ) ) == NULL )
1253 : {
1254 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
1255 : }
1256 : }
1257 : else
1258 : {
1259 4512 : hCrend->freq_buffer_im_diffuse[1] = NULL;
1260 : }
1261 4512 : set_zero_l( hCrend->freq_buffer_im_diffuse[0], max_total_ir_len );
1262 4512 : if ( hCrend->freq_buffer_im_diffuse[1] != NULL )
1263 : {
1264 0 : set_zero_l( hCrend->freq_buffer_im_diffuse[1], max_total_ir_len );
1265 : }
1266 : }
1267 : else
1268 : {
1269 4106 : hCrend->freq_buffer_re_diffuse[0] = NULL;
1270 4106 : hCrend->freq_buffer_im_diffuse[0] = NULL;
1271 4106 : hCrend->freq_buffer_re_diffuse[1] = NULL;
1272 4106 : hCrend->freq_buffer_im_diffuse[1] = NULL;
1273 : }
1274 8618 : max_total_ir_len = (int32_t) ( hHrtf->latency_s * output_Fs + 0.5f ) + subframe_length;
1275 8618 : if ( max_total_ir_len > 0 )
1276 : {
1277 8618 : if ( ( hCrend->lfe_delay_line = (float *) malloc( sizeof( float ) * max_total_ir_len ) ) == NULL )
1278 : {
1279 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
1280 : }
1281 8618 : set_zero_l( hCrend->lfe_delay_line, max_total_ir_len );
1282 : }
1283 : else
1284 : {
1285 0 : hCrend->lfe_delay_line = NULL;
1286 : }
1287 :
1288 8618 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
1289 : {
1290 1808 : if ( ( error = ivas_reverb_open( &( hCrend->hReverb ), hHrtfStatistics, hRendCfg, output_Fs ) ) != IVAS_ERR_OK )
1291 : {
1292 0 : return error;
1293 : }
1294 :
1295 1808 : if ( hRendCfg->roomAcoustics.use_er == 1 )
1296 : {
1297 :
1298 : /* Allocate memory for reflections */
1299 204 : hCrend->reflections = (er_struct_t *) malloc( sizeof( er_struct_t ) );
1300 204 : if ( !hCrend->reflections )
1301 : {
1302 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Early Reflections" );
1303 : }
1304 204 : if ( ( error = ivas_er_init_handle( hCrend->reflections ) ) != IVAS_ERR_OK )
1305 : {
1306 0 : return error;
1307 : }
1308 :
1309 204 : hCrend->reflections->use_er = hRendCfg->roomAcoustics.use_er;
1310 204 : hCrend->reflections->lowComplexity = hRendCfg->roomAcoustics.lowComplexity;
1311 :
1312 : /* Set sample rate and frame size */
1313 204 : hCrend->reflections->output_Fs = (float) output_Fs;
1314 204 : hCrend->reflections->max_frame_size = (int16_t) ( output_Fs / FRAMES_PER_SEC );
1315 :
1316 : /* Init Shoebox */
1317 204 : ivas_shoebox_config_init( &hCrend->reflections->shoebox_lib.cal, hRendCfg );
1318 :
1319 : /* Init and compute Reflections */
1320 204 : if ( ( error = ivas_er_init( hCrend->reflections, inConfig ) ) != IVAS_ERR_OK )
1321 : {
1322 0 : return error;
1323 : }
1324 : }
1325 : else
1326 : {
1327 1604 : hCrend->reflections = NULL;
1328 : }
1329 : }
1330 : else
1331 : {
1332 6810 : hCrend->hReverb = NULL;
1333 : }
1334 :
1335 8618 : ( *pCrend )->binaural_latency_ns = (int32_t) ( ( *pCrend )->hHrtfCrend->latency_s * 1000000000.f );
1336 : }
1337 :
1338 8618 : ( *pCrend )->hCrend[pos_idx] = hCrend;
1339 : }
1340 :
1341 7694 : return IVAS_ERR_OK;
1342 : }
1343 :
1344 :
1345 : /*-------------------------------------------------------------------------
1346 : * ivas_rend_closeCrend()
1347 : *
1348 : * Deallocate Crend renderer handle
1349 : *------------------------------------------------------------------------*/
1350 :
1351 328195 : void ivas_rend_closeCrend(
1352 : CREND_WRAPPER_HANDLE *pCrend )
1353 : {
1354 : int16_t i;
1355 : int16_t pos_idx;
1356 : CREND_HANDLE hCrend;
1357 :
1358 328195 : if ( pCrend == NULL || *pCrend == NULL )
1359 : {
1360 320501 : return;
1361 : }
1362 :
1363 7694 : if ( ( *pCrend )->hHrtfCrend != NULL && ( *pCrend )->hHrtfCrend->init_from_rom )
1364 : {
1365 6841 : ivas_hrtf_close( &( *pCrend )->hHrtfCrend );
1366 : }
1367 :
1368 69246 : for ( pos_idx = 0; pos_idx < MAX_HEAD_ROT_POSES; pos_idx++ )
1369 : {
1370 61552 : hCrend = ( *pCrend )->hCrend[pos_idx];
1371 61552 : if ( hCrend != NULL )
1372 : {
1373 146506 : for ( i = 0; i < MAX_INTERN_CHANNELS; i++ )
1374 : {
1375 137888 : if ( hCrend->freq_buffer_re[i] != NULL )
1376 : {
1377 86291 : free( hCrend->freq_buffer_re[i] );
1378 86291 : hCrend->freq_buffer_re[i] = NULL;
1379 : }
1380 137888 : if ( hCrend->freq_buffer_im[i] != NULL )
1381 : {
1382 86291 : free( hCrend->freq_buffer_im[i] );
1383 86291 : hCrend->freq_buffer_im[i] = NULL;
1384 : }
1385 : }
1386 :
1387 25854 : for ( i = 0; i < BINAURAL_CHANNELS; i++ )
1388 : {
1389 17236 : if ( hCrend->prev_out_buffer[i] != NULL )
1390 : {
1391 17236 : free( hCrend->prev_out_buffer[i] );
1392 17236 : hCrend->prev_out_buffer[i] = NULL;
1393 : }
1394 : }
1395 :
1396 8618 : if ( hCrend->lfe_delay_line != NULL )
1397 : {
1398 8618 : free( hCrend->lfe_delay_line );
1399 8618 : hCrend->lfe_delay_line = NULL;
1400 : }
1401 8618 : if ( hCrend->freq_buffer_re_diffuse[0] != NULL )
1402 : {
1403 4512 : free( hCrend->freq_buffer_re_diffuse[0] );
1404 4512 : hCrend->freq_buffer_re_diffuse[0] = NULL;
1405 : }
1406 :
1407 8618 : if ( hCrend->freq_buffer_im_diffuse[0] != NULL )
1408 : {
1409 4512 : free( hCrend->freq_buffer_im_diffuse[0] );
1410 4512 : hCrend->freq_buffer_im_diffuse[0] = NULL;
1411 : }
1412 :
1413 8618 : if ( hCrend->freq_buffer_re_diffuse[1] != NULL )
1414 : {
1415 0 : free( hCrend->freq_buffer_re_diffuse[1] );
1416 0 : hCrend->freq_buffer_re_diffuse[1] = NULL;
1417 : }
1418 :
1419 8618 : if ( hCrend->freq_buffer_im_diffuse[1] != NULL )
1420 : {
1421 0 : free( hCrend->freq_buffer_im_diffuse[1] );
1422 0 : hCrend->freq_buffer_im_diffuse[1] = NULL;
1423 : }
1424 :
1425 8618 : if ( hCrend->hTrack != NULL )
1426 : {
1427 0 : free( hCrend->hTrack );
1428 0 : hCrend->hTrack = NULL;
1429 : }
1430 :
1431 8618 : ivas_reverb_close( &hCrend->hReverb );
1432 :
1433 8618 : if ( hCrend->reflections != NULL )
1434 : {
1435 204 : if ( hCrend->reflections->closest_ch_idx != NULL )
1436 : {
1437 204 : free( hCrend->reflections->closest_ch_idx );
1438 204 : hCrend->reflections->closest_ch_idx = NULL;
1439 : }
1440 :
1441 204 : if ( hCrend->reflections->circ_buffers != NULL )
1442 : {
1443 204 : free( hCrend->reflections->circ_buffers );
1444 204 : hCrend->reflections->circ_buffers = NULL;
1445 : }
1446 :
1447 204 : free( hCrend->reflections );
1448 204 : hCrend->reflections = NULL;
1449 : }
1450 :
1451 8618 : free( hCrend );
1452 8618 : hCrend = NULL;
1453 8618 : ( *pCrend )->hCrend[pos_idx] = hCrend;
1454 : }
1455 : }
1456 :
1457 7694 : free( *pCrend );
1458 7694 : *pCrend = NULL;
1459 :
1460 7694 : return;
1461 : }
1462 :
1463 :
1464 : /*-------------------------------------------------------------------------
1465 : * ivas_rend_closeCldfbRend()
1466 : *
1467 : * Close CLDFB based fastconv binaural renderer memories
1468 : *------------------------------------------------------------------------*/
1469 :
1470 8 : void ivas_rend_closeCldfbRend(
1471 : CLDFB_REND_WRAPPER *pCldfbRend )
1472 : {
1473 8 : if ( pCldfbRend->hCldfbRend->hInputSetup != NULL )
1474 : {
1475 8 : free( pCldfbRend->hCldfbRend->hInputSetup );
1476 8 : pCldfbRend->hCldfbRend->hInputSetup = NULL;
1477 : }
1478 :
1479 8 : ivas_binRenderer_close( &pCldfbRend->hCldfbRend );
1480 8 : ivas_binaural_hrtf_close( &pCldfbRend->hHrtfFastConv );
1481 8 : ivas_HRTF_fastconv_binary_close( &pCldfbRend->hHrtfFastConv );
1482 :
1483 8 : return;
1484 : }
1485 :
1486 :
1487 : /*-----------------------------------------------------------------------------------------*
1488 : * Function ivas_rend_crendConvolver()
1489 : *
1490 : * Convolver block
1491 : *-----------------------------------------------------------------------------------------*/
1492 :
1493 7932254 : static ivas_error ivas_rend_crendConvolver(
1494 : const CREND_WRAPPER *pCrend,
1495 : AUDIO_CONFIG inConfig,
1496 : AUDIO_CONFIG outConfig,
1497 : float *pcm_in[],
1498 : float *pcm_out[],
1499 : const int32_t output_Fs,
1500 : const int16_t i_ts,
1501 : const int16_t pos_idx )
1502 : {
1503 : int16_t i, j, k, m;
1504 : int16_t subframe_length, idx_in;
1505 : int16_t lfe_idx_in;
1506 : int32_t offset, offset_in, offset_diffuse;
1507 : int16_t nchan_in, nchan_out;
1508 : const float *pIn;
1509 : const float *pFreq_filt_re, *pFreq_filt_im;
1510 7932254 : float *pFreq_buf_re = NULL, *pFreq_buf_im = NULL;
1511 7932254 : float *pFreq_buf2_re = NULL, *pFreq_buf2_im = NULL;
1512 : float pOut[2 /*Re,Im*/ * L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
1513 : float tmp_out_re[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES], tmp_out_im[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
1514 : CREND_HANDLE hCrend;
1515 : ivas_error error;
1516 :
1517 7932254 : hCrend = pCrend->hCrend[pos_idx];
1518 :
1519 7932254 : if ( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ) != IVAS_ERR_OK )
1520 : {
1521 0 : return error;
1522 : }
1523 :
1524 7932254 : if ( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ) != IVAS_ERR_OK )
1525 : {
1526 0 : return error;
1527 : }
1528 :
1529 7932254 : subframe_length = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES;
1530 :
1531 7932254 : lfe_idx_in = -1;
1532 7932254 : if ( getAudioConfigType( inConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED )
1533 : {
1534 4631339 : if ( inConfig != IVAS_AUDIO_CONFIG_LS_CUSTOM )
1535 : {
1536 4631339 : lfe_idx_in = LFE_CHANNEL;
1537 : }
1538 : else
1539 : {
1540 0 : assert( 0 && "Custom LS not supported in CRend" );
1541 : }
1542 : }
1543 :
1544 7932254 : offset = hCrend->delay_line_rw_index * subframe_length; /* subframe_length * ( pCrend->hHrtfCrend->max_num_iterations - 1 ); */
1545 7932254 : offset_diffuse = hCrend->diffuse_delay_line_rw_index * subframe_length; /* subframe_length *( pCrend->hHrtfCrend->num_iterations_diffuse[0] - 1 ); */
1546 :
1547 7932254 : if ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 )
1548 : {
1549 4031915 : set_zero( &hCrend->freq_buffer_re_diffuse[0][offset_diffuse], subframe_length );
1550 4031915 : set_zero( &hCrend->freq_buffer_im_diffuse[0][offset_diffuse], subframe_length );
1551 4031915 : if ( pCrend->hHrtfCrend->same_inv_diffuse_weight == 0 )
1552 : {
1553 0 : set_zero( &hCrend->freq_buffer_re_diffuse[1][offset_diffuse], subframe_length );
1554 0 : set_zero( &hCrend->freq_buffer_im_diffuse[1][offset_diffuse], subframe_length );
1555 : }
1556 : }
1557 :
1558 7932254 : if ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 )
1559 : {
1560 4031915 : if ( pCrend->hHrtfCrend->same_inv_diffuse_weight )
1561 : {
1562 4031915 : pFreq_buf_re = &hCrend->freq_buffer_re_diffuse[0][offset_diffuse];
1563 4031915 : pFreq_buf_im = &hCrend->freq_buffer_im_diffuse[0][offset_diffuse];
1564 : }
1565 : else
1566 : {
1567 0 : pFreq_buf_re = &hCrend->freq_buffer_re_diffuse[0][offset_diffuse];
1568 0 : pFreq_buf_im = &hCrend->freq_buffer_im_diffuse[0][offset_diffuse];
1569 0 : pFreq_buf2_re = &hCrend->freq_buffer_re_diffuse[1][offset_diffuse];
1570 0 : pFreq_buf2_im = &hCrend->freq_buffer_im_diffuse[1][offset_diffuse];
1571 : }
1572 : }
1573 :
1574 7932254 : i = 0;
1575 94103561 : for ( idx_in = 0; idx_in < nchan_in; idx_in++ )
1576 : {
1577 86171307 : pIn = &pcm_in[idx_in][i_ts * subframe_length];
1578 86171307 : if ( idx_in != lfe_idx_in )
1579 : {
1580 81539968 : if ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 )
1581 : {
1582 43340441 : if ( pCrend->hHrtfCrend->same_inv_diffuse_weight )
1583 : {
1584 43340441 : pFreq_filt_re = &hCrend->freq_buffer_re[i][offset];
1585 43340441 : pFreq_filt_im = &hCrend->freq_buffer_im[i][offset];
1586 :
1587 3985905274 : for ( k = 0; k < pCrend->hHrtfCrend->index_frequency_max_diffuse; k++ )
1588 : {
1589 3942564833 : pFreq_buf_re[k] += pFreq_filt_re[k] * pCrend->hHrtfCrend->inv_diffuse_weight[0][i];
1590 3942564833 : pFreq_buf_im[k] += pFreq_filt_im[k] * pCrend->hHrtfCrend->inv_diffuse_weight[0][i];
1591 : }
1592 : }
1593 : else
1594 : {
1595 0 : pFreq_filt_re = &hCrend->freq_buffer_re[i][offset];
1596 0 : pFreq_filt_im = &hCrend->freq_buffer_im[i][offset];
1597 :
1598 0 : for ( k = 0; k < pCrend->hHrtfCrend->index_frequency_max_diffuse; k++ )
1599 : {
1600 0 : pFreq_buf_re[k] += pFreq_filt_re[k] * pCrend->hHrtfCrend->inv_diffuse_weight[0][i];
1601 0 : pFreq_buf_im[k] += pFreq_filt_im[k] * pCrend->hHrtfCrend->inv_diffuse_weight[0][i];
1602 0 : pFreq_buf2_re[k] += pFreq_filt_re[k] * pCrend->hHrtfCrend->inv_diffuse_weight[1][i];
1603 0 : pFreq_buf2_im[k] += pFreq_filt_im[k] * pCrend->hHrtfCrend->inv_diffuse_weight[1][i];
1604 : }
1605 : }
1606 : }
1607 :
1608 81539968 : ivas_mdft( pIn, &hCrend->freq_buffer_re[i][offset], &hCrend->freq_buffer_im[i][offset], subframe_length, subframe_length );
1609 81539968 : i++;
1610 : }
1611 : }
1612 :
1613 23796762 : for ( j = 0; j < nchan_out; j++ )
1614 : {
1615 15864508 : set_zero( tmp_out_re, subframe_length );
1616 15864508 : set_zero( tmp_out_im, subframe_length );
1617 :
1618 15864508 : i = 0;
1619 188207122 : for ( idx_in = 0; idx_in < nchan_in; idx_in++ )
1620 : {
1621 172342614 : if ( idx_in != lfe_idx_in )
1622 : {
1623 163079936 : offset = 0;
1624 2174160194 : for ( m = 0; m < pCrend->hHrtfCrend->num_iterations[i][j]; m++ )
1625 : {
1626 2011080258 : offset_in = ( hCrend->delay_line_rw_index + pCrend->hHrtfCrend->max_num_iterations - pCrend->hHrtfCrend->num_iterations[i][j] + m + 1 );
1627 2011080258 : offset_in = offset_in % ( pCrend->hHrtfCrend->max_num_iterations );
1628 2011080258 : offset_in = offset_in * subframe_length;
1629 2011080258 : pFreq_buf_re = &hCrend->freq_buffer_re[i][offset_in];
1630 2011080258 : pFreq_buf_im = &hCrend->freq_buffer_im[i][offset_in];
1631 2011080258 : pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_re[i][j][offset];
1632 2011080258 : pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_im[i][j][offset];
1633 :
1634 >23180*10^7 : for ( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max[i][j][m]; k++ )
1635 : {
1636 >22979*10^7 : tmp_out_re[k] += pFreq_buf_re[k] * pFreq_filt_re[k] - pFreq_buf_im[k] * pFreq_filt_im[k];
1637 >22979*10^7 : tmp_out_im[k] += pFreq_buf_re[k] * pFreq_filt_im[k] + pFreq_buf_im[k] * pFreq_filt_re[k];
1638 : }
1639 2011080258 : offset = offset + k;
1640 : }
1641 163079936 : i++;
1642 : }
1643 : }
1644 :
1645 15864508 : offset = 0;
1646 338417708 : for ( m = 0; m < pCrend->hHrtfCrend->num_iterations_diffuse[j]; m++ )
1647 : {
1648 322553200 : offset_diffuse = ( hCrend->diffuse_delay_line_rw_index + m + 1 );
1649 322553200 : offset_diffuse = offset_diffuse % pCrend->hHrtfCrend->num_iterations_diffuse[0];
1650 322553200 : offset_diffuse = offset_diffuse * subframe_length;
1651 322553200 : if ( pCrend->hHrtfCrend->same_inv_diffuse_weight )
1652 : {
1653 322553200 : pFreq_buf_re = &hCrend->freq_buffer_re_diffuse[0][offset_diffuse];
1654 322553200 : pFreq_buf_im = &hCrend->freq_buffer_im_diffuse[0][offset_diffuse];
1655 : }
1656 : else
1657 : {
1658 0 : pFreq_buf_re = &hCrend->freq_buffer_re_diffuse[j][offset_diffuse];
1659 0 : pFreq_buf_im = &hCrend->freq_buffer_im_diffuse[j][offset_diffuse];
1660 : }
1661 322553200 : pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_re[j][offset];
1662 322553200 : pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_im[j][offset];
1663 :
1664 22492474216 : for ( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max_diffuse[j][m]; k++ )
1665 : {
1666 22169921016 : tmp_out_re[k] += pFreq_buf_re[k] * pFreq_filt_re[k] - pFreq_buf_im[k] * pFreq_filt_im[k];
1667 22169921016 : tmp_out_im[k] += pFreq_buf_re[k] * pFreq_filt_im[k] + pFreq_buf_im[k] * pFreq_filt_re[k];
1668 : }
1669 322553200 : offset = offset + k;
1670 : }
1671 :
1672 15864508 : ivas_imdft( tmp_out_re, tmp_out_im, pOut, subframe_length );
1673 :
1674 15864508 : pFreq_buf_re = &pcm_out[j][i_ts * subframe_length];
1675 2704159228 : for ( k = 0; k < subframe_length; k++ )
1676 : {
1677 2688294720 : pFreq_buf_re[k] = pOut[k] + hCrend->prev_out_buffer[j][k];
1678 2688294720 : hCrend->prev_out_buffer[j][k] = pOut[k + subframe_length];
1679 : }
1680 : }
1681 :
1682 7932254 : hCrend->delay_line_rw_index++;
1683 7932254 : hCrend->delay_line_rw_index = hCrend->delay_line_rw_index % ( pCrend->hHrtfCrend->max_num_iterations );
1684 7932254 : if ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 )
1685 : {
1686 4031915 : hCrend->diffuse_delay_line_rw_index++;
1687 4031915 : hCrend->diffuse_delay_line_rw_index = hCrend->diffuse_delay_line_rw_index % ( pCrend->hHrtfCrend->num_iterations_diffuse[0] );
1688 : }
1689 :
1690 7932254 : return IVAS_ERR_OK;
1691 : }
1692 :
1693 :
1694 : /*-----------------------------------------------------------------------------------------*
1695 : * Function ivas_rend_crendProcessSubframe()
1696 : *
1697 : *
1698 : *-----------------------------------------------------------------------------------------*/
1699 :
1700 4545084 : ivas_error ivas_rend_crendProcessSubframe(
1701 : const CREND_WRAPPER *pCrend, /* i/o: Crend wrapper handle */
1702 : const AUDIO_CONFIG inConfig, /* i : input audio configuration */
1703 : const AUDIO_CONFIG outConfig, /* i : output audio configuration */
1704 : const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : decoder config. structure */
1705 : const COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined orientation handle */
1706 : const IVAS_OUTPUT_SETUP_HANDLE hIntSetup, /* i : internal setup handle */
1707 : const EFAP_HANDLE hEFAPdata, /* i : EFAP handle */
1708 : DECODER_TC_BUFFER_HANDLE hTcBuffer, /* i/o: JBM handle */
1709 : float *input_f[], /* i : transport channels */
1710 : float *output[], /* i/o: input/output audio channels */
1711 : const int16_t n_samples_to_render, /* i : output frame length per channel */
1712 : const int32_t output_Fs, /* i : output sampling rate */
1713 : const int16_t pos_idx /* i : pose index */
1714 : )
1715 : {
1716 : int16_t subframe_idx, subframe_len;
1717 : int16_t nchan_out, nchan_in, ch, first_sf, last_sf, slot_size, slots_to_render;
1718 : float *tc_local[MAX_OUTPUT_CHANNELS];
1719 : float *p_output[BINAURAL_CHANNELS];
1720 : float pcm_tmp[BINAURAL_CHANNELS][L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
1721 : float *p_pcm_tmp[BINAURAL_CHANNELS];
1722 : IVAS_REND_AudioConfigType inConfigType;
1723 : ivas_error error;
1724 : int8_t combinedOrientationEnabled;
1725 : CREND_HANDLE hCrend;
1726 :
1727 4545084 : hCrend = pCrend->hCrend[pos_idx];
1728 :
1729 4545084 : combinedOrientationEnabled = 0;
1730 4545084 : if ( hCombinedOrientationData != NULL )
1731 : {
1732 63148 : if ( hCombinedOrientationData->enableCombinedOrientation[0] != 0 )
1733 : {
1734 63148 : combinedOrientationEnabled = 1;
1735 : }
1736 : }
1737 :
1738 4545084 : push_wmops( "ivas_rend_crendProcessSubframe" );
1739 4545084 : inConfigType = getAudioConfigType( inConfig );
1740 :
1741 4545084 : if ( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ) != IVAS_ERR_OK )
1742 : {
1743 0 : return error;
1744 : }
1745 :
1746 4545084 : if ( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ) != IVAS_ERR_OK )
1747 : {
1748 0 : return error;
1749 : }
1750 :
1751 53607090 : for ( ch = 0; ch < nchan_in; ch++ )
1752 : {
1753 49062006 : tc_local[ch] = input_f[ch];
1754 : }
1755 :
1756 13635252 : for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
1757 : {
1758 9090168 : p_pcm_tmp[ch] = pcm_tmp[ch];
1759 9090168 : p_output[ch] = output[ch];
1760 : }
1761 :
1762 4545084 : if ( hTcBuffer != NULL )
1763 : {
1764 320130 : slot_size = hTcBuffer->n_samples_granularity;
1765 :
1766 : /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
1767 320130 : slots_to_render = min( hTcBuffer->num_slots - hTcBuffer->slots_rendered, n_samples_to_render / slot_size );
1768 320130 : first_sf = hTcBuffer->subframes_rendered;
1769 320130 : last_sf = first_sf;
1770 :
1771 1193447 : while ( slots_to_render > 0 )
1772 : {
1773 873317 : slots_to_render -= hTcBuffer->subframe_nbslots[last_sf];
1774 873317 : last_sf++;
1775 : }
1776 320130 : subframe_len = -1; /* will be set later */
1777 : }
1778 : else
1779 : {
1780 4224954 : subframe_len = (int16_t) ( output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) );
1781 4224954 : first_sf = 0;
1782 4224954 : last_sf = n_samples_to_render / subframe_len;
1783 : }
1784 :
1785 12477338 : for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
1786 : {
1787 7932254 : if ( hTcBuffer != NULL )
1788 : {
1789 873317 : subframe_len = hTcBuffer->subframe_nbslots[subframe_idx] * hTcBuffer->n_samples_granularity;
1790 : }
1791 :
1792 : /* Early Reflections */
1793 7932254 : if ( hCrend->reflections != NULL )
1794 : {
1795 261810 : if ( hCrend->reflections->use_er == 1 && hCrend->reflections->is_ready == 1 )
1796 : {
1797 108900 : if ( ( error = ivas_er_process( hCrend->reflections, subframe_len, 0, tc_local, inConfig ) ) != IVAS_ERR_OK )
1798 : {
1799 0 : return error;
1800 : }
1801 : }
1802 : }
1803 :
1804 7932254 : if ( hDecoderConfig && combinedOrientationEnabled )
1805 : {
1806 : /* Rotation in SHD for:
1807 : MC with elevation (5_1_2 / 5_1_4 / 7_1_4) -> BINAURAL
1808 : SBA SPAR -> BINAURAL or BINAURAL_ROOM
1809 : */
1810 179754 : if ( inConfig == IVAS_AUDIO_CONFIG_FOA || inConfig == IVAS_AUDIO_CONFIG_HOA2 || inConfig == IVAS_AUDIO_CONFIG_HOA3 )
1811 : {
1812 131754 : rotateFrame_shd( hCombinedOrientationData, tc_local, subframe_len, *hIntSetup, 0 );
1813 : }
1814 : /* Rotation in SD for MC -> BINAURAL_ROOM */
1815 48000 : else if ( ( hIntSetup != NULL ) && hIntSetup->is_loudspeaker_setup )
1816 : {
1817 48000 : rotateFrame_sd( hCombinedOrientationData, tc_local, subframe_len, *hIntSetup, hEFAPdata, 0 );
1818 : }
1819 : }
1820 :
1821 7932254 : if ( ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) || ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) )
1822 : {
1823 7932254 : if ( ( error = ivas_rend_crendConvolver( pCrend, inConfig, outConfig, tc_local, p_pcm_tmp, output_Fs, 0, pos_idx ) ) != IVAS_ERR_OK )
1824 : {
1825 0 : return error;
1826 : }
1827 :
1828 7932254 : if ( pCrend->hCrend[0]->hReverb != NULL )
1829 : {
1830 2305047 : if ( ( error = ivas_reverb_process( pCrend->hCrend[pos_idx]->hReverb, inConfig, 1, tc_local, p_pcm_tmp, 0 ) ) != IVAS_ERR_OK )
1831 : {
1832 0 : return error;
1833 : }
1834 : }
1835 :
1836 94103561 : for ( ch = 0; ch < nchan_in; ch++ )
1837 : {
1838 86171307 : tc_local[ch] += subframe_len;
1839 : }
1840 :
1841 7932254 : if ( hTcBuffer != NULL )
1842 : {
1843 873317 : hTcBuffer->slots_rendered += hTcBuffer->subframe_nbslots[subframe_idx];
1844 : }
1845 : }
1846 : else
1847 : {
1848 0 : return IVAS_ERR_INVALID_INPUT_FORMAT;
1849 : }
1850 :
1851 23796762 : for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
1852 : {
1853 : /* move to output */
1854 15864508 : mvr2r( pcm_tmp[ch], p_output[ch], subframe_len );
1855 :
1856 15864508 : p_output[ch] += subframe_len;
1857 : }
1858 :
1859 : /* update combined orientation access index */
1860 7932254 : ivas_combined_orientation_update_index( hCombinedOrientationData, subframe_len );
1861 : }
1862 :
1863 4545084 : if ( hTcBuffer != NULL )
1864 : {
1865 320130 : hTcBuffer->subframes_rendered = last_sf;
1866 : }
1867 :
1868 4545084 : pop_wmops();
1869 :
1870 4545084 : return IVAS_ERR_OK;
1871 : }
1872 :
1873 :
1874 : /*-----------------------------------------------------------------------------------------*
1875 : * Function ivas_rend_crend_ProcessSubframesSplitBin()
1876 : *
1877 : * Process call for IVAS Crend renderer
1878 : *-----------------------------------------------------------------------------------------*/
1879 :
1880 7973 : ivas_error ivas_rend_crendProcessSubframesSplitBin(
1881 : const CREND_WRAPPER *pCrend, /* i/o: Crend wrapper handle */
1882 : const AUDIO_CONFIG inConfig, /* i : input audio configuration */
1883 : const AUDIO_CONFIG outConfig, /* i : output audio configuration */
1884 : const MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData, /* i/o: pose correction data handle */
1885 : const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : decoder config. structure */
1886 : const COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined orientation handle */
1887 : const IVAS_OUTPUT_SETUP_HANDLE hIntSetup, /* i : internal setup handle */
1888 : const EFAP_HANDLE hEFAPdata, /* i : EFAP handle */
1889 : DECODER_TC_BUFFER_HANDLE hTcBuffer, /* i/o: JBM handle */
1890 : float *input_f[], /* i : transport channels */
1891 : float *output[], /* i/o: input/output audio channels */
1892 : const int16_t n_samples_to_render, /* i : output frame length per channel */
1893 : const int32_t output_Fs /* i : output sampling rate */
1894 : )
1895 : {
1896 : int16_t i, j;
1897 : int16_t sf;
1898 : int16_t pos_idx;
1899 : ivas_error error;
1900 : float gain_lfe;
1901 : float tmpLfeBuffer[L_FRAME48k];
1902 : int16_t original_subframes_rendered, original_slots_rendered;
1903 : float tmpInputBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k];
1904 : float *p_tmpInputBuffer[MAX_OUTPUT_CHANNELS];
1905 : float tmpSplitBinBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k];
1906 : COMBINED_ORIENTATION_DATA combinedOrientationDataLocal;
1907 : COMBINED_ORIENTATION_HANDLE pCombinedOrientationDataLocal;
1908 :
1909 : /* save current head positions */
1910 7973 : pCombinedOrientationDataLocal = hCombinedOrientationData;
1911 7973 : combinedOrientationDataLocal = *pCombinedOrientationDataLocal;
1912 7973 : original_subframes_rendered = hTcBuffer->subframes_rendered;
1913 7973 : original_slots_rendered = hTcBuffer->slots_rendered;
1914 :
1915 : /* copy input */
1916 135541 : for ( i = 0; i < hIntSetup->nchan_out_woLFE; ++i )
1917 : {
1918 127568 : mvr2r( input_f[i], tmpInputBuffer[i], n_samples_to_render );
1919 : }
1920 :
1921 135541 : for ( i = 0; i < MAX_OUTPUT_CHANNELS; ++i )
1922 : {
1923 127568 : p_tmpInputBuffer[i] = tmpInputBuffer[i];
1924 : }
1925 :
1926 : /* save current head positions */
1927 7973 : pCombinedOrientationDataLocal = hCombinedOrientationData;
1928 7973 : combinedOrientationDataLocal = *pCombinedOrientationDataLocal;
1929 7973 : if ( pMultiBinPoseData->poseCorrectionMode == ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB )
1930 : {
1931 23032 : for ( sf = 1; sf < hCombinedOrientationData->num_subframes; ++sf )
1932 : {
1933 17274 : combinedOrientationDataLocal.Quaternions[sf] = combinedOrientationDataLocal.Quaternions[0];
1934 69096 : for ( i = 0; i < 3; i++ )
1935 : {
1936 207288 : for ( j = 0; j < 3; j++ )
1937 : {
1938 155466 : combinedOrientationDataLocal.Rmat[sf][i][j] = combinedOrientationDataLocal.Rmat[0][i][j];
1939 : }
1940 : }
1941 : }
1942 : }
1943 :
1944 : /* copy LFE to tmpLfeBuffer and apply gain only once */
1945 7973 : if ( hIntSetup->num_lfe > 0 && hIntSetup->index_lfe[0] != -1 )
1946 : {
1947 0 : mvr2r( output[hIntSetup->index_lfe[0]], tmpLfeBuffer, n_samples_to_render );
1948 0 : gain_lfe = ( ( pCrend != NULL ) && ( pCrend->hHrtfCrend != NULL ) ) ? pCrend->hHrtfCrend->gain_lfe : GAIN_LFE;
1949 0 : v_multc( tmpLfeBuffer, gain_lfe, tmpLfeBuffer, n_samples_to_render );
1950 : }
1951 : else
1952 : {
1953 7973 : set_zero( tmpLfeBuffer, n_samples_to_render );
1954 : }
1955 :
1956 41634 : for ( pos_idx = 0; pos_idx < pMultiBinPoseData->num_poses; ++pos_idx )
1957 : {
1958 : /* Update head positions */
1959 : IVAS_QUATERNION Quaternions_orig[MAX_PARAM_SPATIAL_SUBFRAMES], Quaternions_abs;
1960 168305 : for ( i = 0; i < hCombinedOrientationData->num_subframes; i++ )
1961 : {
1962 134644 : Quaternions_orig[i] = combinedOrientationDataLocal.Quaternions[i];
1963 134644 : Quaternions_abs.w = -3.0f;
1964 134644 : Quat2EulerDegree( combinedOrientationDataLocal.Quaternions[i], &Quaternions_abs.z, &Quaternions_abs.y, &Quaternions_abs.x ); /*order in Quat2Euler seems to be reversed ?*/
1965 :
1966 134644 : Quaternions_abs.x += pMultiBinPoseData->relative_head_poses[pos_idx][0];
1967 134644 : Quaternions_abs.y += pMultiBinPoseData->relative_head_poses[pos_idx][1];
1968 134644 : Quaternions_abs.z += pMultiBinPoseData->relative_head_poses[pos_idx][2];
1969 134644 : combinedOrientationDataLocal.Quaternions[i] = Quaternions_abs;
1970 134644 : QuatToRotMat( combinedOrientationDataLocal.Quaternions[i], combinedOrientationDataLocal.Rmat[i] );
1971 : }
1972 :
1973 33661 : pCombinedOrientationDataLocal = &combinedOrientationDataLocal;
1974 :
1975 33661 : hTcBuffer->subframes_rendered = original_subframes_rendered;
1976 33661 : hTcBuffer->slots_rendered = original_slots_rendered;
1977 :
1978 : /* update combined orientation access index */
1979 33661 : ivas_combined_orientation_set_to_start_index( pCombinedOrientationDataLocal );
1980 :
1981 134644 : for ( i = 0; i < 3; i++ )
1982 : {
1983 100983 : mvr2r( hCombinedOrientationData->Rmat_prev[pos_idx][i], pCombinedOrientationDataLocal->Rmat_prev[0][i], 3 );
1984 : }
1985 :
1986 33661 : if ( ( error = ivas_rend_crendProcessSubframe( pCrend, inConfig, outConfig, hDecoderConfig, pCombinedOrientationDataLocal,
1987 : hIntSetup, hEFAPdata, hTcBuffer, p_tmpInputBuffer, p_tmpInputBuffer, n_samples_to_render, output_Fs, pos_idx ) ) != IVAS_ERR_OK )
1988 : {
1989 0 : return error;
1990 : }
1991 :
1992 134644 : for ( i = 0; i < 3; i++ )
1993 : {
1994 100983 : mvr2r( pCombinedOrientationDataLocal->Rmat_prev[0][i], hCombinedOrientationData->Rmat_prev[pos_idx][i], 3 );
1995 : }
1996 :
1997 100983 : for ( i = 0; i < BINAURAL_CHANNELS; ++i )
1998 : {
1999 : /* accumulate LFE to output */
2000 67322 : v_add( tmpInputBuffer[i], tmpLfeBuffer, tmpInputBuffer[i], n_samples_to_render );
2001 :
2002 : /* move to split bin output buffer */
2003 67322 : mvr2r( tmpInputBuffer[i], tmpSplitBinBuffer[pos_idx * BINAURAL_CHANNELS + i], n_samples_to_render );
2004 : }
2005 :
2006 : /* overwrite rendered channels with input again for next iteration */
2007 572237 : for ( i = 0; i < hIntSetup->nchan_out_woLFE; ++i )
2008 : {
2009 538576 : mvr2r( input_f[i], tmpInputBuffer[i], n_samples_to_render );
2010 : }
2011 :
2012 : /* restore original headrotation data */
2013 168305 : for ( i = 0; i < hCombinedOrientationData->num_subframes; i++ )
2014 : {
2015 134644 : combinedOrientationDataLocal.Quaternions[i] = Quaternions_orig[i];
2016 : }
2017 : }
2018 :
2019 : /* copy split binaural rendered signals to final output */
2020 75295 : for ( i = 0; i < BINAURAL_CHANNELS * pMultiBinPoseData->num_poses; ++i )
2021 : {
2022 67322 : mvr2r( tmpSplitBinBuffer[i], output[i], n_samples_to_render );
2023 : }
2024 :
2025 : /* update main combined orientation access index */
2026 7973 : ivas_combined_orientation_update_index( hCombinedOrientationData, n_samples_to_render );
2027 :
2028 7973 : return IVAS_ERR_OK;
2029 : }
|