• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef bbs_PHASE_EM_H
18 #define bbs_PHASE_EM_H
19 
20 /* ---- includes ----------------------------------------------------------- */
21 
22 /**
23  * Phase data type.
24  * This data type represents a phase or angle value and takes advantage
25  * of the circular value range when doing arithmetig with an integer
26  * by ignoring overflow.
27  * The phase value range lies within [ - PI, PI [;
28  * The corresponding integer value range is [ MININT, MAXINT + 1 [.
29  * The phase data type is to be used whereever an angle is needed.
30  */
31 
32 #include "b_BasicEm/Basic.h"
33 
34 /* ---- related objects  --------------------------------------------------- */
35 
36 /* ---- typedefs ----------------------------------------------------------- */
37 
38 /** 8 bit phase value */
39 typedef int8 phase8;
40 
41 /** 16 bit phase value */
42 typedef int16 phase16;
43 
44 /** 32 bit phase value */
45 typedef int32 phase32;
46 
47 /* ---- constants ---------------------------------------------------------- */
48 
49 /** value PI in a phase16 expression */
50 #define bbs_M_PI_16 32768
51 
52 /** value PI/2 in a phase16 expression */
53 #define bbs_M_PI_2_16 16384
54 
55 /** value PI/4 in a phase16 expression */
56 #define bbs_M_PI_4_16 8192
57 
58 /** value PI in a phase8 expression */
59 #define bbs_M_PI_8 128
60 
61 /** value PI/2 in a phase8 expression */
62 #define bbs_M_PI_2_8 64
63 
64 /** value ( 32768 / PI ) in the format 14.1 */
65 #define bbs_PHASE_MAX_BY_PI 20861
66 
67 /** sine interpolation method */
68 #define bbs_SIN_INTERPOLATION_METHOD_2
69 
70 /* ---- object definition -------------------------------------------------- */
71 
72 /* ---- associated objects ------------------------------------------------- */
73 
74 /* ---- external functions ------------------------------------------------- */
75 
76 /* ---- \ghd{ constructor/destructor } ------------------------------------- */
77 
78 /* ---- \ghd{ operators } -------------------------------------------------- */
79 
80 /* ---- \ghd{ query functions } -------------------------------------------- */
81 
82 /**
83  * Computes sine of a phase
84  * The return value has the format 8.24
85  * The function approximates ( int32 )( sin( ( M_PI * phaseA ) / ( 1<<15 ) ) * ( 1<<24 ) )
86  * Max error: 8.5E-5 (METHOD1); 7.0E-5 (METHOD2)
87  * Std error: 4.4E-5 (METHOD1); 3.2E-5 (METHOD2)
88  */
89 int32 bbs_sin32( phase16 phaseA );
90 
91 /**
92  * Computes cosine of a phase
93  * The return value has the format 8.24
94  * The function approximates ( int32 )( cos( ( M_PI * phaseA ) / ( 1<<15 ) ) * ( 1<<24 ) )
95  * Max error: 8.5E-5 (METHOD1); 7.0E-5 (METHOD2)
96  * Std error: 4.4E-5 (METHOD1); 3.2E-5 (METHOD2)
97  */
98 int32 bbs_cos32( phase16 phaseA );
99 
100 /**
101  * Computes sine of a phase
102  * The return value has the format 2.14
103  * see sin32 for details
104  */
105 int16 bbs_sin16( phase16 phaseA );
106 
107 /**
108  * Computes cosine of a phase
109  * The return value has the format 2.14
110  * see cos32 for details
111  */
112 int16 bbs_cos16( phase16 phaseA );
113 
114 /**
115  * Computes arcus tangens between [0,1[, where valA has the format 16.16
116  * The function approximates ( int16 )( atan( double( valA ) / ( ( 1 << 16 ) ) / M_PI ) * ( 1 << 15 ) )
117  * Max error: 5.1E-5 PI
118  * Std error: 2.7E-5 PI
119  */
120 phase16 bbs_atan16( uint32 valA );
121 
122 /**
123  * Computes phase from a 2d vector as angle enclosed between vector and (0,0).
124  * It is vec = ( cos( angle ), sin( angle ) );
125  * Max error: 5.4E-5 PI
126  * Std error: 2.9E-5 PI
127  */
128 phase16 bbs_phase16( int32 xA, int32 yA );
129 
130 /* ---- \ghd{ modify functions } ------------------------------------------- */
131 
132 /* ---- \ghd{ memory I/O } ------------------------------------------------- */
133 
134 /* ---- \ghd{ exec functions } --------------------------------------------- */
135 
136 #endif /* bbs_PHASE_EM_H */
137 
138