cannam@154
|
1 /***********************************************************************
|
cannam@154
|
2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
|
cannam@154
|
3 Redistribution and use in source and binary forms, with or without
|
cannam@154
|
4 modification, are permitted provided that the following conditions
|
cannam@154
|
5 are met:
|
cannam@154
|
6 - Redistributions of source code must retain the above copyright notice,
|
cannam@154
|
7 this list of conditions and the following disclaimer.
|
cannam@154
|
8 - Redistributions in binary form must reproduce the above copyright
|
cannam@154
|
9 notice, this list of conditions and the following disclaimer in the
|
cannam@154
|
10 documentation and/or other materials provided with the distribution.
|
cannam@154
|
11 - Neither the name of Internet Society, IETF or IETF Trust, nor the
|
cannam@154
|
12 names of specific contributors, may be used to endorse or promote
|
cannam@154
|
13 products derived from this software without specific prior written
|
cannam@154
|
14 permission.
|
cannam@154
|
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
cannam@154
|
16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
cannam@154
|
17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
cannam@154
|
18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
cannam@154
|
19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
cannam@154
|
20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
cannam@154
|
21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
cannam@154
|
22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
cannam@154
|
23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
cannam@154
|
24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
cannam@154
|
25 POSSIBILITY OF SUCH DAMAGE.
|
cannam@154
|
26 ***********************************************************************/
|
cannam@154
|
27
|
cannam@154
|
28 #ifndef SILK_SIGPROC_FLP_H
|
cannam@154
|
29 #define SILK_SIGPROC_FLP_H
|
cannam@154
|
30
|
cannam@154
|
31 #include "SigProc_FIX.h"
|
cannam@154
|
32 #include "float_cast.h"
|
cannam@154
|
33 #include <math.h>
|
cannam@154
|
34
|
cannam@154
|
35 #ifdef __cplusplus
|
cannam@154
|
36 extern "C"
|
cannam@154
|
37 {
|
cannam@154
|
38 #endif
|
cannam@154
|
39
|
cannam@154
|
40 /********************************************************************/
|
cannam@154
|
41 /* SIGNAL PROCESSING FUNCTIONS */
|
cannam@154
|
42 /********************************************************************/
|
cannam@154
|
43
|
cannam@154
|
44 /* Chirp (bw expand) LP AR filter */
|
cannam@154
|
45 void silk_bwexpander_FLP(
|
cannam@154
|
46 silk_float *ar, /* I/O AR filter to be expanded (without leading 1) */
|
cannam@154
|
47 const opus_int d, /* I length of ar */
|
cannam@154
|
48 const silk_float chirp /* I chirp factor (typically in range (0..1) ) */
|
cannam@154
|
49 );
|
cannam@154
|
50
|
cannam@154
|
51 /* compute inverse of LPC prediction gain, and */
|
cannam@154
|
52 /* test if LPC coefficients are stable (all poles within unit circle) */
|
cannam@154
|
53 /* this code is based on silk_FLP_a2k() */
|
cannam@154
|
54 silk_float silk_LPC_inverse_pred_gain_FLP( /* O return inverse prediction gain, energy domain */
|
cannam@154
|
55 const silk_float *A, /* I prediction coefficients [order] */
|
cannam@154
|
56 opus_int32 order /* I prediction order */
|
cannam@154
|
57 );
|
cannam@154
|
58
|
cannam@154
|
59 silk_float silk_schur_FLP( /* O returns residual energy */
|
cannam@154
|
60 silk_float refl_coef[], /* O reflection coefficients (length order) */
|
cannam@154
|
61 const silk_float auto_corr[], /* I autocorrelation sequence (length order+1) */
|
cannam@154
|
62 opus_int order /* I order */
|
cannam@154
|
63 );
|
cannam@154
|
64
|
cannam@154
|
65 void silk_k2a_FLP(
|
cannam@154
|
66 silk_float *A, /* O prediction coefficients [order] */
|
cannam@154
|
67 const silk_float *rc, /* I reflection coefficients [order] */
|
cannam@154
|
68 opus_int32 order /* I prediction order */
|
cannam@154
|
69 );
|
cannam@154
|
70
|
cannam@154
|
71 /* compute autocorrelation */
|
cannam@154
|
72 void silk_autocorrelation_FLP(
|
cannam@154
|
73 silk_float *results, /* O result (length correlationCount) */
|
cannam@154
|
74 const silk_float *inputData, /* I input data to correlate */
|
cannam@154
|
75 opus_int inputDataSize, /* I length of input */
|
cannam@154
|
76 opus_int correlationCount /* I number of correlation taps to compute */
|
cannam@154
|
77 );
|
cannam@154
|
78
|
cannam@154
|
79 opus_int silk_pitch_analysis_core_FLP( /* O Voicing estimate: 0 voiced, 1 unvoiced */
|
cannam@154
|
80 const silk_float *frame, /* I Signal of length PE_FRAME_LENGTH_MS*Fs_kHz */
|
cannam@154
|
81 opus_int *pitch_out, /* O Pitch lag values [nb_subfr] */
|
cannam@154
|
82 opus_int16 *lagIndex, /* O Lag Index */
|
cannam@154
|
83 opus_int8 *contourIndex, /* O Pitch contour Index */
|
cannam@154
|
84 silk_float *LTPCorr, /* I/O Normalized correlation; input: value from previous frame */
|
cannam@154
|
85 opus_int prevLag, /* I Last lag of previous frame; set to zero is unvoiced */
|
cannam@154
|
86 const silk_float search_thres1, /* I First stage threshold for lag candidates 0 - 1 */
|
cannam@154
|
87 const silk_float search_thres2, /* I Final threshold for lag candidates 0 - 1 */
|
cannam@154
|
88 const opus_int Fs_kHz, /* I sample frequency (kHz) */
|
cannam@154
|
89 const opus_int complexity, /* I Complexity setting, 0-2, where 2 is highest */
|
cannam@154
|
90 const opus_int nb_subfr, /* I Number of 5 ms subframes */
|
cannam@154
|
91 int arch /* I Run-time architecture */
|
cannam@154
|
92 );
|
cannam@154
|
93
|
cannam@154
|
94 void silk_insertion_sort_decreasing_FLP(
|
cannam@154
|
95 silk_float *a, /* I/O Unsorted / Sorted vector */
|
cannam@154
|
96 opus_int *idx, /* O Index vector for the sorted elements */
|
cannam@154
|
97 const opus_int L, /* I Vector length */
|
cannam@154
|
98 const opus_int K /* I Number of correctly sorted positions */
|
cannam@154
|
99 );
|
cannam@154
|
100
|
cannam@154
|
101 /* Compute reflection coefficients from input signal */
|
cannam@154
|
102 silk_float silk_burg_modified_FLP( /* O returns residual energy */
|
cannam@154
|
103 silk_float A[], /* O prediction coefficients (length order) */
|
cannam@154
|
104 const silk_float x[], /* I input signal, length: nb_subfr*(D+L_sub) */
|
cannam@154
|
105 const silk_float minInvGain, /* I minimum inverse prediction gain */
|
cannam@154
|
106 const opus_int subfr_length, /* I input signal subframe length (incl. D preceding samples) */
|
cannam@154
|
107 const opus_int nb_subfr, /* I number of subframes stacked in x */
|
cannam@154
|
108 const opus_int D /* I order */
|
cannam@154
|
109 );
|
cannam@154
|
110
|
cannam@154
|
111 /* multiply a vector by a constant */
|
cannam@154
|
112 void silk_scale_vector_FLP(
|
cannam@154
|
113 silk_float *data1,
|
cannam@154
|
114 silk_float gain,
|
cannam@154
|
115 opus_int dataSize
|
cannam@154
|
116 );
|
cannam@154
|
117
|
cannam@154
|
118 /* copy and multiply a vector by a constant */
|
cannam@154
|
119 void silk_scale_copy_vector_FLP(
|
cannam@154
|
120 silk_float *data_out,
|
cannam@154
|
121 const silk_float *data_in,
|
cannam@154
|
122 silk_float gain,
|
cannam@154
|
123 opus_int dataSize
|
cannam@154
|
124 );
|
cannam@154
|
125
|
cannam@154
|
126 /* inner product of two silk_float arrays, with result as double */
|
cannam@154
|
127 double silk_inner_product_FLP(
|
cannam@154
|
128 const silk_float *data1,
|
cannam@154
|
129 const silk_float *data2,
|
cannam@154
|
130 opus_int dataSize
|
cannam@154
|
131 );
|
cannam@154
|
132
|
cannam@154
|
133 /* sum of squares of a silk_float array, with result as double */
|
cannam@154
|
134 double silk_energy_FLP(
|
cannam@154
|
135 const silk_float *data,
|
cannam@154
|
136 opus_int dataSize
|
cannam@154
|
137 );
|
cannam@154
|
138
|
cannam@154
|
139 /********************************************************************/
|
cannam@154
|
140 /* MACROS */
|
cannam@154
|
141 /********************************************************************/
|
cannam@154
|
142
|
cannam@154
|
143 #define PI (3.1415926536f)
|
cannam@154
|
144
|
cannam@154
|
145 #define silk_min_float( a, b ) (((a) < (b)) ? (a) : (b))
|
cannam@154
|
146 #define silk_max_float( a, b ) (((a) > (b)) ? (a) : (b))
|
cannam@154
|
147 #define silk_abs_float( a ) ((silk_float)fabs(a))
|
cannam@154
|
148
|
cannam@154
|
149 /* sigmoid function */
|
cannam@154
|
150 static OPUS_INLINE silk_float silk_sigmoid( silk_float x )
|
cannam@154
|
151 {
|
cannam@154
|
152 return (silk_float)(1.0 / (1.0 + exp(-x)));
|
cannam@154
|
153 }
|
cannam@154
|
154
|
cannam@154
|
155 /* floating-point to integer conversion (rounding) */
|
cannam@154
|
156 static OPUS_INLINE opus_int32 silk_float2int( silk_float x )
|
cannam@154
|
157 {
|
cannam@154
|
158 return (opus_int32)float2int( x );
|
cannam@154
|
159 }
|
cannam@154
|
160
|
cannam@154
|
161 /* floating-point to integer conversion (rounding) */
|
cannam@154
|
162 static OPUS_INLINE void silk_float2short_array(
|
cannam@154
|
163 opus_int16 *out,
|
cannam@154
|
164 const silk_float *in,
|
cannam@154
|
165 opus_int32 length
|
cannam@154
|
166 )
|
cannam@154
|
167 {
|
cannam@154
|
168 opus_int32 k;
|
cannam@154
|
169 for( k = length - 1; k >= 0; k-- ) {
|
cannam@154
|
170 out[k] = silk_SAT16( (opus_int32)float2int( in[k] ) );
|
cannam@154
|
171 }
|
cannam@154
|
172 }
|
cannam@154
|
173
|
cannam@154
|
174 /* integer to floating-point conversion */
|
cannam@154
|
175 static OPUS_INLINE void silk_short2float_array(
|
cannam@154
|
176 silk_float *out,
|
cannam@154
|
177 const opus_int16 *in,
|
cannam@154
|
178 opus_int32 length
|
cannam@154
|
179 )
|
cannam@154
|
180 {
|
cannam@154
|
181 opus_int32 k;
|
cannam@154
|
182 for( k = length - 1; k >= 0; k-- ) {
|
cannam@154
|
183 out[k] = (silk_float)in[k];
|
cannam@154
|
184 }
|
cannam@154
|
185 }
|
cannam@154
|
186
|
cannam@154
|
187 /* using log2() helps the fixed-point conversion */
|
cannam@154
|
188 static OPUS_INLINE silk_float silk_log2( double x )
|
cannam@154
|
189 {
|
cannam@154
|
190 return ( silk_float )( 3.32192809488736 * log10( x ) );
|
cannam@154
|
191 }
|
cannam@154
|
192
|
cannam@154
|
193 #ifdef __cplusplus
|
cannam@154
|
194 }
|
cannam@154
|
195 #endif
|
cannam@154
|
196
|
cannam@154
|
197 #endif /* SILK_SIGPROC_FLP_H */
|