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_fx.h"
36 : #include "ivas_rom_binaural_crend_head.h"
37 : #include "ivas_prot_rend_fx.h"
38 : #include "ivas_error.h"
39 : #include "wmc_auto.h"
40 : #include "ivas_prot_fx.h"
41 :
42 : /*-----------------------------------------------------------------------*
43 : * ivas_HRTF_binary_open()
44 : *
45 : * Allocate HRTF binary handle
46 : *-----------------------------------------------------------------------*/
47 :
48 24 : ivas_error ivas_HRTF_binary_open_fx(
49 : TDREND_HRFILT_FiltSet_t **hHrtfTD )
50 : {
51 : /* Allocate HR filter set for headphones configuration */
52 24 : *hHrtfTD = (TDREND_HRFILT_FiltSet_t *) malloc( sizeof( TDREND_HRFILT_FiltSet_t ) );
53 24 : IF( *hHrtfTD == NULL )
54 : {
55 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary!" );
56 : }
57 :
58 24 : set_c( (int8_t *) ( *hHrtfTD ), 0, (int32_t) sizeof( TDREND_HRFILT_FiltSet_t ) );
59 :
60 24 : return IVAS_ERR_OK;
61 : }
62 :
63 :
64 : /*-------------------------------------------------------------------*
65 : * ivas_HRTF_binary_close()
66 : *
67 : * Close HRTF binary handle
68 : *-------------------------------------------------------------------*/
69 :
70 690 : void ivas_HRTF_binary_close_fx(
71 : TDREND_HRFILT_FiltSet_t **hHrtfTD )
72 : {
73 690 : test();
74 690 : IF( hHrtfTD == NULL || *hHrtfTD == NULL )
75 : {
76 666 : return;
77 : }
78 :
79 24 : free( *hHrtfTD );
80 24 : *hHrtfTD = NULL;
81 :
82 24 : return;
83 : }
84 :
85 :
86 : /*-----------------------------------------------------------------------*
87 : * ivas_HRTF_CRend_binary_open()
88 : *
89 : * Allocate HRTF binary handle
90 : *-----------------------------------------------------------------------*/
91 :
92 24 : ivas_error ivas_HRTF_CRend_binary_open_fx(
93 : HRTFS_CREND **hSetOfHRTF )
94 : {
95 : /* Allocate HR filter set for headphones configuration */
96 24 : *hSetOfHRTF = (HRTFS_CREND *) malloc( sizeof( HRTFS_CREND ) );
97 24 : IF( *hSetOfHRTF == NULL )
98 : {
99 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for set of HRTF binary!" );
100 : }
101 :
102 24 : ( *hSetOfHRTF )->hHRTF_hrir_combined = NULL;
103 24 : ( *hSetOfHRTF )->hHRTF_hrir_hoa3 = NULL;
104 24 : ( *hSetOfHRTF )->hHRTF_hrir_hoa2 = NULL;
105 24 : ( *hSetOfHRTF )->hHRTF_hrir_foa = NULL;
106 24 : ( *hSetOfHRTF )->hHRTF_brir_combined = NULL;
107 :
108 24 : return IVAS_ERR_OK;
109 : }
110 :
111 :
112 : /*-------------------------------------------------------------------*
113 : * ivas_HRTF_CRend_binary_close()
114 : *
115 : * Close HRTF CRend binary handle
116 : *-------------------------------------------------------------------*/
117 :
118 1303 : void ivas_HRTF_CRend_binary_close_fx(
119 : HRTFS_CREND **hSetOfHRTF )
120 : {
121 1303 : test();
122 1303 : IF( hSetOfHRTF == NULL || *hSetOfHRTF == NULL )
123 : {
124 1279 : return;
125 : }
126 :
127 24 : free( *hSetOfHRTF );
128 24 : *hSetOfHRTF = NULL;
129 :
130 24 : return;
131 : }
132 :
133 :
134 : /*-----------------------------------------------------------------------*
135 : * ivas_HRTF_fastconv_binary_open()
136 : *
137 : * Allocate HRTF binary handle for FASTCONV renderer
138 : *-----------------------------------------------------------------------*/
139 :
140 24 : ivas_error ivas_HRTF_fastconv_binary_open_fx(
141 : HRTFS_FASTCONV **hHrtfFastConv )
142 : {
143 24 : *hHrtfFastConv = (HRTFS_FASTCONV *) malloc( sizeof( HRTFS_FASTCONV ) );
144 24 : IF( *hHrtfFastConv == NULL )
145 : {
146 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FASTCONV HRTF tables!" );
147 : }
148 24 : ivas_init_binaural_hrtf_fx( *hHrtfFastConv );
149 24 : return IVAS_ERR_OK;
150 : }
151 :
152 :
153 : /*-----------------------------------------------------------------------*
154 : * ivas_HRTF_fastconv_binary_close()
155 : *
156 : * Close HRTF binary handle for FASTCONV renderer
157 : *-----------------------------------------------------------------------*/
158 :
159 1279 : void ivas_HRTF_fastconv_binary_close_fx(
160 : HRTFS_FASTCONV **hHrtfFastConv )
161 : {
162 1279 : test();
163 1279 : IF( hHrtfFastConv == NULL || *hHrtfFastConv == NULL )
164 : {
165 1211 : return;
166 : }
167 :
168 68 : free( *hHrtfFastConv );
169 68 : *hHrtfFastConv = NULL;
170 :
171 68 : return;
172 : }
173 :
174 :
175 : /*-----------------------------------------------------------------------*
176 : * ivas_HRTF_parambin_binary_open()
177 : *
178 : * Allocate HRTF binary handle for parametric binauralizer
179 : *-----------------------------------------------------------------------*/
180 :
181 24 : ivas_error ivas_HRTF_parambin_binary_open_fx(
182 : HRTFS_PARAMBIN **hHrtfParambin )
183 : {
184 24 : *hHrtfParambin = (HRTFS_PARAMBIN *) malloc( sizeof( HRTFS_PARAMBIN ) );
185 24 : IF( *hHrtfParambin == NULL )
186 : {
187 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for parametric binauralizer HRTF tables!" );
188 : }
189 :
190 24 : set_c( (int8_t *) ( *hHrtfParambin ), 0, (int32_t) sizeof( HRTFS_PARAMBIN ) );
191 :
192 24 : return IVAS_ERR_OK;
193 : }
194 :
195 :
196 : /*-----------------------------------------------------------------------*
197 : * ivas_HRTF_parambin_binary_close()
198 : *
199 : * Close HRTF binary handle for parametric binauralizer
200 : *-----------------------------------------------------------------------*/
201 :
202 1327 : void ivas_HRTF_parambin_binary_close_fx(
203 : HRTFS_PARAMBIN **hHrtfParambin )
204 : {
205 1327 : test();
206 1327 : IF( hHrtfParambin == NULL || *hHrtfParambin == NULL )
207 : {
208 1196 : return;
209 : }
210 :
211 131 : free( *hHrtfParambin );
212 131 : *hHrtfParambin = NULL;
213 :
214 131 : return;
215 : }
216 :
217 : /*-----------------------------------------------------------------------*
218 : * ivas_HRTF_statistics_binary_open()
219 : *
220 : * Allocate HRTF binary handle for statistics handler
221 : *-----------------------------------------------------------------------*/
222 :
223 24 : ivas_error ivas_HRTF_statistics_binary_open(
224 : HRTFS_STATISTICS **hHrtfStatistics )
225 : {
226 24 : *hHrtfStatistics = (HRTFS_STATISTICS *) malloc( sizeof( HRTFS_STATISTICS ) );
227 24 : if ( *hHrtfStatistics == NULL )
228 : {
229 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for statistics HRTF tables!" );
230 : }
231 :
232 24 : return IVAS_ERR_OK;
233 : }
234 :
235 :
236 : /*-----------------------------------------------------------------------*
237 : * ivas_HRTF_statistics_close()
238 : *
239 : * Close HRTF binary handle for statistics handler
240 : *-----------------------------------------------------------------------*/
241 :
242 1945 : void ivas_HRTF_statistics_close(
243 : HRTFS_STATISTICS **hHrtfStatistics )
244 : {
245 1945 : if ( hHrtfStatistics == NULL || *hHrtfStatistics == NULL )
246 : {
247 1816 : return;
248 : }
249 :
250 129 : free( *hHrtfStatistics );
251 129 : *hHrtfStatistics = NULL;
252 :
253 129 : return;
254 : }
255 :
256 :
257 : /*-----------------------------------------------------------------------*
258 : * ivas_HRTF_statistics_init()
259 : *
260 : * Allocates HRTF statistics handle and initializes from ROM
261 : *-----------------------------------------------------------------------*/
262 :
263 111 : ivas_error ivas_HRTF_statistics_init(
264 : HRTFS_STATISTICS_HANDLE *hHrtfStatistics,
265 : const Word32 sampleRate )
266 : {
267 : HRTFS_STATISTICS *HrtfStatistics;
268 :
269 111 : if ( hHrtfStatistics != NULL && *hHrtfStatistics != NULL )
270 : {
271 : /* Tables already loaded from file */
272 6 : return IVAS_ERR_OK;
273 : }
274 :
275 : /* Initialise tables from ROM */
276 105 : if ( ( HrtfStatistics = (HRTFS_STATISTICS *) malloc( sizeof( HRTFS_STATISTICS ) ) ) == NULL )
277 : {
278 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for statistics HRTF tables!" );
279 : }
280 :
281 105 : HrtfStatistics->average_energy_l = NULL;
282 105 : HrtfStatistics->average_energy_r = NULL;
283 105 : HrtfStatistics->inter_aural_coherence = NULL;
284 :
285 105 : switch ( sampleRate )
286 : {
287 95 : case 48000:
288 95 : HrtfStatistics->average_energy_l_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) );
289 95 : if ( HrtfStatistics->average_energy_l_dyn == NULL )
290 : {
291 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
292 : }
293 95 : HrtfStatistics->average_energy_r_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) );
294 95 : if ( HrtfStatistics->average_energy_r_dyn == NULL )
295 : {
296 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
297 : }
298 95 : HrtfStatistics->inter_aural_coherence_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) );
299 95 : if ( HrtfStatistics->inter_aural_coherence_dyn == NULL )
300 : {
301 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
302 : }
303 95 : floatToFixed_arr32( defaultHRIR_left_avg_power_48kHz_fx, HrtfStatistics->average_energy_l_dyn, Q28, LR_IAC_LENGTH_NR_FC ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */
304 95 : floatToFixed_arr32( defaultHRIR_right_avg_power_48kHz_fx, HrtfStatistics->average_energy_r_dyn, Q28, LR_IAC_LENGTH_NR_FC ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */
305 95 : floatToFixed_arr32( defaultHRIR_coherence_48kHz_fx, HrtfStatistics->inter_aural_coherence_dyn, Q26, LR_IAC_LENGTH_NR_FC ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */
306 95 : HrtfStatistics->average_energy_l = (const Word32 *) HrtfStatistics->average_energy_l_dyn;
307 95 : HrtfStatistics->average_energy_r = (const Word32 *) HrtfStatistics->average_energy_r_dyn;
308 95 : HrtfStatistics->inter_aural_coherence = (const Word32 *) HrtfStatistics->inter_aural_coherence_dyn;
309 95 : break;
310 7 : case 32000:
311 7 : HrtfStatistics->average_energy_l_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) );
312 7 : if ( HrtfStatistics->average_energy_l_dyn == NULL )
313 : {
314 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
315 : }
316 7 : HrtfStatistics->average_energy_r_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) );
317 7 : if ( HrtfStatistics->average_energy_r_dyn == NULL )
318 : {
319 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
320 : }
321 7 : HrtfStatistics->inter_aural_coherence_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) );
322 7 : if ( HrtfStatistics->inter_aural_coherence_dyn == NULL )
323 : {
324 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
325 : }
326 7 : floatToFixed_arr32( defaultHRIR_left_avg_power_32kHz_fx, HrtfStatistics->average_energy_l_dyn, Q28, LR_IAC_LENGTH_NR_FC ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */
327 7 : floatToFixed_arr32( defaultHRIR_right_avg_power_32kHz_fx, HrtfStatistics->average_energy_r_dyn, Q28, LR_IAC_LENGTH_NR_FC ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */
328 7 : floatToFixed_arr32( defaultHRIR_coherence_32kHz_fx, HrtfStatistics->inter_aural_coherence_dyn, Q26, LR_IAC_LENGTH_NR_FC ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */
329 7 : HrtfStatistics->average_energy_l = (const Word32 *) HrtfStatistics->average_energy_l_dyn;
330 7 : HrtfStatistics->average_energy_r = (const Word32 *) HrtfStatistics->average_energy_r_dyn;
331 7 : HrtfStatistics->inter_aural_coherence = (const Word32 *) HrtfStatistics->inter_aural_coherence_dyn;
332 7 : break;
333 3 : case 16000:
334 3 : HrtfStatistics->average_energy_l_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC_16KHZ * sizeof( Word32 ) );
335 3 : if ( HrtfStatistics->average_energy_l_dyn == NULL )
336 : {
337 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
338 : }
339 3 : HrtfStatistics->average_energy_r_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC_16KHZ * sizeof( Word32 ) );
340 3 : if ( HrtfStatistics->average_energy_r_dyn == NULL )
341 : {
342 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
343 : }
344 3 : HrtfStatistics->inter_aural_coherence_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC_16KHZ * sizeof( Word32 ) );
345 3 : if ( HrtfStatistics->inter_aural_coherence_dyn == NULL )
346 : {
347 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
348 : }
349 3 : floatToFixed_arr32( defaultHRIR_left_avg_power_16kHz_fx, HrtfStatistics->average_energy_l_dyn, Q28, LR_IAC_LENGTH_NR_FC_16KHZ ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */
350 3 : floatToFixed_arr32( defaultHRIR_right_avg_power_16kHz_fx, HrtfStatistics->average_energy_r_dyn, Q28, LR_IAC_LENGTH_NR_FC_16KHZ ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */
351 3 : floatToFixed_arr32( defaultHRIR_coherence_16kHz_fx, HrtfStatistics->inter_aural_coherence_dyn, Q26, LR_IAC_LENGTH_NR_FC_16KHZ ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */
352 3 : HrtfStatistics->average_energy_l = (const Word32 *) HrtfStatistics->average_energy_l_dyn;
353 3 : HrtfStatistics->average_energy_r = (const Word32 *) HrtfStatistics->average_energy_r_dyn;
354 3 : HrtfStatistics->inter_aural_coherence = (const Word32 *) HrtfStatistics->inter_aural_coherence_dyn;
355 3 : break;
356 : }
357 105 : HrtfStatistics->fromROM = TRUE;
358 :
359 105 : *hHrtfStatistics = HrtfStatistics;
360 :
361 :
362 105 : return IVAS_ERR_OK;
363 : }
|