OLD | NEW |
1 /*********************************************************************** | 1 /*********************************************************************** |
2 Copyright (c) 2006-2011, Skype Limited. All rights reserved. | 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved. |
3 Redistribution and use in source and binary forms, with or without | 3 Redistribution and use in source and binary forms, with or without |
4 modification, are permitted provided that the following conditions | 4 modification, are permitted provided that the following conditions |
5 are met: | 5 are met: |
6 - Redistributions of source code must retain the above copyright notice, | 6 - Redistributions of source code must retain the above copyright notice, |
7 this list of conditions and the following disclaimer. | 7 this list of conditions and the following disclaimer. |
8 - Redistributions in binary form must reproduce the above copyright | 8 - Redistributions in binary form must reproduce the above copyright |
9 notice, this list of conditions and the following disclaimer in the | 9 notice, this list of conditions and the following disclaimer in the |
10 documentation and/or other materials provided with the distribution. | 10 documentation and/or other materials provided with the distribution. |
11 - Neither the name of Internet Society, IETF or IETF Trust, nor the | 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the |
12 names of specific contributors, may be used to endorse or promote | 12 names of specific contributors, may be used to endorse or promote |
13 products derived from this software without specific prior written | 13 products derived from this software without specific prior written |
14 permission. | 14 permission. |
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25 POSSIBILITY OF SUCH DAMAGE. | 25 POSSIBILITY OF SUCH DAMAGE. |
26 ***********************************************************************/ | 26 ***********************************************************************/ |
27 | 27 |
28 /*! \file silk_Inlines.h | 28 /*! \file silk_Inlines.h |
29 * \brief silk_Inlines.h defines inline signal processing functions. | 29 * \brief silk_Inlines.h defines OPUS_INLINE signal processing functions. |
30 */ | 30 */ |
31 | 31 |
32 #ifndef SILK_FIX_INLINES_H | 32 #ifndef SILK_FIX_INLINES_H |
33 #define SILK_FIX_INLINES_H | 33 #define SILK_FIX_INLINES_H |
34 | 34 |
35 #ifdef __cplusplus | 35 #ifdef __cplusplus |
36 extern "C" | 36 extern "C" |
37 { | 37 { |
38 #endif | 38 #endif |
39 | 39 |
40 /* count leading zeros of opus_int64 */ | 40 /* count leading zeros of opus_int64 */ |
41 static inline opus_int32 silk_CLZ64( opus_int64 in ) | 41 static OPUS_INLINE opus_int32 silk_CLZ64( opus_int64 in ) |
42 { | 42 { |
43 opus_int32 in_upper; | 43 opus_int32 in_upper; |
44 | 44 |
45 in_upper = (opus_int32)silk_RSHIFT64(in, 32); | 45 in_upper = (opus_int32)silk_RSHIFT64(in, 32); |
46 if (in_upper == 0) { | 46 if (in_upper == 0) { |
47 /* Search in the lower 32 bits */ | 47 /* Search in the lower 32 bits */ |
48 return 32 + silk_CLZ32( (opus_int32) in ); | 48 return 32 + silk_CLZ32( (opus_int32) in ); |
49 } else { | 49 } else { |
50 /* Search in the upper 32 bits */ | 50 /* Search in the upper 32 bits */ |
51 return silk_CLZ32( in_upper ); | 51 return silk_CLZ32( in_upper ); |
52 } | 52 } |
53 } | 53 } |
54 | 54 |
55 /* get number of leading zeros and fractional part (the bits right after the lea
ding one */ | 55 /* get number of leading zeros and fractional part (the bits right after the lea
ding one */ |
56 static inline void silk_CLZ_FRAC( | 56 static OPUS_INLINE void silk_CLZ_FRAC( |
57 opus_int32 in, /* I input */ | 57 opus_int32 in, /* I input */ |
58 opus_int32 *lz, /* O number of leading zeros */ | 58 opus_int32 *lz, /* O number of leading zeros */ |
59 opus_int32 *frac_Q7 /* O the 7 bits right after the leading one */ | 59 opus_int32 *frac_Q7 /* O the 7 bits right after the leading one */ |
60 ) | 60 ) |
61 { | 61 { |
62 opus_int32 lzeros = silk_CLZ32(in); | 62 opus_int32 lzeros = silk_CLZ32(in); |
63 | 63 |
64 * lz = lzeros; | 64 * lz = lzeros; |
65 * frac_Q7 = silk_ROR32(in, 24 - lzeros) & 0x7f; | 65 * frac_Q7 = silk_ROR32(in, 24 - lzeros) & 0x7f; |
66 } | 66 } |
67 | 67 |
68 /* Approximation of square root */ | 68 /* Approximation of square root */ |
69 /* Accuracy: < +/- 10% for output values > 15 */ | 69 /* Accuracy: < +/- 10% for output values > 15 */ |
70 /* < +/- 2.5% for output values > 120 */ | 70 /* < +/- 2.5% for output values > 120 */ |
71 static inline opus_int32 silk_SQRT_APPROX( opus_int32 x ) | 71 static OPUS_INLINE opus_int32 silk_SQRT_APPROX( opus_int32 x ) |
72 { | 72 { |
73 opus_int32 y, lz, frac_Q7; | 73 opus_int32 y, lz, frac_Q7; |
74 | 74 |
75 if( x <= 0 ) { | 75 if( x <= 0 ) { |
76 return 0; | 76 return 0; |
77 } | 77 } |
78 | 78 |
79 silk_CLZ_FRAC(x, &lz, &frac_Q7); | 79 silk_CLZ_FRAC(x, &lz, &frac_Q7); |
80 | 80 |
81 if( lz & 1 ) { | 81 if( lz & 1 ) { |
82 y = 32768; | 82 y = 32768; |
83 } else { | 83 } else { |
84 y = 46214; /* 46214 = sqrt(2) * 32768 */ | 84 y = 46214; /* 46214 = sqrt(2) * 32768 */ |
85 } | 85 } |
86 | 86 |
87 /* get scaling right */ | 87 /* get scaling right */ |
88 y >>= silk_RSHIFT(lz, 1); | 88 y >>= silk_RSHIFT(lz, 1); |
89 | 89 |
90 /* increment using fractional part of input */ | 90 /* increment using fractional part of input */ |
91 y = silk_SMLAWB(y, y, silk_SMULBB(213, frac_Q7)); | 91 y = silk_SMLAWB(y, y, silk_SMULBB(213, frac_Q7)); |
92 | 92 |
93 return y; | 93 return y; |
94 } | 94 } |
95 | 95 |
96 /* Divide two int32 values and return result as int32 in a given Q-domain */ | 96 /* Divide two int32 values and return result as int32 in a given Q-domain */ |
97 static inline opus_int32 silk_DIV32_varQ( /* O returns a good approximation
of "(a32 << Qres) / b32" */ | 97 static OPUS_INLINE opus_int32 silk_DIV32_varQ( /* O returns a good approxim
ation of "(a32 << Qres) / b32" */ |
98 const opus_int32 a32, /* I numerator (Q0)
*/ | 98 const opus_int32 a32, /* I numerator (Q0)
*/ |
99 const opus_int32 b32, /* I denominator (Q0)
*/ | 99 const opus_int32 b32, /* I denominator (Q0)
*/ |
100 const opus_int Qres /* I Q-domain of result (>= 0)
*/ | 100 const opus_int Qres /* I Q-domain of result (>= 0)
*/ |
101 ) | 101 ) |
102 { | 102 { |
103 opus_int a_headrm, b_headrm, lshift; | 103 opus_int a_headrm, b_headrm, lshift; |
104 opus_int32 b32_inv, a32_nrm, b32_nrm, result; | 104 opus_int32 b32_inv, a32_nrm, b32_nrm, result; |
105 | 105 |
106 silk_assert( b32 != 0 ); | 106 silk_assert( b32 != 0 ); |
107 silk_assert( Qres >= 0 ); | 107 silk_assert( Qres >= 0 ); |
(...skipping 25 matching lines...) Expand all Loading... |
133 if( lshift < 32){ | 133 if( lshift < 32){ |
134 return silk_RSHIFT(result, lshift); | 134 return silk_RSHIFT(result, lshift); |
135 } else { | 135 } else { |
136 /* Avoid undefined result */ | 136 /* Avoid undefined result */ |
137 return 0; | 137 return 0; |
138 } | 138 } |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 /* Invert int32 value and return result as int32 in a given Q-domain */ | 142 /* Invert int32 value and return result as int32 in a given Q-domain */ |
143 static inline opus_int32 silk_INVERSE32_varQ( /* O returns a good approxima
tion of "(1 << Qres) / b32" */ | 143 static OPUS_INLINE opus_int32 silk_INVERSE32_varQ( /* O returns a good appr
oximation of "(1 << Qres) / b32" */ |
144 const opus_int32 b32, /* I denominator (Q0)
*/ | 144 const opus_int32 b32, /* I denominator (Q0)
*/ |
145 const opus_int Qres /* I Q-domain of result (> 0)
*/ | 145 const opus_int Qres /* I Q-domain of result (> 0)
*/ |
146 ) | 146 ) |
147 { | 147 { |
148 opus_int b_headrm, lshift; | 148 opus_int b_headrm, lshift; |
149 opus_int32 b32_inv, b32_nrm, err_Q32, result; | 149 opus_int32 b32_inv, b32_nrm, err_Q32, result; |
150 | 150 |
151 silk_assert( b32 != 0 ); | 151 silk_assert( b32 != 0 ); |
152 silk_assert( Qres > 0 ); | 152 silk_assert( Qres > 0 ); |
153 | 153 |
(...skipping 25 matching lines...) Expand all Loading... |
179 return 0; | 179 return 0; |
180 } | 180 } |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
184 #ifdef __cplusplus | 184 #ifdef __cplusplus |
185 } | 185 } |
186 #endif | 186 #endif |
187 | 187 |
188 #endif /* SILK_FIX_INLINES_H */ | 188 #endif /* SILK_FIX_INLINES_H */ |
OLD | NEW |