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