diff options
Diffstat (limited to 'lib/rbcodec/codecs/libopus/silk/float')
31 files changed, 4322 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libopus/silk/float/LPC_analysis_filter_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/LPC_analysis_filter_FLP.c new file mode 100644 index 0000000000..0e1a1fed0f --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/LPC_analysis_filter_FLP.c | |||
@@ -0,0 +1,249 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include <stdlib.h> | ||
33 | #include "main_FLP.h" | ||
34 | |||
35 | /************************************************/ | ||
36 | /* LPC analysis filter */ | ||
37 | /* NB! State is kept internally and the */ | ||
38 | /* filter always starts with zero state */ | ||
39 | /* first Order output samples are set to zero */ | ||
40 | /************************************************/ | ||
41 | |||
42 | /* 16th order LPC analysis filter, does not write first 16 samples */ | ||
43 | static OPUS_INLINE void silk_LPC_analysis_filter16_FLP( | ||
44 | silk_float r_LPC[], /* O LPC residual signal */ | ||
45 | const silk_float PredCoef[], /* I LPC coefficients */ | ||
46 | const silk_float s[], /* I Input signal */ | ||
47 | const opus_int length /* I Length of input signal */ | ||
48 | ) | ||
49 | { | ||
50 | opus_int ix; | ||
51 | silk_float LPC_pred; | ||
52 | const silk_float *s_ptr; | ||
53 | |||
54 | for( ix = 16; ix < length; ix++ ) { | ||
55 | s_ptr = &s[ix - 1]; | ||
56 | |||
57 | /* short-term prediction */ | ||
58 | LPC_pred = s_ptr[ 0 ] * PredCoef[ 0 ] + | ||
59 | s_ptr[ -1 ] * PredCoef[ 1 ] + | ||
60 | s_ptr[ -2 ] * PredCoef[ 2 ] + | ||
61 | s_ptr[ -3 ] * PredCoef[ 3 ] + | ||
62 | s_ptr[ -4 ] * PredCoef[ 4 ] + | ||
63 | s_ptr[ -5 ] * PredCoef[ 5 ] + | ||
64 | s_ptr[ -6 ] * PredCoef[ 6 ] + | ||
65 | s_ptr[ -7 ] * PredCoef[ 7 ] + | ||
66 | s_ptr[ -8 ] * PredCoef[ 8 ] + | ||
67 | s_ptr[ -9 ] * PredCoef[ 9 ] + | ||
68 | s_ptr[ -10 ] * PredCoef[ 10 ] + | ||
69 | s_ptr[ -11 ] * PredCoef[ 11 ] + | ||
70 | s_ptr[ -12 ] * PredCoef[ 12 ] + | ||
71 | s_ptr[ -13 ] * PredCoef[ 13 ] + | ||
72 | s_ptr[ -14 ] * PredCoef[ 14 ] + | ||
73 | s_ptr[ -15 ] * PredCoef[ 15 ]; | ||
74 | |||
75 | /* prediction error */ | ||
76 | r_LPC[ix] = s_ptr[ 1 ] - LPC_pred; | ||
77 | } | ||
78 | } | ||
79 | |||
80 | /* 12th order LPC analysis filter, does not write first 12 samples */ | ||
81 | static OPUS_INLINE void silk_LPC_analysis_filter12_FLP( | ||
82 | silk_float r_LPC[], /* O LPC residual signal */ | ||
83 | const silk_float PredCoef[], /* I LPC coefficients */ | ||
84 | const silk_float s[], /* I Input signal */ | ||
85 | const opus_int length /* I Length of input signal */ | ||
86 | ) | ||
87 | { | ||
88 | opus_int ix; | ||
89 | silk_float LPC_pred; | ||
90 | const silk_float *s_ptr; | ||
91 | |||
92 | for( ix = 12; ix < length; ix++ ) { | ||
93 | s_ptr = &s[ix - 1]; | ||
94 | |||
95 | /* short-term prediction */ | ||
96 | LPC_pred = s_ptr[ 0 ] * PredCoef[ 0 ] + | ||
97 | s_ptr[ -1 ] * PredCoef[ 1 ] + | ||
98 | s_ptr[ -2 ] * PredCoef[ 2 ] + | ||
99 | s_ptr[ -3 ] * PredCoef[ 3 ] + | ||
100 | s_ptr[ -4 ] * PredCoef[ 4 ] + | ||
101 | s_ptr[ -5 ] * PredCoef[ 5 ] + | ||
102 | s_ptr[ -6 ] * PredCoef[ 6 ] + | ||
103 | s_ptr[ -7 ] * PredCoef[ 7 ] + | ||
104 | s_ptr[ -8 ] * PredCoef[ 8 ] + | ||
105 | s_ptr[ -9 ] * PredCoef[ 9 ] + | ||
106 | s_ptr[ -10 ] * PredCoef[ 10 ] + | ||
107 | s_ptr[ -11 ] * PredCoef[ 11 ]; | ||
108 | |||
109 | /* prediction error */ | ||
110 | r_LPC[ix] = s_ptr[ 1 ] - LPC_pred; | ||
111 | } | ||
112 | } | ||
113 | |||
114 | /* 10th order LPC analysis filter, does not write first 10 samples */ | ||
115 | static OPUS_INLINE void silk_LPC_analysis_filter10_FLP( | ||
116 | silk_float r_LPC[], /* O LPC residual signal */ | ||
117 | const silk_float PredCoef[], /* I LPC coefficients */ | ||
118 | const silk_float s[], /* I Input signal */ | ||
119 | const opus_int length /* I Length of input signal */ | ||
120 | ) | ||
121 | { | ||
122 | opus_int ix; | ||
123 | silk_float LPC_pred; | ||
124 | const silk_float *s_ptr; | ||
125 | |||
126 | for( ix = 10; ix < length; ix++ ) { | ||
127 | s_ptr = &s[ix - 1]; | ||
128 | |||
129 | /* short-term prediction */ | ||
130 | LPC_pred = s_ptr[ 0 ] * PredCoef[ 0 ] + | ||
131 | s_ptr[ -1 ] * PredCoef[ 1 ] + | ||
132 | s_ptr[ -2 ] * PredCoef[ 2 ] + | ||
133 | s_ptr[ -3 ] * PredCoef[ 3 ] + | ||
134 | s_ptr[ -4 ] * PredCoef[ 4 ] + | ||
135 | s_ptr[ -5 ] * PredCoef[ 5 ] + | ||
136 | s_ptr[ -6 ] * PredCoef[ 6 ] + | ||
137 | s_ptr[ -7 ] * PredCoef[ 7 ] + | ||
138 | s_ptr[ -8 ] * PredCoef[ 8 ] + | ||
139 | s_ptr[ -9 ] * PredCoef[ 9 ]; | ||
140 | |||
141 | /* prediction error */ | ||
142 | r_LPC[ix] = s_ptr[ 1 ] - LPC_pred; | ||
143 | } | ||
144 | } | ||
145 | |||
146 | /* 8th order LPC analysis filter, does not write first 8 samples */ | ||
147 | static OPUS_INLINE void silk_LPC_analysis_filter8_FLP( | ||
148 | silk_float r_LPC[], /* O LPC residual signal */ | ||
149 | const silk_float PredCoef[], /* I LPC coefficients */ | ||
150 | const silk_float s[], /* I Input signal */ | ||
151 | const opus_int length /* I Length of input signal */ | ||
152 | ) | ||
153 | { | ||
154 | opus_int ix; | ||
155 | silk_float LPC_pred; | ||
156 | const silk_float *s_ptr; | ||
157 | |||
158 | for( ix = 8; ix < length; ix++ ) { | ||
159 | s_ptr = &s[ix - 1]; | ||
160 | |||
161 | /* short-term prediction */ | ||
162 | LPC_pred = s_ptr[ 0 ] * PredCoef[ 0 ] + | ||
163 | s_ptr[ -1 ] * PredCoef[ 1 ] + | ||
164 | s_ptr[ -2 ] * PredCoef[ 2 ] + | ||
165 | s_ptr[ -3 ] * PredCoef[ 3 ] + | ||
166 | s_ptr[ -4 ] * PredCoef[ 4 ] + | ||
167 | s_ptr[ -5 ] * PredCoef[ 5 ] + | ||
168 | s_ptr[ -6 ] * PredCoef[ 6 ] + | ||
169 | s_ptr[ -7 ] * PredCoef[ 7 ]; | ||
170 | |||
171 | /* prediction error */ | ||
172 | r_LPC[ix] = s_ptr[ 1 ] - LPC_pred; | ||
173 | } | ||
174 | } | ||
175 | |||
176 | /* 6th order LPC analysis filter, does not write first 6 samples */ | ||
177 | static OPUS_INLINE void silk_LPC_analysis_filter6_FLP( | ||
178 | silk_float r_LPC[], /* O LPC residual signal */ | ||
179 | const silk_float PredCoef[], /* I LPC coefficients */ | ||
180 | const silk_float s[], /* I Input signal */ | ||
181 | const opus_int length /* I Length of input signal */ | ||
182 | ) | ||
183 | { | ||
184 | opus_int ix; | ||
185 | silk_float LPC_pred; | ||
186 | const silk_float *s_ptr; | ||
187 | |||
188 | for( ix = 6; ix < length; ix++ ) { | ||
189 | s_ptr = &s[ix - 1]; | ||
190 | |||
191 | /* short-term prediction */ | ||
192 | LPC_pred = s_ptr[ 0 ] * PredCoef[ 0 ] + | ||
193 | s_ptr[ -1 ] * PredCoef[ 1 ] + | ||
194 | s_ptr[ -2 ] * PredCoef[ 2 ] + | ||
195 | s_ptr[ -3 ] * PredCoef[ 3 ] + | ||
196 | s_ptr[ -4 ] * PredCoef[ 4 ] + | ||
197 | s_ptr[ -5 ] * PredCoef[ 5 ]; | ||
198 | |||
199 | /* prediction error */ | ||
200 | r_LPC[ix] = s_ptr[ 1 ] - LPC_pred; | ||
201 | } | ||
202 | } | ||
203 | |||
204 | /************************************************/ | ||
205 | /* LPC analysis filter */ | ||
206 | /* NB! State is kept internally and the */ | ||
207 | /* filter always starts with zero state */ | ||
208 | /* first Order output samples are set to zero */ | ||
209 | /************************************************/ | ||
210 | void silk_LPC_analysis_filter_FLP( | ||
211 | silk_float r_LPC[], /* O LPC residual signal */ | ||
212 | const silk_float PredCoef[], /* I LPC coefficients */ | ||
213 | const silk_float s[], /* I Input signal */ | ||
214 | const opus_int length, /* I Length of input signal */ | ||
215 | const opus_int Order /* I LPC order */ | ||
216 | ) | ||
217 | { | ||
218 | celt_assert( Order <= length ); | ||
219 | |||
220 | switch( Order ) { | ||
221 | case 6: | ||
222 | silk_LPC_analysis_filter6_FLP( r_LPC, PredCoef, s, length ); | ||
223 | break; | ||
224 | |||
225 | case 8: | ||
226 | silk_LPC_analysis_filter8_FLP( r_LPC, PredCoef, s, length ); | ||
227 | break; | ||
228 | |||
229 | case 10: | ||
230 | silk_LPC_analysis_filter10_FLP( r_LPC, PredCoef, s, length ); | ||
231 | break; | ||
232 | |||
233 | case 12: | ||
234 | silk_LPC_analysis_filter12_FLP( r_LPC, PredCoef, s, length ); | ||
235 | break; | ||
236 | |||
237 | case 16: | ||
238 | silk_LPC_analysis_filter16_FLP( r_LPC, PredCoef, s, length ); | ||
239 | break; | ||
240 | |||
241 | default: | ||
242 | celt_assert( 0 ); | ||
243 | break; | ||
244 | } | ||
245 | |||
246 | /* Set first Order output samples to zero */ | ||
247 | silk_memset( r_LPC, 0, Order * sizeof( silk_float ) ); | ||
248 | } | ||
249 | |||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/LPC_inv_pred_gain_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/LPC_inv_pred_gain_FLP.c new file mode 100644 index 0000000000..2be2122d61 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/LPC_inv_pred_gain_FLP.c | |||
@@ -0,0 +1,73 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "SigProc_FIX.h" | ||
33 | #include "SigProc_FLP.h" | ||
34 | #include "define.h" | ||
35 | |||
36 | /* compute inverse of LPC prediction gain, and */ | ||
37 | /* test if LPC coefficients are stable (all poles within unit circle) */ | ||
38 | /* this code is based on silk_a2k_FLP() */ | ||
39 | silk_float silk_LPC_inverse_pred_gain_FLP( /* O return inverse prediction gain, energy domain */ | ||
40 | const silk_float *A, /* I prediction coefficients [order] */ | ||
41 | opus_int32 order /* I prediction order */ | ||
42 | ) | ||
43 | { | ||
44 | opus_int k, n; | ||
45 | double invGain, rc, rc_mult1, rc_mult2, tmp1, tmp2; | ||
46 | silk_float Atmp[ SILK_MAX_ORDER_LPC ]; | ||
47 | |||
48 | silk_memcpy( Atmp, A, order * sizeof(silk_float) ); | ||
49 | |||
50 | invGain = 1.0; | ||
51 | for( k = order - 1; k > 0; k-- ) { | ||
52 | rc = -Atmp[ k ]; | ||
53 | rc_mult1 = 1.0f - rc * rc; | ||
54 | invGain *= rc_mult1; | ||
55 | if( invGain * MAX_PREDICTION_POWER_GAIN < 1.0f ) { | ||
56 | return 0.0f; | ||
57 | } | ||
58 | rc_mult2 = 1.0f / rc_mult1; | ||
59 | for( n = 0; n < (k + 1) >> 1; n++ ) { | ||
60 | tmp1 = Atmp[ n ]; | ||
61 | tmp2 = Atmp[ k - n - 1 ]; | ||
62 | Atmp[ n ] = (silk_float)( ( tmp1 - tmp2 * rc ) * rc_mult2 ); | ||
63 | Atmp[ k - n - 1 ] = (silk_float)( ( tmp2 - tmp1 * rc ) * rc_mult2 ); | ||
64 | } | ||
65 | } | ||
66 | rc = -Atmp[ 0 ]; | ||
67 | rc_mult1 = 1.0f - rc * rc; | ||
68 | invGain *= rc_mult1; | ||
69 | if( invGain * MAX_PREDICTION_POWER_GAIN < 1.0f ) { | ||
70 | return 0.0f; | ||
71 | } | ||
72 | return (silk_float)invGain; | ||
73 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/LTP_analysis_filter_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/LTP_analysis_filter_FLP.c new file mode 100644 index 0000000000..849b7c1c52 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/LTP_analysis_filter_FLP.c | |||
@@ -0,0 +1,75 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "main_FLP.h" | ||
33 | |||
34 | void silk_LTP_analysis_filter_FLP( | ||
35 | silk_float *LTP_res, /* O LTP res MAX_NB_SUBFR*(pre_lgth+subfr_lngth) */ | ||
36 | const silk_float *x, /* I Input signal, with preceding samples */ | ||
37 | const silk_float B[ LTP_ORDER * MAX_NB_SUBFR ], /* I LTP coefficients for each subframe */ | ||
38 | const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */ | ||
39 | const silk_float invGains[ MAX_NB_SUBFR ], /* I Inverse quantization gains */ | ||
40 | const opus_int subfr_length, /* I Length of each subframe */ | ||
41 | const opus_int nb_subfr, /* I number of subframes */ | ||
42 | const opus_int pre_length /* I Preceding samples for each subframe */ | ||
43 | ) | ||
44 | { | ||
45 | const silk_float *x_ptr, *x_lag_ptr; | ||
46 | silk_float Btmp[ LTP_ORDER ]; | ||
47 | silk_float *LTP_res_ptr; | ||
48 | silk_float inv_gain; | ||
49 | opus_int k, i, j; | ||
50 | |||
51 | x_ptr = x; | ||
52 | LTP_res_ptr = LTP_res; | ||
53 | for( k = 0; k < nb_subfr; k++ ) { | ||
54 | x_lag_ptr = x_ptr - pitchL[ k ]; | ||
55 | inv_gain = invGains[ k ]; | ||
56 | for( i = 0; i < LTP_ORDER; i++ ) { | ||
57 | Btmp[ i ] = B[ k * LTP_ORDER + i ]; | ||
58 | } | ||
59 | |||
60 | /* LTP analysis FIR filter */ | ||
61 | for( i = 0; i < subfr_length + pre_length; i++ ) { | ||
62 | LTP_res_ptr[ i ] = x_ptr[ i ]; | ||
63 | /* Subtract long-term prediction */ | ||
64 | for( j = 0; j < LTP_ORDER; j++ ) { | ||
65 | LTP_res_ptr[ i ] -= Btmp[ j ] * x_lag_ptr[ LTP_ORDER / 2 - j ]; | ||
66 | } | ||
67 | LTP_res_ptr[ i ] *= inv_gain; | ||
68 | x_lag_ptr++; | ||
69 | } | ||
70 | |||
71 | /* Update pointers */ | ||
72 | LTP_res_ptr += subfr_length + pre_length; | ||
73 | x_ptr += subfr_length; | ||
74 | } | ||
75 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/LTP_scale_ctrl_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/LTP_scale_ctrl_FLP.c new file mode 100644 index 0000000000..8dbe29d0fa --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/LTP_scale_ctrl_FLP.c | |||
@@ -0,0 +1,52 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "main_FLP.h" | ||
33 | |||
34 | void silk_LTP_scale_ctrl_FLP( | ||
35 | silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ | ||
36 | silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ | ||
37 | opus_int condCoding /* I The type of conditional coding to use */ | ||
38 | ) | ||
39 | { | ||
40 | opus_int round_loss; | ||
41 | |||
42 | if( condCoding == CODE_INDEPENDENTLY ) { | ||
43 | /* Only scale if first frame in packet */ | ||
44 | round_loss = psEnc->sCmn.PacketLoss_perc + psEnc->sCmn.nFramesPerPacket; | ||
45 | psEnc->sCmn.indices.LTP_scaleIndex = (opus_int8)silk_LIMIT( round_loss * psEncCtrl->LTPredCodGain * 0.1f, 0.0f, 2.0f ); | ||
46 | } else { | ||
47 | /* Default is minimum scaling */ | ||
48 | psEnc->sCmn.indices.LTP_scaleIndex = 0; | ||
49 | } | ||
50 | |||
51 | psEncCtrl->LTP_scale = (silk_float)silk_LTPScales_table_Q14[ psEnc->sCmn.indices.LTP_scaleIndex ] / 16384.0f; | ||
52 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/SigProc_FLP.h b/lib/rbcodec/codecs/libopus/silk/float/SigProc_FLP.h new file mode 100644 index 0000000000..953de8b09e --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/SigProc_FLP.h | |||
@@ -0,0 +1,197 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifndef SILK_SIGPROC_FLP_H | ||
29 | #define SILK_SIGPROC_FLP_H | ||
30 | |||
31 | #include "SigProc_FIX.h" | ||
32 | #include "float_cast.h" | ||
33 | #include <math.h> | ||
34 | |||
35 | #ifdef __cplusplus | ||
36 | extern "C" | ||
37 | { | ||
38 | #endif | ||
39 | |||
40 | /********************************************************************/ | ||
41 | /* SIGNAL PROCESSING FUNCTIONS */ | ||
42 | /********************************************************************/ | ||
43 | |||
44 | /* Chirp (bw expand) LP AR filter */ | ||
45 | void silk_bwexpander_FLP( | ||
46 | silk_float *ar, /* I/O AR filter to be expanded (without leading 1) */ | ||
47 | const opus_int d, /* I length of ar */ | ||
48 | const silk_float chirp /* I chirp factor (typically in range (0..1) ) */ | ||
49 | ); | ||
50 | |||
51 | /* compute inverse of LPC prediction gain, and */ | ||
52 | /* test if LPC coefficients are stable (all poles within unit circle) */ | ||
53 | /* this code is based on silk_FLP_a2k() */ | ||
54 | silk_float silk_LPC_inverse_pred_gain_FLP( /* O return inverse prediction gain, energy domain */ | ||
55 | const silk_float *A, /* I prediction coefficients [order] */ | ||
56 | opus_int32 order /* I prediction order */ | ||
57 | ); | ||
58 | |||
59 | silk_float silk_schur_FLP( /* O returns residual energy */ | ||
60 | silk_float refl_coef[], /* O reflection coefficients (length order) */ | ||
61 | const silk_float auto_corr[], /* I autocorrelation sequence (length order+1) */ | ||
62 | opus_int order /* I order */ | ||
63 | ); | ||
64 | |||
65 | void silk_k2a_FLP( | ||
66 | silk_float *A, /* O prediction coefficients [order] */ | ||
67 | const silk_float *rc, /* I reflection coefficients [order] */ | ||
68 | opus_int32 order /* I prediction order */ | ||
69 | ); | ||
70 | |||
71 | /* compute autocorrelation */ | ||
72 | void silk_autocorrelation_FLP( | ||
73 | silk_float *results, /* O result (length correlationCount) */ | ||
74 | const silk_float *inputData, /* I input data to correlate */ | ||
75 | opus_int inputDataSize, /* I length of input */ | ||
76 | opus_int correlationCount /* I number of correlation taps to compute */ | ||
77 | ); | ||
78 | |||
79 | opus_int silk_pitch_analysis_core_FLP( /* O Voicing estimate: 0 voiced, 1 unvoiced */ | ||
80 | const silk_float *frame, /* I Signal of length PE_FRAME_LENGTH_MS*Fs_kHz */ | ||
81 | opus_int *pitch_out, /* O Pitch lag values [nb_subfr] */ | ||
82 | opus_int16 *lagIndex, /* O Lag Index */ | ||
83 | opus_int8 *contourIndex, /* O Pitch contour Index */ | ||
84 | silk_float *LTPCorr, /* I/O Normalized correlation; input: value from previous frame */ | ||
85 | opus_int prevLag, /* I Last lag of previous frame; set to zero is unvoiced */ | ||
86 | const silk_float search_thres1, /* I First stage threshold for lag candidates 0 - 1 */ | ||
87 | const silk_float search_thres2, /* I Final threshold for lag candidates 0 - 1 */ | ||
88 | const opus_int Fs_kHz, /* I sample frequency (kHz) */ | ||
89 | const opus_int complexity, /* I Complexity setting, 0-2, where 2 is highest */ | ||
90 | const opus_int nb_subfr, /* I Number of 5 ms subframes */ | ||
91 | int arch /* I Run-time architecture */ | ||
92 | ); | ||
93 | |||
94 | void silk_insertion_sort_decreasing_FLP( | ||
95 | silk_float *a, /* I/O Unsorted / Sorted vector */ | ||
96 | opus_int *idx, /* O Index vector for the sorted elements */ | ||
97 | const opus_int L, /* I Vector length */ | ||
98 | const opus_int K /* I Number of correctly sorted positions */ | ||
99 | ); | ||
100 | |||
101 | /* Compute reflection coefficients from input signal */ | ||
102 | silk_float silk_burg_modified_FLP( /* O returns residual energy */ | ||
103 | silk_float A[], /* O prediction coefficients (length order) */ | ||
104 | const silk_float x[], /* I input signal, length: nb_subfr*(D+L_sub) */ | ||
105 | const silk_float minInvGain, /* I minimum inverse prediction gain */ | ||
106 | const opus_int subfr_length, /* I input signal subframe length (incl. D preceding samples) */ | ||
107 | const opus_int nb_subfr, /* I number of subframes stacked in x */ | ||
108 | const opus_int D /* I order */ | ||
109 | ); | ||
110 | |||
111 | /* multiply a vector by a constant */ | ||
112 | void silk_scale_vector_FLP( | ||
113 | silk_float *data1, | ||
114 | silk_float gain, | ||
115 | opus_int dataSize | ||
116 | ); | ||
117 | |||
118 | /* copy and multiply a vector by a constant */ | ||
119 | void silk_scale_copy_vector_FLP( | ||
120 | silk_float *data_out, | ||
121 | const silk_float *data_in, | ||
122 | silk_float gain, | ||
123 | opus_int dataSize | ||
124 | ); | ||
125 | |||
126 | /* inner product of two silk_float arrays, with result as double */ | ||
127 | double silk_inner_product_FLP( | ||
128 | const silk_float *data1, | ||
129 | const silk_float *data2, | ||
130 | opus_int dataSize | ||
131 | ); | ||
132 | |||
133 | /* sum of squares of a silk_float array, with result as double */ | ||
134 | double silk_energy_FLP( | ||
135 | const silk_float *data, | ||
136 | opus_int dataSize | ||
137 | ); | ||
138 | |||
139 | /********************************************************************/ | ||
140 | /* MACROS */ | ||
141 | /********************************************************************/ | ||
142 | |||
143 | #define PI (3.1415926536f) | ||
144 | |||
145 | #define silk_min_float( a, b ) (((a) < (b)) ? (a) : (b)) | ||
146 | #define silk_max_float( a, b ) (((a) > (b)) ? (a) : (b)) | ||
147 | #define silk_abs_float( a ) ((silk_float)fabs(a)) | ||
148 | |||
149 | /* sigmoid function */ | ||
150 | static OPUS_INLINE silk_float silk_sigmoid( silk_float x ) | ||
151 | { | ||
152 | return (silk_float)(1.0 / (1.0 + exp(-x))); | ||
153 | } | ||
154 | |||
155 | /* floating-point to integer conversion (rounding) */ | ||
156 | static OPUS_INLINE opus_int32 silk_float2int( silk_float x ) | ||
157 | { | ||
158 | return (opus_int32)float2int( x ); | ||
159 | } | ||
160 | |||
161 | /* floating-point to integer conversion (rounding) */ | ||
162 | static OPUS_INLINE void silk_float2short_array( | ||
163 | opus_int16 *out, | ||
164 | const silk_float *in, | ||
165 | opus_int32 length | ||
166 | ) | ||
167 | { | ||
168 | opus_int32 k; | ||
169 | for( k = length - 1; k >= 0; k-- ) { | ||
170 | out[k] = silk_SAT16( (opus_int32)float2int( in[k] ) ); | ||
171 | } | ||
172 | } | ||
173 | |||
174 | /* integer to floating-point conversion */ | ||
175 | static OPUS_INLINE void silk_short2float_array( | ||
176 | silk_float *out, | ||
177 | const opus_int16 *in, | ||
178 | opus_int32 length | ||
179 | ) | ||
180 | { | ||
181 | opus_int32 k; | ||
182 | for( k = length - 1; k >= 0; k-- ) { | ||
183 | out[k] = (silk_float)in[k]; | ||
184 | } | ||
185 | } | ||
186 | |||
187 | /* using log2() helps the fixed-point conversion */ | ||
188 | static OPUS_INLINE silk_float silk_log2( double x ) | ||
189 | { | ||
190 | return ( silk_float )( 3.32192809488736 * log10( x ) ); | ||
191 | } | ||
192 | |||
193 | #ifdef __cplusplus | ||
194 | } | ||
195 | #endif | ||
196 | |||
197 | #endif /* SILK_SIGPROC_FLP_H */ | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/apply_sine_window_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/apply_sine_window_FLP.c new file mode 100644 index 0000000000..e49e717991 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/apply_sine_window_FLP.c | |||
@@ -0,0 +1,81 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "main_FLP.h" | ||
33 | |||
34 | /* Apply sine window to signal vector */ | ||
35 | /* Window types: */ | ||
36 | /* 1 -> sine window from 0 to pi/2 */ | ||
37 | /* 2 -> sine window from pi/2 to pi */ | ||
38 | void silk_apply_sine_window_FLP( | ||
39 | silk_float px_win[], /* O Pointer to windowed signal */ | ||
40 | const silk_float px[], /* I Pointer to input signal */ | ||
41 | const opus_int win_type, /* I Selects a window type */ | ||
42 | const opus_int length /* I Window length, multiple of 4 */ | ||
43 | ) | ||
44 | { | ||
45 | opus_int k; | ||
46 | silk_float freq, c, S0, S1; | ||
47 | |||
48 | celt_assert( win_type == 1 || win_type == 2 ); | ||
49 | |||
50 | /* Length must be multiple of 4 */ | ||
51 | celt_assert( ( length & 3 ) == 0 ); | ||
52 | |||
53 | freq = PI / ( length + 1 ); | ||
54 | |||
55 | /* Approximation of 2 * cos(f) */ | ||
56 | c = 2.0f - freq * freq; | ||
57 | |||
58 | /* Initialize state */ | ||
59 | if( win_type < 2 ) { | ||
60 | /* Start from 0 */ | ||
61 | S0 = 0.0f; | ||
62 | /* Approximation of sin(f) */ | ||
63 | S1 = freq; | ||
64 | } else { | ||
65 | /* Start from 1 */ | ||
66 | S0 = 1.0f; | ||
67 | /* Approximation of cos(f) */ | ||
68 | S1 = 0.5f * c; | ||
69 | } | ||
70 | |||
71 | /* Uses the recursive equation: sin(n*f) = 2 * cos(f) * sin((n-1)*f) - sin((n-2)*f) */ | ||
72 | /* 4 samples at a time */ | ||
73 | for( k = 0; k < length; k += 4 ) { | ||
74 | px_win[ k + 0 ] = px[ k + 0 ] * 0.5f * ( S0 + S1 ); | ||
75 | px_win[ k + 1 ] = px[ k + 1 ] * S1; | ||
76 | S0 = c * S1 - S0; | ||
77 | px_win[ k + 2 ] = px[ k + 2 ] * 0.5f * ( S1 + S0 ); | ||
78 | px_win[ k + 3 ] = px[ k + 3 ] * S0; | ||
79 | S1 = c * S0 - S1; | ||
80 | } | ||
81 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/autocorrelation_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/autocorrelation_FLP.c new file mode 100644 index 0000000000..8b8a9e659a --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/autocorrelation_FLP.c | |||
@@ -0,0 +1,52 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "typedef.h" | ||
33 | #include "SigProc_FLP.h" | ||
34 | |||
35 | /* compute autocorrelation */ | ||
36 | void silk_autocorrelation_FLP( | ||
37 | silk_float *results, /* O result (length correlationCount) */ | ||
38 | const silk_float *inputData, /* I input data to correlate */ | ||
39 | opus_int inputDataSize, /* I length of input */ | ||
40 | opus_int correlationCount /* I number of correlation taps to compute */ | ||
41 | ) | ||
42 | { | ||
43 | opus_int i; | ||
44 | |||
45 | if( correlationCount > inputDataSize ) { | ||
46 | correlationCount = inputDataSize; | ||
47 | } | ||
48 | |||
49 | for( i = 0; i < correlationCount; i++ ) { | ||
50 | results[ i ] = (silk_float)silk_inner_product_FLP( inputData, inputData + i, inputDataSize - i ); | ||
51 | } | ||
52 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/burg_modified_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/burg_modified_FLP.c new file mode 100644 index 0000000000..756b76a35b --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/burg_modified_FLP.c | |||
@@ -0,0 +1,186 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "SigProc_FLP.h" | ||
33 | #include "tuning_parameters.h" | ||
34 | #include "define.h" | ||
35 | |||
36 | #define MAX_FRAME_SIZE 384 /* subfr_length * nb_subfr = ( 0.005 * 16000 + 16 ) * 4 = 384*/ | ||
37 | |||
38 | /* Compute reflection coefficients from input signal */ | ||
39 | silk_float silk_burg_modified_FLP( /* O returns residual energy */ | ||
40 | silk_float A[], /* O prediction coefficients (length order) */ | ||
41 | const silk_float x[], /* I input signal, length: nb_subfr*(D+L_sub) */ | ||
42 | const silk_float minInvGain, /* I minimum inverse prediction gain */ | ||
43 | const opus_int subfr_length, /* I input signal subframe length (incl. D preceding samples) */ | ||
44 | const opus_int nb_subfr, /* I number of subframes stacked in x */ | ||
45 | const opus_int D /* I order */ | ||
46 | ) | ||
47 | { | ||
48 | opus_int k, n, s, reached_max_gain; | ||
49 | double C0, invGain, num, nrg_f, nrg_b, rc, Atmp, tmp1, tmp2; | ||
50 | const silk_float *x_ptr; | ||
51 | double C_first_row[ SILK_MAX_ORDER_LPC ], C_last_row[ SILK_MAX_ORDER_LPC ]; | ||
52 | double CAf[ SILK_MAX_ORDER_LPC + 1 ], CAb[ SILK_MAX_ORDER_LPC + 1 ]; | ||
53 | double Af[ SILK_MAX_ORDER_LPC ]; | ||
54 | |||
55 | celt_assert( subfr_length * nb_subfr <= MAX_FRAME_SIZE ); | ||
56 | |||
57 | /* Compute autocorrelations, added over subframes */ | ||
58 | C0 = silk_energy_FLP( x, nb_subfr * subfr_length ); | ||
59 | silk_memset( C_first_row, 0, SILK_MAX_ORDER_LPC * sizeof( double ) ); | ||
60 | for( s = 0; s < nb_subfr; s++ ) { | ||
61 | x_ptr = x + s * subfr_length; | ||
62 | for( n = 1; n < D + 1; n++ ) { | ||
63 | C_first_row[ n - 1 ] += silk_inner_product_FLP( x_ptr, x_ptr + n, subfr_length - n ); | ||
64 | } | ||
65 | } | ||
66 | silk_memcpy( C_last_row, C_first_row, SILK_MAX_ORDER_LPC * sizeof( double ) ); | ||
67 | |||
68 | /* Initialize */ | ||
69 | CAb[ 0 ] = CAf[ 0 ] = C0 + FIND_LPC_COND_FAC * C0 + 1e-9f; | ||
70 | invGain = 1.0f; | ||
71 | reached_max_gain = 0; | ||
72 | for( n = 0; n < D; n++ ) { | ||
73 | /* Update first row of correlation matrix (without first element) */ | ||
74 | /* Update last row of correlation matrix (without last element, stored in reversed order) */ | ||
75 | /* Update C * Af */ | ||
76 | /* Update C * flipud(Af) (stored in reversed order) */ | ||
77 | for( s = 0; s < nb_subfr; s++ ) { | ||
78 | x_ptr = x + s * subfr_length; | ||
79 | tmp1 = x_ptr[ n ]; | ||
80 | tmp2 = x_ptr[ subfr_length - n - 1 ]; | ||
81 | for( k = 0; k < n; k++ ) { | ||
82 | C_first_row[ k ] -= x_ptr[ n ] * x_ptr[ n - k - 1 ]; | ||
83 | C_last_row[ k ] -= x_ptr[ subfr_length - n - 1 ] * x_ptr[ subfr_length - n + k ]; | ||
84 | Atmp = Af[ k ]; | ||
85 | tmp1 += x_ptr[ n - k - 1 ] * Atmp; | ||
86 | tmp2 += x_ptr[ subfr_length - n + k ] * Atmp; | ||
87 | } | ||
88 | for( k = 0; k <= n; k++ ) { | ||
89 | CAf[ k ] -= tmp1 * x_ptr[ n - k ]; | ||
90 | CAb[ k ] -= tmp2 * x_ptr[ subfr_length - n + k - 1 ]; | ||
91 | } | ||
92 | } | ||
93 | tmp1 = C_first_row[ n ]; | ||
94 | tmp2 = C_last_row[ n ]; | ||
95 | for( k = 0; k < n; k++ ) { | ||
96 | Atmp = Af[ k ]; | ||
97 | tmp1 += C_last_row[ n - k - 1 ] * Atmp; | ||
98 | tmp2 += C_first_row[ n - k - 1 ] * Atmp; | ||
99 | } | ||
100 | CAf[ n + 1 ] = tmp1; | ||
101 | CAb[ n + 1 ] = tmp2; | ||
102 | |||
103 | /* Calculate nominator and denominator for the next order reflection (parcor) coefficient */ | ||
104 | num = CAb[ n + 1 ]; | ||
105 | nrg_b = CAb[ 0 ]; | ||
106 | nrg_f = CAf[ 0 ]; | ||
107 | for( k = 0; k < n; k++ ) { | ||
108 | Atmp = Af[ k ]; | ||
109 | num += CAb[ n - k ] * Atmp; | ||
110 | nrg_b += CAb[ k + 1 ] * Atmp; | ||
111 | nrg_f += CAf[ k + 1 ] * Atmp; | ||
112 | } | ||
113 | silk_assert( nrg_f > 0.0 ); | ||
114 | silk_assert( nrg_b > 0.0 ); | ||
115 | |||
116 | /* Calculate the next order reflection (parcor) coefficient */ | ||
117 | rc = -2.0 * num / ( nrg_f + nrg_b ); | ||
118 | silk_assert( rc > -1.0 && rc < 1.0 ); | ||
119 | |||
120 | /* Update inverse prediction gain */ | ||
121 | tmp1 = invGain * ( 1.0 - rc * rc ); | ||
122 | if( tmp1 <= minInvGain ) { | ||
123 | /* Max prediction gain exceeded; set reflection coefficient such that max prediction gain is exactly hit */ | ||
124 | rc = sqrt( 1.0 - minInvGain / invGain ); | ||
125 | if( num > 0 ) { | ||
126 | /* Ensure adjusted reflection coefficients has the original sign */ | ||
127 | rc = -rc; | ||
128 | } | ||
129 | invGain = minInvGain; | ||
130 | reached_max_gain = 1; | ||
131 | } else { | ||
132 | invGain = tmp1; | ||
133 | } | ||
134 | |||
135 | /* Update the AR coefficients */ | ||
136 | for( k = 0; k < (n + 1) >> 1; k++ ) { | ||
137 | tmp1 = Af[ k ]; | ||
138 | tmp2 = Af[ n - k - 1 ]; | ||
139 | Af[ k ] = tmp1 + rc * tmp2; | ||
140 | Af[ n - k - 1 ] = tmp2 + rc * tmp1; | ||
141 | } | ||
142 | Af[ n ] = rc; | ||
143 | |||
144 | if( reached_max_gain ) { | ||
145 | /* Reached max prediction gain; set remaining coefficients to zero and exit loop */ | ||
146 | for( k = n + 1; k < D; k++ ) { | ||
147 | Af[ k ] = 0.0; | ||
148 | } | ||
149 | break; | ||
150 | } | ||
151 | |||
152 | /* Update C * Af and C * Ab */ | ||
153 | for( k = 0; k <= n + 1; k++ ) { | ||
154 | tmp1 = CAf[ k ]; | ||
155 | CAf[ k ] += rc * CAb[ n - k + 1 ]; | ||
156 | CAb[ n - k + 1 ] += rc * tmp1; | ||
157 | } | ||
158 | } | ||
159 | |||
160 | if( reached_max_gain ) { | ||
161 | /* Convert to silk_float */ | ||
162 | for( k = 0; k < D; k++ ) { | ||
163 | A[ k ] = (silk_float)( -Af[ k ] ); | ||
164 | } | ||
165 | /* Subtract energy of preceding samples from C0 */ | ||
166 | for( s = 0; s < nb_subfr; s++ ) { | ||
167 | C0 -= silk_energy_FLP( x + s * subfr_length, D ); | ||
168 | } | ||
169 | /* Approximate residual energy */ | ||
170 | nrg_f = C0 * invGain; | ||
171 | } else { | ||
172 | /* Compute residual energy and store coefficients as silk_float */ | ||
173 | nrg_f = CAf[ 0 ]; | ||
174 | tmp1 = 1.0; | ||
175 | for( k = 0; k < D; k++ ) { | ||
176 | Atmp = Af[ k ]; | ||
177 | nrg_f += CAf[ k + 1 ] * Atmp; | ||
178 | tmp1 += Atmp * Atmp; | ||
179 | A[ k ] = (silk_float)(-Atmp); | ||
180 | } | ||
181 | nrg_f -= FIND_LPC_COND_FAC * C0 * tmp1; | ||
182 | } | ||
183 | |||
184 | /* Return residual energy */ | ||
185 | return (silk_float)nrg_f; | ||
186 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/bwexpander_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/bwexpander_FLP.c new file mode 100644 index 0000000000..d55a4d79ab --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/bwexpander_FLP.c | |||
@@ -0,0 +1,49 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "SigProc_FLP.h" | ||
33 | |||
34 | /* Chirp (bw expand) LP AR filter */ | ||
35 | void silk_bwexpander_FLP( | ||
36 | silk_float *ar, /* I/O AR filter to be expanded (without leading 1) */ | ||
37 | const opus_int d, /* I length of ar */ | ||
38 | const silk_float chirp /* I chirp factor (typically in range (0..1) ) */ | ||
39 | ) | ||
40 | { | ||
41 | opus_int i; | ||
42 | silk_float cfac = chirp; | ||
43 | |||
44 | for( i = 0; i < d - 1; i++ ) { | ||
45 | ar[ i ] *= cfac; | ||
46 | cfac *= chirp; | ||
47 | } | ||
48 | ar[ d - 1 ] *= cfac; | ||
49 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/corrMatrix_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/corrMatrix_FLP.c new file mode 100644 index 0000000000..eae6a1cfca --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/corrMatrix_FLP.c | |||
@@ -0,0 +1,93 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | /********************************************************************** | ||
33 | * Correlation matrix computations for LS estimate. | ||
34 | **********************************************************************/ | ||
35 | |||
36 | #include "main_FLP.h" | ||
37 | |||
38 | /* Calculates correlation vector X'*t */ | ||
39 | void silk_corrVector_FLP( | ||
40 | const silk_float *x, /* I x vector [L+order-1] used to create X */ | ||
41 | const silk_float *t, /* I Target vector [L] */ | ||
42 | const opus_int L, /* I Length of vecors */ | ||
43 | const opus_int Order, /* I Max lag for correlation */ | ||
44 | silk_float *Xt /* O X'*t correlation vector [order] */ | ||
45 | ) | ||
46 | { | ||
47 | opus_int lag; | ||
48 | const silk_float *ptr1; | ||
49 | |||
50 | ptr1 = &x[ Order - 1 ]; /* Points to first sample of column 0 of X: X[:,0] */ | ||
51 | for( lag = 0; lag < Order; lag++ ) { | ||
52 | /* Calculate X[:,lag]'*t */ | ||
53 | Xt[ lag ] = (silk_float)silk_inner_product_FLP( ptr1, t, L ); | ||
54 | ptr1--; /* Next column of X */ | ||
55 | } | ||
56 | } | ||
57 | |||
58 | /* Calculates correlation matrix X'*X */ | ||
59 | void silk_corrMatrix_FLP( | ||
60 | const silk_float *x, /* I x vector [ L+order-1 ] used to create X */ | ||
61 | const opus_int L, /* I Length of vectors */ | ||
62 | const opus_int Order, /* I Max lag for correlation */ | ||
63 | silk_float *XX /* O X'*X correlation matrix [order x order] */ | ||
64 | ) | ||
65 | { | ||
66 | opus_int j, lag; | ||
67 | double energy; | ||
68 | const silk_float *ptr1, *ptr2; | ||
69 | |||
70 | ptr1 = &x[ Order - 1 ]; /* First sample of column 0 of X */ | ||
71 | energy = silk_energy_FLP( ptr1, L ); /* X[:,0]'*X[:,0] */ | ||
72 | matrix_ptr( XX, 0, 0, Order ) = ( silk_float )energy; | ||
73 | for( j = 1; j < Order; j++ ) { | ||
74 | /* Calculate X[:,j]'*X[:,j] */ | ||
75 | energy += ptr1[ -j ] * ptr1[ -j ] - ptr1[ L - j ] * ptr1[ L - j ]; | ||
76 | matrix_ptr( XX, j, j, Order ) = ( silk_float )energy; | ||
77 | } | ||
78 | |||
79 | ptr2 = &x[ Order - 2 ]; /* First sample of column 1 of X */ | ||
80 | for( lag = 1; lag < Order; lag++ ) { | ||
81 | /* Calculate X[:,0]'*X[:,lag] */ | ||
82 | energy = silk_inner_product_FLP( ptr1, ptr2, L ); | ||
83 | matrix_ptr( XX, lag, 0, Order ) = ( silk_float )energy; | ||
84 | matrix_ptr( XX, 0, lag, Order ) = ( silk_float )energy; | ||
85 | /* Calculate X[:,j]'*X[:,j + lag] */ | ||
86 | for( j = 1; j < ( Order - lag ); j++ ) { | ||
87 | energy += ptr1[ -j ] * ptr2[ -j ] - ptr1[ L - j ] * ptr2[ L - j ]; | ||
88 | matrix_ptr( XX, lag + j, j, Order ) = ( silk_float )energy; | ||
89 | matrix_ptr( XX, j, lag + j, Order ) = ( silk_float )energy; | ||
90 | } | ||
91 | ptr2--; /* Next column of X */ | ||
92 | } | ||
93 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/encode_frame_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/encode_frame_FLP.c new file mode 100644 index 0000000000..b029c3f5ca --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/encode_frame_FLP.c | |||
@@ -0,0 +1,435 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include <stdlib.h> | ||
33 | #include "main_FLP.h" | ||
34 | #include "tuning_parameters.h" | ||
35 | |||
36 | /* Low Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode with lower bitrate */ | ||
37 | static OPUS_INLINE void silk_LBRR_encode_FLP( | ||
38 | silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ | ||
39 | silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ | ||
40 | const silk_float xfw[], /* I Input signal */ | ||
41 | opus_int condCoding /* I The type of conditional coding used so far for this frame */ | ||
42 | ); | ||
43 | |||
44 | void silk_encode_do_VAD_FLP( | ||
45 | silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ | ||
46 | opus_int activity /* I Decision of Opus voice activity detector */ | ||
47 | ) | ||
48 | { | ||
49 | const opus_int activity_threshold = SILK_FIX_CONST( SPEECH_ACTIVITY_DTX_THRES, 8 ); | ||
50 | |||
51 | /****************************/ | ||
52 | /* Voice Activity Detection */ | ||
53 | /****************************/ | ||
54 | silk_VAD_GetSA_Q8( &psEnc->sCmn, psEnc->sCmn.inputBuf + 1, psEnc->sCmn.arch ); | ||
55 | /* If Opus VAD is inactive and Silk VAD is active: lower Silk VAD to just under the threshold */ | ||
56 | if( activity == VAD_NO_ACTIVITY && psEnc->sCmn.speech_activity_Q8 >= activity_threshold ) { | ||
57 | psEnc->sCmn.speech_activity_Q8 = activity_threshold - 1; | ||
58 | } | ||
59 | |||
60 | /**************************************************/ | ||
61 | /* Convert speech activity into VAD and DTX flags */ | ||
62 | /**************************************************/ | ||
63 | if( psEnc->sCmn.speech_activity_Q8 < activity_threshold ) { | ||
64 | psEnc->sCmn.indices.signalType = TYPE_NO_VOICE_ACTIVITY; | ||
65 | psEnc->sCmn.noSpeechCounter++; | ||
66 | if( psEnc->sCmn.noSpeechCounter <= NB_SPEECH_FRAMES_BEFORE_DTX ) { | ||
67 | psEnc->sCmn.inDTX = 0; | ||
68 | } else if( psEnc->sCmn.noSpeechCounter > MAX_CONSECUTIVE_DTX + NB_SPEECH_FRAMES_BEFORE_DTX ) { | ||
69 | psEnc->sCmn.noSpeechCounter = NB_SPEECH_FRAMES_BEFORE_DTX; | ||
70 | psEnc->sCmn.inDTX = 0; | ||
71 | } | ||
72 | psEnc->sCmn.VAD_flags[ psEnc->sCmn.nFramesEncoded ] = 0; | ||
73 | } else { | ||
74 | psEnc->sCmn.noSpeechCounter = 0; | ||
75 | psEnc->sCmn.inDTX = 0; | ||
76 | psEnc->sCmn.indices.signalType = TYPE_UNVOICED; | ||
77 | psEnc->sCmn.VAD_flags[ psEnc->sCmn.nFramesEncoded ] = 1; | ||
78 | } | ||
79 | } | ||
80 | |||
81 | /****************/ | ||
82 | /* Encode frame */ | ||
83 | /****************/ | ||
84 | opus_int silk_encode_frame_FLP( | ||
85 | silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ | ||
86 | opus_int32 *pnBytesOut, /* O Number of payload bytes; */ | ||
87 | ec_enc *psRangeEnc, /* I/O compressor data structure */ | ||
88 | opus_int condCoding, /* I The type of conditional coding to use */ | ||
89 | opus_int maxBits, /* I If > 0: maximum number of output bits */ | ||
90 | opus_int useCBR /* I Flag to force constant-bitrate operation */ | ||
91 | ) | ||
92 | { | ||
93 | silk_encoder_control_FLP sEncCtrl; | ||
94 | opus_int i, iter, maxIter, found_upper, found_lower, ret = 0; | ||
95 | silk_float *x_frame, *res_pitch_frame; | ||
96 | silk_float res_pitch[ 2 * MAX_FRAME_LENGTH + LA_PITCH_MAX ]; | ||
97 | ec_enc sRangeEnc_copy, sRangeEnc_copy2; | ||
98 | silk_nsq_state sNSQ_copy, sNSQ_copy2; | ||
99 | opus_int32 seed_copy, nBits, nBits_lower, nBits_upper, gainMult_lower, gainMult_upper; | ||
100 | opus_int32 gainsID, gainsID_lower, gainsID_upper; | ||
101 | opus_int16 gainMult_Q8; | ||
102 | opus_int16 ec_prevLagIndex_copy; | ||
103 | opus_int ec_prevSignalType_copy; | ||
104 | opus_int8 LastGainIndex_copy2; | ||
105 | opus_int32 pGains_Q16[ MAX_NB_SUBFR ]; | ||
106 | opus_uint8 ec_buf_copy[ 1275 ]; | ||
107 | opus_int gain_lock[ MAX_NB_SUBFR ] = {0}; | ||
108 | opus_int16 best_gain_mult[ MAX_NB_SUBFR ]; | ||
109 | opus_int best_sum[ MAX_NB_SUBFR ]; | ||
110 | |||
111 | /* This is totally unnecessary but many compilers (including gcc) are too dumb to realise it */ | ||
112 | LastGainIndex_copy2 = nBits_lower = nBits_upper = gainMult_lower = gainMult_upper = 0; | ||
113 | |||
114 | psEnc->sCmn.indices.Seed = psEnc->sCmn.frameCounter++ & 3; | ||
115 | |||
116 | /**************************************************************/ | ||
117 | /* Set up Input Pointers, and insert frame in input buffer */ | ||
118 | /**************************************************************/ | ||
119 | /* pointers aligned with start of frame to encode */ | ||
120 | x_frame = psEnc->x_buf + psEnc->sCmn.ltp_mem_length; /* start of frame to encode */ | ||
121 | res_pitch_frame = res_pitch + psEnc->sCmn.ltp_mem_length; /* start of pitch LPC residual frame */ | ||
122 | |||
123 | /***************************************/ | ||
124 | /* Ensure smooth bandwidth transitions */ | ||
125 | /***************************************/ | ||
126 | silk_LP_variable_cutoff( &psEnc->sCmn.sLP, psEnc->sCmn.inputBuf + 1, psEnc->sCmn.frame_length ); | ||
127 | |||
128 | /*******************************************/ | ||
129 | /* Copy new frame to front of input buffer */ | ||
130 | /*******************************************/ | ||
131 | silk_short2float_array( x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.inputBuf + 1, psEnc->sCmn.frame_length ); | ||
132 | |||
133 | /* Add tiny signal to avoid high CPU load from denormalized floating point numbers */ | ||
134 | for( i = 0; i < 8; i++ ) { | ||
135 | x_frame[ LA_SHAPE_MS * psEnc->sCmn.fs_kHz + i * ( psEnc->sCmn.frame_length >> 3 ) ] += ( 1 - ( i & 2 ) ) * 1e-6f; | ||
136 | } | ||
137 | |||
138 | if( !psEnc->sCmn.prefillFlag ) { | ||
139 | /*****************************************/ | ||
140 | /* Find pitch lags, initial LPC analysis */ | ||
141 | /*****************************************/ | ||
142 | silk_find_pitch_lags_FLP( psEnc, &sEncCtrl, res_pitch, x_frame, psEnc->sCmn.arch ); | ||
143 | |||
144 | /************************/ | ||
145 | /* Noise shape analysis */ | ||
146 | /************************/ | ||
147 | silk_noise_shape_analysis_FLP( psEnc, &sEncCtrl, res_pitch_frame, x_frame ); | ||
148 | |||
149 | /***************************************************/ | ||
150 | /* Find linear prediction coefficients (LPC + LTP) */ | ||
151 | /***************************************************/ | ||
152 | silk_find_pred_coefs_FLP( psEnc, &sEncCtrl, res_pitch_frame, x_frame, condCoding ); | ||
153 | |||
154 | /****************************************/ | ||
155 | /* Process gains */ | ||
156 | /****************************************/ | ||
157 | silk_process_gains_FLP( psEnc, &sEncCtrl, condCoding ); | ||
158 | |||
159 | /****************************************/ | ||
160 | /* Low Bitrate Redundant Encoding */ | ||
161 | /****************************************/ | ||
162 | silk_LBRR_encode_FLP( psEnc, &sEncCtrl, x_frame, condCoding ); | ||
163 | |||
164 | /* Loop over quantizer and entroy coding to control bitrate */ | ||
165 | maxIter = 6; | ||
166 | gainMult_Q8 = SILK_FIX_CONST( 1, 8 ); | ||
167 | found_lower = 0; | ||
168 | found_upper = 0; | ||
169 | gainsID = silk_gains_ID( psEnc->sCmn.indices.GainsIndices, psEnc->sCmn.nb_subfr ); | ||
170 | gainsID_lower = -1; | ||
171 | gainsID_upper = -1; | ||
172 | /* Copy part of the input state */ | ||
173 | silk_memcpy( &sRangeEnc_copy, psRangeEnc, sizeof( ec_enc ) ); | ||
174 | silk_memcpy( &sNSQ_copy, &psEnc->sCmn.sNSQ, sizeof( silk_nsq_state ) ); | ||
175 | seed_copy = psEnc->sCmn.indices.Seed; | ||
176 | ec_prevLagIndex_copy = psEnc->sCmn.ec_prevLagIndex; | ||
177 | ec_prevSignalType_copy = psEnc->sCmn.ec_prevSignalType; | ||
178 | for( iter = 0; ; iter++ ) { | ||
179 | if( gainsID == gainsID_lower ) { | ||
180 | nBits = nBits_lower; | ||
181 | } else if( gainsID == gainsID_upper ) { | ||
182 | nBits = nBits_upper; | ||
183 | } else { | ||
184 | /* Restore part of the input state */ | ||
185 | if( iter > 0 ) { | ||
186 | silk_memcpy( psRangeEnc, &sRangeEnc_copy, sizeof( ec_enc ) ); | ||
187 | silk_memcpy( &psEnc->sCmn.sNSQ, &sNSQ_copy, sizeof( silk_nsq_state ) ); | ||
188 | psEnc->sCmn.indices.Seed = seed_copy; | ||
189 | psEnc->sCmn.ec_prevLagIndex = ec_prevLagIndex_copy; | ||
190 | psEnc->sCmn.ec_prevSignalType = ec_prevSignalType_copy; | ||
191 | } | ||
192 | |||
193 | /*****************************************/ | ||
194 | /* Noise shaping quantization */ | ||
195 | /*****************************************/ | ||
196 | silk_NSQ_wrapper_FLP( psEnc, &sEncCtrl, &psEnc->sCmn.indices, &psEnc->sCmn.sNSQ, psEnc->sCmn.pulses, x_frame ); | ||
197 | |||
198 | if ( iter == maxIter && !found_lower ) { | ||
199 | silk_memcpy( &sRangeEnc_copy2, psRangeEnc, sizeof( ec_enc ) ); | ||
200 | } | ||
201 | |||
202 | /****************************************/ | ||
203 | /* Encode Parameters */ | ||
204 | /****************************************/ | ||
205 | silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFramesEncoded, 0, condCoding ); | ||
206 | |||
207 | /****************************************/ | ||
208 | /* Encode Excitation Signal */ | ||
209 | /****************************************/ | ||
210 | silk_encode_pulses( psRangeEnc, psEnc->sCmn.indices.signalType, psEnc->sCmn.indices.quantOffsetType, | ||
211 | psEnc->sCmn.pulses, psEnc->sCmn.frame_length ); | ||
212 | |||
213 | nBits = ec_tell( psRangeEnc ); | ||
214 | |||
215 | /* If we still bust after the last iteration, do some damage control. */ | ||
216 | if ( iter == maxIter && !found_lower && nBits > maxBits ) { | ||
217 | silk_memcpy( psRangeEnc, &sRangeEnc_copy2, sizeof( ec_enc ) ); | ||
218 | |||
219 | /* Keep gains the same as the last frame. */ | ||
220 | psEnc->sShape.LastGainIndex = sEncCtrl.lastGainIndexPrev; | ||
221 | for ( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { | ||
222 | psEnc->sCmn.indices.GainsIndices[ i ] = 4; | ||
223 | } | ||
224 | if (condCoding != CODE_CONDITIONALLY) { | ||
225 | psEnc->sCmn.indices.GainsIndices[ 0 ] = sEncCtrl.lastGainIndexPrev; | ||
226 | } | ||
227 | psEnc->sCmn.ec_prevLagIndex = ec_prevLagIndex_copy; | ||
228 | psEnc->sCmn.ec_prevSignalType = ec_prevSignalType_copy; | ||
229 | /* Clear all pulses. */ | ||
230 | for ( i = 0; i < psEnc->sCmn.frame_length; i++ ) { | ||
231 | psEnc->sCmn.pulses[ i ] = 0; | ||
232 | } | ||
233 | |||
234 | silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFramesEncoded, 0, condCoding ); | ||
235 | |||
236 | silk_encode_pulses( psRangeEnc, psEnc->sCmn.indices.signalType, psEnc->sCmn.indices.quantOffsetType, | ||
237 | psEnc->sCmn.pulses, psEnc->sCmn.frame_length ); | ||
238 | |||
239 | nBits = ec_tell( psRangeEnc ); | ||
240 | } | ||
241 | |||
242 | if( useCBR == 0 && iter == 0 && nBits <= maxBits ) { | ||
243 | break; | ||
244 | } | ||
245 | } | ||
246 | |||
247 | if( iter == maxIter ) { | ||
248 | if( found_lower && ( gainsID == gainsID_lower || nBits > maxBits ) ) { | ||
249 | /* Restore output state from earlier iteration that did meet the bitrate budget */ | ||
250 | silk_memcpy( psRangeEnc, &sRangeEnc_copy2, sizeof( ec_enc ) ); | ||
251 | celt_assert( sRangeEnc_copy2.offs <= 1275 ); | ||
252 | silk_memcpy( psRangeEnc->buf, ec_buf_copy, sRangeEnc_copy2.offs ); | ||
253 | silk_memcpy( &psEnc->sCmn.sNSQ, &sNSQ_copy2, sizeof( silk_nsq_state ) ); | ||
254 | psEnc->sShape.LastGainIndex = LastGainIndex_copy2; | ||
255 | } | ||
256 | break; | ||
257 | } | ||
258 | |||
259 | if( nBits > maxBits ) { | ||
260 | if( found_lower == 0 && iter >= 2 ) { | ||
261 | /* Adjust the quantizer's rate/distortion tradeoff and discard previous "upper" results */ | ||
262 | sEncCtrl.Lambda = silk_max_float(sEncCtrl.Lambda*1.5f, 1.5f); | ||
263 | /* Reducing dithering can help us hit the target. */ | ||
264 | psEnc->sCmn.indices.quantOffsetType = 0; | ||
265 | found_upper = 0; | ||
266 | gainsID_upper = -1; | ||
267 | } else { | ||
268 | found_upper = 1; | ||
269 | nBits_upper = nBits; | ||
270 | gainMult_upper = gainMult_Q8; | ||
271 | gainsID_upper = gainsID; | ||
272 | } | ||
273 | } else if( nBits < maxBits - 5 ) { | ||
274 | found_lower = 1; | ||
275 | nBits_lower = nBits; | ||
276 | gainMult_lower = gainMult_Q8; | ||
277 | if( gainsID != gainsID_lower ) { | ||
278 | gainsID_lower = gainsID; | ||
279 | /* Copy part of the output state */ | ||
280 | silk_memcpy( &sRangeEnc_copy2, psRangeEnc, sizeof( ec_enc ) ); | ||
281 | celt_assert( psRangeEnc->offs <= 1275 ); | ||
282 | silk_memcpy( ec_buf_copy, psRangeEnc->buf, psRangeEnc->offs ); | ||
283 | silk_memcpy( &sNSQ_copy2, &psEnc->sCmn.sNSQ, sizeof( silk_nsq_state ) ); | ||
284 | LastGainIndex_copy2 = psEnc->sShape.LastGainIndex; | ||
285 | } | ||
286 | } else { | ||
287 | /* Within 5 bits of budget: close enough */ | ||
288 | break; | ||
289 | } | ||
290 | |||
291 | if ( !found_lower && nBits > maxBits ) { | ||
292 | int j; | ||
293 | for ( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { | ||
294 | int sum=0; | ||
295 | for ( j = i*psEnc->sCmn.subfr_length; j < (i+1)*psEnc->sCmn.subfr_length; j++ ) { | ||
296 | sum += abs( psEnc->sCmn.pulses[j] ); | ||
297 | } | ||
298 | if ( iter == 0 || (sum < best_sum[i] && !gain_lock[i]) ) { | ||
299 | best_sum[i] = sum; | ||
300 | best_gain_mult[i] = gainMult_Q8; | ||
301 | } else { | ||
302 | gain_lock[i] = 1; | ||
303 | } | ||
304 | } | ||
305 | } | ||
306 | if( ( found_lower & found_upper ) == 0 ) { | ||
307 | /* Adjust gain according to high-rate rate/distortion curve */ | ||
308 | if( nBits > maxBits ) { | ||
309 | if (gainMult_Q8 < 16384) { | ||
310 | gainMult_Q8 *= 2; | ||
311 | } else { | ||
312 | gainMult_Q8 = 32767; | ||
313 | } | ||
314 | } else { | ||
315 | opus_int32 gain_factor_Q16; | ||
316 | gain_factor_Q16 = silk_log2lin( silk_LSHIFT( nBits - maxBits, 7 ) / psEnc->sCmn.frame_length + SILK_FIX_CONST( 16, 7 ) ); | ||
317 | gainMult_Q8 = silk_SMULWB( gain_factor_Q16, gainMult_Q8 ); | ||
318 | } | ||
319 | } else { | ||
320 | /* Adjust gain by interpolating */ | ||
321 | gainMult_Q8 = gainMult_lower + ( ( gainMult_upper - gainMult_lower ) * ( maxBits - nBits_lower ) ) / ( nBits_upper - nBits_lower ); | ||
322 | /* New gain multplier must be between 25% and 75% of old range (note that gainMult_upper < gainMult_lower) */ | ||
323 | if( gainMult_Q8 > silk_ADD_RSHIFT32( gainMult_lower, gainMult_upper - gainMult_lower, 2 ) ) { | ||
324 | gainMult_Q8 = silk_ADD_RSHIFT32( gainMult_lower, gainMult_upper - gainMult_lower, 2 ); | ||
325 | } else | ||
326 | if( gainMult_Q8 < silk_SUB_RSHIFT32( gainMult_upper, gainMult_upper - gainMult_lower, 2 ) ) { | ||
327 | gainMult_Q8 = silk_SUB_RSHIFT32( gainMult_upper, gainMult_upper - gainMult_lower, 2 ); | ||
328 | } | ||
329 | } | ||
330 | |||
331 | for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { | ||
332 | opus_int16 tmp; | ||
333 | if ( gain_lock[i] ) { | ||
334 | tmp = best_gain_mult[i]; | ||
335 | } else { | ||
336 | tmp = gainMult_Q8; | ||
337 | } | ||
338 | pGains_Q16[ i ] = silk_LSHIFT_SAT32( silk_SMULWB( sEncCtrl.GainsUnq_Q16[ i ], tmp ), 8 ); | ||
339 | } | ||
340 | |||
341 | /* Quantize gains */ | ||
342 | psEnc->sShape.LastGainIndex = sEncCtrl.lastGainIndexPrev; | ||
343 | silk_gains_quant( psEnc->sCmn.indices.GainsIndices, pGains_Q16, | ||
344 | &psEnc->sShape.LastGainIndex, condCoding == CODE_CONDITIONALLY, psEnc->sCmn.nb_subfr ); | ||
345 | |||
346 | /* Unique identifier of gains vector */ | ||
347 | gainsID = silk_gains_ID( psEnc->sCmn.indices.GainsIndices, psEnc->sCmn.nb_subfr ); | ||
348 | |||
349 | /* Overwrite unquantized gains with quantized gains and convert back to Q0 from Q16 */ | ||
350 | for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { | ||
351 | sEncCtrl.Gains[ i ] = pGains_Q16[ i ] / 65536.0f; | ||
352 | } | ||
353 | } | ||
354 | } | ||
355 | |||
356 | /* Update input buffer */ | ||
357 | silk_memmove( psEnc->x_buf, &psEnc->x_buf[ psEnc->sCmn.frame_length ], | ||
358 | ( psEnc->sCmn.ltp_mem_length + LA_SHAPE_MS * psEnc->sCmn.fs_kHz ) * sizeof( silk_float ) ); | ||
359 | |||
360 | /* Exit without entropy coding */ | ||
361 | if( psEnc->sCmn.prefillFlag ) { | ||
362 | /* No payload */ | ||
363 | *pnBytesOut = 0; | ||
364 | return ret; | ||
365 | } | ||
366 | |||
367 | /* Parameters needed for next frame */ | ||
368 | psEnc->sCmn.prevLag = sEncCtrl.pitchL[ psEnc->sCmn.nb_subfr - 1 ]; | ||
369 | psEnc->sCmn.prevSignalType = psEnc->sCmn.indices.signalType; | ||
370 | |||
371 | /****************************************/ | ||
372 | /* Finalize payload */ | ||
373 | /****************************************/ | ||
374 | psEnc->sCmn.first_frame_after_reset = 0; | ||
375 | /* Payload size */ | ||
376 | *pnBytesOut = silk_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 ); | ||
377 | |||
378 | return ret; | ||
379 | } | ||
380 | |||
381 | /* Low-Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode excitation at lower bitrate */ | ||
382 | static OPUS_INLINE void silk_LBRR_encode_FLP( | ||
383 | silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ | ||
384 | silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ | ||
385 | const silk_float xfw[], /* I Input signal */ | ||
386 | opus_int condCoding /* I The type of conditional coding used so far for this frame */ | ||
387 | ) | ||
388 | { | ||
389 | opus_int k; | ||
390 | opus_int32 Gains_Q16[ MAX_NB_SUBFR ]; | ||
391 | silk_float TempGains[ MAX_NB_SUBFR ]; | ||
392 | SideInfoIndices *psIndices_LBRR = &psEnc->sCmn.indices_LBRR[ psEnc->sCmn.nFramesEncoded ]; | ||
393 | silk_nsq_state sNSQ_LBRR; | ||
394 | |||
395 | /*******************************************/ | ||
396 | /* Control use of inband LBRR */ | ||
397 | /*******************************************/ | ||
398 | if( psEnc->sCmn.LBRR_enabled && psEnc->sCmn.speech_activity_Q8 > SILK_FIX_CONST( LBRR_SPEECH_ACTIVITY_THRES, 8 ) ) { | ||
399 | psEnc->sCmn.LBRR_flags[ psEnc->sCmn.nFramesEncoded ] = 1; | ||
400 | |||
401 | /* Copy noise shaping quantizer state and quantization indices from regular encoding */ | ||
402 | silk_memcpy( &sNSQ_LBRR, &psEnc->sCmn.sNSQ, sizeof( silk_nsq_state ) ); | ||
403 | silk_memcpy( psIndices_LBRR, &psEnc->sCmn.indices, sizeof( SideInfoIndices ) ); | ||
404 | |||
405 | /* Save original gains */ | ||
406 | silk_memcpy( TempGains, psEncCtrl->Gains, psEnc->sCmn.nb_subfr * sizeof( silk_float ) ); | ||
407 | |||
408 | if( psEnc->sCmn.nFramesEncoded == 0 || psEnc->sCmn.LBRR_flags[ psEnc->sCmn.nFramesEncoded - 1 ] == 0 ) { | ||
409 | /* First frame in packet or previous frame not LBRR coded */ | ||
410 | psEnc->sCmn.LBRRprevLastGainIndex = psEnc->sShape.LastGainIndex; | ||
411 | |||
412 | /* Increase Gains to get target LBRR rate */ | ||
413 | psIndices_LBRR->GainsIndices[ 0 ] += psEnc->sCmn.LBRR_GainIncreases; | ||
414 | psIndices_LBRR->GainsIndices[ 0 ] = silk_min_int( psIndices_LBRR->GainsIndices[ 0 ], N_LEVELS_QGAIN - 1 ); | ||
415 | } | ||
416 | |||
417 | /* Decode to get gains in sync with decoder */ | ||
418 | silk_gains_dequant( Gains_Q16, psIndices_LBRR->GainsIndices, | ||
419 | &psEnc->sCmn.LBRRprevLastGainIndex, condCoding == CODE_CONDITIONALLY, psEnc->sCmn.nb_subfr ); | ||
420 | |||
421 | /* Overwrite unquantized gains with quantized gains and convert back to Q0 from Q16 */ | ||
422 | for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { | ||
423 | psEncCtrl->Gains[ k ] = Gains_Q16[ k ] * ( 1.0f / 65536.0f ); | ||
424 | } | ||
425 | |||
426 | /*****************************************/ | ||
427 | /* Noise shaping quantization */ | ||
428 | /*****************************************/ | ||
429 | silk_NSQ_wrapper_FLP( psEnc, psEncCtrl, psIndices_LBRR, &sNSQ_LBRR, | ||
430 | psEnc->sCmn.pulses_LBRR[ psEnc->sCmn.nFramesEncoded ], xfw ); | ||
431 | |||
432 | /* Restore original gains */ | ||
433 | silk_memcpy( psEncCtrl->Gains, TempGains, psEnc->sCmn.nb_subfr * sizeof( silk_float ) ); | ||
434 | } | ||
435 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/energy_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/energy_FLP.c new file mode 100644 index 0000000000..7bc7173c9c --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/energy_FLP.c | |||
@@ -0,0 +1,59 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "SigProc_FLP.h" | ||
33 | |||
34 | /* sum of squares of a silk_float array, with result as double */ | ||
35 | double silk_energy_FLP( | ||
36 | const silk_float *data, | ||
37 | opus_int dataSize | ||
38 | ) | ||
39 | { | ||
40 | opus_int i; | ||
41 | double result; | ||
42 | |||
43 | /* 4x unrolled loop */ | ||
44 | result = 0.0; | ||
45 | for( i = 0; i < dataSize - 3; i += 4 ) { | ||
46 | result += data[ i + 0 ] * (double)data[ i + 0 ] + | ||
47 | data[ i + 1 ] * (double)data[ i + 1 ] + | ||
48 | data[ i + 2 ] * (double)data[ i + 2 ] + | ||
49 | data[ i + 3 ] * (double)data[ i + 3 ]; | ||
50 | } | ||
51 | |||
52 | /* add any remaining products */ | ||
53 | for( ; i < dataSize; i++ ) { | ||
54 | result += data[ i ] * (double)data[ i ]; | ||
55 | } | ||
56 | |||
57 | silk_assert( result >= 0.0 ); | ||
58 | return result; | ||
59 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/find_LPC_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/find_LPC_FLP.c new file mode 100644 index 0000000000..fa3ffe7f8b --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/find_LPC_FLP.c | |||
@@ -0,0 +1,104 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "define.h" | ||
33 | #include "main_FLP.h" | ||
34 | #include "tuning_parameters.h" | ||
35 | |||
36 | /* LPC analysis */ | ||
37 | void silk_find_LPC_FLP( | ||
38 | silk_encoder_state *psEncC, /* I/O Encoder state */ | ||
39 | opus_int16 NLSF_Q15[], /* O NLSFs */ | ||
40 | const silk_float x[], /* I Input signal */ | ||
41 | const silk_float minInvGain /* I Inverse of max prediction gain */ | ||
42 | ) | ||
43 | { | ||
44 | opus_int k, subfr_length; | ||
45 | silk_float a[ MAX_LPC_ORDER ]; | ||
46 | |||
47 | /* Used only for NLSF interpolation */ | ||
48 | silk_float res_nrg, res_nrg_2nd, res_nrg_interp; | ||
49 | opus_int16 NLSF0_Q15[ MAX_LPC_ORDER ]; | ||
50 | silk_float a_tmp[ MAX_LPC_ORDER ]; | ||
51 | silk_float LPC_res[ MAX_FRAME_LENGTH + MAX_NB_SUBFR * MAX_LPC_ORDER ]; | ||
52 | |||
53 | subfr_length = psEncC->subfr_length + psEncC->predictLPCOrder; | ||
54 | |||
55 | /* Default: No interpolation */ | ||
56 | psEncC->indices.NLSFInterpCoef_Q2 = 4; | ||
57 | |||
58 | /* Burg AR analysis for the full frame */ | ||
59 | res_nrg = silk_burg_modified_FLP( a, x, minInvGain, subfr_length, psEncC->nb_subfr, psEncC->predictLPCOrder ); | ||
60 | |||
61 | if( psEncC->useInterpolatedNLSFs && !psEncC->first_frame_after_reset && psEncC->nb_subfr == MAX_NB_SUBFR ) { | ||
62 | /* Optimal solution for last 10 ms; subtract residual energy here, as that's easier than */ | ||
63 | /* adding it to the residual energy of the first 10 ms in each iteration of the search below */ | ||
64 | res_nrg -= silk_burg_modified_FLP( a_tmp, x + ( MAX_NB_SUBFR / 2 ) * subfr_length, minInvGain, subfr_length, MAX_NB_SUBFR / 2, psEncC->predictLPCOrder ); | ||
65 | |||
66 | /* Convert to NLSFs */ | ||
67 | silk_A2NLSF_FLP( NLSF_Q15, a_tmp, psEncC->predictLPCOrder ); | ||
68 | |||
69 | /* Search over interpolation indices to find the one with lowest residual energy */ | ||
70 | res_nrg_2nd = silk_float_MAX; | ||
71 | for( k = 3; k >= 0; k-- ) { | ||
72 | /* Interpolate NLSFs for first half */ | ||
73 | silk_interpolate( NLSF0_Q15, psEncC->prev_NLSFq_Q15, NLSF_Q15, k, psEncC->predictLPCOrder ); | ||
74 | |||
75 | /* Convert to LPC for residual energy evaluation */ | ||
76 | silk_NLSF2A_FLP( a_tmp, NLSF0_Q15, psEncC->predictLPCOrder, psEncC->arch ); | ||
77 | |||
78 | /* Calculate residual energy with LSF interpolation */ | ||
79 | silk_LPC_analysis_filter_FLP( LPC_res, a_tmp, x, 2 * subfr_length, psEncC->predictLPCOrder ); | ||
80 | res_nrg_interp = (silk_float)( | ||
81 | silk_energy_FLP( LPC_res + psEncC->predictLPCOrder, subfr_length - psEncC->predictLPCOrder ) + | ||
82 | silk_energy_FLP( LPC_res + psEncC->predictLPCOrder + subfr_length, subfr_length - psEncC->predictLPCOrder ) ); | ||
83 | |||
84 | /* Determine whether current interpolated NLSFs are best so far */ | ||
85 | if( res_nrg_interp < res_nrg ) { | ||
86 | /* Interpolation has lower residual energy */ | ||
87 | res_nrg = res_nrg_interp; | ||
88 | psEncC->indices.NLSFInterpCoef_Q2 = (opus_int8)k; | ||
89 | } else if( res_nrg_interp > res_nrg_2nd ) { | ||
90 | /* No reason to continue iterating - residual energies will continue to climb */ | ||
91 | break; | ||
92 | } | ||
93 | res_nrg_2nd = res_nrg_interp; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | if( psEncC->indices.NLSFInterpCoef_Q2 == 4 ) { | ||
98 | /* NLSF interpolation is currently inactive, calculate NLSFs from full frame AR coefficients */ | ||
99 | silk_A2NLSF_FLP( NLSF_Q15, a, psEncC->predictLPCOrder ); | ||
100 | } | ||
101 | |||
102 | celt_assert( psEncC->indices.NLSFInterpCoef_Q2 == 4 || | ||
103 | ( psEncC->useInterpolatedNLSFs && !psEncC->first_frame_after_reset && psEncC->nb_subfr == MAX_NB_SUBFR ) ); | ||
104 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/find_LTP_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/find_LTP_FLP.c new file mode 100644 index 0000000000..f97064930e --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/find_LTP_FLP.c | |||
@@ -0,0 +1,64 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "main_FLP.h" | ||
33 | #include "tuning_parameters.h" | ||
34 | |||
35 | void silk_find_LTP_FLP( | ||
36 | silk_float XX[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Weight for LTP quantization */ | ||
37 | silk_float xX[ MAX_NB_SUBFR * LTP_ORDER ], /* O Weight for LTP quantization */ | ||
38 | const silk_float r_ptr[], /* I LPC residual */ | ||
39 | const opus_int lag[ MAX_NB_SUBFR ], /* I LTP lags */ | ||
40 | const opus_int subfr_length, /* I Subframe length */ | ||
41 | const opus_int nb_subfr /* I number of subframes */ | ||
42 | ) | ||
43 | { | ||
44 | opus_int k; | ||
45 | silk_float *xX_ptr, *XX_ptr; | ||
46 | const silk_float *lag_ptr; | ||
47 | silk_float xx, temp; | ||
48 | |||
49 | xX_ptr = xX; | ||
50 | XX_ptr = XX; | ||
51 | for( k = 0; k < nb_subfr; k++ ) { | ||
52 | lag_ptr = r_ptr - ( lag[ k ] + LTP_ORDER / 2 ); | ||
53 | silk_corrMatrix_FLP( lag_ptr, subfr_length, LTP_ORDER, XX_ptr ); | ||
54 | silk_corrVector_FLP( lag_ptr, r_ptr, subfr_length, LTP_ORDER, xX_ptr ); | ||
55 | xx = ( silk_float )silk_energy_FLP( r_ptr, subfr_length + LTP_ORDER ); | ||
56 | temp = 1.0f / silk_max( xx, LTP_CORR_INV_MAX * 0.5f * ( XX_ptr[ 0 ] + XX_ptr[ 24 ] ) + 1.0f ); | ||
57 | silk_scale_vector_FLP( XX_ptr, temp, LTP_ORDER * LTP_ORDER ); | ||
58 | silk_scale_vector_FLP( xX_ptr, temp, LTP_ORDER ); | ||
59 | |||
60 | r_ptr += subfr_length; | ||
61 | XX_ptr += LTP_ORDER * LTP_ORDER; | ||
62 | xX_ptr += LTP_ORDER; | ||
63 | } | ||
64 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/find_pitch_lags_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/find_pitch_lags_FLP.c new file mode 100644 index 0000000000..dedbcd2836 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/find_pitch_lags_FLP.c | |||
@@ -0,0 +1,132 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include <stdlib.h> | ||
33 | #include "main_FLP.h" | ||
34 | #include "tuning_parameters.h" | ||
35 | |||
36 | void silk_find_pitch_lags_FLP( | ||
37 | silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ | ||
38 | silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ | ||
39 | silk_float res[], /* O Residual */ | ||
40 | const silk_float x[], /* I Speech signal */ | ||
41 | int arch /* I Run-time architecture */ | ||
42 | ) | ||
43 | { | ||
44 | opus_int buf_len; | ||
45 | silk_float thrhld, res_nrg; | ||
46 | const silk_float *x_buf_ptr, *x_buf; | ||
47 | silk_float auto_corr[ MAX_FIND_PITCH_LPC_ORDER + 1 ]; | ||
48 | silk_float A[ MAX_FIND_PITCH_LPC_ORDER ]; | ||
49 | silk_float refl_coef[ MAX_FIND_PITCH_LPC_ORDER ]; | ||
50 | silk_float Wsig[ FIND_PITCH_LPC_WIN_MAX ]; | ||
51 | silk_float *Wsig_ptr; | ||
52 | |||
53 | /******************************************/ | ||
54 | /* Set up buffer lengths etc based on Fs */ | ||
55 | /******************************************/ | ||
56 | buf_len = psEnc->sCmn.la_pitch + psEnc->sCmn.frame_length + psEnc->sCmn.ltp_mem_length; | ||
57 | |||
58 | /* Safety check */ | ||
59 | celt_assert( buf_len >= psEnc->sCmn.pitch_LPC_win_length ); | ||
60 | |||
61 | x_buf = x - psEnc->sCmn.ltp_mem_length; | ||
62 | |||
63 | /******************************************/ | ||
64 | /* Estimate LPC AR coeficients */ | ||
65 | /******************************************/ | ||
66 | |||
67 | /* Calculate windowed signal */ | ||
68 | |||
69 | /* First LA_LTP samples */ | ||
70 | x_buf_ptr = x_buf + buf_len - psEnc->sCmn.pitch_LPC_win_length; | ||
71 | Wsig_ptr = Wsig; | ||
72 | silk_apply_sine_window_FLP( Wsig_ptr, x_buf_ptr, 1, psEnc->sCmn.la_pitch ); | ||
73 | |||
74 | /* Middle non-windowed samples */ | ||
75 | Wsig_ptr += psEnc->sCmn.la_pitch; | ||
76 | x_buf_ptr += psEnc->sCmn.la_pitch; | ||
77 | silk_memcpy( Wsig_ptr, x_buf_ptr, ( psEnc->sCmn.pitch_LPC_win_length - ( psEnc->sCmn.la_pitch << 1 ) ) * sizeof( silk_float ) ); | ||
78 | |||
79 | /* Last LA_LTP samples */ | ||
80 | Wsig_ptr += psEnc->sCmn.pitch_LPC_win_length - ( psEnc->sCmn.la_pitch << 1 ); | ||
81 | x_buf_ptr += psEnc->sCmn.pitch_LPC_win_length - ( psEnc->sCmn.la_pitch << 1 ); | ||
82 | silk_apply_sine_window_FLP( Wsig_ptr, x_buf_ptr, 2, psEnc->sCmn.la_pitch ); | ||
83 | |||
84 | /* Calculate autocorrelation sequence */ | ||
85 | silk_autocorrelation_FLP( auto_corr, Wsig, psEnc->sCmn.pitch_LPC_win_length, psEnc->sCmn.pitchEstimationLPCOrder + 1 ); | ||
86 | |||
87 | /* Add white noise, as a fraction of the energy */ | ||
88 | auto_corr[ 0 ] += auto_corr[ 0 ] * FIND_PITCH_WHITE_NOISE_FRACTION + 1; | ||
89 | |||
90 | /* Calculate the reflection coefficients using Schur */ | ||
91 | res_nrg = silk_schur_FLP( refl_coef, auto_corr, psEnc->sCmn.pitchEstimationLPCOrder ); | ||
92 | |||
93 | /* Prediction gain */ | ||
94 | psEncCtrl->predGain = auto_corr[ 0 ] / silk_max_float( res_nrg, 1.0f ); | ||
95 | |||
96 | /* Convert reflection coefficients to prediction coefficients */ | ||
97 | silk_k2a_FLP( A, refl_coef, psEnc->sCmn.pitchEstimationLPCOrder ); | ||
98 | |||
99 | /* Bandwidth expansion */ | ||
100 | silk_bwexpander_FLP( A, psEnc->sCmn.pitchEstimationLPCOrder, FIND_PITCH_BANDWIDTH_EXPANSION ); | ||
101 | |||
102 | /*****************************************/ | ||
103 | /* LPC analysis filtering */ | ||
104 | /*****************************************/ | ||
105 | silk_LPC_analysis_filter_FLP( res, A, x_buf, buf_len, psEnc->sCmn.pitchEstimationLPCOrder ); | ||
106 | |||
107 | if( psEnc->sCmn.indices.signalType != TYPE_NO_VOICE_ACTIVITY && psEnc->sCmn.first_frame_after_reset == 0 ) { | ||
108 | /* Threshold for pitch estimator */ | ||
109 | thrhld = 0.6f; | ||
110 | thrhld -= 0.004f * psEnc->sCmn.pitchEstimationLPCOrder; | ||
111 | thrhld -= 0.1f * psEnc->sCmn.speech_activity_Q8 * ( 1.0f / 256.0f ); | ||
112 | thrhld -= 0.15f * (psEnc->sCmn.prevSignalType >> 1); | ||
113 | thrhld -= 0.1f * psEnc->sCmn.input_tilt_Q15 * ( 1.0f / 32768.0f ); | ||
114 | |||
115 | /*****************************************/ | ||
116 | /* Call Pitch estimator */ | ||
117 | /*****************************************/ | ||
118 | if( silk_pitch_analysis_core_FLP( res, psEncCtrl->pitchL, &psEnc->sCmn.indices.lagIndex, | ||
119 | &psEnc->sCmn.indices.contourIndex, &psEnc->LTPCorr, psEnc->sCmn.prevLag, psEnc->sCmn.pitchEstimationThreshold_Q16 / 65536.0f, | ||
120 | thrhld, psEnc->sCmn.fs_kHz, psEnc->sCmn.pitchEstimationComplexity, psEnc->sCmn.nb_subfr, arch ) == 0 ) | ||
121 | { | ||
122 | psEnc->sCmn.indices.signalType = TYPE_VOICED; | ||
123 | } else { | ||
124 | psEnc->sCmn.indices.signalType = TYPE_UNVOICED; | ||
125 | } | ||
126 | } else { | ||
127 | silk_memset( psEncCtrl->pitchL, 0, sizeof( psEncCtrl->pitchL ) ); | ||
128 | psEnc->sCmn.indices.lagIndex = 0; | ||
129 | psEnc->sCmn.indices.contourIndex = 0; | ||
130 | psEnc->LTPCorr = 0; | ||
131 | } | ||
132 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/find_pred_coefs_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/find_pred_coefs_FLP.c new file mode 100644 index 0000000000..dcf7c5202d --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/find_pred_coefs_FLP.c | |||
@@ -0,0 +1,116 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "main_FLP.h" | ||
33 | |||
34 | /* Find LPC and LTP coefficients */ | ||
35 | void silk_find_pred_coefs_FLP( | ||
36 | silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ | ||
37 | silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ | ||
38 | const silk_float res_pitch[], /* I Residual from pitch analysis */ | ||
39 | const silk_float x[], /* I Speech signal */ | ||
40 | opus_int condCoding /* I The type of conditional coding to use */ | ||
41 | ) | ||
42 | { | ||
43 | opus_int i; | ||
44 | silk_float XXLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ]; | ||
45 | silk_float xXLTP[ MAX_NB_SUBFR * LTP_ORDER ]; | ||
46 | silk_float invGains[ MAX_NB_SUBFR ]; | ||
47 | opus_int16 NLSF_Q15[ MAX_LPC_ORDER ]; | ||
48 | const silk_float *x_ptr; | ||
49 | silk_float *x_pre_ptr, LPC_in_pre[ MAX_NB_SUBFR * MAX_LPC_ORDER + MAX_FRAME_LENGTH ]; | ||
50 | silk_float minInvGain; | ||
51 | |||
52 | /* Weighting for weighted least squares */ | ||
53 | for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { | ||
54 | silk_assert( psEncCtrl->Gains[ i ] > 0.0f ); | ||
55 | invGains[ i ] = 1.0f / psEncCtrl->Gains[ i ]; | ||
56 | } | ||
57 | |||
58 | if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { | ||
59 | /**********/ | ||
60 | /* VOICED */ | ||
61 | /**********/ | ||
62 | celt_assert( psEnc->sCmn.ltp_mem_length - psEnc->sCmn.predictLPCOrder >= psEncCtrl->pitchL[ 0 ] + LTP_ORDER / 2 ); | ||
63 | |||
64 | /* LTP analysis */ | ||
65 | silk_find_LTP_FLP( XXLTP, xXLTP, res_pitch, psEncCtrl->pitchL, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr ); | ||
66 | |||
67 | /* Quantize LTP gain parameters */ | ||
68 | silk_quant_LTP_gains_FLP( psEncCtrl->LTPCoef, psEnc->sCmn.indices.LTPIndex, &psEnc->sCmn.indices.PERIndex, | ||
69 | &psEnc->sCmn.sum_log_gain_Q7, &psEncCtrl->LTPredCodGain, XXLTP, xXLTP, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.arch ); | ||
70 | |||
71 | /* Control LTP scaling */ | ||
72 | silk_LTP_scale_ctrl_FLP( psEnc, psEncCtrl, condCoding ); | ||
73 | |||
74 | /* Create LTP residual */ | ||
75 | silk_LTP_analysis_filter_FLP( LPC_in_pre, x - psEnc->sCmn.predictLPCOrder, psEncCtrl->LTPCoef, | ||
76 | psEncCtrl->pitchL, invGains, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.predictLPCOrder ); | ||
77 | } else { | ||
78 | /************/ | ||
79 | /* UNVOICED */ | ||
80 | /************/ | ||
81 | /* Create signal with prepended subframes, scaled by inverse gains */ | ||
82 | x_ptr = x - psEnc->sCmn.predictLPCOrder; | ||
83 | x_pre_ptr = LPC_in_pre; | ||
84 | for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { | ||
85 | silk_scale_copy_vector_FLP( x_pre_ptr, x_ptr, invGains[ i ], | ||
86 | psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder ); | ||
87 | x_pre_ptr += psEnc->sCmn.subfr_length + psEnc->sCmn.predictLPCOrder; | ||
88 | x_ptr += psEnc->sCmn.subfr_length; | ||
89 | } | ||
90 | silk_memset( psEncCtrl->LTPCoef, 0, psEnc->sCmn.nb_subfr * LTP_ORDER * sizeof( silk_float ) ); | ||
91 | psEncCtrl->LTPredCodGain = 0.0f; | ||
92 | psEnc->sCmn.sum_log_gain_Q7 = 0; | ||
93 | } | ||
94 | |||
95 | /* Limit on total predictive coding gain */ | ||
96 | if( psEnc->sCmn.first_frame_after_reset ) { | ||
97 | minInvGain = 1.0f / MAX_PREDICTION_POWER_GAIN_AFTER_RESET; | ||
98 | } else { | ||
99 | minInvGain = (silk_float)pow( 2, psEncCtrl->LTPredCodGain / 3 ) / MAX_PREDICTION_POWER_GAIN; | ||
100 | minInvGain /= 0.25f + 0.75f * psEncCtrl->coding_quality; | ||
101 | } | ||
102 | |||
103 | /* LPC_in_pre contains the LTP-filtered input for voiced, and the unfiltered input for unvoiced */ | ||
104 | silk_find_LPC_FLP( &psEnc->sCmn, NLSF_Q15, LPC_in_pre, minInvGain ); | ||
105 | |||
106 | /* Quantize LSFs */ | ||
107 | silk_process_NLSFs_FLP( &psEnc->sCmn, psEncCtrl->PredCoef, NLSF_Q15, psEnc->sCmn.prev_NLSFq_Q15 ); | ||
108 | |||
109 | /* Calculate residual energy using quantized LPC coefficients */ | ||
110 | silk_residual_energy_FLP( psEncCtrl->ResNrg, LPC_in_pre, psEncCtrl->PredCoef, psEncCtrl->Gains, | ||
111 | psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.predictLPCOrder ); | ||
112 | |||
113 | /* Copy to prediction struct for use in next frame for interpolation */ | ||
114 | silk_memcpy( psEnc->sCmn.prev_NLSFq_Q15, NLSF_Q15, sizeof( psEnc->sCmn.prev_NLSFq_Q15 ) ); | ||
115 | } | ||
116 | |||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/inner_product_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/inner_product_FLP.c new file mode 100644 index 0000000000..cdd39d24ce --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/inner_product_FLP.c | |||
@@ -0,0 +1,59 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "SigProc_FLP.h" | ||
33 | |||
34 | /* inner product of two silk_float arrays, with result as double */ | ||
35 | double silk_inner_product_FLP( | ||
36 | const silk_float *data1, | ||
37 | const silk_float *data2, | ||
38 | opus_int dataSize | ||
39 | ) | ||
40 | { | ||
41 | opus_int i; | ||
42 | double result; | ||
43 | |||
44 | /* 4x unrolled loop */ | ||
45 | result = 0.0; | ||
46 | for( i = 0; i < dataSize - 3; i += 4 ) { | ||
47 | result += data1[ i + 0 ] * (double)data2[ i + 0 ] + | ||
48 | data1[ i + 1 ] * (double)data2[ i + 1 ] + | ||
49 | data1[ i + 2 ] * (double)data2[ i + 2 ] + | ||
50 | data1[ i + 3 ] * (double)data2[ i + 3 ]; | ||
51 | } | ||
52 | |||
53 | /* add any remaining products */ | ||
54 | for( ; i < dataSize; i++ ) { | ||
55 | result += data1[ i ] * (double)data2[ i ]; | ||
56 | } | ||
57 | |||
58 | return result; | ||
59 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/k2a_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/k2a_FLP.c new file mode 100644 index 0000000000..1448008dbb --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/k2a_FLP.c | |||
@@ -0,0 +1,54 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "SigProc_FLP.h" | ||
33 | |||
34 | /* step up function, converts reflection coefficients to prediction coefficients */ | ||
35 | void silk_k2a_FLP( | ||
36 | silk_float *A, /* O prediction coefficients [order] */ | ||
37 | const silk_float *rc, /* I reflection coefficients [order] */ | ||
38 | opus_int32 order /* I prediction order */ | ||
39 | ) | ||
40 | { | ||
41 | opus_int k, n; | ||
42 | silk_float rck, tmp1, tmp2; | ||
43 | |||
44 | for( k = 0; k < order; k++ ) { | ||
45 | rck = rc[ k ]; | ||
46 | for( n = 0; n < (k + 1) >> 1; n++ ) { | ||
47 | tmp1 = A[ n ]; | ||
48 | tmp2 = A[ k - n - 1 ]; | ||
49 | A[ n ] = tmp1 + tmp2 * rck; | ||
50 | A[ k - n - 1 ] = tmp2 + tmp1 * rck; | ||
51 | } | ||
52 | A[ k ] = -rck; | ||
53 | } | ||
54 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/main_FLP.h b/lib/rbcodec/codecs/libopus/silk/float/main_FLP.h new file mode 100644 index 0000000000..5dc0ccf4a4 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/main_FLP.h | |||
@@ -0,0 +1,286 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifndef SILK_MAIN_FLP_H | ||
29 | #define SILK_MAIN_FLP_H | ||
30 | |||
31 | #include "SigProc_FLP.h" | ||
32 | #include "SigProc_FIX.h" | ||
33 | #include "structs_FLP.h" | ||
34 | #include "main.h" | ||
35 | #include "define.h" | ||
36 | #include "debug.h" | ||
37 | #include "entenc.h" | ||
38 | |||
39 | #ifdef __cplusplus | ||
40 | extern "C" | ||
41 | { | ||
42 | #endif | ||
43 | |||
44 | #define silk_encoder_state_Fxx silk_encoder_state_FLP | ||
45 | #define silk_encode_do_VAD_Fxx silk_encode_do_VAD_FLP | ||
46 | #define silk_encode_frame_Fxx silk_encode_frame_FLP | ||
47 | |||
48 | /*********************/ | ||
49 | /* Encoder Functions */ | ||
50 | /*********************/ | ||
51 | |||
52 | /* High-pass filter with cutoff frequency adaptation based on pitch lag statistics */ | ||
53 | void silk_HP_variable_cutoff( | ||
54 | silk_encoder_state_Fxx state_Fxx[] /* I/O Encoder states */ | ||
55 | ); | ||
56 | |||
57 | /* Encoder main function */ | ||
58 | void silk_encode_do_VAD_FLP( | ||
59 | silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ | ||
60 | opus_int activity /* I Decision of Opus voice activity detector */ | ||
61 | ); | ||
62 | |||
63 | /* Encoder main function */ | ||
64 | opus_int silk_encode_frame_FLP( | ||
65 | silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ | ||
66 | opus_int32 *pnBytesOut, /* O Number of payload bytes; */ | ||
67 | ec_enc *psRangeEnc, /* I/O compressor data structure */ | ||
68 | opus_int condCoding, /* I The type of conditional coding to use */ | ||
69 | opus_int maxBits, /* I If > 0: maximum number of output bits */ | ||
70 | opus_int useCBR /* I Flag to force constant-bitrate operation */ | ||
71 | ); | ||
72 | |||
73 | /* Initializes the Silk encoder state */ | ||
74 | opus_int silk_init_encoder( | ||
75 | silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ | ||
76 | int arch /* I Run-tim architecture */ | ||
77 | ); | ||
78 | |||
79 | /* Control the Silk encoder */ | ||
80 | opus_int silk_control_encoder( | ||
81 | silk_encoder_state_FLP *psEnc, /* I/O Pointer to Silk encoder state FLP */ | ||
82 | silk_EncControlStruct *encControl, /* I Control structure */ | ||
83 | const opus_int allow_bw_switch, /* I Flag to allow switching audio bandwidth */ | ||
84 | const opus_int channelNb, /* I Channel number */ | ||
85 | const opus_int force_fs_kHz | ||
86 | ); | ||
87 | |||
88 | /**************************/ | ||
89 | /* Noise shaping analysis */ | ||
90 | /**************************/ | ||
91 | /* Compute noise shaping coefficients and initial gain values */ | ||
92 | void silk_noise_shape_analysis_FLP( | ||
93 | silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ | ||
94 | silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ | ||
95 | const silk_float *pitch_res, /* I LPC residual from pitch analysis */ | ||
96 | const silk_float *x /* I Input signal [frame_length + la_shape] */ | ||
97 | ); | ||
98 | |||
99 | /* Autocorrelations for a warped frequency axis */ | ||
100 | void silk_warped_autocorrelation_FLP( | ||
101 | silk_float *corr, /* O Result [order + 1] */ | ||
102 | const silk_float *input, /* I Input data to correlate */ | ||
103 | const silk_float warping, /* I Warping coefficient */ | ||
104 | const opus_int length, /* I Length of input */ | ||
105 | const opus_int order /* I Correlation order (even) */ | ||
106 | ); | ||
107 | |||
108 | /* Calculation of LTP state scaling */ | ||
109 | void silk_LTP_scale_ctrl_FLP( | ||
110 | silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ | ||
111 | silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ | ||
112 | opus_int condCoding /* I The type of conditional coding to use */ | ||
113 | ); | ||
114 | |||
115 | /**********************************************/ | ||
116 | /* Prediction Analysis */ | ||
117 | /**********************************************/ | ||
118 | /* Find pitch lags */ | ||
119 | void silk_find_pitch_lags_FLP( | ||
120 | silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ | ||
121 | silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ | ||
122 | silk_float res[], /* O Residual */ | ||
123 | const silk_float x[], /* I Speech signal */ | ||
124 | int arch /* I Run-time architecture */ | ||
125 | ); | ||
126 | |||
127 | /* Find LPC and LTP coefficients */ | ||
128 | void silk_find_pred_coefs_FLP( | ||
129 | silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ | ||
130 | silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ | ||
131 | const silk_float res_pitch[], /* I Residual from pitch analysis */ | ||
132 | const silk_float x[], /* I Speech signal */ | ||
133 | opus_int condCoding /* I The type of conditional coding to use */ | ||
134 | ); | ||
135 | |||
136 | /* LPC analysis */ | ||
137 | void silk_find_LPC_FLP( | ||
138 | silk_encoder_state *psEncC, /* I/O Encoder state */ | ||
139 | opus_int16 NLSF_Q15[], /* O NLSFs */ | ||
140 | const silk_float x[], /* I Input signal */ | ||
141 | const silk_float minInvGain /* I Prediction gain from LTP (dB) */ | ||
142 | ); | ||
143 | |||
144 | /* LTP analysis */ | ||
145 | void silk_find_LTP_FLP( | ||
146 | silk_float XX[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Weight for LTP quantization */ | ||
147 | silk_float xX[ MAX_NB_SUBFR * LTP_ORDER ], /* O Weight for LTP quantization */ | ||
148 | const silk_float r_ptr[], /* I LPC residual */ | ||
149 | const opus_int lag[ MAX_NB_SUBFR ], /* I LTP lags */ | ||
150 | const opus_int subfr_length, /* I Subframe length */ | ||
151 | const opus_int nb_subfr /* I number of subframes */ | ||
152 | ); | ||
153 | |||
154 | void silk_LTP_analysis_filter_FLP( | ||
155 | silk_float *LTP_res, /* O LTP res MAX_NB_SUBFR*(pre_lgth+subfr_lngth) */ | ||
156 | const silk_float *x, /* I Input signal, with preceding samples */ | ||
157 | const silk_float B[ LTP_ORDER * MAX_NB_SUBFR ], /* I LTP coefficients for each subframe */ | ||
158 | const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */ | ||
159 | const silk_float invGains[ MAX_NB_SUBFR ], /* I Inverse quantization gains */ | ||
160 | const opus_int subfr_length, /* I Length of each subframe */ | ||
161 | const opus_int nb_subfr, /* I number of subframes */ | ||
162 | const opus_int pre_length /* I Preceding samples for each subframe */ | ||
163 | ); | ||
164 | |||
165 | /* Calculates residual energies of input subframes where all subframes have LPC_order */ | ||
166 | /* of preceding samples */ | ||
167 | void silk_residual_energy_FLP( | ||
168 | silk_float nrgs[ MAX_NB_SUBFR ], /* O Residual energy per subframe */ | ||
169 | const silk_float x[], /* I Input signal */ | ||
170 | silk_float a[ 2 ][ MAX_LPC_ORDER ], /* I AR coefs for each frame half */ | ||
171 | const silk_float gains[], /* I Quantization gains */ | ||
172 | const opus_int subfr_length, /* I Subframe length */ | ||
173 | const opus_int nb_subfr, /* I number of subframes */ | ||
174 | const opus_int LPC_order /* I LPC order */ | ||
175 | ); | ||
176 | |||
177 | /* 16th order LPC analysis filter */ | ||
178 | void silk_LPC_analysis_filter_FLP( | ||
179 | silk_float r_LPC[], /* O LPC residual signal */ | ||
180 | const silk_float PredCoef[], /* I LPC coefficients */ | ||
181 | const silk_float s[], /* I Input signal */ | ||
182 | const opus_int length, /* I Length of input signal */ | ||
183 | const opus_int Order /* I LPC order */ | ||
184 | ); | ||
185 | |||
186 | /* LTP tap quantizer */ | ||
187 | void silk_quant_LTP_gains_FLP( | ||
188 | silk_float B[ MAX_NB_SUBFR * LTP_ORDER ], /* O Quantized LTP gains */ | ||
189 | opus_int8 cbk_index[ MAX_NB_SUBFR ], /* O Codebook index */ | ||
190 | opus_int8 *periodicity_index, /* O Periodicity index */ | ||
191 | opus_int32 *sum_log_gain_Q7, /* I/O Cumulative max prediction gain */ | ||
192 | silk_float *pred_gain_dB, /* O LTP prediction gain */ | ||
193 | const silk_float XX[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* I Correlation matrix */ | ||
194 | const silk_float xX[ MAX_NB_SUBFR * LTP_ORDER ], /* I Correlation vector */ | ||
195 | const opus_int subfr_len, /* I Number of samples per subframe */ | ||
196 | const opus_int nb_subfr, /* I Number of subframes */ | ||
197 | int arch /* I Run-time architecture */ | ||
198 | ); | ||
199 | |||
200 | /* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */ | ||
201 | silk_float silk_residual_energy_covar_FLP( /* O Weighted residual energy */ | ||
202 | const silk_float *c, /* I Filter coefficients */ | ||
203 | silk_float *wXX, /* I/O Weighted correlation matrix, reg. out */ | ||
204 | const silk_float *wXx, /* I Weighted correlation vector */ | ||
205 | const silk_float wxx, /* I Weighted correlation value */ | ||
206 | const opus_int D /* I Dimension */ | ||
207 | ); | ||
208 | |||
209 | /* Processing of gains */ | ||
210 | void silk_process_gains_FLP( | ||
211 | silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ | ||
212 | silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ | ||
213 | opus_int condCoding /* I The type of conditional coding to use */ | ||
214 | ); | ||
215 | |||
216 | /******************/ | ||
217 | /* Linear Algebra */ | ||
218 | /******************/ | ||
219 | /* Calculates correlation matrix X'*X */ | ||
220 | void silk_corrMatrix_FLP( | ||
221 | const silk_float *x, /* I x vector [ L+order-1 ] used to create X */ | ||
222 | const opus_int L, /* I Length of vectors */ | ||
223 | const opus_int Order, /* I Max lag for correlation */ | ||
224 | silk_float *XX /* O X'*X correlation matrix [order x order] */ | ||
225 | ); | ||
226 | |||
227 | /* Calculates correlation vector X'*t */ | ||
228 | void silk_corrVector_FLP( | ||
229 | const silk_float *x, /* I x vector [L+order-1] used to create X */ | ||
230 | const silk_float *t, /* I Target vector [L] */ | ||
231 | const opus_int L, /* I Length of vecors */ | ||
232 | const opus_int Order, /* I Max lag for correlation */ | ||
233 | silk_float *Xt /* O X'*t correlation vector [order] */ | ||
234 | ); | ||
235 | |||
236 | /* Apply sine window to signal vector. */ | ||
237 | /* Window types: */ | ||
238 | /* 1 -> sine window from 0 to pi/2 */ | ||
239 | /* 2 -> sine window from pi/2 to pi */ | ||
240 | void silk_apply_sine_window_FLP( | ||
241 | silk_float px_win[], /* O Pointer to windowed signal */ | ||
242 | const silk_float px[], /* I Pointer to input signal */ | ||
243 | const opus_int win_type, /* I Selects a window type */ | ||
244 | const opus_int length /* I Window length, multiple of 4 */ | ||
245 | ); | ||
246 | |||
247 | /* Wrapper functions. Call flp / fix code */ | ||
248 | |||
249 | /* Convert AR filter coefficients to NLSF parameters */ | ||
250 | void silk_A2NLSF_FLP( | ||
251 | opus_int16 *NLSF_Q15, /* O NLSF vector [ LPC_order ] */ | ||
252 | const silk_float *pAR, /* I LPC coefficients [ LPC_order ] */ | ||
253 | const opus_int LPC_order /* I LPC order */ | ||
254 | ); | ||
255 | |||
256 | /* Convert NLSF parameters to AR prediction filter coefficients */ | ||
257 | void silk_NLSF2A_FLP( | ||
258 | silk_float *pAR, /* O LPC coefficients [ LPC_order ] */ | ||
259 | const opus_int16 *NLSF_Q15, /* I NLSF vector [ LPC_order ] */ | ||
260 | const opus_int LPC_order, /* I LPC order */ | ||
261 | int arch /* I Run-time architecture */ | ||
262 | ); | ||
263 | |||
264 | /* Limit, stabilize, and quantize NLSFs */ | ||
265 | void silk_process_NLSFs_FLP( | ||
266 | silk_encoder_state *psEncC, /* I/O Encoder state */ | ||
267 | silk_float PredCoef[ 2 ][ MAX_LPC_ORDER ], /* O Prediction coefficients */ | ||
268 | opus_int16 NLSF_Q15[ MAX_LPC_ORDER ], /* I/O Normalized LSFs (quant out) (0 - (2^15-1)) */ | ||
269 | const opus_int16 prev_NLSF_Q15[ MAX_LPC_ORDER ] /* I Previous Normalized LSFs (0 - (2^15-1)) */ | ||
270 | ); | ||
271 | |||
272 | /* Floating-point Silk NSQ wrapper */ | ||
273 | void silk_NSQ_wrapper_FLP( | ||
274 | silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ | ||
275 | silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ | ||
276 | SideInfoIndices *psIndices, /* I/O Quantization indices */ | ||
277 | silk_nsq_state *psNSQ, /* I/O Noise Shaping Quantzation state */ | ||
278 | opus_int8 pulses[], /* O Quantized pulse signal */ | ||
279 | const silk_float x[] /* I Prefiltered input signal */ | ||
280 | ); | ||
281 | |||
282 | #ifdef __cplusplus | ||
283 | } | ||
284 | #endif | ||
285 | |||
286 | #endif | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/noise_shape_analysis_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/noise_shape_analysis_FLP.c new file mode 100644 index 0000000000..cb3d8a50b7 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/noise_shape_analysis_FLP.c | |||
@@ -0,0 +1,350 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "main_FLP.h" | ||
33 | #include "tuning_parameters.h" | ||
34 | |||
35 | /* Compute gain to make warped filter coefficients have a zero mean log frequency response on a */ | ||
36 | /* non-warped frequency scale. (So that it can be implemented with a minimum-phase monic filter.) */ | ||
37 | /* Note: A monic filter is one with the first coefficient equal to 1.0. In Silk we omit the first */ | ||
38 | /* coefficient in an array of coefficients, for monic filters. */ | ||
39 | static OPUS_INLINE silk_float warped_gain( | ||
40 | const silk_float *coefs, | ||
41 | silk_float lambda, | ||
42 | opus_int order | ||
43 | ) { | ||
44 | opus_int i; | ||
45 | silk_float gain; | ||
46 | |||
47 | lambda = -lambda; | ||
48 | gain = coefs[ order - 1 ]; | ||
49 | for( i = order - 2; i >= 0; i-- ) { | ||
50 | gain = lambda * gain + coefs[ i ]; | ||
51 | } | ||
52 | return (silk_float)( 1.0f / ( 1.0f - lambda * gain ) ); | ||
53 | } | ||
54 | |||
55 | /* Convert warped filter coefficients to monic pseudo-warped coefficients and limit maximum */ | ||
56 | /* amplitude of monic warped coefficients by using bandwidth expansion on the true coefficients */ | ||
57 | static OPUS_INLINE void warped_true2monic_coefs( | ||
58 | silk_float *coefs, | ||
59 | silk_float lambda, | ||
60 | silk_float limit, | ||
61 | opus_int order | ||
62 | ) { | ||
63 | opus_int i, iter, ind = 0; | ||
64 | silk_float tmp, maxabs, chirp, gain; | ||
65 | |||
66 | /* Convert to monic coefficients */ | ||
67 | for( i = order - 1; i > 0; i-- ) { | ||
68 | coefs[ i - 1 ] -= lambda * coefs[ i ]; | ||
69 | } | ||
70 | gain = ( 1.0f - lambda * lambda ) / ( 1.0f + lambda * coefs[ 0 ] ); | ||
71 | for( i = 0; i < order; i++ ) { | ||
72 | coefs[ i ] *= gain; | ||
73 | } | ||
74 | |||
75 | /* Limit */ | ||
76 | for( iter = 0; iter < 10; iter++ ) { | ||
77 | /* Find maximum absolute value */ | ||
78 | maxabs = -1.0f; | ||
79 | for( i = 0; i < order; i++ ) { | ||
80 | tmp = silk_abs_float( coefs[ i ] ); | ||
81 | if( tmp > maxabs ) { | ||
82 | maxabs = tmp; | ||
83 | ind = i; | ||
84 | } | ||
85 | } | ||
86 | if( maxabs <= limit ) { | ||
87 | /* Coefficients are within range - done */ | ||
88 | return; | ||
89 | } | ||
90 | |||
91 | /* Convert back to true warped coefficients */ | ||
92 | for( i = 1; i < order; i++ ) { | ||
93 | coefs[ i - 1 ] += lambda * coefs[ i ]; | ||
94 | } | ||
95 | gain = 1.0f / gain; | ||
96 | for( i = 0; i < order; i++ ) { | ||
97 | coefs[ i ] *= gain; | ||
98 | } | ||
99 | |||
100 | /* Apply bandwidth expansion */ | ||
101 | chirp = 0.99f - ( 0.8f + 0.1f * iter ) * ( maxabs - limit ) / ( maxabs * ( ind + 1 ) ); | ||
102 | silk_bwexpander_FLP( coefs, order, chirp ); | ||
103 | |||
104 | /* Convert to monic warped coefficients */ | ||
105 | for( i = order - 1; i > 0; i-- ) { | ||
106 | coefs[ i - 1 ] -= lambda * coefs[ i ]; | ||
107 | } | ||
108 | gain = ( 1.0f - lambda * lambda ) / ( 1.0f + lambda * coefs[ 0 ] ); | ||
109 | for( i = 0; i < order; i++ ) { | ||
110 | coefs[ i ] *= gain; | ||
111 | } | ||
112 | } | ||
113 | silk_assert( 0 ); | ||
114 | } | ||
115 | |||
116 | static OPUS_INLINE void limit_coefs( | ||
117 | silk_float *coefs, | ||
118 | silk_float limit, | ||
119 | opus_int order | ||
120 | ) { | ||
121 | opus_int i, iter, ind = 0; | ||
122 | silk_float tmp, maxabs, chirp; | ||
123 | |||
124 | for( iter = 0; iter < 10; iter++ ) { | ||
125 | /* Find maximum absolute value */ | ||
126 | maxabs = -1.0f; | ||
127 | for( i = 0; i < order; i++ ) { | ||
128 | tmp = silk_abs_float( coefs[ i ] ); | ||
129 | if( tmp > maxabs ) { | ||
130 | maxabs = tmp; | ||
131 | ind = i; | ||
132 | } | ||
133 | } | ||
134 | if( maxabs <= limit ) { | ||
135 | /* Coefficients are within range - done */ | ||
136 | return; | ||
137 | } | ||
138 | |||
139 | /* Apply bandwidth expansion */ | ||
140 | chirp = 0.99f - ( 0.8f + 0.1f * iter ) * ( maxabs - limit ) / ( maxabs * ( ind + 1 ) ); | ||
141 | silk_bwexpander_FLP( coefs, order, chirp ); | ||
142 | } | ||
143 | silk_assert( 0 ); | ||
144 | } | ||
145 | |||
146 | /* Compute noise shaping coefficients and initial gain values */ | ||
147 | void silk_noise_shape_analysis_FLP( | ||
148 | silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ | ||
149 | silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ | ||
150 | const silk_float *pitch_res, /* I LPC residual from pitch analysis */ | ||
151 | const silk_float *x /* I Input signal [frame_length + la_shape] */ | ||
152 | ) | ||
153 | { | ||
154 | silk_shape_state_FLP *psShapeSt = &psEnc->sShape; | ||
155 | opus_int k, nSamples, nSegs; | ||
156 | silk_float SNR_adj_dB, HarmShapeGain, Tilt; | ||
157 | silk_float nrg, log_energy, log_energy_prev, energy_variation; | ||
158 | silk_float BWExp, gain_mult, gain_add, strength, b, warping; | ||
159 | silk_float x_windowed[ SHAPE_LPC_WIN_MAX ]; | ||
160 | silk_float auto_corr[ MAX_SHAPE_LPC_ORDER + 1 ]; | ||
161 | silk_float rc[ MAX_SHAPE_LPC_ORDER + 1 ]; | ||
162 | const silk_float *x_ptr, *pitch_res_ptr; | ||
163 | |||
164 | /* Point to start of first LPC analysis block */ | ||
165 | x_ptr = x - psEnc->sCmn.la_shape; | ||
166 | |||
167 | /****************/ | ||
168 | /* GAIN CONTROL */ | ||
169 | /****************/ | ||
170 | SNR_adj_dB = psEnc->sCmn.SNR_dB_Q7 * ( 1 / 128.0f ); | ||
171 | |||
172 | /* Input quality is the average of the quality in the lowest two VAD bands */ | ||
173 | psEncCtrl->input_quality = 0.5f * ( psEnc->sCmn.input_quality_bands_Q15[ 0 ] + psEnc->sCmn.input_quality_bands_Q15[ 1 ] ) * ( 1.0f / 32768.0f ); | ||
174 | |||
175 | /* Coding quality level, between 0.0 and 1.0 */ | ||
176 | psEncCtrl->coding_quality = silk_sigmoid( 0.25f * ( SNR_adj_dB - 20.0f ) ); | ||
177 | |||
178 | if( psEnc->sCmn.useCBR == 0 ) { | ||
179 | /* Reduce coding SNR during low speech activity */ | ||
180 | b = 1.0f - psEnc->sCmn.speech_activity_Q8 * ( 1.0f / 256.0f ); | ||
181 | SNR_adj_dB -= BG_SNR_DECR_dB * psEncCtrl->coding_quality * ( 0.5f + 0.5f * psEncCtrl->input_quality ) * b * b; | ||
182 | } | ||
183 | |||
184 | if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { | ||
185 | /* Reduce gains for periodic signals */ | ||
186 | SNR_adj_dB += HARM_SNR_INCR_dB * psEnc->LTPCorr; | ||
187 | } else { | ||
188 | /* For unvoiced signals and low-quality input, adjust the quality slower than SNR_dB setting */ | ||
189 | SNR_adj_dB += ( -0.4f * psEnc->sCmn.SNR_dB_Q7 * ( 1 / 128.0f ) + 6.0f ) * ( 1.0f - psEncCtrl->input_quality ); | ||
190 | } | ||
191 | |||
192 | /*************************/ | ||
193 | /* SPARSENESS PROCESSING */ | ||
194 | /*************************/ | ||
195 | /* Set quantizer offset */ | ||
196 | if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { | ||
197 | /* Initially set to 0; may be overruled in process_gains(..) */ | ||
198 | psEnc->sCmn.indices.quantOffsetType = 0; | ||
199 | } else { | ||
200 | /* Sparseness measure, based on relative fluctuations of energy per 2 milliseconds */ | ||
201 | nSamples = 2 * psEnc->sCmn.fs_kHz; | ||
202 | energy_variation = 0.0f; | ||
203 | log_energy_prev = 0.0f; | ||
204 | pitch_res_ptr = pitch_res; | ||
205 | nSegs = silk_SMULBB( SUB_FRAME_LENGTH_MS, psEnc->sCmn.nb_subfr ) / 2; | ||
206 | for( k = 0; k < nSegs; k++ ) { | ||
207 | nrg = ( silk_float )nSamples + ( silk_float )silk_energy_FLP( pitch_res_ptr, nSamples ); | ||
208 | log_energy = silk_log2( nrg ); | ||
209 | if( k > 0 ) { | ||
210 | energy_variation += silk_abs_float( log_energy - log_energy_prev ); | ||
211 | } | ||
212 | log_energy_prev = log_energy; | ||
213 | pitch_res_ptr += nSamples; | ||
214 | } | ||
215 | |||
216 | /* Set quantization offset depending on sparseness measure */ | ||
217 | if( energy_variation > ENERGY_VARIATION_THRESHOLD_QNT_OFFSET * (nSegs-1) ) { | ||
218 | psEnc->sCmn.indices.quantOffsetType = 0; | ||
219 | } else { | ||
220 | psEnc->sCmn.indices.quantOffsetType = 1; | ||
221 | } | ||
222 | } | ||
223 | |||
224 | /*******************************/ | ||
225 | /* Control bandwidth expansion */ | ||
226 | /*******************************/ | ||
227 | /* More BWE for signals with high prediction gain */ | ||
228 | strength = FIND_PITCH_WHITE_NOISE_FRACTION * psEncCtrl->predGain; /* between 0.0 and 1.0 */ | ||
229 | BWExp = BANDWIDTH_EXPANSION / ( 1.0f + strength * strength ); | ||
230 | |||
231 | /* Slightly more warping in analysis will move quantization noise up in frequency, where it's better masked */ | ||
232 | warping = (silk_float)psEnc->sCmn.warping_Q16 / 65536.0f + 0.01f * psEncCtrl->coding_quality; | ||
233 | |||
234 | /********************************************/ | ||
235 | /* Compute noise shaping AR coefs and gains */ | ||
236 | /********************************************/ | ||
237 | for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { | ||
238 | /* Apply window: sine slope followed by flat part followed by cosine slope */ | ||
239 | opus_int shift, slope_part, flat_part; | ||
240 | flat_part = psEnc->sCmn.fs_kHz * 3; | ||
241 | slope_part = ( psEnc->sCmn.shapeWinLength - flat_part ) / 2; | ||
242 | |||
243 | silk_apply_sine_window_FLP( x_windowed, x_ptr, 1, slope_part ); | ||
244 | shift = slope_part; | ||
245 | silk_memcpy( x_windowed + shift, x_ptr + shift, flat_part * sizeof(silk_float) ); | ||
246 | shift += flat_part; | ||
247 | silk_apply_sine_window_FLP( x_windowed + shift, x_ptr + shift, 2, slope_part ); | ||
248 | |||
249 | /* Update pointer: next LPC analysis block */ | ||
250 | x_ptr += psEnc->sCmn.subfr_length; | ||
251 | |||
252 | if( psEnc->sCmn.warping_Q16 > 0 ) { | ||
253 | /* Calculate warped auto correlation */ | ||
254 | silk_warped_autocorrelation_FLP( auto_corr, x_windowed, warping, | ||
255 | psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder ); | ||
256 | } else { | ||
257 | /* Calculate regular auto correlation */ | ||
258 | silk_autocorrelation_FLP( auto_corr, x_windowed, psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder + 1 ); | ||
259 | } | ||
260 | |||
261 | /* Add white noise, as a fraction of energy */ | ||
262 | auto_corr[ 0 ] += auto_corr[ 0 ] * SHAPE_WHITE_NOISE_FRACTION + 1.0f; | ||
263 | |||
264 | /* Convert correlations to prediction coefficients, and compute residual energy */ | ||
265 | nrg = silk_schur_FLP( rc, auto_corr, psEnc->sCmn.shapingLPCOrder ); | ||
266 | silk_k2a_FLP( &psEncCtrl->AR[ k * MAX_SHAPE_LPC_ORDER ], rc, psEnc->sCmn.shapingLPCOrder ); | ||
267 | psEncCtrl->Gains[ k ] = ( silk_float )sqrt( nrg ); | ||
268 | |||
269 | if( psEnc->sCmn.warping_Q16 > 0 ) { | ||
270 | /* Adjust gain for warping */ | ||
271 | psEncCtrl->Gains[ k ] *= warped_gain( &psEncCtrl->AR[ k * MAX_SHAPE_LPC_ORDER ], warping, psEnc->sCmn.shapingLPCOrder ); | ||
272 | } | ||
273 | |||
274 | /* Bandwidth expansion for synthesis filter shaping */ | ||
275 | silk_bwexpander_FLP( &psEncCtrl->AR[ k * MAX_SHAPE_LPC_ORDER ], psEnc->sCmn.shapingLPCOrder, BWExp ); | ||
276 | |||
277 | if( psEnc->sCmn.warping_Q16 > 0 ) { | ||
278 | /* Convert to monic warped prediction coefficients and limit absolute values */ | ||
279 | warped_true2monic_coefs( &psEncCtrl->AR[ k * MAX_SHAPE_LPC_ORDER ], warping, 3.999f, psEnc->sCmn.shapingLPCOrder ); | ||
280 | } else { | ||
281 | /* Limit absolute values */ | ||
282 | limit_coefs( &psEncCtrl->AR[ k * MAX_SHAPE_LPC_ORDER ], 3.999f, psEnc->sCmn.shapingLPCOrder ); | ||
283 | } | ||
284 | } | ||
285 | |||
286 | /*****************/ | ||
287 | /* Gain tweaking */ | ||
288 | /*****************/ | ||
289 | /* Increase gains during low speech activity */ | ||
290 | gain_mult = (silk_float)pow( 2.0f, -0.16f * SNR_adj_dB ); | ||
291 | gain_add = (silk_float)pow( 2.0f, 0.16f * MIN_QGAIN_DB ); | ||
292 | for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { | ||
293 | psEncCtrl->Gains[ k ] *= gain_mult; | ||
294 | psEncCtrl->Gains[ k ] += gain_add; | ||
295 | } | ||
296 | |||
297 | /************************************************/ | ||
298 | /* Control low-frequency shaping and noise tilt */ | ||
299 | /************************************************/ | ||
300 | /* Less low frequency shaping for noisy inputs */ | ||
301 | strength = LOW_FREQ_SHAPING * ( 1.0f + LOW_QUALITY_LOW_FREQ_SHAPING_DECR * ( psEnc->sCmn.input_quality_bands_Q15[ 0 ] * ( 1.0f / 32768.0f ) - 1.0f ) ); | ||
302 | strength *= psEnc->sCmn.speech_activity_Q8 * ( 1.0f / 256.0f ); | ||
303 | if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { | ||
304 | /* Reduce low frequencies quantization noise for periodic signals, depending on pitch lag */ | ||
305 | /*f = 400; freqz([1, -0.98 + 2e-4 * f], [1, -0.97 + 7e-4 * f], 2^12, Fs); axis([0, 1000, -10, 1])*/ | ||
306 | for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { | ||
307 | b = 0.2f / psEnc->sCmn.fs_kHz + 3.0f / psEncCtrl->pitchL[ k ]; | ||
308 | psEncCtrl->LF_MA_shp[ k ] = -1.0f + b; | ||
309 | psEncCtrl->LF_AR_shp[ k ] = 1.0f - b - b * strength; | ||
310 | } | ||
311 | Tilt = - HP_NOISE_COEF - | ||
312 | (1 - HP_NOISE_COEF) * HARM_HP_NOISE_COEF * psEnc->sCmn.speech_activity_Q8 * ( 1.0f / 256.0f ); | ||
313 | } else { | ||
314 | b = 1.3f / psEnc->sCmn.fs_kHz; | ||
315 | psEncCtrl->LF_MA_shp[ 0 ] = -1.0f + b; | ||
316 | psEncCtrl->LF_AR_shp[ 0 ] = 1.0f - b - b * strength * 0.6f; | ||
317 | for( k = 1; k < psEnc->sCmn.nb_subfr; k++ ) { | ||
318 | psEncCtrl->LF_MA_shp[ k ] = psEncCtrl->LF_MA_shp[ 0 ]; | ||
319 | psEncCtrl->LF_AR_shp[ k ] = psEncCtrl->LF_AR_shp[ 0 ]; | ||
320 | } | ||
321 | Tilt = -HP_NOISE_COEF; | ||
322 | } | ||
323 | |||
324 | /****************************/ | ||
325 | /* HARMONIC SHAPING CONTROL */ | ||
326 | /****************************/ | ||
327 | if( USE_HARM_SHAPING && psEnc->sCmn.indices.signalType == TYPE_VOICED ) { | ||
328 | /* Harmonic noise shaping */ | ||
329 | HarmShapeGain = HARMONIC_SHAPING; | ||
330 | |||
331 | /* More harmonic noise shaping for high bitrates or noisy input */ | ||
332 | HarmShapeGain += HIGH_RATE_OR_LOW_QUALITY_HARMONIC_SHAPING * | ||
333 | ( 1.0f - ( 1.0f - psEncCtrl->coding_quality ) * psEncCtrl->input_quality ); | ||
334 | |||
335 | /* Less harmonic noise shaping for less periodic signals */ | ||
336 | HarmShapeGain *= ( silk_float )sqrt( psEnc->LTPCorr ); | ||
337 | } else { | ||
338 | HarmShapeGain = 0.0f; | ||
339 | } | ||
340 | |||
341 | /*************************/ | ||
342 | /* Smooth over subframes */ | ||
343 | /*************************/ | ||
344 | for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { | ||
345 | psShapeSt->HarmShapeGain_smth += SUBFR_SMTH_COEF * ( HarmShapeGain - psShapeSt->HarmShapeGain_smth ); | ||
346 | psEncCtrl->HarmShapeGain[ k ] = psShapeSt->HarmShapeGain_smth; | ||
347 | psShapeSt->Tilt_smth += SUBFR_SMTH_COEF * ( Tilt - psShapeSt->Tilt_smth ); | ||
348 | psEncCtrl->Tilt[ k ] = psShapeSt->Tilt_smth; | ||
349 | } | ||
350 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/pitch_analysis_core_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/pitch_analysis_core_FLP.c new file mode 100644 index 0000000000..f351bc3718 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/pitch_analysis_core_FLP.c | |||
@@ -0,0 +1,630 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | /***************************************************************************** | ||
33 | * Pitch analyser function | ||
34 | ******************************************************************************/ | ||
35 | #include "SigProc_FLP.h" | ||
36 | #include "SigProc_FIX.h" | ||
37 | #include "pitch_est_defines.h" | ||
38 | #include "pitch.h" | ||
39 | |||
40 | #define SCRATCH_SIZE 22 | ||
41 | |||
42 | /************************************************************/ | ||
43 | /* Internally used functions */ | ||
44 | /************************************************************/ | ||
45 | static void silk_P_Ana_calc_corr_st3( | ||
46 | silk_float cross_corr_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ], /* O 3 DIM correlation array */ | ||
47 | const silk_float frame[], /* I vector to correlate */ | ||
48 | opus_int start_lag, /* I start lag */ | ||
49 | opus_int sf_length, /* I sub frame length */ | ||
50 | opus_int nb_subfr, /* I number of subframes */ | ||
51 | opus_int complexity, /* I Complexity setting */ | ||
52 | int arch /* I Run-time architecture */ | ||
53 | ); | ||
54 | |||
55 | static void silk_P_Ana_calc_energy_st3( | ||
56 | silk_float energies_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ], /* O 3 DIM correlation array */ | ||
57 | const silk_float frame[], /* I vector to correlate */ | ||
58 | opus_int start_lag, /* I start lag */ | ||
59 | opus_int sf_length, /* I sub frame length */ | ||
60 | opus_int nb_subfr, /* I number of subframes */ | ||
61 | opus_int complexity /* I Complexity setting */ | ||
62 | ); | ||
63 | |||
64 | /************************************************************/ | ||
65 | /* CORE PITCH ANALYSIS FUNCTION */ | ||
66 | /************************************************************/ | ||
67 | opus_int silk_pitch_analysis_core_FLP( /* O Voicing estimate: 0 voiced, 1 unvoiced */ | ||
68 | const silk_float *frame, /* I Signal of length PE_FRAME_LENGTH_MS*Fs_kHz */ | ||
69 | opus_int *pitch_out, /* O Pitch lag values [nb_subfr] */ | ||
70 | opus_int16 *lagIndex, /* O Lag Index */ | ||
71 | opus_int8 *contourIndex, /* O Pitch contour Index */ | ||
72 | silk_float *LTPCorr, /* I/O Normalized correlation; input: value from previous frame */ | ||
73 | opus_int prevLag, /* I Last lag of previous frame; set to zero is unvoiced */ | ||
74 | const silk_float search_thres1, /* I First stage threshold for lag candidates 0 - 1 */ | ||
75 | const silk_float search_thres2, /* I Final threshold for lag candidates 0 - 1 */ | ||
76 | const opus_int Fs_kHz, /* I sample frequency (kHz) */ | ||
77 | const opus_int complexity, /* I Complexity setting, 0-2, where 2 is highest */ | ||
78 | const opus_int nb_subfr, /* I Number of 5 ms subframes */ | ||
79 | int arch /* I Run-time architecture */ | ||
80 | ) | ||
81 | { | ||
82 | opus_int i, k, d, j; | ||
83 | silk_float frame_8kHz[ PE_MAX_FRAME_LENGTH_MS * 8 ]; | ||
84 | silk_float frame_4kHz[ PE_MAX_FRAME_LENGTH_MS * 4 ]; | ||
85 | opus_int16 frame_8_FIX[ PE_MAX_FRAME_LENGTH_MS * 8 ]; | ||
86 | opus_int16 frame_4_FIX[ PE_MAX_FRAME_LENGTH_MS * 4 ]; | ||
87 | opus_int32 filt_state[ 6 ]; | ||
88 | silk_float threshold, contour_bias; | ||
89 | silk_float C[ PE_MAX_NB_SUBFR][ (PE_MAX_LAG >> 1) + 5 ]; | ||
90 | opus_val32 xcorr[ PE_MAX_LAG_MS * 4 - PE_MIN_LAG_MS * 4 + 1 ]; | ||
91 | silk_float CC[ PE_NB_CBKS_STAGE2_EXT ]; | ||
92 | const silk_float *target_ptr, *basis_ptr; | ||
93 | double cross_corr, normalizer, energy, energy_tmp; | ||
94 | opus_int d_srch[ PE_D_SRCH_LENGTH ]; | ||
95 | opus_int16 d_comp[ (PE_MAX_LAG >> 1) + 5 ]; | ||
96 | opus_int length_d_srch, length_d_comp; | ||
97 | silk_float Cmax, CCmax, CCmax_b, CCmax_new_b, CCmax_new; | ||
98 | opus_int CBimax, CBimax_new, lag, start_lag, end_lag, lag_new; | ||
99 | opus_int cbk_size; | ||
100 | silk_float lag_log2, prevLag_log2, delta_lag_log2_sqr; | ||
101 | silk_float energies_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ]; | ||
102 | silk_float cross_corr_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ]; | ||
103 | opus_int lag_counter; | ||
104 | opus_int frame_length, frame_length_8kHz, frame_length_4kHz; | ||
105 | opus_int sf_length, sf_length_8kHz, sf_length_4kHz; | ||
106 | opus_int min_lag, min_lag_8kHz, min_lag_4kHz; | ||
107 | opus_int max_lag, max_lag_8kHz, max_lag_4kHz; | ||
108 | opus_int nb_cbk_search; | ||
109 | const opus_int8 *Lag_CB_ptr; | ||
110 | |||
111 | /* Check for valid sampling frequency */ | ||
112 | celt_assert( Fs_kHz == 8 || Fs_kHz == 12 || Fs_kHz == 16 ); | ||
113 | |||
114 | /* Check for valid complexity setting */ | ||
115 | celt_assert( complexity >= SILK_PE_MIN_COMPLEX ); | ||
116 | celt_assert( complexity <= SILK_PE_MAX_COMPLEX ); | ||
117 | |||
118 | silk_assert( search_thres1 >= 0.0f && search_thres1 <= 1.0f ); | ||
119 | silk_assert( search_thres2 >= 0.0f && search_thres2 <= 1.0f ); | ||
120 | |||
121 | /* Set up frame lengths max / min lag for the sampling frequency */ | ||
122 | frame_length = ( PE_LTP_MEM_LENGTH_MS + nb_subfr * PE_SUBFR_LENGTH_MS ) * Fs_kHz; | ||
123 | frame_length_4kHz = ( PE_LTP_MEM_LENGTH_MS + nb_subfr * PE_SUBFR_LENGTH_MS ) * 4; | ||
124 | frame_length_8kHz = ( PE_LTP_MEM_LENGTH_MS + nb_subfr * PE_SUBFR_LENGTH_MS ) * 8; | ||
125 | sf_length = PE_SUBFR_LENGTH_MS * Fs_kHz; | ||
126 | sf_length_4kHz = PE_SUBFR_LENGTH_MS * 4; | ||
127 | sf_length_8kHz = PE_SUBFR_LENGTH_MS * 8; | ||
128 | min_lag = PE_MIN_LAG_MS * Fs_kHz; | ||
129 | min_lag_4kHz = PE_MIN_LAG_MS * 4; | ||
130 | min_lag_8kHz = PE_MIN_LAG_MS * 8; | ||
131 | max_lag = PE_MAX_LAG_MS * Fs_kHz - 1; | ||
132 | max_lag_4kHz = PE_MAX_LAG_MS * 4; | ||
133 | max_lag_8kHz = PE_MAX_LAG_MS * 8 - 1; | ||
134 | |||
135 | /* Resample from input sampled at Fs_kHz to 8 kHz */ | ||
136 | if( Fs_kHz == 16 ) { | ||
137 | /* Resample to 16 -> 8 khz */ | ||
138 | opus_int16 frame_16_FIX[ 16 * PE_MAX_FRAME_LENGTH_MS ]; | ||
139 | silk_float2short_array( frame_16_FIX, frame, frame_length ); | ||
140 | silk_memset( filt_state, 0, 2 * sizeof( opus_int32 ) ); | ||
141 | silk_resampler_down2( filt_state, frame_8_FIX, frame_16_FIX, frame_length ); | ||
142 | silk_short2float_array( frame_8kHz, frame_8_FIX, frame_length_8kHz ); | ||
143 | } else if( Fs_kHz == 12 ) { | ||
144 | /* Resample to 12 -> 8 khz */ | ||
145 | opus_int16 frame_12_FIX[ 12 * PE_MAX_FRAME_LENGTH_MS ]; | ||
146 | silk_float2short_array( frame_12_FIX, frame, frame_length ); | ||
147 | silk_memset( filt_state, 0, 6 * sizeof( opus_int32 ) ); | ||
148 | silk_resampler_down2_3( filt_state, frame_8_FIX, frame_12_FIX, frame_length ); | ||
149 | silk_short2float_array( frame_8kHz, frame_8_FIX, frame_length_8kHz ); | ||
150 | } else { | ||
151 | celt_assert( Fs_kHz == 8 ); | ||
152 | silk_float2short_array( frame_8_FIX, frame, frame_length_8kHz ); | ||
153 | } | ||
154 | |||
155 | /* Decimate again to 4 kHz */ | ||
156 | silk_memset( filt_state, 0, 2 * sizeof( opus_int32 ) ); | ||
157 | silk_resampler_down2( filt_state, frame_4_FIX, frame_8_FIX, frame_length_8kHz ); | ||
158 | silk_short2float_array( frame_4kHz, frame_4_FIX, frame_length_4kHz ); | ||
159 | |||
160 | /* Low-pass filter */ | ||
161 | for( i = frame_length_4kHz - 1; i > 0; i-- ) { | ||
162 | frame_4kHz[ i ] = silk_ADD_SAT16( frame_4kHz[ i ], frame_4kHz[ i - 1 ] ); | ||
163 | } | ||
164 | |||
165 | /****************************************************************************** | ||
166 | * FIRST STAGE, operating in 4 khz | ||
167 | ******************************************************************************/ | ||
168 | silk_memset(C, 0, sizeof(silk_float) * nb_subfr * ((PE_MAX_LAG >> 1) + 5)); | ||
169 | target_ptr = &frame_4kHz[ silk_LSHIFT( sf_length_4kHz, 2 ) ]; | ||
170 | for( k = 0; k < nb_subfr >> 1; k++ ) { | ||
171 | /* Check that we are within range of the array */ | ||
172 | celt_assert( target_ptr >= frame_4kHz ); | ||
173 | celt_assert( target_ptr + sf_length_8kHz <= frame_4kHz + frame_length_4kHz ); | ||
174 | |||
175 | basis_ptr = target_ptr - min_lag_4kHz; | ||
176 | |||
177 | /* Check that we are within range of the array */ | ||
178 | celt_assert( basis_ptr >= frame_4kHz ); | ||
179 | celt_assert( basis_ptr + sf_length_8kHz <= frame_4kHz + frame_length_4kHz ); | ||
180 | |||
181 | celt_pitch_xcorr( target_ptr, target_ptr-max_lag_4kHz, xcorr, sf_length_8kHz, max_lag_4kHz - min_lag_4kHz + 1, arch ); | ||
182 | |||
183 | /* Calculate first vector products before loop */ | ||
184 | cross_corr = xcorr[ max_lag_4kHz - min_lag_4kHz ]; | ||
185 | normalizer = silk_energy_FLP( target_ptr, sf_length_8kHz ) + | ||
186 | silk_energy_FLP( basis_ptr, sf_length_8kHz ) + | ||
187 | sf_length_8kHz * 4000.0f; | ||
188 | |||
189 | C[ 0 ][ min_lag_4kHz ] += (silk_float)( 2 * cross_corr / normalizer ); | ||
190 | |||
191 | /* From now on normalizer is computed recursively */ | ||
192 | for( d = min_lag_4kHz + 1; d <= max_lag_4kHz; d++ ) { | ||
193 | basis_ptr--; | ||
194 | |||
195 | /* Check that we are within range of the array */ | ||
196 | silk_assert( basis_ptr >= frame_4kHz ); | ||
197 | silk_assert( basis_ptr + sf_length_8kHz <= frame_4kHz + frame_length_4kHz ); | ||
198 | |||
199 | cross_corr = xcorr[ max_lag_4kHz - d ]; | ||
200 | |||
201 | /* Add contribution of new sample and remove contribution from oldest sample */ | ||
202 | normalizer += | ||
203 | basis_ptr[ 0 ] * (double)basis_ptr[ 0 ] - | ||
204 | basis_ptr[ sf_length_8kHz ] * (double)basis_ptr[ sf_length_8kHz ]; | ||
205 | C[ 0 ][ d ] += (silk_float)( 2 * cross_corr / normalizer ); | ||
206 | } | ||
207 | /* Update target pointer */ | ||
208 | target_ptr += sf_length_8kHz; | ||
209 | } | ||
210 | |||
211 | /* Apply short-lag bias */ | ||
212 | for( i = max_lag_4kHz; i >= min_lag_4kHz; i-- ) { | ||
213 | C[ 0 ][ i ] -= C[ 0 ][ i ] * i / 4096.0f; | ||
214 | } | ||
215 | |||
216 | /* Sort */ | ||
217 | length_d_srch = 4 + 2 * complexity; | ||
218 | celt_assert( 3 * length_d_srch <= PE_D_SRCH_LENGTH ); | ||
219 | silk_insertion_sort_decreasing_FLP( &C[ 0 ][ min_lag_4kHz ], d_srch, max_lag_4kHz - min_lag_4kHz + 1, length_d_srch ); | ||
220 | |||
221 | /* Escape if correlation is very low already here */ | ||
222 | Cmax = C[ 0 ][ min_lag_4kHz ]; | ||
223 | if( Cmax < 0.2f ) { | ||
224 | silk_memset( pitch_out, 0, nb_subfr * sizeof( opus_int ) ); | ||
225 | *LTPCorr = 0.0f; | ||
226 | *lagIndex = 0; | ||
227 | *contourIndex = 0; | ||
228 | return 1; | ||
229 | } | ||
230 | |||
231 | threshold = search_thres1 * Cmax; | ||
232 | for( i = 0; i < length_d_srch; i++ ) { | ||
233 | /* Convert to 8 kHz indices for the sorted correlation that exceeds the threshold */ | ||
234 | if( C[ 0 ][ min_lag_4kHz + i ] > threshold ) { | ||
235 | d_srch[ i ] = silk_LSHIFT( d_srch[ i ] + min_lag_4kHz, 1 ); | ||
236 | } else { | ||
237 | length_d_srch = i; | ||
238 | break; | ||
239 | } | ||
240 | } | ||
241 | celt_assert( length_d_srch > 0 ); | ||
242 | |||
243 | for( i = min_lag_8kHz - 5; i < max_lag_8kHz + 5; i++ ) { | ||
244 | d_comp[ i ] = 0; | ||
245 | } | ||
246 | for( i = 0; i < length_d_srch; i++ ) { | ||
247 | d_comp[ d_srch[ i ] ] = 1; | ||
248 | } | ||
249 | |||
250 | /* Convolution */ | ||
251 | for( i = max_lag_8kHz + 3; i >= min_lag_8kHz; i-- ) { | ||
252 | d_comp[ i ] += d_comp[ i - 1 ] + d_comp[ i - 2 ]; | ||
253 | } | ||
254 | |||
255 | length_d_srch = 0; | ||
256 | for( i = min_lag_8kHz; i < max_lag_8kHz + 1; i++ ) { | ||
257 | if( d_comp[ i + 1 ] > 0 ) { | ||
258 | d_srch[ length_d_srch ] = i; | ||
259 | length_d_srch++; | ||
260 | } | ||
261 | } | ||
262 | |||
263 | /* Convolution */ | ||
264 | for( i = max_lag_8kHz + 3; i >= min_lag_8kHz; i-- ) { | ||
265 | d_comp[ i ] += d_comp[ i - 1 ] + d_comp[ i - 2 ] + d_comp[ i - 3 ]; | ||
266 | } | ||
267 | |||
268 | length_d_comp = 0; | ||
269 | for( i = min_lag_8kHz; i < max_lag_8kHz + 4; i++ ) { | ||
270 | if( d_comp[ i ] > 0 ) { | ||
271 | d_comp[ length_d_comp ] = (opus_int16)( i - 2 ); | ||
272 | length_d_comp++; | ||
273 | } | ||
274 | } | ||
275 | |||
276 | /********************************************************************************** | ||
277 | ** SECOND STAGE, operating at 8 kHz, on lag sections with high correlation | ||
278 | *************************************************************************************/ | ||
279 | /********************************************************************************* | ||
280 | * Find energy of each subframe projected onto its history, for a range of delays | ||
281 | *********************************************************************************/ | ||
282 | silk_memset( C, 0, PE_MAX_NB_SUBFR*((PE_MAX_LAG >> 1) + 5) * sizeof(silk_float)); | ||
283 | |||
284 | if( Fs_kHz == 8 ) { | ||
285 | target_ptr = &frame[ PE_LTP_MEM_LENGTH_MS * 8 ]; | ||
286 | } else { | ||
287 | target_ptr = &frame_8kHz[ PE_LTP_MEM_LENGTH_MS * 8 ]; | ||
288 | } | ||
289 | for( k = 0; k < nb_subfr; k++ ) { | ||
290 | energy_tmp = silk_energy_FLP( target_ptr, sf_length_8kHz ) + 1.0; | ||
291 | for( j = 0; j < length_d_comp; j++ ) { | ||
292 | d = d_comp[ j ]; | ||
293 | basis_ptr = target_ptr - d; | ||
294 | cross_corr = silk_inner_product_FLP( basis_ptr, target_ptr, sf_length_8kHz ); | ||
295 | if( cross_corr > 0.0f ) { | ||
296 | energy = silk_energy_FLP( basis_ptr, sf_length_8kHz ); | ||
297 | C[ k ][ d ] = (silk_float)( 2 * cross_corr / ( energy + energy_tmp ) ); | ||
298 | } else { | ||
299 | C[ k ][ d ] = 0.0f; | ||
300 | } | ||
301 | } | ||
302 | target_ptr += sf_length_8kHz; | ||
303 | } | ||
304 | |||
305 | /* search over lag range and lags codebook */ | ||
306 | /* scale factor for lag codebook, as a function of center lag */ | ||
307 | |||
308 | CCmax = 0.0f; /* This value doesn't matter */ | ||
309 | CCmax_b = -1000.0f; | ||
310 | |||
311 | CBimax = 0; /* To avoid returning undefined lag values */ | ||
312 | lag = -1; /* To check if lag with strong enough correlation has been found */ | ||
313 | |||
314 | if( prevLag > 0 ) { | ||
315 | if( Fs_kHz == 12 ) { | ||
316 | prevLag = silk_LSHIFT( prevLag, 1 ) / 3; | ||
317 | } else if( Fs_kHz == 16 ) { | ||
318 | prevLag = silk_RSHIFT( prevLag, 1 ); | ||
319 | } | ||
320 | prevLag_log2 = silk_log2( (silk_float)prevLag ); | ||
321 | } else { | ||
322 | prevLag_log2 = 0; | ||
323 | } | ||
324 | |||
325 | /* Set up stage 2 codebook based on number of subframes */ | ||
326 | if( nb_subfr == PE_MAX_NB_SUBFR ) { | ||
327 | cbk_size = PE_NB_CBKS_STAGE2_EXT; | ||
328 | Lag_CB_ptr = &silk_CB_lags_stage2[ 0 ][ 0 ]; | ||
329 | if( Fs_kHz == 8 && complexity > SILK_PE_MIN_COMPLEX ) { | ||
330 | /* If input is 8 khz use a larger codebook here because it is last stage */ | ||
331 | nb_cbk_search = PE_NB_CBKS_STAGE2_EXT; | ||
332 | } else { | ||
333 | nb_cbk_search = PE_NB_CBKS_STAGE2; | ||
334 | } | ||
335 | } else { | ||
336 | cbk_size = PE_NB_CBKS_STAGE2_10MS; | ||
337 | Lag_CB_ptr = &silk_CB_lags_stage2_10_ms[ 0 ][ 0 ]; | ||
338 | nb_cbk_search = PE_NB_CBKS_STAGE2_10MS; | ||
339 | } | ||
340 | |||
341 | for( k = 0; k < length_d_srch; k++ ) { | ||
342 | d = d_srch[ k ]; | ||
343 | for( j = 0; j < nb_cbk_search; j++ ) { | ||
344 | CC[j] = 0.0f; | ||
345 | for( i = 0; i < nb_subfr; i++ ) { | ||
346 | /* Try all codebooks */ | ||
347 | CC[ j ] += C[ i ][ d + matrix_ptr( Lag_CB_ptr, i, j, cbk_size )]; | ||
348 | } | ||
349 | } | ||
350 | /* Find best codebook */ | ||
351 | CCmax_new = -1000.0f; | ||
352 | CBimax_new = 0; | ||
353 | for( i = 0; i < nb_cbk_search; i++ ) { | ||
354 | if( CC[ i ] > CCmax_new ) { | ||
355 | CCmax_new = CC[ i ]; | ||
356 | CBimax_new = i; | ||
357 | } | ||
358 | } | ||
359 | |||
360 | /* Bias towards shorter lags */ | ||
361 | lag_log2 = silk_log2( (silk_float)d ); | ||
362 | CCmax_new_b = CCmax_new - PE_SHORTLAG_BIAS * nb_subfr * lag_log2; | ||
363 | |||
364 | /* Bias towards previous lag */ | ||
365 | if( prevLag > 0 ) { | ||
366 | delta_lag_log2_sqr = lag_log2 - prevLag_log2; | ||
367 | delta_lag_log2_sqr *= delta_lag_log2_sqr; | ||
368 | CCmax_new_b -= PE_PREVLAG_BIAS * nb_subfr * (*LTPCorr) * delta_lag_log2_sqr / ( delta_lag_log2_sqr + 0.5f ); | ||
369 | } | ||
370 | |||
371 | if( CCmax_new_b > CCmax_b && /* Find maximum biased correlation */ | ||
372 | CCmax_new > nb_subfr * search_thres2 /* Correlation needs to be high enough to be voiced */ | ||
373 | ) { | ||
374 | CCmax_b = CCmax_new_b; | ||
375 | CCmax = CCmax_new; | ||
376 | lag = d; | ||
377 | CBimax = CBimax_new; | ||
378 | } | ||
379 | } | ||
380 | |||
381 | if( lag == -1 ) { | ||
382 | /* No suitable candidate found */ | ||
383 | silk_memset( pitch_out, 0, PE_MAX_NB_SUBFR * sizeof(opus_int) ); | ||
384 | *LTPCorr = 0.0f; | ||
385 | *lagIndex = 0; | ||
386 | *contourIndex = 0; | ||
387 | return 1; | ||
388 | } | ||
389 | |||
390 | /* Output normalized correlation */ | ||
391 | *LTPCorr = (silk_float)( CCmax / nb_subfr ); | ||
392 | silk_assert( *LTPCorr >= 0.0f ); | ||
393 | |||
394 | if( Fs_kHz > 8 ) { | ||
395 | /* Search in original signal */ | ||
396 | |||
397 | /* Compensate for decimation */ | ||
398 | silk_assert( lag == silk_SAT16( lag ) ); | ||
399 | if( Fs_kHz == 12 ) { | ||
400 | lag = silk_RSHIFT_ROUND( silk_SMULBB( lag, 3 ), 1 ); | ||
401 | } else { /* Fs_kHz == 16 */ | ||
402 | lag = silk_LSHIFT( lag, 1 ); | ||
403 | } | ||
404 | |||
405 | lag = silk_LIMIT_int( lag, min_lag, max_lag ); | ||
406 | start_lag = silk_max_int( lag - 2, min_lag ); | ||
407 | end_lag = silk_min_int( lag + 2, max_lag ); | ||
408 | lag_new = lag; /* to avoid undefined lag */ | ||
409 | CBimax = 0; /* to avoid undefined lag */ | ||
410 | |||
411 | CCmax = -1000.0f; | ||
412 | |||
413 | /* Calculate the correlations and energies needed in stage 3 */ | ||
414 | silk_P_Ana_calc_corr_st3( cross_corr_st3, frame, start_lag, sf_length, nb_subfr, complexity, arch ); | ||
415 | silk_P_Ana_calc_energy_st3( energies_st3, frame, start_lag, sf_length, nb_subfr, complexity ); | ||
416 | |||
417 | lag_counter = 0; | ||
418 | silk_assert( lag == silk_SAT16( lag ) ); | ||
419 | contour_bias = PE_FLATCONTOUR_BIAS / lag; | ||
420 | |||
421 | /* Set up cbk parameters according to complexity setting and frame length */ | ||
422 | if( nb_subfr == PE_MAX_NB_SUBFR ) { | ||
423 | nb_cbk_search = (opus_int)silk_nb_cbk_searchs_stage3[ complexity ]; | ||
424 | cbk_size = PE_NB_CBKS_STAGE3_MAX; | ||
425 | Lag_CB_ptr = &silk_CB_lags_stage3[ 0 ][ 0 ]; | ||
426 | } else { | ||
427 | nb_cbk_search = PE_NB_CBKS_STAGE3_10MS; | ||
428 | cbk_size = PE_NB_CBKS_STAGE3_10MS; | ||
429 | Lag_CB_ptr = &silk_CB_lags_stage3_10_ms[ 0 ][ 0 ]; | ||
430 | } | ||
431 | |||
432 | target_ptr = &frame[ PE_LTP_MEM_LENGTH_MS * Fs_kHz ]; | ||
433 | energy_tmp = silk_energy_FLP( target_ptr, nb_subfr * sf_length ) + 1.0; | ||
434 | for( d = start_lag; d <= end_lag; d++ ) { | ||
435 | for( j = 0; j < nb_cbk_search; j++ ) { | ||
436 | cross_corr = 0.0; | ||
437 | energy = energy_tmp; | ||
438 | for( k = 0; k < nb_subfr; k++ ) { | ||
439 | cross_corr += cross_corr_st3[ k ][ j ][ lag_counter ]; | ||
440 | energy += energies_st3[ k ][ j ][ lag_counter ]; | ||
441 | } | ||
442 | if( cross_corr > 0.0 ) { | ||
443 | CCmax_new = (silk_float)( 2 * cross_corr / energy ); | ||
444 | /* Reduce depending on flatness of contour */ | ||
445 | CCmax_new *= 1.0f - contour_bias * j; | ||
446 | } else { | ||
447 | CCmax_new = 0.0f; | ||
448 | } | ||
449 | |||
450 | if( CCmax_new > CCmax && ( d + (opus_int)silk_CB_lags_stage3[ 0 ][ j ] ) <= max_lag ) { | ||
451 | CCmax = CCmax_new; | ||
452 | lag_new = d; | ||
453 | CBimax = j; | ||
454 | } | ||
455 | } | ||
456 | lag_counter++; | ||
457 | } | ||
458 | |||
459 | for( k = 0; k < nb_subfr; k++ ) { | ||
460 | pitch_out[ k ] = lag_new + matrix_ptr( Lag_CB_ptr, k, CBimax, cbk_size ); | ||
461 | pitch_out[ k ] = silk_LIMIT( pitch_out[ k ], min_lag, PE_MAX_LAG_MS * Fs_kHz ); | ||
462 | } | ||
463 | *lagIndex = (opus_int16)( lag_new - min_lag ); | ||
464 | *contourIndex = (opus_int8)CBimax; | ||
465 | } else { /* Fs_kHz == 8 */ | ||
466 | /* Save Lags */ | ||
467 | for( k = 0; k < nb_subfr; k++ ) { | ||
468 | pitch_out[ k ] = lag + matrix_ptr( Lag_CB_ptr, k, CBimax, cbk_size ); | ||
469 | pitch_out[ k ] = silk_LIMIT( pitch_out[ k ], min_lag_8kHz, PE_MAX_LAG_MS * 8 ); | ||
470 | } | ||
471 | *lagIndex = (opus_int16)( lag - min_lag_8kHz ); | ||
472 | *contourIndex = (opus_int8)CBimax; | ||
473 | } | ||
474 | celt_assert( *lagIndex >= 0 ); | ||
475 | /* return as voiced */ | ||
476 | return 0; | ||
477 | } | ||
478 | |||
479 | /*********************************************************************** | ||
480 | * Calculates the correlations used in stage 3 search. In order to cover | ||
481 | * the whole lag codebook for all the searched offset lags (lag +- 2), | ||
482 | * the following correlations are needed in each sub frame: | ||
483 | * | ||
484 | * sf1: lag range [-8,...,7] total 16 correlations | ||
485 | * sf2: lag range [-4,...,4] total 9 correlations | ||
486 | * sf3: lag range [-3,....4] total 8 correltions | ||
487 | * sf4: lag range [-6,....8] total 15 correlations | ||
488 | * | ||
489 | * In total 48 correlations. The direct implementation computed in worst | ||
490 | * case 4*12*5 = 240 correlations, but more likely around 120. | ||
491 | ***********************************************************************/ | ||
492 | static void silk_P_Ana_calc_corr_st3( | ||
493 | silk_float cross_corr_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ], /* O 3 DIM correlation array */ | ||
494 | const silk_float frame[], /* I vector to correlate */ | ||
495 | opus_int start_lag, /* I start lag */ | ||
496 | opus_int sf_length, /* I sub frame length */ | ||
497 | opus_int nb_subfr, /* I number of subframes */ | ||
498 | opus_int complexity, /* I Complexity setting */ | ||
499 | int arch /* I Run-time architecture */ | ||
500 | ) | ||
501 | { | ||
502 | const silk_float *target_ptr; | ||
503 | opus_int i, j, k, lag_counter, lag_low, lag_high; | ||
504 | opus_int nb_cbk_search, delta, idx, cbk_size; | ||
505 | silk_float scratch_mem[ SCRATCH_SIZE ]; | ||
506 | opus_val32 xcorr[ SCRATCH_SIZE ]; | ||
507 | const opus_int8 *Lag_range_ptr, *Lag_CB_ptr; | ||
508 | |||
509 | celt_assert( complexity >= SILK_PE_MIN_COMPLEX ); | ||
510 | celt_assert( complexity <= SILK_PE_MAX_COMPLEX ); | ||
511 | |||
512 | if( nb_subfr == PE_MAX_NB_SUBFR ) { | ||
513 | Lag_range_ptr = &silk_Lag_range_stage3[ complexity ][ 0 ][ 0 ]; | ||
514 | Lag_CB_ptr = &silk_CB_lags_stage3[ 0 ][ 0 ]; | ||
515 | nb_cbk_search = silk_nb_cbk_searchs_stage3[ complexity ]; | ||
516 | cbk_size = PE_NB_CBKS_STAGE3_MAX; | ||
517 | } else { | ||
518 | celt_assert( nb_subfr == PE_MAX_NB_SUBFR >> 1); | ||
519 | Lag_range_ptr = &silk_Lag_range_stage3_10_ms[ 0 ][ 0 ]; | ||
520 | Lag_CB_ptr = &silk_CB_lags_stage3_10_ms[ 0 ][ 0 ]; | ||
521 | nb_cbk_search = PE_NB_CBKS_STAGE3_10MS; | ||
522 | cbk_size = PE_NB_CBKS_STAGE3_10MS; | ||
523 | } | ||
524 | |||
525 | target_ptr = &frame[ silk_LSHIFT( sf_length, 2 ) ]; /* Pointer to middle of frame */ | ||
526 | for( k = 0; k < nb_subfr; k++ ) { | ||
527 | lag_counter = 0; | ||
528 | |||
529 | /* Calculate the correlations for each subframe */ | ||
530 | lag_low = matrix_ptr( Lag_range_ptr, k, 0, 2 ); | ||
531 | lag_high = matrix_ptr( Lag_range_ptr, k, 1, 2 ); | ||
532 | silk_assert(lag_high-lag_low+1 <= SCRATCH_SIZE); | ||
533 | celt_pitch_xcorr( target_ptr, target_ptr - start_lag - lag_high, xcorr, sf_length, lag_high - lag_low + 1, arch ); | ||
534 | for( j = lag_low; j <= lag_high; j++ ) { | ||
535 | silk_assert( lag_counter < SCRATCH_SIZE ); | ||
536 | scratch_mem[ lag_counter ] = xcorr[ lag_high - j ]; | ||
537 | lag_counter++; | ||
538 | } | ||
539 | |||
540 | delta = matrix_ptr( Lag_range_ptr, k, 0, 2 ); | ||
541 | for( i = 0; i < nb_cbk_search; i++ ) { | ||
542 | /* Fill out the 3 dim array that stores the correlations for */ | ||
543 | /* each code_book vector for each start lag */ | ||
544 | idx = matrix_ptr( Lag_CB_ptr, k, i, cbk_size ) - delta; | ||
545 | for( j = 0; j < PE_NB_STAGE3_LAGS; j++ ) { | ||
546 | silk_assert( idx + j < SCRATCH_SIZE ); | ||
547 | silk_assert( idx + j < lag_counter ); | ||
548 | cross_corr_st3[ k ][ i ][ j ] = scratch_mem[ idx + j ]; | ||
549 | } | ||
550 | } | ||
551 | target_ptr += sf_length; | ||
552 | } | ||
553 | } | ||
554 | |||
555 | /********************************************************************/ | ||
556 | /* Calculate the energies for first two subframes. The energies are */ | ||
557 | /* calculated recursively. */ | ||
558 | /********************************************************************/ | ||
559 | static void silk_P_Ana_calc_energy_st3( | ||
560 | silk_float energies_st3[ PE_MAX_NB_SUBFR ][ PE_NB_CBKS_STAGE3_MAX ][ PE_NB_STAGE3_LAGS ], /* O 3 DIM correlation array */ | ||
561 | const silk_float frame[], /* I vector to correlate */ | ||
562 | opus_int start_lag, /* I start lag */ | ||
563 | opus_int sf_length, /* I sub frame length */ | ||
564 | opus_int nb_subfr, /* I number of subframes */ | ||
565 | opus_int complexity /* I Complexity setting */ | ||
566 | ) | ||
567 | { | ||
568 | const silk_float *target_ptr, *basis_ptr; | ||
569 | double energy; | ||
570 | opus_int k, i, j, lag_counter; | ||
571 | opus_int nb_cbk_search, delta, idx, cbk_size, lag_diff; | ||
572 | silk_float scratch_mem[ SCRATCH_SIZE ]; | ||
573 | const opus_int8 *Lag_range_ptr, *Lag_CB_ptr; | ||
574 | |||
575 | celt_assert( complexity >= SILK_PE_MIN_COMPLEX ); | ||
576 | celt_assert( complexity <= SILK_PE_MAX_COMPLEX ); | ||
577 | |||
578 | if( nb_subfr == PE_MAX_NB_SUBFR ) { | ||
579 | Lag_range_ptr = &silk_Lag_range_stage3[ complexity ][ 0 ][ 0 ]; | ||
580 | Lag_CB_ptr = &silk_CB_lags_stage3[ 0 ][ 0 ]; | ||
581 | nb_cbk_search = silk_nb_cbk_searchs_stage3[ complexity ]; | ||
582 | cbk_size = PE_NB_CBKS_STAGE3_MAX; | ||
583 | } else { | ||
584 | celt_assert( nb_subfr == PE_MAX_NB_SUBFR >> 1); | ||
585 | Lag_range_ptr = &silk_Lag_range_stage3_10_ms[ 0 ][ 0 ]; | ||
586 | Lag_CB_ptr = &silk_CB_lags_stage3_10_ms[ 0 ][ 0 ]; | ||
587 | nb_cbk_search = PE_NB_CBKS_STAGE3_10MS; | ||
588 | cbk_size = PE_NB_CBKS_STAGE3_10MS; | ||
589 | } | ||
590 | |||
591 | target_ptr = &frame[ silk_LSHIFT( sf_length, 2 ) ]; | ||
592 | for( k = 0; k < nb_subfr; k++ ) { | ||
593 | lag_counter = 0; | ||
594 | |||
595 | /* Calculate the energy for first lag */ | ||
596 | basis_ptr = target_ptr - ( start_lag + matrix_ptr( Lag_range_ptr, k, 0, 2 ) ); | ||
597 | energy = silk_energy_FLP( basis_ptr, sf_length ) + 1e-3; | ||
598 | silk_assert( energy >= 0.0 ); | ||
599 | scratch_mem[lag_counter] = (silk_float)energy; | ||
600 | lag_counter++; | ||
601 | |||
602 | lag_diff = ( matrix_ptr( Lag_range_ptr, k, 1, 2 ) - matrix_ptr( Lag_range_ptr, k, 0, 2 ) + 1 ); | ||
603 | for( i = 1; i < lag_diff; i++ ) { | ||
604 | /* remove part outside new window */ | ||
605 | energy -= basis_ptr[sf_length - i] * (double)basis_ptr[sf_length - i]; | ||
606 | silk_assert( energy >= 0.0 ); | ||
607 | |||
608 | /* add part that comes into window */ | ||
609 | energy += basis_ptr[ -i ] * (double)basis_ptr[ -i ]; | ||
610 | silk_assert( energy >= 0.0 ); | ||
611 | silk_assert( lag_counter < SCRATCH_SIZE ); | ||
612 | scratch_mem[lag_counter] = (silk_float)energy; | ||
613 | lag_counter++; | ||
614 | } | ||
615 | |||
616 | delta = matrix_ptr( Lag_range_ptr, k, 0, 2 ); | ||
617 | for( i = 0; i < nb_cbk_search; i++ ) { | ||
618 | /* Fill out the 3 dim array that stores the correlations for */ | ||
619 | /* each code_book vector for each start lag */ | ||
620 | idx = matrix_ptr( Lag_CB_ptr, k, i, cbk_size ) - delta; | ||
621 | for( j = 0; j < PE_NB_STAGE3_LAGS; j++ ) { | ||
622 | silk_assert( idx + j < SCRATCH_SIZE ); | ||
623 | silk_assert( idx + j < lag_counter ); | ||
624 | energies_st3[ k ][ i ][ j ] = scratch_mem[ idx + j ]; | ||
625 | silk_assert( energies_st3[ k ][ i ][ j ] >= 0.0f ); | ||
626 | } | ||
627 | } | ||
628 | target_ptr += sf_length; | ||
629 | } | ||
630 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/process_gains_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/process_gains_FLP.c new file mode 100644 index 0000000000..c0da0dae44 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/process_gains_FLP.c | |||
@@ -0,0 +1,103 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "main_FLP.h" | ||
33 | #include "tuning_parameters.h" | ||
34 | |||
35 | /* Processing of gains */ | ||
36 | void silk_process_gains_FLP( | ||
37 | silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ | ||
38 | silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ | ||
39 | opus_int condCoding /* I The type of conditional coding to use */ | ||
40 | ) | ||
41 | { | ||
42 | silk_shape_state_FLP *psShapeSt = &psEnc->sShape; | ||
43 | opus_int k; | ||
44 | opus_int32 pGains_Q16[ MAX_NB_SUBFR ]; | ||
45 | silk_float s, InvMaxSqrVal, gain, quant_offset; | ||
46 | |||
47 | /* Gain reduction when LTP coding gain is high */ | ||
48 | if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { | ||
49 | s = 1.0f - 0.5f * silk_sigmoid( 0.25f * ( psEncCtrl->LTPredCodGain - 12.0f ) ); | ||
50 | for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { | ||
51 | psEncCtrl->Gains[ k ] *= s; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | /* Limit the quantized signal */ | ||
56 | InvMaxSqrVal = ( silk_float )( pow( 2.0f, 0.33f * ( 21.0f - psEnc->sCmn.SNR_dB_Q7 * ( 1 / 128.0f ) ) ) / psEnc->sCmn.subfr_length ); | ||
57 | |||
58 | for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { | ||
59 | /* Soft limit on ratio residual energy and squared gains */ | ||
60 | gain = psEncCtrl->Gains[ k ]; | ||
61 | gain = ( silk_float )sqrt( gain * gain + psEncCtrl->ResNrg[ k ] * InvMaxSqrVal ); | ||
62 | psEncCtrl->Gains[ k ] = silk_min_float( gain, 32767.0f ); | ||
63 | } | ||
64 | |||
65 | /* Prepare gains for noise shaping quantization */ | ||
66 | for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { | ||
67 | pGains_Q16[ k ] = (opus_int32)( psEncCtrl->Gains[ k ] * 65536.0f ); | ||
68 | } | ||
69 | |||
70 | /* Save unquantized gains and gain Index */ | ||
71 | silk_memcpy( psEncCtrl->GainsUnq_Q16, pGains_Q16, psEnc->sCmn.nb_subfr * sizeof( opus_int32 ) ); | ||
72 | psEncCtrl->lastGainIndexPrev = psShapeSt->LastGainIndex; | ||
73 | |||
74 | /* Quantize gains */ | ||
75 | silk_gains_quant( psEnc->sCmn.indices.GainsIndices, pGains_Q16, | ||
76 | &psShapeSt->LastGainIndex, condCoding == CODE_CONDITIONALLY, psEnc->sCmn.nb_subfr ); | ||
77 | |||
78 | /* Overwrite unquantized gains with quantized gains and convert back to Q0 from Q16 */ | ||
79 | for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { | ||
80 | psEncCtrl->Gains[ k ] = pGains_Q16[ k ] / 65536.0f; | ||
81 | } | ||
82 | |||
83 | /* Set quantizer offset for voiced signals. Larger offset when LTP coding gain is low or tilt is high (ie low-pass) */ | ||
84 | if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { | ||
85 | if( psEncCtrl->LTPredCodGain + psEnc->sCmn.input_tilt_Q15 * ( 1.0f / 32768.0f ) > 1.0f ) { | ||
86 | psEnc->sCmn.indices.quantOffsetType = 0; | ||
87 | } else { | ||
88 | psEnc->sCmn.indices.quantOffsetType = 1; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | /* Quantizer boundary adjustment */ | ||
93 | quant_offset = silk_Quantization_Offsets_Q10[ psEnc->sCmn.indices.signalType >> 1 ][ psEnc->sCmn.indices.quantOffsetType ] / 1024.0f; | ||
94 | psEncCtrl->Lambda = LAMBDA_OFFSET | ||
95 | + LAMBDA_DELAYED_DECISIONS * psEnc->sCmn.nStatesDelayedDecision | ||
96 | + LAMBDA_SPEECH_ACT * psEnc->sCmn.speech_activity_Q8 * ( 1.0f / 256.0f ) | ||
97 | + LAMBDA_INPUT_QUALITY * psEncCtrl->input_quality | ||
98 | + LAMBDA_CODING_QUALITY * psEncCtrl->coding_quality | ||
99 | + LAMBDA_QUANT_OFFSET * quant_offset; | ||
100 | |||
101 | silk_assert( psEncCtrl->Lambda > 0.0f ); | ||
102 | silk_assert( psEncCtrl->Lambda < 2.0f ); | ||
103 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/regularize_correlations_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/regularize_correlations_FLP.c new file mode 100644 index 0000000000..df4612604c --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/regularize_correlations_FLP.c | |||
@@ -0,0 +1,48 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "main_FLP.h" | ||
33 | |||
34 | /* Add noise to matrix diagonal */ | ||
35 | void silk_regularize_correlations_FLP( | ||
36 | silk_float *XX, /* I/O Correlation matrices */ | ||
37 | silk_float *xx, /* I/O Correlation values */ | ||
38 | const silk_float noise, /* I Noise energy to add */ | ||
39 | const opus_int D /* I Dimension of XX */ | ||
40 | ) | ||
41 | { | ||
42 | opus_int i; | ||
43 | |||
44 | for( i = 0; i < D; i++ ) { | ||
45 | matrix_ptr( &XX[ 0 ], i, i, D ) += noise; | ||
46 | } | ||
47 | xx[ 0 ] += noise; | ||
48 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/residual_energy_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/residual_energy_FLP.c new file mode 100644 index 0000000000..1bd07b33a4 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/residual_energy_FLP.c | |||
@@ -0,0 +1,117 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "main_FLP.h" | ||
33 | |||
34 | #define MAX_ITERATIONS_RESIDUAL_NRG 10 | ||
35 | #define REGULARIZATION_FACTOR 1e-8f | ||
36 | |||
37 | /* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */ | ||
38 | silk_float silk_residual_energy_covar_FLP( /* O Weighted residual energy */ | ||
39 | const silk_float *c, /* I Filter coefficients */ | ||
40 | silk_float *wXX, /* I/O Weighted correlation matrix, reg. out */ | ||
41 | const silk_float *wXx, /* I Weighted correlation vector */ | ||
42 | const silk_float wxx, /* I Weighted correlation value */ | ||
43 | const opus_int D /* I Dimension */ | ||
44 | ) | ||
45 | { | ||
46 | opus_int i, j, k; | ||
47 | silk_float tmp, nrg = 0.0f, regularization; | ||
48 | |||
49 | /* Safety checks */ | ||
50 | celt_assert( D >= 0 ); | ||
51 | |||
52 | regularization = REGULARIZATION_FACTOR * ( wXX[ 0 ] + wXX[ D * D - 1 ] ); | ||
53 | for( k = 0; k < MAX_ITERATIONS_RESIDUAL_NRG; k++ ) { | ||
54 | nrg = wxx; | ||
55 | |||
56 | tmp = 0.0f; | ||
57 | for( i = 0; i < D; i++ ) { | ||
58 | tmp += wXx[ i ] * c[ i ]; | ||
59 | } | ||
60 | nrg -= 2.0f * tmp; | ||
61 | |||
62 | /* compute c' * wXX * c, assuming wXX is symmetric */ | ||
63 | for( i = 0; i < D; i++ ) { | ||
64 | tmp = 0.0f; | ||
65 | for( j = i + 1; j < D; j++ ) { | ||
66 | tmp += matrix_c_ptr( wXX, i, j, D ) * c[ j ]; | ||
67 | } | ||
68 | nrg += c[ i ] * ( 2.0f * tmp + matrix_c_ptr( wXX, i, i, D ) * c[ i ] ); | ||
69 | } | ||
70 | if( nrg > 0 ) { | ||
71 | break; | ||
72 | } else { | ||
73 | /* Add white noise */ | ||
74 | for( i = 0; i < D; i++ ) { | ||
75 | matrix_c_ptr( wXX, i, i, D ) += regularization; | ||
76 | } | ||
77 | /* Increase noise for next run */ | ||
78 | regularization *= 2.0f; | ||
79 | } | ||
80 | } | ||
81 | if( k == MAX_ITERATIONS_RESIDUAL_NRG ) { | ||
82 | silk_assert( nrg == 0 ); | ||
83 | nrg = 1.0f; | ||
84 | } | ||
85 | |||
86 | return nrg; | ||
87 | } | ||
88 | |||
89 | /* Calculates residual energies of input subframes where all subframes have LPC_order */ | ||
90 | /* of preceding samples */ | ||
91 | void silk_residual_energy_FLP( | ||
92 | silk_float nrgs[ MAX_NB_SUBFR ], /* O Residual energy per subframe */ | ||
93 | const silk_float x[], /* I Input signal */ | ||
94 | silk_float a[ 2 ][ MAX_LPC_ORDER ], /* I AR coefs for each frame half */ | ||
95 | const silk_float gains[], /* I Quantization gains */ | ||
96 | const opus_int subfr_length, /* I Subframe length */ | ||
97 | const opus_int nb_subfr, /* I number of subframes */ | ||
98 | const opus_int LPC_order /* I LPC order */ | ||
99 | ) | ||
100 | { | ||
101 | opus_int shift; | ||
102 | silk_float *LPC_res_ptr, LPC_res[ ( MAX_FRAME_LENGTH + MAX_NB_SUBFR * MAX_LPC_ORDER ) / 2 ]; | ||
103 | |||
104 | LPC_res_ptr = LPC_res + LPC_order; | ||
105 | shift = LPC_order + subfr_length; | ||
106 | |||
107 | /* Filter input to create the LPC residual for each frame half, and measure subframe energies */ | ||
108 | silk_LPC_analysis_filter_FLP( LPC_res, a[ 0 ], x + 0 * shift, 2 * shift, LPC_order ); | ||
109 | nrgs[ 0 ] = ( silk_float )( gains[ 0 ] * gains[ 0 ] * silk_energy_FLP( LPC_res_ptr + 0 * shift, subfr_length ) ); | ||
110 | nrgs[ 1 ] = ( silk_float )( gains[ 1 ] * gains[ 1 ] * silk_energy_FLP( LPC_res_ptr + 1 * shift, subfr_length ) ); | ||
111 | |||
112 | if( nb_subfr == MAX_NB_SUBFR ) { | ||
113 | silk_LPC_analysis_filter_FLP( LPC_res, a[ 1 ], x + 2 * shift, 2 * shift, LPC_order ); | ||
114 | nrgs[ 2 ] = ( silk_float )( gains[ 2 ] * gains[ 2 ] * silk_energy_FLP( LPC_res_ptr + 0 * shift, subfr_length ) ); | ||
115 | nrgs[ 3 ] = ( silk_float )( gains[ 3 ] * gains[ 3 ] * silk_energy_FLP( LPC_res_ptr + 1 * shift, subfr_length ) ); | ||
116 | } | ||
117 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/scale_copy_vector_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/scale_copy_vector_FLP.c new file mode 100644 index 0000000000..20db32b3b1 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/scale_copy_vector_FLP.c | |||
@@ -0,0 +1,57 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "SigProc_FLP.h" | ||
33 | |||
34 | /* copy and multiply a vector by a constant */ | ||
35 | void silk_scale_copy_vector_FLP( | ||
36 | silk_float *data_out, | ||
37 | const silk_float *data_in, | ||
38 | silk_float gain, | ||
39 | opus_int dataSize | ||
40 | ) | ||
41 | { | ||
42 | opus_int i, dataSize4; | ||
43 | |||
44 | /* 4x unrolled loop */ | ||
45 | dataSize4 = dataSize & 0xFFFC; | ||
46 | for( i = 0; i < dataSize4; i += 4 ) { | ||
47 | data_out[ i + 0 ] = gain * data_in[ i + 0 ]; | ||
48 | data_out[ i + 1 ] = gain * data_in[ i + 1 ]; | ||
49 | data_out[ i + 2 ] = gain * data_in[ i + 2 ]; | ||
50 | data_out[ i + 3 ] = gain * data_in[ i + 3 ]; | ||
51 | } | ||
52 | |||
53 | /* any remaining elements */ | ||
54 | for( ; i < dataSize; i++ ) { | ||
55 | data_out[ i ] = gain * data_in[ i ]; | ||
56 | } | ||
57 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/scale_vector_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/scale_vector_FLP.c new file mode 100644 index 0000000000..108fdcbed5 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/scale_vector_FLP.c | |||
@@ -0,0 +1,56 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "SigProc_FLP.h" | ||
33 | |||
34 | /* multiply a vector by a constant */ | ||
35 | void silk_scale_vector_FLP( | ||
36 | silk_float *data1, | ||
37 | silk_float gain, | ||
38 | opus_int dataSize | ||
39 | ) | ||
40 | { | ||
41 | opus_int i, dataSize4; | ||
42 | |||
43 | /* 4x unrolled loop */ | ||
44 | dataSize4 = dataSize & 0xFFFC; | ||
45 | for( i = 0; i < dataSize4; i += 4 ) { | ||
46 | data1[ i + 0 ] *= gain; | ||
47 | data1[ i + 1 ] *= gain; | ||
48 | data1[ i + 2 ] *= gain; | ||
49 | data1[ i + 3 ] *= gain; | ||
50 | } | ||
51 | |||
52 | /* any remaining elements */ | ||
53 | for( ; i < dataSize; i++ ) { | ||
54 | data1[ i ] *= gain; | ||
55 | } | ||
56 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/schur_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/schur_FLP.c new file mode 100644 index 0000000000..8526c748d3 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/schur_FLP.c | |||
@@ -0,0 +1,70 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "SigProc_FLP.h" | ||
33 | |||
34 | silk_float silk_schur_FLP( /* O returns residual energy */ | ||
35 | silk_float refl_coef[], /* O reflection coefficients (length order) */ | ||
36 | const silk_float auto_corr[], /* I autocorrelation sequence (length order+1) */ | ||
37 | opus_int order /* I order */ | ||
38 | ) | ||
39 | { | ||
40 | opus_int k, n; | ||
41 | double C[ SILK_MAX_ORDER_LPC + 1 ][ 2 ]; | ||
42 | double Ctmp1, Ctmp2, rc_tmp; | ||
43 | |||
44 | celt_assert( order >= 0 && order <= SILK_MAX_ORDER_LPC ); | ||
45 | |||
46 | /* Copy correlations */ | ||
47 | k = 0; | ||
48 | do { | ||
49 | C[ k ][ 0 ] = C[ k ][ 1 ] = auto_corr[ k ]; | ||
50 | } while( ++k <= order ); | ||
51 | |||
52 | for( k = 0; k < order; k++ ) { | ||
53 | /* Get reflection coefficient */ | ||
54 | rc_tmp = -C[ k + 1 ][ 0 ] / silk_max_float( C[ 0 ][ 1 ], 1e-9f ); | ||
55 | |||
56 | /* Save the output */ | ||
57 | refl_coef[ k ] = (silk_float)rc_tmp; | ||
58 | |||
59 | /* Update correlations */ | ||
60 | for( n = 0; n < order - k; n++ ) { | ||
61 | Ctmp1 = C[ n + k + 1 ][ 0 ]; | ||
62 | Ctmp2 = C[ n ][ 1 ]; | ||
63 | C[ n + k + 1 ][ 0 ] = Ctmp1 + Ctmp2 * rc_tmp; | ||
64 | C[ n ][ 1 ] = Ctmp2 + Ctmp1 * rc_tmp; | ||
65 | } | ||
66 | } | ||
67 | |||
68 | /* Return residual energy */ | ||
69 | return (silk_float)C[ 0 ][ 1 ]; | ||
70 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/sort_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/sort_FLP.c new file mode 100644 index 0000000000..0e18f31950 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/sort_FLP.c | |||
@@ -0,0 +1,83 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | /* Insertion sort (fast for already almost sorted arrays): */ | ||
33 | /* Best case: O(n) for an already sorted array */ | ||
34 | /* Worst case: O(n^2) for an inversely sorted array */ | ||
35 | |||
36 | #include "typedef.h" | ||
37 | #include "SigProc_FLP.h" | ||
38 | |||
39 | void silk_insertion_sort_decreasing_FLP( | ||
40 | silk_float *a, /* I/O Unsorted / Sorted vector */ | ||
41 | opus_int *idx, /* O Index vector for the sorted elements */ | ||
42 | const opus_int L, /* I Vector length */ | ||
43 | const opus_int K /* I Number of correctly sorted positions */ | ||
44 | ) | ||
45 | { | ||
46 | silk_float value; | ||
47 | opus_int i, j; | ||
48 | |||
49 | /* Safety checks */ | ||
50 | celt_assert( K > 0 ); | ||
51 | celt_assert( L > 0 ); | ||
52 | celt_assert( L >= K ); | ||
53 | |||
54 | /* Write start indices in index vector */ | ||
55 | for( i = 0; i < K; i++ ) { | ||
56 | idx[ i ] = i; | ||
57 | } | ||
58 | |||
59 | /* Sort vector elements by value, decreasing order */ | ||
60 | for( i = 1; i < K; i++ ) { | ||
61 | value = a[ i ]; | ||
62 | for( j = i - 1; ( j >= 0 ) && ( value > a[ j ] ); j-- ) { | ||
63 | a[ j + 1 ] = a[ j ]; /* Shift value */ | ||
64 | idx[ j + 1 ] = idx[ j ]; /* Shift index */ | ||
65 | } | ||
66 | a[ j + 1 ] = value; /* Write value */ | ||
67 | idx[ j + 1 ] = i; /* Write index */ | ||
68 | } | ||
69 | |||
70 | /* If less than L values are asked check the remaining values, */ | ||
71 | /* but only spend CPU to ensure that the K first values are correct */ | ||
72 | for( i = K; i < L; i++ ) { | ||
73 | value = a[ i ]; | ||
74 | if( value > a[ K - 1 ] ) { | ||
75 | for( j = K - 2; ( j >= 0 ) && ( value > a[ j ] ); j-- ) { | ||
76 | a[ j + 1 ] = a[ j ]; /* Shift value */ | ||
77 | idx[ j + 1 ] = idx[ j ]; /* Shift index */ | ||
78 | } | ||
79 | a[ j + 1 ] = value; /* Write value */ | ||
80 | idx[ j + 1 ] = i; /* Write index */ | ||
81 | } | ||
82 | } | ||
83 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/structs_FLP.h b/lib/rbcodec/codecs/libopus/silk/float/structs_FLP.h new file mode 100644 index 0000000000..3150b386e4 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/structs_FLP.h | |||
@@ -0,0 +1,112 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifndef SILK_STRUCTS_FLP_H | ||
29 | #define SILK_STRUCTS_FLP_H | ||
30 | |||
31 | #include "typedef.h" | ||
32 | #include "main.h" | ||
33 | #include "structs.h" | ||
34 | |||
35 | #ifdef __cplusplus | ||
36 | extern "C" | ||
37 | { | ||
38 | #endif | ||
39 | |||
40 | /********************************/ | ||
41 | /* Noise shaping analysis state */ | ||
42 | /********************************/ | ||
43 | typedef struct { | ||
44 | opus_int8 LastGainIndex; | ||
45 | silk_float HarmShapeGain_smth; | ||
46 | silk_float Tilt_smth; | ||
47 | } silk_shape_state_FLP; | ||
48 | |||
49 | /********************************/ | ||
50 | /* Encoder state FLP */ | ||
51 | /********************************/ | ||
52 | typedef struct { | ||
53 | silk_encoder_state sCmn; /* Common struct, shared with fixed-point code */ | ||
54 | silk_shape_state_FLP sShape; /* Noise shaping state */ | ||
55 | |||
56 | /* Buffer for find pitch and noise shape analysis */ | ||
57 | silk_float x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ];/* Buffer for find pitch and noise shape analysis */ | ||
58 | silk_float LTPCorr; /* Normalized correlation from pitch lag estimator */ | ||
59 | } silk_encoder_state_FLP; | ||
60 | |||
61 | /************************/ | ||
62 | /* Encoder control FLP */ | ||
63 | /************************/ | ||
64 | typedef struct { | ||
65 | /* Prediction and coding parameters */ | ||
66 | silk_float Gains[ MAX_NB_SUBFR ]; | ||
67 | silk_float PredCoef[ 2 ][ MAX_LPC_ORDER ]; /* holds interpolated and final coefficients */ | ||
68 | silk_float LTPCoef[LTP_ORDER * MAX_NB_SUBFR]; | ||
69 | silk_float LTP_scale; | ||
70 | opus_int pitchL[ MAX_NB_SUBFR ]; | ||
71 | |||
72 | /* Noise shaping parameters */ | ||
73 | silk_float AR[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ]; | ||
74 | silk_float LF_MA_shp[ MAX_NB_SUBFR ]; | ||
75 | silk_float LF_AR_shp[ MAX_NB_SUBFR ]; | ||
76 | silk_float Tilt[ MAX_NB_SUBFR ]; | ||
77 | silk_float HarmShapeGain[ MAX_NB_SUBFR ]; | ||
78 | silk_float Lambda; | ||
79 | silk_float input_quality; | ||
80 | silk_float coding_quality; | ||
81 | |||
82 | /* Measures */ | ||
83 | silk_float predGain; | ||
84 | silk_float LTPredCodGain; | ||
85 | silk_float ResNrg[ MAX_NB_SUBFR ]; /* Residual energy per subframe */ | ||
86 | |||
87 | /* Parameters for CBR mode */ | ||
88 | opus_int32 GainsUnq_Q16[ MAX_NB_SUBFR ]; | ||
89 | opus_int8 lastGainIndexPrev; | ||
90 | } silk_encoder_control_FLP; | ||
91 | |||
92 | /************************/ | ||
93 | /* Encoder Super Struct */ | ||
94 | /************************/ | ||
95 | typedef struct { | ||
96 | silk_encoder_state_FLP state_Fxx[ ENCODER_NUM_CHANNELS ]; | ||
97 | stereo_enc_state sStereo; | ||
98 | opus_int32 nBitsUsedLBRR; | ||
99 | opus_int32 nBitsExceeded; | ||
100 | opus_int nChannelsAPI; | ||
101 | opus_int nChannelsInternal; | ||
102 | opus_int nPrevChannelsInternal; | ||
103 | opus_int timeSinceSwitchAllowed_ms; | ||
104 | opus_int allowBandwidthSwitch; | ||
105 | opus_int prev_decode_only_middle; | ||
106 | } silk_encoder; | ||
107 | |||
108 | #ifdef __cplusplus | ||
109 | } | ||
110 | #endif | ||
111 | |||
112 | #endif | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/warped_autocorrelation_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/warped_autocorrelation_FLP.c new file mode 100644 index 0000000000..09186e73d4 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/warped_autocorrelation_FLP.c | |||
@@ -0,0 +1,73 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "main_FLP.h" | ||
33 | |||
34 | /* Autocorrelations for a warped frequency axis */ | ||
35 | void silk_warped_autocorrelation_FLP( | ||
36 | silk_float *corr, /* O Result [order + 1] */ | ||
37 | const silk_float *input, /* I Input data to correlate */ | ||
38 | const silk_float warping, /* I Warping coefficient */ | ||
39 | const opus_int length, /* I Length of input */ | ||
40 | const opus_int order /* I Correlation order (even) */ | ||
41 | ) | ||
42 | { | ||
43 | opus_int n, i; | ||
44 | double tmp1, tmp2; | ||
45 | double state[ MAX_SHAPE_LPC_ORDER + 1 ] = { 0 }; | ||
46 | double C[ MAX_SHAPE_LPC_ORDER + 1 ] = { 0 }; | ||
47 | |||
48 | /* Order must be even */ | ||
49 | celt_assert( ( order & 1 ) == 0 ); | ||
50 | |||
51 | /* Loop over samples */ | ||
52 | for( n = 0; n < length; n++ ) { | ||
53 | tmp1 = input[ n ]; | ||
54 | /* Loop over allpass sections */ | ||
55 | for( i = 0; i < order; i += 2 ) { | ||
56 | /* Output of allpass section */ | ||
57 | tmp2 = state[ i ] + warping * ( state[ i + 1 ] - tmp1 ); | ||
58 | state[ i ] = tmp1; | ||
59 | C[ i ] += state[ 0 ] * tmp1; | ||
60 | /* Output of allpass section */ | ||
61 | tmp1 = state[ i + 1 ] + warping * ( state[ i + 2 ] - tmp2 ); | ||
62 | state[ i + 1 ] = tmp2; | ||
63 | C[ i + 1 ] += state[ 0 ] * tmp2; | ||
64 | } | ||
65 | state[ order ] = tmp1; | ||
66 | C[ order ] += state[ 0 ] * tmp1; | ||
67 | } | ||
68 | |||
69 | /* Copy correlations in silk_float output format */ | ||
70 | for( i = 0; i < order + 1; i++ ) { | ||
71 | corr[ i ] = ( silk_float )C[ i ]; | ||
72 | } | ||
73 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/float/wrappers_FLP.c b/lib/rbcodec/codecs/libopus/silk/float/wrappers_FLP.c new file mode 100644 index 0000000000..ad90b874a4 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/float/wrappers_FLP.c | |||
@@ -0,0 +1,207 @@ | |||
1 | /*********************************************************************** | ||
2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. | ||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions | ||
5 | are met: | ||
6 | - Redistributions of source code must retain the above copyright notice, | ||
7 | this list of conditions and the following disclaimer. | ||
8 | - Redistributions in binary form must reproduce the above copyright | ||
9 | notice, this list of conditions and the following disclaimer in the | ||
10 | documentation and/or other materials provided with the distribution. | ||
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 | ||
13 | products derived from this software without specific prior written | ||
14 | permission. | ||
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 | ||
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
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 | ||
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 | ||
25 | POSSIBILITY OF SUCH DAMAGE. | ||
26 | ***********************************************************************/ | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | #include "config.h" | ||
30 | #endif | ||
31 | |||
32 | #include "main_FLP.h" | ||
33 | |||
34 | /* Wrappers. Calls flp / fix code */ | ||
35 | |||
36 | /* Convert AR filter coefficients to NLSF parameters */ | ||
37 | void silk_A2NLSF_FLP( | ||
38 | opus_int16 *NLSF_Q15, /* O NLSF vector [ LPC_order ] */ | ||
39 | const silk_float *pAR, /* I LPC coefficients [ LPC_order ] */ | ||
40 | const opus_int LPC_order /* I LPC order */ | ||
41 | ) | ||
42 | { | ||
43 | opus_int i; | ||
44 | opus_int32 a_fix_Q16[ MAX_LPC_ORDER ]; | ||
45 | |||
46 | for( i = 0; i < LPC_order; i++ ) { | ||
47 | a_fix_Q16[ i ] = silk_float2int( pAR[ i ] * 65536.0f ); | ||
48 | } | ||
49 | |||
50 | silk_A2NLSF( NLSF_Q15, a_fix_Q16, LPC_order ); | ||
51 | } | ||
52 | |||
53 | /* Convert LSF parameters to AR prediction filter coefficients */ | ||
54 | void silk_NLSF2A_FLP( | ||
55 | silk_float *pAR, /* O LPC coefficients [ LPC_order ] */ | ||
56 | const opus_int16 *NLSF_Q15, /* I NLSF vector [ LPC_order ] */ | ||
57 | const opus_int LPC_order, /* I LPC order */ | ||
58 | int arch /* I Run-time architecture */ | ||
59 | ) | ||
60 | { | ||
61 | opus_int i; | ||
62 | opus_int16 a_fix_Q12[ MAX_LPC_ORDER ]; | ||
63 | |||
64 | silk_NLSF2A( a_fix_Q12, NLSF_Q15, LPC_order, arch ); | ||
65 | |||
66 | for( i = 0; i < LPC_order; i++ ) { | ||
67 | pAR[ i ] = ( silk_float )a_fix_Q12[ i ] * ( 1.0f / 4096.0f ); | ||
68 | } | ||
69 | } | ||
70 | |||
71 | /******************************************/ | ||
72 | /* Floating-point NLSF processing wrapper */ | ||
73 | /******************************************/ | ||
74 | void silk_process_NLSFs_FLP( | ||
75 | silk_encoder_state *psEncC, /* I/O Encoder state */ | ||
76 | silk_float PredCoef[ 2 ][ MAX_LPC_ORDER ], /* O Prediction coefficients */ | ||
77 | opus_int16 NLSF_Q15[ MAX_LPC_ORDER ], /* I/O Normalized LSFs (quant out) (0 - (2^15-1)) */ | ||
78 | const opus_int16 prev_NLSF_Q15[ MAX_LPC_ORDER ] /* I Previous Normalized LSFs (0 - (2^15-1)) */ | ||
79 | ) | ||
80 | { | ||
81 | opus_int i, j; | ||
82 | opus_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ]; | ||
83 | |||
84 | silk_process_NLSFs( psEncC, PredCoef_Q12, NLSF_Q15, prev_NLSF_Q15); | ||
85 | |||
86 | for( j = 0; j < 2; j++ ) { | ||
87 | for( i = 0; i < psEncC->predictLPCOrder; i++ ) { | ||
88 | PredCoef[ j ][ i ] = ( silk_float )PredCoef_Q12[ j ][ i ] * ( 1.0f / 4096.0f ); | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | |||
93 | /****************************************/ | ||
94 | /* Floating-point Silk NSQ wrapper */ | ||
95 | /****************************************/ | ||
96 | void silk_NSQ_wrapper_FLP( | ||
97 | silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ | ||
98 | silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ | ||
99 | SideInfoIndices *psIndices, /* I/O Quantization indices */ | ||
100 | silk_nsq_state *psNSQ, /* I/O Noise Shaping Quantzation state */ | ||
101 | opus_int8 pulses[], /* O Quantized pulse signal */ | ||
102 | const silk_float x[] /* I Prefiltered input signal */ | ||
103 | ) | ||
104 | { | ||
105 | opus_int i, j; | ||
106 | opus_int16 x16[ MAX_FRAME_LENGTH ]; | ||
107 | opus_int32 Gains_Q16[ MAX_NB_SUBFR ]; | ||
108 | silk_DWORD_ALIGN opus_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ]; | ||
109 | opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ]; | ||
110 | opus_int LTP_scale_Q14; | ||
111 | |||
112 | /* Noise shaping parameters */ | ||
113 | opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ]; | ||
114 | opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ]; /* Packs two int16 coefficients per int32 value */ | ||
115 | opus_int Lambda_Q10; | ||
116 | opus_int Tilt_Q14[ MAX_NB_SUBFR ]; | ||
117 | opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ]; | ||
118 | |||
119 | /* Convert control struct to fix control struct */ | ||
120 | /* Noise shape parameters */ | ||
121 | for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { | ||
122 | for( j = 0; j < psEnc->sCmn.shapingLPCOrder; j++ ) { | ||
123 | AR_Q13[ i * MAX_SHAPE_LPC_ORDER + j ] = silk_float2int( psEncCtrl->AR[ i * MAX_SHAPE_LPC_ORDER + j ] * 8192.0f ); | ||
124 | } | ||
125 | } | ||
126 | |||
127 | for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { | ||
128 | LF_shp_Q14[ i ] = silk_LSHIFT32( silk_float2int( psEncCtrl->LF_AR_shp[ i ] * 16384.0f ), 16 ) | | ||
129 | (opus_uint16)silk_float2int( psEncCtrl->LF_MA_shp[ i ] * 16384.0f ); | ||
130 | Tilt_Q14[ i ] = (opus_int)silk_float2int( psEncCtrl->Tilt[ i ] * 16384.0f ); | ||
131 | HarmShapeGain_Q14[ i ] = (opus_int)silk_float2int( psEncCtrl->HarmShapeGain[ i ] * 16384.0f ); | ||
132 | } | ||
133 | Lambda_Q10 = ( opus_int )silk_float2int( psEncCtrl->Lambda * 1024.0f ); | ||
134 | |||
135 | /* prediction and coding parameters */ | ||
136 | for( i = 0; i < psEnc->sCmn.nb_subfr * LTP_ORDER; i++ ) { | ||
137 | LTPCoef_Q14[ i ] = (opus_int16)silk_float2int( psEncCtrl->LTPCoef[ i ] * 16384.0f ); | ||
138 | } | ||
139 | |||
140 | for( j = 0; j < 2; j++ ) { | ||
141 | for( i = 0; i < psEnc->sCmn.predictLPCOrder; i++ ) { | ||
142 | PredCoef_Q12[ j ][ i ] = (opus_int16)silk_float2int( psEncCtrl->PredCoef[ j ][ i ] * 4096.0f ); | ||
143 | } | ||
144 | } | ||
145 | |||
146 | for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { | ||
147 | Gains_Q16[ i ] = silk_float2int( psEncCtrl->Gains[ i ] * 65536.0f ); | ||
148 | silk_assert( Gains_Q16[ i ] > 0 ); | ||
149 | } | ||
150 | |||
151 | if( psIndices->signalType == TYPE_VOICED ) { | ||
152 | LTP_scale_Q14 = silk_LTPScales_table_Q14[ psIndices->LTP_scaleIndex ]; | ||
153 | } else { | ||
154 | LTP_scale_Q14 = 0; | ||
155 | } | ||
156 | |||
157 | /* Convert input to fix */ | ||
158 | for( i = 0; i < psEnc->sCmn.frame_length; i++ ) { | ||
159 | x16[ i ] = silk_float2int( x[ i ] ); | ||
160 | } | ||
161 | |||
162 | /* Call NSQ */ | ||
163 | if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) { | ||
164 | silk_NSQ_del_dec( &psEnc->sCmn, psNSQ, psIndices, x16, pulses, PredCoef_Q12[ 0 ], LTPCoef_Q14, | ||
165 | AR_Q13, HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, psEncCtrl->pitchL, Lambda_Q10, LTP_scale_Q14, psEnc->sCmn.arch ); | ||
166 | } else { | ||
167 | silk_NSQ( &psEnc->sCmn, psNSQ, psIndices, x16, pulses, PredCoef_Q12[ 0 ], LTPCoef_Q14, | ||
168 | AR_Q13, HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, psEncCtrl->pitchL, Lambda_Q10, LTP_scale_Q14, psEnc->sCmn.arch ); | ||
169 | } | ||
170 | } | ||
171 | |||
172 | /***********************************************/ | ||
173 | /* Floating-point Silk LTP quantiation wrapper */ | ||
174 | /***********************************************/ | ||
175 | void silk_quant_LTP_gains_FLP( | ||
176 | silk_float B[ MAX_NB_SUBFR * LTP_ORDER ], /* O Quantized LTP gains */ | ||
177 | opus_int8 cbk_index[ MAX_NB_SUBFR ], /* O Codebook index */ | ||
178 | opus_int8 *periodicity_index, /* O Periodicity index */ | ||
179 | opus_int32 *sum_log_gain_Q7, /* I/O Cumulative max prediction gain */ | ||
180 | silk_float *pred_gain_dB, /* O LTP prediction gain */ | ||
181 | const silk_float XX[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* I Correlation matrix */ | ||
182 | const silk_float xX[ MAX_NB_SUBFR * LTP_ORDER ], /* I Correlation vector */ | ||
183 | const opus_int subfr_len, /* I Number of samples per subframe */ | ||
184 | const opus_int nb_subfr, /* I Number of subframes */ | ||
185 | int arch /* I Run-time architecture */ | ||
186 | ) | ||
187 | { | ||
188 | opus_int i, pred_gain_dB_Q7; | ||
189 | opus_int16 B_Q14[ MAX_NB_SUBFR * LTP_ORDER ]; | ||
190 | opus_int32 XX_Q17[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ]; | ||
191 | opus_int32 xX_Q17[ MAX_NB_SUBFR * LTP_ORDER ]; | ||
192 | |||
193 | for( i = 0; i < nb_subfr * LTP_ORDER * LTP_ORDER; i++ ) { | ||
194 | XX_Q17[ i ] = (opus_int32)silk_float2int( XX[ i ] * 131072.0f ); | ||
195 | } | ||
196 | for( i = 0; i < nb_subfr * LTP_ORDER; i++ ) { | ||
197 | xX_Q17[ i ] = (opus_int32)silk_float2int( xX[ i ] * 131072.0f ); | ||
198 | } | ||
199 | |||
200 | silk_quant_LTP_gains( B_Q14, cbk_index, periodicity_index, sum_log_gain_Q7, &pred_gain_dB_Q7, XX_Q17, xX_Q17, subfr_len, nb_subfr, arch ); | ||
201 | |||
202 | for( i = 0; i < nb_subfr * LTP_ORDER; i++ ) { | ||
203 | B[ i ] = (silk_float)B_Q14[ i ] * ( 1.0f / 16384.0f ); | ||
204 | } | ||
205 | |||
206 | *pred_gain_dB = (silk_float)pred_gain_dB_Q7 * ( 1.0f / 128.0f ); | ||
207 | } | ||