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 <math.h>
36 : #include "prot.h"
37 : #include "ivas_prot_rend.h"
38 : #include "wmc_auto.h"
39 : #ifdef DEBUGGING
40 : #include "debug.h"
41 : #endif
42 :
43 :
44 : /*-------------------------------------------------------------------*
45 : * TDREND_SPATIAL_VecInit()
46 : *
47 : * Initialize 3-dim vector
48 : *-------------------------------------------------------------------*/
49 :
50 148357 : void TDREND_SPATIAL_VecInit(
51 : float *Pos_p, /* o : Output vector */
52 : const float PosX, /* i : X value */
53 : const float PosY, /* i : Y value */
54 : const float PosZ /* i : Z value */
55 : )
56 : {
57 148357 : Pos_p[0] = PosX;
58 148357 : Pos_p[1] = PosY;
59 148357 : Pos_p[2] = PosZ;
60 :
61 148357 : return;
62 : }
63 :
64 :
65 : /*-------------------------------------------------------------------*
66 : * TDREND_SPATIAL_VecNorm()
67 : *
68 : * Compute Euclidian norm of vector
69 : *-------------------------------------------------------------------*/
70 :
71 : /*! r: Euclidian norm value */
72 9430944 : float TDREND_SPATIAL_VecNorm(
73 : const float *Vec_p /* i : Vector for norm calculation */
74 : )
75 : {
76 9430944 : return sqrtf( Vec_p[0] * Vec_p[0] + Vec_p[1] * Vec_p[1] + Vec_p[2] * Vec_p[2] );
77 : }
78 :
79 :
80 : /*-------------------------------------------------------------------*
81 : * TDREND_SPATIAL_VecNormalize()
82 : *
83 : * Normalize vector to unit norm
84 : *-------------------------------------------------------------------*/
85 :
86 14869959 : void TDREND_SPATIAL_VecNormalize(
87 : const float *Vec_p, /* i : Input vector */
88 : float *VecNorm_p /* o : Output vector */
89 : )
90 : {
91 : float scaler;
92 :
93 14869959 : scaler = inv_sqrt( Vec_p[0] * Vec_p[0] + Vec_p[1] * Vec_p[1] + Vec_p[2] * Vec_p[2] );
94 14869959 : VecNorm_p[0] = scaler * Vec_p[0];
95 14869959 : VecNorm_p[1] = scaler * Vec_p[1];
96 14869959 : VecNorm_p[2] = scaler * Vec_p[2];
97 :
98 14869959 : return;
99 : }
100 :
101 :
102 : /*-------------------------------------------------------------------*
103 : * TDREND_SPATIAL_VecMapToNewCoordSystem()
104 : *
105 : * Transform vector to new coordinate system
106 : *-------------------------------------------------------------------*/
107 :
108 4715472 : void TDREND_SPATIAL_VecMapToNewCoordSystem(
109 : const float *Vec_p, /* i : Input vector */
110 : const float *TranslVec_p, /* i : Translation vector */
111 : const float *DirVec_p, /* i : Direction vector */
112 : const float *UpVec_p, /* i : Up vector */
113 : const float *RightVec_p, /* i : Right vector */
114 : float *MappedVec_p, /* o : Transformed vector */
115 : float *LisRelPosAbs /* o : Transformed vector ignoring orientation */
116 : )
117 : {
118 4715472 : v_sub( Vec_p, TranslVec_p, LisRelPosAbs, 3 );
119 : /* Evalute the relative Vec in the coordinates of the Orientation vectors, */
120 : /* which form an orthonormal basis */
121 4715472 : MappedVec_p[0] = dotp( LisRelPosAbs, DirVec_p, 3 );
122 4715472 : MappedVec_p[1] = dotp( LisRelPosAbs, RightVec_p, 3 );
123 4715472 : MappedVec_p[2] = dotp( LisRelPosAbs, UpVec_p, 3 );
124 4715472 : return;
125 : }
126 :
127 :
128 : /*-------------------------------------------------------------------*
129 : * TDREND_SPATIAL_EvalOrthonormOrient()
130 : *
131 : * Evaluate the normalized orientation vectors
132 : *-------------------------------------------------------------------*/
133 :
134 : /*! r: Flag if the orientation has been updated */
135 4087340 : int16_t TDREND_SPATIAL_EvalOrthonormOrient(
136 : float *FrontVecON_p, /* o : Normalized front vector */
137 : float *UpVecON_p, /* o : Normalized up vector */
138 : float *RightVecON_p, /* o : Normalized right vector */
139 : const float *FrontVec_p, /* i : Input front vector */
140 : const float *UpVec_p /* i : Input up vector */
141 : )
142 : {
143 : float tmp[9];
144 : int16_t orientation_updated;
145 :
146 4087340 : orientation_updated = FALSE;
147 :
148 : /* Store current state to detect change */
149 4087340 : mvr2r( FrontVecON_p, tmp, 3 );
150 4087340 : mvr2r( RightVecON_p, tmp + 3, 3 );
151 4087340 : mvr2r( UpVecON_p, tmp + 6, 3 );
152 :
153 : /* Evaluate the normalized front vector */
154 4087340 : TDREND_SPATIAL_VecNormalize( FrontVec_p, FrontVecON_p );
155 :
156 : /* Evaluate the orthonormal right vector */
157 : /* through the cross product of the front and the up vectors */
158 4087340 : RightVecON_p[0] = FrontVecON_p[1] * UpVec_p[2] - FrontVecON_p[2] * UpVec_p[1];
159 4087340 : RightVecON_p[1] = FrontVecON_p[2] * UpVec_p[0] - FrontVecON_p[0] * UpVec_p[2];
160 4087340 : RightVecON_p[2] = FrontVecON_p[0] * UpVec_p[1] - FrontVecON_p[1] * UpVec_p[0];
161 :
162 4087340 : TDREND_SPATIAL_VecNormalize( RightVecON_p, RightVecON_p );
163 :
164 : /* Evaluate the orthonormal up vector */
165 : /* through the cross product of the front and the right vectors */
166 4087340 : UpVecON_p[0] = RightVecON_p[1] * FrontVecON_p[2] - RightVecON_p[2] * FrontVecON_p[1];
167 4087340 : UpVecON_p[1] = RightVecON_p[2] * FrontVecON_p[0] - RightVecON_p[0] * FrontVecON_p[2];
168 4087340 : UpVecON_p[2] = RightVecON_p[0] * FrontVecON_p[1] - RightVecON_p[1] * FrontVecON_p[0];
169 :
170 4087340 : TDREND_SPATIAL_VecNormalize( UpVecON_p, UpVecON_p );
171 :
172 : /* Check if vectors have been changed */
173 4087340 : if ( FrontVecON_p[0] != tmp[0] || FrontVecON_p[1] != tmp[1] || FrontVecON_p[2] != tmp[2] ||
174 2940026 : RightVecON_p[0] != tmp[3] || RightVecON_p[1] != tmp[4] || RightVecON_p[2] != tmp[5] ||
175 2940026 : UpVecON_p[0] != tmp[6] || UpVecON_p[1] != tmp[7] || UpVecON_p[2] != tmp[8] )
176 : {
177 1147314 : orientation_updated = TRUE;
178 : }
179 :
180 4087340 : return orientation_updated;
181 : }
|