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 19343 : ivas_error ivas_Crend_hrtf_init(
57 : HRTFS_CREND_DATA *hHrtf /* i/o: HRTF handle */
58 : )
59 : {
60 : int16_t i, j;
61 :
62 19343 : if ( hHrtf == NULL )
63 : {
64 0 : return IVAS_ERR_WRONG_PARAMS;
65 : }
66 :
67 19343 : hHrtf->latency_s = 0;
68 19343 : hHrtf->gain_lfe = 0;
69 19343 : hHrtf->max_num_ir = 0;
70 19343 : hHrtf->max_num_iterations = 0;
71 19343 : hHrtf->index_frequency_max_diffuse = 0;
72 19343 : hHrtf->same_inv_diffuse_weight = 1;
73 :
74 328831 : for ( i = 0; i < MAX_INTERN_CHANNELS; i++ )
75 : {
76 928464 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
77 : {
78 618976 : hHrtf->inv_diffuse_weight[j][i] = 0;
79 618976 : hHrtf->num_iterations[i][j] = 0;
80 618976 : hHrtf->pIndex_frequency_max[i][j] = NULL;
81 618976 : hHrtf->pOut_to_bin_re[i][j] = NULL;
82 618976 : hHrtf->pOut_to_bin_im[i][j] = NULL;
83 618976 : hHrtf->pOut_to_bin_re_dyn[i][j] = NULL;
84 618976 : hHrtf->pOut_to_bin_im_dyn[i][j] = NULL;
85 618976 : hHrtf->pIndex_frequency_max_dyn[i][j] = NULL;
86 : }
87 : }
88 :
89 58029 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
90 : {
91 38686 : hHrtf->num_iterations_diffuse[j] = 0;
92 38686 : hHrtf->pIndex_frequency_max_diffuse[j] = NULL;
93 38686 : hHrtf->pOut_to_bin_diffuse_re[j] = NULL;
94 38686 : hHrtf->pOut_to_bin_diffuse_im[j] = NULL;
95 38686 : hHrtf->pIndex_frequency_max_diffuse_dyn[j] = NULL;
96 38686 : hHrtf->pOut_to_bin_diffuse_re_dyn[j] = NULL;
97 38686 : hHrtf->pOut_to_bin_diffuse_im_dyn[j] = NULL;
98 : }
99 :
100 19343 : hHrtf->init_from_rom = 1;
101 :
102 19343 : return IVAS_ERR_OK;
103 : }
104 :
105 :
106 : /*-------------------------------------------------------------------------
107 : * ivas_hrtf_open()
108 : *
109 : * Open hHrtf handle for Crend renderer
110 : *------------------------------------------------------------------------*/
111 :
112 17055 : 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 17055 : if ( *hHrtf_out == NULL )
120 : {
121 17055 : 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 17055 : if ( ( error = ivas_Crend_hrtf_init( hHrtf ) ) != IVAS_ERR_OK )
127 : {
128 0 : return error;
129 : }
130 :
131 17055 : *hHrtf_out = hHrtf;
132 : }
133 : else
134 : {
135 0 : return IVAS_ERR_INTERNAL;
136 : }
137 :
138 17055 : return IVAS_ERR_OK;
139 : }
140 :
141 :
142 : /*-------------------------------------------------------------------------
143 : * ivas_hrtf_close()
144 : *
145 : * Close hHrtf handle
146 : *------------------------------------------------------------------------*/
147 :
148 17055 : static void ivas_hrtf_close(
149 : HRTFS_CREND_HANDLE *hHrtf /* i/o: Crend HRTF handle */
150 : )
151 : {
152 17055 : if ( hHrtf == NULL || *hHrtf == NULL )
153 : {
154 0 : return;
155 : }
156 :
157 17055 : free( *hHrtf );
158 17055 : *hHrtf = NULL;
159 :
160 17055 : return;
161 : }
162 :
163 :
164 : /*-------------------------------------------------------------------------
165 : * ivas_rend_initCrend()
166 : *
167 : * Allocate and initialize crend renderer handle
168 : *------------------------------------------------------------------------*/
169 :
170 19343 : 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 19343 : inConfigType = getAudioConfigType( inConfig );
185 19343 : hHrtf = pCrend->hHrtfCrend;
186 :
187 : /* Do all error checks up front so that the nested if later is easier */
188 19343 : 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 19343 : 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 19343 : if ( hHrtf == NULL )
199 : {
200 19343 : if ( hHrtfCrend != NULL && ext_rend_flag == 0 )
201 : {
202 : /* HRTF set loaded from binary file */
203 2288 : hHrtf = hHrtfCrend;
204 2288 : 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 17055 : if ( ( error = ivas_hrtf_open( &hHrtf ) ) != IVAS_ERR_OK )
210 : {
211 0 : return error;
212 : }
213 :
214 17055 : hHrtf->init_from_rom = 1;
215 17055 : if ( hHrtfCrend != NULL )
216 : {
217 0 : hHrtf->init_from_rom = 0;
218 : }
219 : }
220 : }
221 :
222 19343 : if ( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ) != IVAS_ERR_OK )
223 : {
224 0 : return error;
225 : }
226 19343 : hHrtf->max_num_ir = nchan_in;
227 :
228 19343 : if ( hHrtf->max_num_ir <= 0 )
229 : {
230 0 : return IVAS_ERR_INTERNAL_FATAL;
231 : }
232 :
233 19343 : if ( hHrtf->init_from_rom )
234 : {
235 17055 : if ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED )
236 : {
237 14075 : hHrtf->max_num_ir -= 1; /* subtract LFE */
238 14075 : hHrtf->gain_lfe = GAIN_LFE;
239 :
240 14075 : if ( output_Fs == 48000 )
241 : {
242 6501 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
243 : {
244 5010 : hHrtf->latency_s = CRendBin_Combined_BRIR_latency_s;
245 5010 : hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_48kHz;
246 5010 : hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_48kHz;
247 : }
248 : else
249 : {
250 1491 : hHrtf->latency_s = CRendBin_Combined_HRIR_latency_s;
251 1491 : hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_48kHz;
252 1491 : hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_48kHz;
253 : }
254 :
255 19503 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
256 : {
257 13002 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
258 : {
259 10020 : hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_48kHz[j];
260 10020 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_48kHz[j];
261 10020 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_48kHz[j];
262 10020 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_48kHz[j];
263 : }
264 : else
265 : {
266 2982 : hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_48kHz[j];
267 2982 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_48kHz[j];
268 2982 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_48kHz[j];
269 2982 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_48kHz[j];
270 : }
271 : }
272 : }
273 7574 : else if ( output_Fs == 32000 )
274 : {
275 3407 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
276 : {
277 3044 : hHrtf->latency_s = CRendBin_Combined_BRIR_latency_s;
278 3044 : hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_32kHz;
279 3044 : hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_32kHz;
280 : }
281 : else
282 : {
283 363 : hHrtf->latency_s = CRendBin_Combined_HRIR_latency_s;
284 363 : hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_32kHz;
285 363 : hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_32kHz;
286 : }
287 :
288 10221 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
289 : {
290 6814 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
291 : {
292 6088 : hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_32kHz[j];
293 6088 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_32kHz[j];
294 6088 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_32kHz[j];
295 6088 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_32kHz[j];
296 : }
297 : else
298 : {
299 726 : hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_32kHz[j];
300 726 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_32kHz[j];
301 726 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_32kHz[j];
302 726 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_32kHz[j];
303 : }
304 : }
305 : }
306 4167 : else if ( output_Fs == 16000 )
307 : {
308 4167 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
309 : {
310 2094 : hHrtf->latency_s = CRendBin_Combined_BRIR_latency_s;
311 :
312 2094 : hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_16kHz;
313 2094 : hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_16kHz;
314 : }
315 : else
316 : {
317 2073 : hHrtf->latency_s = CRendBin_Combined_HRIR_latency_s;
318 2073 : hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_16kHz;
319 2073 : hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_16kHz;
320 : }
321 :
322 12501 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
323 : {
324 8334 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
325 : {
326 4188 : hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_16kHz[j];
327 4188 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_16kHz[j];
328 4188 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_16kHz[j];
329 4188 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_16kHz[j];
330 : }
331 : else
332 : {
333 4146 : hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_16kHz[j];
334 4146 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_16kHz[j];
335 4146 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_16kHz[j];
336 4146 : 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 135008 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
346 : {
347 120933 : if ( inConfig == IVAS_AUDIO_CONFIG_5_1 )
348 : {
349 23680 : tmp = channelIndex_CICP6[i];
350 : }
351 97253 : else if ( inConfig == IVAS_AUDIO_CONFIG_7_1 )
352 : {
353 1848 : tmp = channelIndex_CICP12[i];
354 : }
355 95405 : else if ( inConfig == IVAS_AUDIO_CONFIG_5_1_2 )
356 : {
357 6636 : tmp = channelIndex_CICP14[i];
358 : }
359 88769 : else if ( inConfig == IVAS_AUDIO_CONFIG_5_1_4 )
360 : {
361 2826 : tmp = channelIndex_CICP16[i];
362 : }
363 85943 : else if ( inConfig == IVAS_AUDIO_CONFIG_7_1_4 )
364 : {
365 85943 : 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 120933 : if ( output_Fs == 48000 )
373 : {
374 160173 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
375 : {
376 106782 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
377 : {
378 88328 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_Combined_BRIR_inv_diffuse_weight_48kHz[j][tmp];
379 88328 : hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_48kHz[tmp][j];
380 88328 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_48kHz[tmp][j];
381 88328 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_Combined_BRIR_coeff_re_48kHz[tmp][j];
382 88328 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_Combined_BRIR_coeff_im_48kHz[tmp][j];
383 : }
384 : else
385 : {
386 18454 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_Combined_HRIR_inv_diffuse_weight_48kHz[j][tmp];
387 18454 : hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_48kHz[tmp][j];
388 18454 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_48kHz[tmp][j];
389 18454 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_Combined_HRIR_coeff_re_48kHz[tmp][j];
390 18454 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_Combined_HRIR_coeff_im_48kHz[tmp][j];
391 : }
392 : }
393 : }
394 67542 : else if ( output_Fs == 32000 )
395 : {
396 108021 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
397 : {
398 72014 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
399 : {
400 66112 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_Combined_BRIR_inv_diffuse_weight_32kHz[j][tmp];
401 66112 : hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_32kHz[tmp][j];
402 66112 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_32kHz[tmp][j];
403 66112 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_Combined_BRIR_coeff_re_32kHz[tmp][j];
404 66112 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_Combined_BRIR_coeff_im_32kHz[tmp][j];
405 : }
406 : else
407 : {
408 5902 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_Combined_HRIR_inv_diffuse_weight_32kHz[j][tmp];
409 5902 : hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_32kHz[tmp][j];
410 5902 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_32kHz[tmp][j];
411 5902 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_Combined_HRIR_coeff_re_32kHz[tmp][j];
412 5902 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_Combined_HRIR_coeff_im_32kHz[tmp][j];
413 : }
414 : }
415 : }
416 31535 : else if ( output_Fs == 16000 )
417 : {
418 94605 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
419 : {
420 63070 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
421 : {
422 40068 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_Combined_BRIR_inv_diffuse_weight_16kHz[j][tmp];
423 40068 : hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_16kHz[tmp][j];
424 40068 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_16kHz[tmp][j];
425 40068 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_Combined_BRIR_coeff_re_16kHz[tmp][j];
426 40068 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_Combined_BRIR_coeff_im_16kHz[tmp][j];
427 : }
428 : else
429 : {
430 23002 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_Combined_HRIR_inv_diffuse_weight_16kHz[j][tmp];
431 23002 : hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_16kHz[tmp][j];
432 23002 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_16kHz[tmp][j];
433 23002 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_Combined_HRIR_coeff_re_16kHz[tmp][j];
434 23002 : 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 2980 : else if ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS )
445 : {
446 2980 : if ( inConfig == IVAS_AUDIO_CONFIG_HOA3 )
447 : {
448 1484 : if ( output_Fs == 48000 )
449 : {
450 1044 : hHrtf->latency_s = CRendBin_HOA3_HRIR_latency_s;
451 1044 : hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_48kHz;
452 1044 : hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_48kHz;
453 :
454 17748 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
455 : {
456 50112 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
457 : {
458 33408 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_48kHz[j][i];
459 33408 : hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_48kHz[i][j];
460 33408 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_48kHz[i][j];
461 33408 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_HOA3_HRIR_coeff_re_48kHz[i][j];
462 33408 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_HOA3_HRIR_coeff_im_48kHz[i][j];
463 : }
464 : }
465 3132 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
466 : {
467 2088 : hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_48kHz[j];
468 2088 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_48kHz[j];
469 2088 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_48kHz[j];
470 2088 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_48kHz[j];
471 : }
472 : }
473 440 : else if ( output_Fs == 32000 )
474 : {
475 219 : hHrtf->latency_s = CRendBin_HOA3_HRIR_latency_s;
476 219 : hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_32kHz;
477 219 : hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_32kHz;
478 :
479 3723 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
480 : {
481 10512 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
482 : {
483 7008 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_32kHz[j][i];
484 7008 : hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_32kHz[i][j];
485 7008 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_32kHz[i][j];
486 7008 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_HOA3_HRIR_coeff_re_32kHz[i][j];
487 7008 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_HOA3_HRIR_coeff_im_32kHz[i][j];
488 : }
489 : }
490 :
491 657 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
492 : {
493 438 : hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_32kHz[j];
494 438 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_32kHz[j];
495 438 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_32kHz[j];
496 438 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_32kHz[j];
497 : }
498 : }
499 221 : else if ( output_Fs == 16000 )
500 : {
501 221 : hHrtf->latency_s = CRendBin_HOA3_HRIR_latency_s;
502 221 : hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_16kHz;
503 221 : hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_16kHz;
504 :
505 3757 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
506 : {
507 10608 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
508 : {
509 7072 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_16kHz[j][i];
510 7072 : hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_16kHz[i][j];
511 7072 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_16kHz[i][j];
512 7072 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_HOA3_HRIR_coeff_re_16kHz[i][j];
513 7072 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_HOA3_HRIR_coeff_im_16kHz[i][j];
514 : }
515 : }
516 :
517 663 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
518 : {
519 442 : hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_16kHz[j];
520 442 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_16kHz[j];
521 442 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_16kHz[j];
522 442 : 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 1496 : else if ( inConfig == IVAS_AUDIO_CONFIG_HOA2 )
531 : {
532 706 : if ( output_Fs == 48000 )
533 : {
534 278 : hHrtf->latency_s = CRendBin_HOA2_HRIR_latency_s;
535 278 : hHrtf->max_num_iterations = CRendBin_HOA2_HRIR_max_num_iterations_48kHz;
536 278 : hHrtf->index_frequency_max_diffuse = CRendBin_HOA2_HRIR_index_frequency_max_diffuse_48kHz;
537 :
538 2780 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
539 : {
540 7506 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
541 : {
542 5004 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_48kHz[j][i];
543 5004 : hHrtf->num_iterations[i][j] = CRendBin_HOA2_HRIR_num_iterations_48kHz[i][j];
544 5004 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_48kHz[i][j];
545 5004 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_HOA2_HRIR_coeff_re_48kHz[i][j];
546 5004 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_HOA2_HRIR_coeff_im_48kHz[i][j];
547 : }
548 : }
549 834 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
550 : {
551 556 : hHrtf->num_iterations_diffuse[j] = CRendBin_HOA2_HRIR_num_iterations_diffuse_48kHz[j];
552 556 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_48kHz[j];
553 556 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_48kHz[j];
554 556 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_48kHz[j];
555 : }
556 : }
557 428 : else if ( output_Fs == 32000 )
558 : {
559 214 : hHrtf->latency_s = CRendBin_HOA2_HRIR_latency_s;
560 214 : hHrtf->max_num_iterations = CRendBin_HOA2_HRIR_max_num_iterations_32kHz;
561 214 : hHrtf->index_frequency_max_diffuse = CRendBin_HOA2_HRIR_index_frequency_max_diffuse_32kHz;
562 :
563 2140 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
564 : {
565 5778 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
566 : {
567 3852 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_32kHz[j][i];
568 3852 : hHrtf->num_iterations[i][j] = CRendBin_HOA2_HRIR_num_iterations_32kHz[i][j];
569 3852 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_32kHz[i][j];
570 3852 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_HOA2_HRIR_coeff_re_32kHz[i][j];
571 3852 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_HOA2_HRIR_coeff_im_32kHz[i][j];
572 : }
573 : }
574 :
575 642 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
576 : {
577 428 : hHrtf->num_iterations_diffuse[j] = CRendBin_HOA2_HRIR_num_iterations_diffuse_32kHz[j];
578 428 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_32kHz[j];
579 428 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_32kHz[j];
580 428 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_32kHz[j];
581 : }
582 : }
583 214 : else if ( output_Fs == 16000 )
584 : {
585 214 : hHrtf->latency_s = CRendBin_HOA2_HRIR_latency_s;
586 214 : hHrtf->max_num_iterations = CRendBin_HOA2_HRIR_max_num_iterations_16kHz;
587 214 : hHrtf->index_frequency_max_diffuse = CRendBin_HOA2_HRIR_index_frequency_max_diffuse_16kHz;
588 :
589 2140 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
590 : {
591 5778 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
592 : {
593 3852 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_16kHz[j][i];
594 3852 : hHrtf->num_iterations[i][j] = CRendBin_HOA2_HRIR_num_iterations_16kHz[i][j];
595 3852 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_16kHz[i][j];
596 3852 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_HOA2_HRIR_coeff_re_16kHz[i][j];
597 3852 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_HOA2_HRIR_coeff_im_16kHz[i][j];
598 : }
599 : }
600 :
601 642 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
602 : {
603 428 : hHrtf->num_iterations_diffuse[j] = CRendBin_HOA2_HRIR_num_iterations_diffuse_16kHz[j];
604 428 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_16kHz[j];
605 428 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_16kHz[j];
606 428 : 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 790 : else if ( inConfig == IVAS_AUDIO_CONFIG_FOA )
615 : {
616 790 : if ( output_Fs == 48000 )
617 : {
618 353 : hHrtf->latency_s = CRendBin_FOA_HRIR_latency_s;
619 353 : hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_48kHz;
620 353 : hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_48kHz;
621 :
622 1765 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
623 : {
624 4236 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
625 : {
626 2824 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_FOA_HRIR_inv_diffuse_weight_48kHz[j][i];
627 2824 : hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_48kHz[i][j];
628 2824 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_48kHz[i][j];
629 2824 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_FOA_HRIR_coeff_re_48kHz[i][j];
630 2824 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_FOA_HRIR_coeff_im_48kHz[i][j];
631 : }
632 : }
633 1059 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
634 : {
635 706 : hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_48kHz[j];
636 706 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_48kHz[j];
637 706 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_48kHz[j];
638 706 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_48kHz[j];
639 : }
640 : }
641 437 : else if ( output_Fs == 32000 )
642 : {
643 219 : hHrtf->latency_s = CRendBin_FOA_HRIR_latency_s;
644 219 : hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_32kHz;
645 219 : hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_32kHz;
646 :
647 1095 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
648 : {
649 2628 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
650 : {
651 1752 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_FOA_HRIR_inv_diffuse_weight_32kHz[j][i];
652 1752 : hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_32kHz[i][j];
653 1752 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_32kHz[i][j];
654 1752 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_FOA_HRIR_coeff_re_32kHz[i][j];
655 1752 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_FOA_HRIR_coeff_im_32kHz[i][j];
656 : }
657 : }
658 :
659 657 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
660 : {
661 438 : hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_32kHz[j];
662 438 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_32kHz[j];
663 438 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_32kHz[j];
664 438 : hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_32kHz[j];
665 : }
666 : }
667 218 : else if ( output_Fs == 16000 )
668 : {
669 218 : hHrtf->latency_s = CRendBin_FOA_HRIR_latency_s;
670 218 : hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_16kHz;
671 218 : hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_16kHz;
672 :
673 1090 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
674 : {
675 2616 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
676 : {
677 1744 : hHrtf->inv_diffuse_weight[j][i] = CRendBin_FOA_HRIR_inv_diffuse_weight_16kHz[j][i];
678 1744 : hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_16kHz[i][j];
679 1744 : hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_16kHz[i][j];
680 1744 : hHrtf->pOut_to_bin_re[i][j] = CRendBin_FOA_HRIR_coeff_re_16kHz[i][j];
681 1744 : hHrtf->pOut_to_bin_im[i][j] = CRendBin_FOA_HRIR_coeff_im_16kHz[i][j];
682 : }
683 : }
684 :
685 654 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
686 : {
687 436 : hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_16kHz[j];
688 436 : hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_16kHz[j];
689 436 : hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_16kHz[j];
690 436 : 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 2288 : if ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED )
711 : {
712 2288 : hHrtf->max_num_ir -= 1; /* subtract LFE */
713 2288 : hHrtf->gain_lfe = GAIN_LFE;
714 : }
715 :
716 2288 : 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 2288 : 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 26384 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
755 : {
756 24096 : if ( inConfig == IVAS_AUDIO_CONFIG_5_1 )
757 : {
758 360 : tmp = channelIndex_CICP6[i];
759 : }
760 23736 : 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 23295 : else if ( inConfig == IVAS_AUDIO_CONFIG_5_1_2 )
772 : {
773 441 : tmp = channelIndex_CICP14[i];
774 : }
775 22854 : else if ( inConfig == IVAS_AUDIO_CONFIG_5_1_4 )
776 : {
777 612 : tmp = channelIndex_CICP16[i];
778 : }
779 22242 : else if ( inConfig == IVAS_AUDIO_CONFIG_7_1_4 )
780 : {
781 22242 : 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 72288 : for ( j = 0; j < BINAURAL_CHANNELS; j++ )
793 : {
794 48192 : hHrtf->inv_diffuse_weight[j][i] = hHrtfCrend->inv_diffuse_weight[j][tmp];
795 48192 : hHrtf->num_iterations[i][j] = hHrtfCrend->num_iterations[tmp][j];
796 :
797 48192 : 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 48192 : swap( hHrtf->pIndex_frequency_max[i][j], hHrtf->pIndex_frequency_max[tmp][j], const uint16_t * );
802 : MOVE( 3 );
803 48192 : swap( hHrtf->pOut_to_bin_re[i][j], hHrtf->pOut_to_bin_re[tmp][j], const float * );
804 : MOVE( 3 );
805 48192 : 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 19343 : hHrtf->same_inv_diffuse_weight = 1;
820 197630 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
821 : {
822 178287 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
823 : {
824 108706 : 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 19343 : pCrend->hHrtfCrend = hHrtf;
833 :
834 19343 : return IVAS_ERR_OK;
835 : }
836 :
837 :
838 : /*-------------------------------------------------------------------------
839 : * ivas_shoebox_data_init()
840 : *
841 : * Initialize shoebox_data_t handle
842 : *------------------------------------------------------------------------*/
843 :
844 1304 : 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 1304 : if ( hShoeboxData == NULL )
851 : {
852 0 : return IVAS_ERR_WRONG_PARAMS;
853 : }
854 :
855 196904 : for ( i = 0; i < 150; i++ )
856 : {
857 195600 : hShoeboxData->data[i] = 0.0f;
858 : }
859 2608 : for ( i = 0; i < 1; i++ )
860 : {
861 1304 : hShoeboxData->size[i] = 0;
862 : }
863 :
864 1304 : return IVAS_ERR_OK;
865 : }
866 :
867 :
868 : /*-------------------------------------------------------------------------
869 : * ivas_shoebox_output_init()
870 : *
871 : * Initialize shoebox_output_t handle
872 : *------------------------------------------------------------------------*/
873 :
874 326 : 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 326 : if ( hShoeboxOutput == NULL )
881 : {
882 0 : return IVAS_ERR_WRONG_PARAMS;
883 : }
884 :
885 326 : hShoeboxOutput->n_sources = 0;
886 326 : hShoeboxOutput->n_ref = 0;
887 :
888 326 : if ( ( error = ivas_shoebox_data_init( &hShoeboxOutput->times ) ) != IVAS_ERR_OK )
889 : {
890 0 : return error;
891 : }
892 :
893 326 : if ( ( error = ivas_shoebox_data_init( &hShoeboxOutput->gains ) ) != IVAS_ERR_OK )
894 : {
895 0 : return error;
896 : }
897 :
898 326 : if ( ( error = ivas_shoebox_data_init( &hShoeboxOutput->az_angle ) ) != IVAS_ERR_OK )
899 : {
900 0 : return error;
901 : }
902 :
903 326 : if ( ( error = ivas_shoebox_data_init( &hShoeboxOutput->el_angle ) ) != IVAS_ERR_OK )
904 : {
905 0 : return error;
906 : }
907 :
908 326 : return IVAS_ERR_OK;
909 : }
910 :
911 :
912 : /*-------------------------------------------------------------------------
913 : * ivas_shoebox_config_init()
914 : *
915 : * Initialize shoebox_config_t handle
916 : *------------------------------------------------------------------------*/
917 :
918 326 : 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 326 : if ( hShoeboxConfig == NULL )
925 : {
926 0 : return IVAS_ERR_WRONG_PARAMS;
927 : }
928 :
929 326 : hShoeboxConfig->room_L = 0.0f;
930 326 : hShoeboxConfig->room_W = 0.0f;
931 326 : hShoeboxConfig->room_H = 0.0f;
932 :
933 2282 : for ( i = 0; i < IVAS_ROOM_ABS_COEFF; i++ )
934 : {
935 1956 : hShoeboxConfig->abs_coeff[i] = 0.0f;
936 : }
937 1304 : for ( i = 0; i < 3; i++ )
938 : {
939 978 : hShoeboxConfig->list_orig[i] = 0.0f;
940 : }
941 :
942 326 : return IVAS_ERR_OK;
943 : }
944 :
945 :
946 : /*-------------------------------------------------------------------------
947 : * ivas_shoebox_obj_init()
948 : *
949 : * Initialize shoebox_obj_t handle
950 : *------------------------------------------------------------------------*/
951 :
952 326 : 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 326 : if ( hShoeboxObj == NULL )
960 : {
961 0 : return IVAS_ERR_WRONG_PARAMS;
962 : }
963 :
964 326 : hShoeboxObj->isCartesian = 0;
965 326 : hShoeboxObj->isRelative = 0;
966 326 : hShoeboxObj->isZHeight = 0;
967 326 : hShoeboxObj->isRadians = 0;
968 326 : hShoeboxObj->MAX_SOURCES = 0;
969 326 : hShoeboxObj->max_bands = 0;
970 326 : hShoeboxObj->REF_ORDER = 0;
971 :
972 24776 : for ( i = 0; i < 75; i++ )
973 : {
974 24450 : hShoeboxObj->src_pos[i] = 0.0f;
975 : }
976 8476 : for ( i = 0; i < 25; i++ )
977 : {
978 8150 : hShoeboxObj->src_dist[i] = 0.0f;
979 : }
980 1304 : for ( i = 0; i < 3; i++ )
981 : {
982 978 : hShoeboxObj->list_pos[i] = 0.0f;
983 : }
984 :
985 326 : hShoeboxObj->nSrc = 0;
986 326 : hShoeboxObj->radius = 0.0f;
987 326 : hShoeboxObj->min_wall_dist = 0.0f;
988 326 : hShoeboxObj->soundspeed = 0.0f;
989 326 : hShoeboxObj->air_coeff = 0.0f;
990 :
991 326 : if ( ( error = ivas_shoebox_config_init_params( &hShoeboxObj->cal ) ) != IVAS_ERR_OK )
992 : {
993 0 : return error;
994 : }
995 :
996 326 : return IVAS_ERR_OK;
997 : }
998 :
999 :
1000 : /*-------------------------------------------------------------------------
1001 : * ivas_er_init_handle()
1002 : *
1003 : * Initialize early reflections handle
1004 : *------------------------------------------------------------------------*/
1005 :
1006 326 : 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 326 : if ( reflections == NULL )
1014 : {
1015 0 : return IVAS_ERR_WRONG_PARAMS;
1016 : }
1017 :
1018 326 : reflections->audio_config = IVAS_AUDIO_CONFIG_INVALID;
1019 326 : reflections->use_er = 0;
1020 326 : reflections->is_ready = 0;
1021 326 : reflections->circ_len = 0;
1022 326 : reflections->circ_insert = 0;
1023 326 : reflections->n_total_reflections = 0;
1024 326 : reflections->is_cartesian = 0;
1025 326 : reflections->is_relative = 0;
1026 326 : reflections->max_frame_size = 0;
1027 326 : reflections->output_Fs = 0.0f;
1028 :
1029 24776 : for ( i = 0; i < 75; i++ )
1030 : {
1031 24450 : reflections->source_positions[i] = 0.0f;
1032 : }
1033 1304 : for ( i = 0; i < 3; i++ )
1034 : {
1035 978 : reflections->user_origin[i] = 0.0f;
1036 978 : if ( i == 2 )
1037 : {
1038 326 : reflections->user_origin[i] = ER_LIST_HEIGHT;
1039 : }
1040 : }
1041 :
1042 326 : reflections->circ_buffers = NULL;
1043 326 : reflections->closest_ch_idx = NULL;
1044 :
1045 326 : if ( ( error = ivas_shoebox_output_init( &reflections->shoebox_data ) ) != IVAS_ERR_OK )
1046 : {
1047 0 : return error;
1048 : }
1049 :
1050 326 : if ( ( error = ivas_shoebox_obj_init( &reflections->shoebox_lib ) ) != IVAS_ERR_OK )
1051 : {
1052 0 : return error;
1053 : }
1054 :
1055 326 : return IVAS_ERR_OK;
1056 : }
1057 :
1058 :
1059 : /*-------------------------------------------------------------------------
1060 : * ivas_rend_initCrendWrapper()
1061 : *
1062 : * Allocate and initialize crend renderer handle
1063 : *------------------------------------------------------------------------*/
1064 :
1065 19343 : 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 19343 : if ( pCrend == NULL )
1074 : {
1075 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for renderer handle" );
1076 : }
1077 :
1078 19343 : 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 19343 : ( *pCrend )->binaural_latency_ns = 0;
1084 19343 : ( *pCrend )->hHrtfCrend = NULL;
1085 :
1086 174087 : for ( pos_idx = 0; pos_idx < MAX_HEAD_ROT_POSES; pos_idx++ )
1087 : {
1088 154744 : ( *pCrend )->hCrend[pos_idx] = NULL;
1089 : }
1090 :
1091 39726 : for ( pos_idx = 0; pos_idx < num_poses; pos_idx++ )
1092 : {
1093 20383 : hCrend = NULL;
1094 20383 : 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 20383 : hCrend->lfe_delay_line = NULL;
1100 :
1101 346511 : for ( i = 0; i < MAX_INTERN_CHANNELS; i++ )
1102 : {
1103 326128 : hCrend->freq_buffer_re[i] = NULL;
1104 326128 : hCrend->freq_buffer_im[i] = NULL;
1105 : }
1106 :
1107 61149 : for ( i = 0; i < BINAURAL_CHANNELS; i++ )
1108 : {
1109 40766 : hCrend->prev_out_buffer[i] = NULL;
1110 : }
1111 :
1112 20383 : hCrend->freq_buffer_re_diffuse[0] = NULL;
1113 20383 : hCrend->freq_buffer_re_diffuse[1] = NULL;
1114 20383 : hCrend->freq_buffer_im_diffuse[0] = NULL;
1115 20383 : hCrend->freq_buffer_im_diffuse[1] = NULL;
1116 20383 : hCrend->hReverb = NULL;
1117 20383 : hCrend->reflections = NULL;
1118 20383 : hCrend->delay_line_rw_index = 0;
1119 20383 : hCrend->diffuse_delay_line_rw_index = 0;
1120 20383 : hCrend->hTrack = NULL;
1121 20383 : hCrend->m_fYaw = 0;
1122 20383 : hCrend->m_fPitch = 0;
1123 20383 : hCrend->m_fRoll = 0;
1124 :
1125 20383 : ( *pCrend )->hCrend[pos_idx] = hCrend;
1126 : }
1127 :
1128 19343 : 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 19343 : 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 19343 : if ( ( error = ivas_rend_initCrendWrapper( pCrend, num_poses ) ) != IVAS_ERR_OK )
1174 : {
1175 0 : return error;
1176 : }
1177 :
1178 19343 : subframe_length = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES;
1179 :
1180 19343 : if ( ( *pCrend )->hHrtfCrend == NULL )
1181 : {
1182 19343 : 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 39726 : for ( pos_idx = 0; pos_idx < num_poses; pos_idx++ )
1189 : {
1190 20383 : hCrend = ( *pCrend )->hCrend[pos_idx];
1191 20383 : hHrtf = ( *pCrend )->hHrtfCrend;
1192 :
1193 20383 : if ( hHrtf != NULL )
1194 : {
1195 20383 : max_total_ir_len = hHrtf->max_num_iterations * subframe_length;
1196 :
1197 212150 : for ( i = 0; i < hHrtf->max_num_ir; i++ )
1198 : {
1199 191767 : 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 191767 : set_zero_l( hCrend->freq_buffer_re[i], max_total_ir_len );
1204 :
1205 191767 : 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 191767 : set_zero_l( hCrend->freq_buffer_im[i], max_total_ir_len );
1210 : }
1211 :
1212 61149 : for ( i = 0; i < BINAURAL_CHANNELS; i++ )
1213 : {
1214 40766 : 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 40766 : set_zero_l( hCrend->prev_out_buffer[i], subframe_length );
1219 : }
1220 :
1221 20383 : max_total_ir_len = hHrtf->num_iterations_diffuse[0] * subframe_length;
1222 :
1223 20383 : if ( max_total_ir_len > 0 )
1224 : {
1225 11222 : 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 11222 : 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 11222 : hCrend->freq_buffer_re_diffuse[1] = NULL;
1239 : }
1240 11222 : set_zero_l( hCrend->freq_buffer_re_diffuse[0], max_total_ir_len );
1241 11222 : 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 11222 : 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 11222 : 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 11222 : hCrend->freq_buffer_im_diffuse[1] = NULL;
1260 : }
1261 11222 : set_zero_l( hCrend->freq_buffer_im_diffuse[0], max_total_ir_len );
1262 11222 : 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 9161 : hCrend->freq_buffer_re_diffuse[0] = NULL;
1270 9161 : hCrend->freq_buffer_im_diffuse[0] = NULL;
1271 9161 : hCrend->freq_buffer_re_diffuse[1] = NULL;
1272 9161 : hCrend->freq_buffer_im_diffuse[1] = NULL;
1273 : }
1274 20383 : max_total_ir_len = (int32_t) ( hHrtf->latency_s * output_Fs + 0.5f ) + subframe_length;
1275 20383 : if ( max_total_ir_len > 0 )
1276 : {
1277 20383 : 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 20383 : 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 20383 : if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
1289 : {
1290 4130 : if ( ( error = ivas_reverb_open( &( hCrend->hReverb ), hHrtfStatistics, hRendCfg, output_Fs ) ) != IVAS_ERR_OK )
1291 : {
1292 0 : return error;
1293 : }
1294 :
1295 4130 : if ( hRendCfg->roomAcoustics.use_er == 1 )
1296 : {
1297 :
1298 : /* Allocate memory for reflections */
1299 326 : hCrend->reflections = (er_struct_t *) malloc( sizeof( er_struct_t ) );
1300 326 : if ( !hCrend->reflections )
1301 : {
1302 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Early Reflections" );
1303 : }
1304 326 : if ( ( error = ivas_er_init_handle( hCrend->reflections ) ) != IVAS_ERR_OK )
1305 : {
1306 0 : return error;
1307 : }
1308 :
1309 326 : hCrend->reflections->use_er = hRendCfg->roomAcoustics.use_er;
1310 326 : hCrend->reflections->lowComplexity = hRendCfg->roomAcoustics.lowComplexity;
1311 :
1312 : /* Set sample rate and frame size */
1313 326 : hCrend->reflections->output_Fs = (float) output_Fs;
1314 326 : hCrend->reflections->max_frame_size = (int16_t) ( output_Fs / FRAMES_PER_SEC );
1315 :
1316 : /* Init Shoebox */
1317 326 : ivas_shoebox_config_init( &hCrend->reflections->shoebox_lib.cal, hRendCfg );
1318 :
1319 : /* Init and compute Reflections */
1320 326 : if ( ( error = ivas_er_init( hCrend->reflections, inConfig ) ) != IVAS_ERR_OK )
1321 : {
1322 0 : return error;
1323 : }
1324 : }
1325 : else
1326 : {
1327 3804 : hCrend->reflections = NULL;
1328 : }
1329 : }
1330 : else
1331 : {
1332 16253 : hCrend->hReverb = NULL;
1333 : }
1334 :
1335 20383 : ( *pCrend )->binaural_latency_ns = (int32_t) ( ( *pCrend )->hHrtfCrend->latency_s * 1000000000.f );
1336 : }
1337 :
1338 20383 : ( *pCrend )->hCrend[pos_idx] = hCrend;
1339 : }
1340 :
1341 19343 : return IVAS_ERR_OK;
1342 : }
1343 :
1344 :
1345 : /*-------------------------------------------------------------------------
1346 : * ivas_rend_closeCrend()
1347 : *
1348 : * Deallocate Crend renderer handle
1349 : *------------------------------------------------------------------------*/
1350 :
1351 2391458 : 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 2391458 : if ( pCrend == NULL || *pCrend == NULL )
1359 : {
1360 2372115 : return;
1361 : }
1362 :
1363 19343 : if ( ( *pCrend )->hHrtfCrend != NULL && ( *pCrend )->hHrtfCrend->init_from_rom )
1364 : {
1365 17055 : ivas_hrtf_close( &( *pCrend )->hHrtfCrend );
1366 : }
1367 :
1368 174087 : for ( pos_idx = 0; pos_idx < MAX_HEAD_ROT_POSES; pos_idx++ )
1369 : {
1370 154744 : hCrend = ( *pCrend )->hCrend[pos_idx];
1371 154744 : if ( hCrend != NULL )
1372 : {
1373 346511 : for ( i = 0; i < MAX_INTERN_CHANNELS; i++ )
1374 : {
1375 326128 : if ( hCrend->freq_buffer_re[i] != NULL )
1376 : {
1377 191767 : free( hCrend->freq_buffer_re[i] );
1378 191767 : hCrend->freq_buffer_re[i] = NULL;
1379 : }
1380 326128 : if ( hCrend->freq_buffer_im[i] != NULL )
1381 : {
1382 191767 : free( hCrend->freq_buffer_im[i] );
1383 191767 : hCrend->freq_buffer_im[i] = NULL;
1384 : }
1385 : }
1386 :
1387 61149 : for ( i = 0; i < BINAURAL_CHANNELS; i++ )
1388 : {
1389 40766 : if ( hCrend->prev_out_buffer[i] != NULL )
1390 : {
1391 40766 : free( hCrend->prev_out_buffer[i] );
1392 40766 : hCrend->prev_out_buffer[i] = NULL;
1393 : }
1394 : }
1395 :
1396 20383 : if ( hCrend->lfe_delay_line != NULL )
1397 : {
1398 20383 : free( hCrend->lfe_delay_line );
1399 20383 : hCrend->lfe_delay_line = NULL;
1400 : }
1401 20383 : if ( hCrend->freq_buffer_re_diffuse[0] != NULL )
1402 : {
1403 11222 : free( hCrend->freq_buffer_re_diffuse[0] );
1404 11222 : hCrend->freq_buffer_re_diffuse[0] = NULL;
1405 : }
1406 :
1407 20383 : if ( hCrend->freq_buffer_im_diffuse[0] != NULL )
1408 : {
1409 11222 : free( hCrend->freq_buffer_im_diffuse[0] );
1410 11222 : hCrend->freq_buffer_im_diffuse[0] = NULL;
1411 : }
1412 :
1413 20383 : 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 20383 : 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 20383 : if ( hCrend->hTrack != NULL )
1426 : {
1427 0 : free( hCrend->hTrack );
1428 0 : hCrend->hTrack = NULL;
1429 : }
1430 :
1431 20383 : ivas_reverb_close( &hCrend->hReverb );
1432 :
1433 20383 : if ( hCrend->reflections != NULL )
1434 : {
1435 326 : if ( hCrend->reflections->closest_ch_idx != NULL )
1436 : {
1437 326 : free( hCrend->reflections->closest_ch_idx );
1438 326 : hCrend->reflections->closest_ch_idx = NULL;
1439 : }
1440 :
1441 326 : if ( hCrend->reflections->circ_buffers != NULL )
1442 : {
1443 326 : free( hCrend->reflections->circ_buffers );
1444 326 : hCrend->reflections->circ_buffers = NULL;
1445 : }
1446 :
1447 326 : free( hCrend->reflections );
1448 326 : hCrend->reflections = NULL;
1449 : }
1450 :
1451 20383 : free( hCrend );
1452 20383 : hCrend = NULL;
1453 20383 : ( *pCrend )->hCrend[pos_idx] = hCrend;
1454 : }
1455 : }
1456 :
1457 19343 : free( *pCrend );
1458 19343 : *pCrend = NULL;
1459 :
1460 19343 : 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 75219445 : 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 75219445 : float *pFreq_buf_re = NULL, *pFreq_buf_im = NULL;
1511 75219445 : 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 75219445 : hCrend = pCrend->hCrend[pos_idx];
1518 :
1519 75219445 : if ( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ) != IVAS_ERR_OK )
1520 : {
1521 0 : return error;
1522 : }
1523 :
1524 75219445 : if ( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ) != IVAS_ERR_OK )
1525 : {
1526 0 : return error;
1527 : }
1528 :
1529 75219445 : subframe_length = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES;
1530 :
1531 75219445 : lfe_idx_in = -1;
1532 75219445 : if ( getAudioConfigType( inConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED )
1533 : {
1534 48695725 : if ( inConfig != IVAS_AUDIO_CONFIG_LS_CUSTOM )
1535 : {
1536 48695725 : lfe_idx_in = LFE_CHANNEL;
1537 : }
1538 : else
1539 : {
1540 0 : assert( 0 && "Custom LS not supported in CRend" );
1541 : }
1542 : }
1543 :
1544 75219445 : offset = hCrend->delay_line_rw_index * subframe_length; /* subframe_length * ( pCrend->hHrtfCrend->max_num_iterations - 1 ); */
1545 75219445 : offset_diffuse = hCrend->diffuse_delay_line_rw_index * subframe_length; /* subframe_length *( pCrend->hHrtfCrend->num_iterations_diffuse[0] - 1 ); */
1546 :
1547 75219445 : if ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 )
1548 : {
1549 38822868 : set_zero( &hCrend->freq_buffer_re_diffuse[0][offset_diffuse], subframe_length );
1550 38822868 : set_zero( &hCrend->freq_buffer_im_diffuse[0][offset_diffuse], subframe_length );
1551 38822868 : 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 75219445 : if ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 )
1559 : {
1560 38822868 : if ( pCrend->hHrtfCrend->same_inv_diffuse_weight )
1561 : {
1562 38822868 : pFreq_buf_re = &hCrend->freq_buffer_re_diffuse[0][offset_diffuse];
1563 38822868 : 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 75219445 : i = 0;
1575 880917157 : for ( idx_in = 0; idx_in < nchan_in; idx_in++ )
1576 : {
1577 805697712 : pIn = &pcm_in[idx_in][i_ts * subframe_length];
1578 805697712 : if ( idx_in != lfe_idx_in )
1579 : {
1580 757001987 : if ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 )
1581 : {
1582 415026528 : if ( pCrend->hHrtfCrend->same_inv_diffuse_weight )
1583 : {
1584 415026528 : pFreq_filt_re = &hCrend->freq_buffer_re[i][offset];
1585 415026528 : pFreq_filt_im = &hCrend->freq_buffer_im[i][offset];
1586 :
1587 38337807809 : for ( k = 0; k < pCrend->hHrtfCrend->index_frequency_max_diffuse; k++ )
1588 : {
1589 37922781281 : pFreq_buf_re[k] += pFreq_filt_re[k] * pCrend->hHrtfCrend->inv_diffuse_weight[0][i];
1590 37922781281 : 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 757001987 : ivas_mdft( pIn, &hCrend->freq_buffer_re[i][offset], &hCrend->freq_buffer_im[i][offset], subframe_length, subframe_length );
1609 757001987 : i++;
1610 : }
1611 : }
1612 :
1613 225658335 : for ( j = 0; j < nchan_out; j++ )
1614 : {
1615 150438890 : set_zero( tmp_out_re, subframe_length );
1616 150438890 : set_zero( tmp_out_im, subframe_length );
1617 :
1618 150438890 : i = 0;
1619 1761834314 : for ( idx_in = 0; idx_in < nchan_in; idx_in++ )
1620 : {
1621 1611395424 : if ( idx_in != lfe_idx_in )
1622 : {
1623 1514003974 : offset = 0;
1624 20709115074 : for ( m = 0; m < pCrend->hHrtfCrend->num_iterations[i][j]; m++ )
1625 : {
1626 19195111100 : offset_in = ( hCrend->delay_line_rw_index + pCrend->hHrtfCrend->max_num_iterations - pCrend->hHrtfCrend->num_iterations[i][j] + m + 1 );
1627 19195111100 : offset_in = offset_in % ( pCrend->hHrtfCrend->max_num_iterations );
1628 19195111100 : offset_in = offset_in * subframe_length;
1629 19195111100 : pFreq_buf_re = &hCrend->freq_buffer_re[i][offset_in];
1630 19195111100 : pFreq_buf_im = &hCrend->freq_buffer_im[i][offset_in];
1631 19195111100 : pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_re[i][j][offset];
1632 19195111100 : pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_im[i][j][offset];
1633 :
1634 >22258*10^8 : for ( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max[i][j][m]; k++ )
1635 : {
1636 >22066*10^8 : tmp_out_re[k] += pFreq_buf_re[k] * pFreq_filt_re[k] - pFreq_buf_im[k] * pFreq_filt_im[k];
1637 >22066*10^8 : tmp_out_im[k] += pFreq_buf_re[k] * pFreq_filt_im[k] + pFreq_buf_im[k] * pFreq_filt_re[k];
1638 : }
1639 19195111100 : offset = offset + k;
1640 : }
1641 1514003974 : i++;
1642 : }
1643 : }
1644 :
1645 150438890 : offset = 0;
1646 3256268330 : for ( m = 0; m < pCrend->hHrtfCrend->num_iterations_diffuse[j]; m++ )
1647 : {
1648 3105829440 : offset_diffuse = ( hCrend->diffuse_delay_line_rw_index + m + 1 );
1649 3105829440 : offset_diffuse = offset_diffuse % pCrend->hHrtfCrend->num_iterations_diffuse[0];
1650 3105829440 : offset_diffuse = offset_diffuse * subframe_length;
1651 3105829440 : if ( pCrend->hHrtfCrend->same_inv_diffuse_weight )
1652 : {
1653 3105829440 : pFreq_buf_re = &hCrend->freq_buffer_re_diffuse[0][offset_diffuse];
1654 3105829440 : 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 3105829440 : pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_re[j][offset];
1662 3105829440 : pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_im[j][offset];
1663 :
1664 >21718*10^7 : for ( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max_diffuse[j][m]; k++ )
1665 : {
1666 >21407*10^7 : tmp_out_re[k] += pFreq_buf_re[k] * pFreq_filt_re[k] - pFreq_buf_im[k] * pFreq_filt_im[k];
1667 >21407*10^7 : tmp_out_im[k] += pFreq_buf_re[k] * pFreq_filt_im[k] + pFreq_buf_im[k] * pFreq_filt_re[k];
1668 : }
1669 3105829440 : offset = offset + k;
1670 : }
1671 :
1672 150438890 : ivas_imdft( tmp_out_re, tmp_out_im, pOut, subframe_length );
1673 :
1674 150438890 : pFreq_buf_re = &pcm_out[j][i_ts * subframe_length];
1675 25733646250 : for ( k = 0; k < subframe_length; k++ )
1676 : {
1677 25583207360 : pFreq_buf_re[k] = pOut[k] + hCrend->prev_out_buffer[j][k];
1678 25583207360 : hCrend->prev_out_buffer[j][k] = pOut[k + subframe_length];
1679 : }
1680 : }
1681 :
1682 75219445 : hCrend->delay_line_rw_index++;
1683 75219445 : hCrend->delay_line_rw_index = hCrend->delay_line_rw_index % ( pCrend->hHrtfCrend->max_num_iterations );
1684 75219445 : if ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 )
1685 : {
1686 38822868 : hCrend->diffuse_delay_line_rw_index++;
1687 38822868 : hCrend->diffuse_delay_line_rw_index = hCrend->diffuse_delay_line_rw_index % ( pCrend->hHrtfCrend->num_iterations_diffuse[0] );
1688 : }
1689 :
1690 75219445 : return IVAS_ERR_OK;
1691 : }
1692 :
1693 :
1694 : /*-----------------------------------------------------------------------------------------*
1695 : * Function ivas_rend_crendProcessSubframe()
1696 : *
1697 : *
1698 : *-----------------------------------------------------------------------------------------*/
1699 :
1700 48286546 : 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 48286546 : hCrend = pCrend->hCrend[pos_idx];
1728 :
1729 48286546 : combinedOrientationEnabled = 0;
1730 48286546 : if ( hCombinedOrientationData != NULL )
1731 : {
1732 393724 : if ( hCombinedOrientationData->enableCombinedOrientation[0] != 0 )
1733 : {
1734 393724 : combinedOrientationEnabled = 1;
1735 : }
1736 : }
1737 :
1738 48286546 : push_wmops( "ivas_rend_crendProcessSubframe" );
1739 48286546 : inConfigType = getAudioConfigType( inConfig );
1740 :
1741 48286546 : if ( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ) != IVAS_ERR_OK )
1742 : {
1743 0 : return error;
1744 : }
1745 :
1746 48286546 : if ( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ) != IVAS_ERR_OK )
1747 : {
1748 0 : return error;
1749 : }
1750 :
1751 564744333 : for ( ch = 0; ch < nchan_in; ch++ )
1752 : {
1753 516457787 : tc_local[ch] = input_f[ch];
1754 : }
1755 :
1756 144859638 : for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
1757 : {
1758 96573092 : p_pcm_tmp[ch] = pcm_tmp[ch];
1759 96573092 : p_output[ch] = output[ch];
1760 : }
1761 :
1762 48286546 : if ( hTcBuffer != NULL )
1763 : {
1764 2266507 : 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 2266507 : slots_to_render = min( hTcBuffer->num_slots - hTcBuffer->slots_rendered, n_samples_to_render / slot_size );
1768 2266507 : first_sf = hTcBuffer->subframes_rendered;
1769 2266507 : last_sf = first_sf;
1770 :
1771 6579983 : while ( slots_to_render > 0 )
1772 : {
1773 4313476 : slots_to_render -= hTcBuffer->subframe_nbslots[last_sf];
1774 4313476 : last_sf++;
1775 : }
1776 2266507 : subframe_len = -1; /* will be set later */
1777 : }
1778 : else
1779 : {
1780 46020039 : subframe_len = (int16_t) ( output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) );
1781 46020039 : first_sf = 0;
1782 46020039 : last_sf = n_samples_to_render / subframe_len;
1783 : }
1784 :
1785 123505991 : for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
1786 : {
1787 75219445 : if ( hTcBuffer != NULL )
1788 : {
1789 4313476 : subframe_len = hTcBuffer->subframe_nbslots[subframe_idx] * hTcBuffer->n_samples_granularity;
1790 : }
1791 :
1792 : /* Early Reflections */
1793 75219445 : if ( hCrend->reflections != NULL )
1794 : {
1795 3804290 : if ( hCrend->reflections->use_er == 1 && hCrend->reflections->is_ready == 1 )
1796 : {
1797 2472374 : 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 75219445 : 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 806152 : if ( inConfig == IVAS_AUDIO_CONFIG_FOA || inConfig == IVAS_AUDIO_CONFIG_HOA2 || inConfig == IVAS_AUDIO_CONFIG_HOA3 )
1811 : {
1812 351720 : rotateFrame_shd( hCombinedOrientationData, tc_local, subframe_len, *hIntSetup, 0 );
1813 : }
1814 : /* Rotation in SD for MC -> BINAURAL_ROOM */
1815 454432 : else if ( ( hIntSetup != NULL ) && hIntSetup->is_loudspeaker_setup )
1816 : {
1817 454432 : rotateFrame_sd( hCombinedOrientationData, tc_local, subframe_len, *hIntSetup, hEFAPdata, 0 );
1818 : }
1819 : }
1820 :
1821 75219445 : if ( ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) || ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) )
1822 : {
1823 75219445 : 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 75219445 : if ( pCrend->hCrend[0]->hReverb != NULL )
1829 : {
1830 25144598 : 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 880917157 : for ( ch = 0; ch < nchan_in; ch++ )
1837 : {
1838 805697712 : tc_local[ch] += subframe_len;
1839 : }
1840 :
1841 75219445 : if ( hTcBuffer != NULL )
1842 : {
1843 4313476 : hTcBuffer->slots_rendered += hTcBuffer->subframe_nbslots[subframe_idx];
1844 : }
1845 : }
1846 : else
1847 : {
1848 0 : return IVAS_ERR_INVALID_INPUT_FORMAT;
1849 : }
1850 :
1851 225658335 : for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
1852 : {
1853 : /* move to output */
1854 150438890 : mvr2r( pcm_tmp[ch], p_output[ch], subframe_len );
1855 :
1856 150438890 : p_output[ch] += subframe_len;
1857 : }
1858 :
1859 : /* update combined orientation access index */
1860 75219445 : ivas_combined_orientation_update_index( hCombinedOrientationData, subframe_len );
1861 : }
1862 :
1863 48286546 : if ( hTcBuffer != NULL )
1864 : {
1865 2266507 : hTcBuffer->subframes_rendered = last_sf;
1866 : }
1867 :
1868 48286546 : pop_wmops();
1869 :
1870 48286546 : 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 13535 : 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 13535 : pCombinedOrientationDataLocal = hCombinedOrientationData;
1911 13535 : combinedOrientationDataLocal = *pCombinedOrientationDataLocal;
1912 13535 : original_subframes_rendered = hTcBuffer->subframes_rendered;
1913 13535 : original_slots_rendered = hTcBuffer->slots_rendered;
1914 :
1915 : /* copy input */
1916 230095 : for ( i = 0; i < hIntSetup->nchan_out_woLFE; ++i )
1917 : {
1918 216560 : mvr2r( input_f[i], tmpInputBuffer[i], n_samples_to_render );
1919 : }
1920 :
1921 230095 : for ( i = 0; i < MAX_OUTPUT_CHANNELS; ++i )
1922 : {
1923 216560 : p_tmpInputBuffer[i] = tmpInputBuffer[i];
1924 : }
1925 :
1926 : /* save current head positions */
1927 13535 : pCombinedOrientationDataLocal = hCombinedOrientationData;
1928 13535 : combinedOrientationDataLocal = *pCombinedOrientationDataLocal;
1929 13535 : if ( pMultiBinPoseData->poseCorrectionMode == ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB )
1930 : {
1931 39100 : for ( sf = 1; sf < hCombinedOrientationData->num_subframes; ++sf )
1932 : {
1933 29325 : combinedOrientationDataLocal.Quaternions[sf] = combinedOrientationDataLocal.Quaternions[0];
1934 117300 : for ( i = 0; i < 3; i++ )
1935 : {
1936 351900 : for ( j = 0; j < 3; j++ )
1937 : {
1938 263925 : 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 13535 : 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 13535 : set_zero( tmpLfeBuffer, n_samples_to_render );
1954 : }
1955 :
1956 70680 : 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 285725 : for ( i = 0; i < hCombinedOrientationData->num_subframes; i++ )
1961 : {
1962 228580 : Quaternions_orig[i] = combinedOrientationDataLocal.Quaternions[i];
1963 228580 : Quaternions_abs.w = -3.0f;
1964 228580 : Quat2EulerDegree( combinedOrientationDataLocal.Quaternions[i], &Quaternions_abs.z, &Quaternions_abs.y, &Quaternions_abs.x ); /*order in Quat2Euler seems to be reversed ?*/
1965 :
1966 228580 : Quaternions_abs.x += pMultiBinPoseData->relative_head_poses[pos_idx][0];
1967 228580 : Quaternions_abs.y += pMultiBinPoseData->relative_head_poses[pos_idx][1];
1968 228580 : Quaternions_abs.z += pMultiBinPoseData->relative_head_poses[pos_idx][2];
1969 228580 : combinedOrientationDataLocal.Quaternions[i] = Quaternions_abs;
1970 228580 : QuatToRotMat( combinedOrientationDataLocal.Quaternions[i], combinedOrientationDataLocal.Rmat[i] );
1971 : }
1972 :
1973 57145 : pCombinedOrientationDataLocal = &combinedOrientationDataLocal;
1974 :
1975 57145 : hTcBuffer->subframes_rendered = original_subframes_rendered;
1976 57145 : hTcBuffer->slots_rendered = original_slots_rendered;
1977 :
1978 : /* update combined orientation access index */
1979 57145 : ivas_combined_orientation_set_to_start_index( pCombinedOrientationDataLocal );
1980 :
1981 228580 : for ( i = 0; i < 3; i++ )
1982 : {
1983 171435 : mvr2r( hCombinedOrientationData->Rmat_prev[pos_idx][i], pCombinedOrientationDataLocal->Rmat_prev[0][i], 3 );
1984 : }
1985 :
1986 57145 : 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 228580 : for ( i = 0; i < 3; i++ )
1993 : {
1994 171435 : mvr2r( pCombinedOrientationDataLocal->Rmat_prev[0][i], hCombinedOrientationData->Rmat_prev[pos_idx][i], 3 );
1995 : }
1996 :
1997 171435 : for ( i = 0; i < BINAURAL_CHANNELS; ++i )
1998 : {
1999 : /* accumulate LFE to output */
2000 114290 : v_add( tmpInputBuffer[i], tmpLfeBuffer, tmpInputBuffer[i], n_samples_to_render );
2001 :
2002 : /* move to split bin output buffer */
2003 114290 : 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 971465 : for ( i = 0; i < hIntSetup->nchan_out_woLFE; ++i )
2008 : {
2009 914320 : mvr2r( input_f[i], tmpInputBuffer[i], n_samples_to_render );
2010 : }
2011 :
2012 : /* restore original headrotation data */
2013 285725 : for ( i = 0; i < hCombinedOrientationData->num_subframes; i++ )
2014 : {
2015 228580 : combinedOrientationDataLocal.Quaternions[i] = Quaternions_orig[i];
2016 : }
2017 : }
2018 :
2019 : /* copy split binaural rendered signals to final output */
2020 127825 : for ( i = 0; i < BINAURAL_CHANNELS * pMultiBinPoseData->num_poses; ++i )
2021 : {
2022 114290 : mvr2r( tmpSplitBinBuffer[i], output[i], n_samples_to_render );
2023 : }
2024 :
2025 : /* update main combined orientation access index */
2026 13535 : ivas_combined_orientation_update_index( hCombinedOrientationData, n_samples_to_render );
2027 :
2028 13535 : return IVAS_ERR_OK;
2029 : }
|