summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/codecs/aacdec/pv_sine.cpp
blob: 54319b1220c016e902c24fa9b24de91a2bbb942c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* ------------------------------------------------------------------
 * Copyright (C) 1998-2009 PacketVideo
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 * -------------------------------------------------------------------
 */
/*

 Filename: pv_sine.c

------------------------------------------------------------------------------
 REVISION HISTORY


 Who:                                   Date: MM/DD/YYYY
 Description:

------------------------------------------------------------------------------
 INPUT AND OUTPUT DEFINITIONS

    Int32 x             32-bit integer angle (in Q30) between 0 and pi/2


------------------------------------------------------------------------------
 FUNCTION DESCRIPTION

    Find the sine of a number between 0 and pi/2
------------------------------------------------------------------------------
 REQUIREMENTS


------------------------------------------------------------------------------
 REFERENCES

------------------------------------------------------------------------------
 PSEUDO-CODE

------------------------------------------------------------------------------
*/


/*----------------------------------------------------------------------------
; INCLUDES
----------------------------------------------------------------------------*/

#ifdef AAC_PLUS

#ifdef PARAMETRICSTEREO

#include "pv_audio_type_defs.h"
#include "fxp_mul32.h"
#include "pv_sine.h"

/*----------------------------------------------------------------------------
; MACROS
; Define module specific macros here
----------------------------------------------------------------------------*/


/*----------------------------------------------------------------------------
; DEFINES
; Include all pre-processor statements here. Include conditional
; compile variables also.
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
; LOCAL FUNCTION DEFINITIONS
; Function Prototype declaration
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
; Variable declaration - defined here and used outside this module
----------------------------------------------------------------------------*/

#define R_SHIFT     30

#define Q_fmt(x)   (Int32)(x*((Int32)1<<R_SHIFT) + (x>=0?0.5F:-0.5F))

const Int32 sin_table[9] =
{
    Q_fmt(0.00001724684028), Q_fmt(-0.00024606242846),
    Q_fmt(0.00007297328923), Q_fmt(0.00826706596417),
    Q_fmt(0.00003585160465), Q_fmt(-0.16667772526248),
    Q_fmt(0.00000174197440), Q_fmt(0.99999989138797),
    Q_fmt(0.00000000110513)
};


/*----------------------------------------------------------------------------
; EXTERNAL FUNCTION REFERENCES
; Declare functions defined elsewhere and referenced in this module
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
; Declare variables used in this module but defined elsewhere
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
; FUNCTION CODE
----------------------------------------------------------------------------*/


Int32 pv_sine(Int32 z)
{
    Int32 sine;
    Int32 i;
    const Int32 *pt_table = sin_table;
    Int32 sign = 0;

    if (z < 0)
    {
        z = -z;
        sign = 1;
    }

    if (z > Q_fmt(0.0015))
    {
        sine  = fxp_mul32_Q30(*(pt_table++), z);

        for (i = 7; i != 0; i--)
        {
            sine += *(pt_table++);
            sine  = fxp_mul32_Q30(sine, z);
        }

    }
    else
    {
        sine = z;  /*  better approximation in this range */
    }

    if (sign)
    {
        sine = -sine;
    }

    return sine;
}



Int32 pv_cosine(Int32 z)
{
    Int32 cosine;

    if (z < 0)
    {
        z = -z;     /* sign does not play a role in cosine */
    }

    if (z > Q_fmt(0.0015))
    {
        z = Q_fmt(1.57079632679490) - z;   /* pi/2 - z */

        cosine  = pv_sine(z);
    }
    else
    {   /*  better approximation in this range  */
        cosine = Q_fmt(0.99999999906868) - (fxp_mul32_Q30(z, z) >> 1);
    }

    return cosine;
}

#endif

#endif