diff options
author | William Wilgus <me.theuser@yahoo.com> | 2019-01-04 02:01:18 -0600 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2021-04-23 14:23:04 +0000 |
commit | 14c6bb798d6bebc80f07e863236adbaf8d156a9c (patch) | |
tree | 551a4b641906c2626af844fa3239c1b2b1ff0ad3 /lib/rbcodec/codecs/libopus/silk/fixed/mips | |
parent | 75d93937965ec4df70d37df6d4feea04577c996b (diff) | |
download | rockbox-14c6bb798d6bebc80f07e863236adbaf8d156a9c.tar.gz rockbox-14c6bb798d6bebc80f07e863236adbaf8d156a9c.zip |
Sync opus codec to upstream git
Change-Id: I0cfcc0005c4ad7bfbb1aaf454188ce70fb043dc1
Diffstat (limited to 'lib/rbcodec/codecs/libopus/silk/fixed/mips')
3 files changed, 686 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libopus/silk/fixed/mips/noise_shape_analysis_FIX_mipsr1.h b/lib/rbcodec/codecs/libopus/silk/fixed/mips/noise_shape_analysis_FIX_mipsr1.h new file mode 100644 index 0000000000..3999b5bd09 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/fixed/mips/noise_shape_analysis_FIX_mipsr1.h | |||
@@ -0,0 +1,336 @@ | |||
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 | |||
29 | /**************************************************************/ | ||
30 | /* Compute noise shaping coefficients and initial gain values */ | ||
31 | /**************************************************************/ | ||
32 | #define OVERRIDE_silk_noise_shape_analysis_FIX | ||
33 | |||
34 | void silk_noise_shape_analysis_FIX( | ||
35 | silk_encoder_state_FIX *psEnc, /* I/O Encoder state FIX */ | ||
36 | silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control FIX */ | ||
37 | const opus_int16 *pitch_res, /* I LPC residual from pitch analysis */ | ||
38 | const opus_int16 *x, /* I Input signal [ frame_length + la_shape ] */ | ||
39 | int arch /* I Run-time architecture */ | ||
40 | ) | ||
41 | { | ||
42 | silk_shape_state_FIX *psShapeSt = &psEnc->sShape; | ||
43 | opus_int k, i, nSamples, Qnrg, b_Q14, warping_Q16, scale = 0; | ||
44 | opus_int32 SNR_adj_dB_Q7, HarmBoost_Q16, HarmShapeGain_Q16, Tilt_Q16, tmp32; | ||
45 | opus_int32 nrg, pre_nrg_Q30, log_energy_Q7, log_energy_prev_Q7, energy_variation_Q7; | ||
46 | opus_int32 delta_Q16, BWExp1_Q16, BWExp2_Q16, gain_mult_Q16, gain_add_Q16, strength_Q16, b_Q8; | ||
47 | opus_int32 auto_corr[ MAX_SHAPE_LPC_ORDER + 1 ]; | ||
48 | opus_int32 refl_coef_Q16[ MAX_SHAPE_LPC_ORDER ]; | ||
49 | opus_int32 AR1_Q24[ MAX_SHAPE_LPC_ORDER ]; | ||
50 | opus_int32 AR2_Q24[ MAX_SHAPE_LPC_ORDER ]; | ||
51 | VARDECL( opus_int16, x_windowed ); | ||
52 | const opus_int16 *x_ptr, *pitch_res_ptr; | ||
53 | SAVE_STACK; | ||
54 | |||
55 | /* Point to start of first LPC analysis block */ | ||
56 | x_ptr = x - psEnc->sCmn.la_shape; | ||
57 | |||
58 | /****************/ | ||
59 | /* GAIN CONTROL */ | ||
60 | /****************/ | ||
61 | SNR_adj_dB_Q7 = psEnc->sCmn.SNR_dB_Q7; | ||
62 | |||
63 | /* Input quality is the average of the quality in the lowest two VAD bands */ | ||
64 | psEncCtrl->input_quality_Q14 = ( opus_int )silk_RSHIFT( (opus_int32)psEnc->sCmn.input_quality_bands_Q15[ 0 ] | ||
65 | + psEnc->sCmn.input_quality_bands_Q15[ 1 ], 2 ); | ||
66 | |||
67 | /* Coding quality level, between 0.0_Q0 and 1.0_Q0, but in Q14 */ | ||
68 | psEncCtrl->coding_quality_Q14 = silk_RSHIFT( silk_sigm_Q15( silk_RSHIFT_ROUND( SNR_adj_dB_Q7 - | ||
69 | SILK_FIX_CONST( 20.0, 7 ), 4 ) ), 1 ); | ||
70 | |||
71 | /* Reduce coding SNR during low speech activity */ | ||
72 | if( psEnc->sCmn.useCBR == 0 ) { | ||
73 | b_Q8 = SILK_FIX_CONST( 1.0, 8 ) - psEnc->sCmn.speech_activity_Q8; | ||
74 | b_Q8 = silk_SMULWB( silk_LSHIFT( b_Q8, 8 ), b_Q8 ); | ||
75 | SNR_adj_dB_Q7 = silk_SMLAWB( SNR_adj_dB_Q7, | ||
76 | silk_SMULBB( SILK_FIX_CONST( -BG_SNR_DECR_dB, 7 ) >> ( 4 + 1 ), b_Q8 ), /* Q11*/ | ||
77 | silk_SMULWB( SILK_FIX_CONST( 1.0, 14 ) + psEncCtrl->input_quality_Q14, psEncCtrl->coding_quality_Q14 ) ); /* Q12*/ | ||
78 | } | ||
79 | |||
80 | if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { | ||
81 | /* Reduce gains for periodic signals */ | ||
82 | SNR_adj_dB_Q7 = silk_SMLAWB( SNR_adj_dB_Q7, SILK_FIX_CONST( HARM_SNR_INCR_dB, 8 ), psEnc->LTPCorr_Q15 ); | ||
83 | } else { | ||
84 | /* For unvoiced signals and low-quality input, adjust the quality slower than SNR_dB setting */ | ||
85 | SNR_adj_dB_Q7 = silk_SMLAWB( SNR_adj_dB_Q7, | ||
86 | silk_SMLAWB( SILK_FIX_CONST( 6.0, 9 ), -SILK_FIX_CONST( 0.4, 18 ), psEnc->sCmn.SNR_dB_Q7 ), | ||
87 | SILK_FIX_CONST( 1.0, 14 ) - psEncCtrl->input_quality_Q14 ); | ||
88 | } | ||
89 | |||
90 | /*************************/ | ||
91 | /* SPARSENESS PROCESSING */ | ||
92 | /*************************/ | ||
93 | /* Set quantizer offset */ | ||
94 | if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { | ||
95 | /* Initially set to 0; may be overruled in process_gains(..) */ | ||
96 | psEnc->sCmn.indices.quantOffsetType = 0; | ||
97 | psEncCtrl->sparseness_Q8 = 0; | ||
98 | } else { | ||
99 | /* Sparseness measure, based on relative fluctuations of energy per 2 milliseconds */ | ||
100 | nSamples = silk_LSHIFT( psEnc->sCmn.fs_kHz, 1 ); | ||
101 | energy_variation_Q7 = 0; | ||
102 | log_energy_prev_Q7 = 0; | ||
103 | pitch_res_ptr = pitch_res; | ||
104 | for( k = 0; k < silk_SMULBB( SUB_FRAME_LENGTH_MS, psEnc->sCmn.nb_subfr ) / 2; k++ ) { | ||
105 | silk_sum_sqr_shift( &nrg, &scale, pitch_res_ptr, nSamples ); | ||
106 | nrg += silk_RSHIFT( nSamples, scale ); /* Q(-scale)*/ | ||
107 | |||
108 | log_energy_Q7 = silk_lin2log( nrg ); | ||
109 | if( k > 0 ) { | ||
110 | energy_variation_Q7 += silk_abs( log_energy_Q7 - log_energy_prev_Q7 ); | ||
111 | } | ||
112 | log_energy_prev_Q7 = log_energy_Q7; | ||
113 | pitch_res_ptr += nSamples; | ||
114 | } | ||
115 | |||
116 | psEncCtrl->sparseness_Q8 = silk_RSHIFT( silk_sigm_Q15( silk_SMULWB( energy_variation_Q7 - | ||
117 | SILK_FIX_CONST( 5.0, 7 ), SILK_FIX_CONST( 0.1, 16 ) ) ), 7 ); | ||
118 | |||
119 | /* Set quantization offset depending on sparseness measure */ | ||
120 | if( psEncCtrl->sparseness_Q8 > SILK_FIX_CONST( SPARSENESS_THRESHOLD_QNT_OFFSET, 8 ) ) { | ||
121 | psEnc->sCmn.indices.quantOffsetType = 0; | ||
122 | } else { | ||
123 | psEnc->sCmn.indices.quantOffsetType = 1; | ||
124 | } | ||
125 | |||
126 | /* Increase coding SNR for sparse signals */ | ||
127 | SNR_adj_dB_Q7 = silk_SMLAWB( SNR_adj_dB_Q7, SILK_FIX_CONST( SPARSE_SNR_INCR_dB, 15 ), psEncCtrl->sparseness_Q8 - SILK_FIX_CONST( 0.5, 8 ) ); | ||
128 | } | ||
129 | |||
130 | /*******************************/ | ||
131 | /* Control bandwidth expansion */ | ||
132 | /*******************************/ | ||
133 | /* More BWE for signals with high prediction gain */ | ||
134 | strength_Q16 = silk_SMULWB( psEncCtrl->predGain_Q16, SILK_FIX_CONST( FIND_PITCH_WHITE_NOISE_FRACTION, 16 ) ); | ||
135 | BWExp1_Q16 = BWExp2_Q16 = silk_DIV32_varQ( SILK_FIX_CONST( BANDWIDTH_EXPANSION, 16 ), | ||
136 | silk_SMLAWW( SILK_FIX_CONST( 1.0, 16 ), strength_Q16, strength_Q16 ), 16 ); | ||
137 | delta_Q16 = silk_SMULWB( SILK_FIX_CONST( 1.0, 16 ) - silk_SMULBB( 3, psEncCtrl->coding_quality_Q14 ), | ||
138 | SILK_FIX_CONST( LOW_RATE_BANDWIDTH_EXPANSION_DELTA, 16 ) ); | ||
139 | BWExp1_Q16 = silk_SUB32( BWExp1_Q16, delta_Q16 ); | ||
140 | BWExp2_Q16 = silk_ADD32( BWExp2_Q16, delta_Q16 ); | ||
141 | /* BWExp1 will be applied after BWExp2, so make it relative */ | ||
142 | BWExp1_Q16 = silk_DIV32_16( silk_LSHIFT( BWExp1_Q16, 14 ), silk_RSHIFT( BWExp2_Q16, 2 ) ); | ||
143 | |||
144 | if( psEnc->sCmn.warping_Q16 > 0 ) { | ||
145 | /* Slightly more warping in analysis will move quantization noise up in frequency, where it's better masked */ | ||
146 | warping_Q16 = silk_SMLAWB( psEnc->sCmn.warping_Q16, (opus_int32)psEncCtrl->coding_quality_Q14, SILK_FIX_CONST( 0.01, 18 ) ); | ||
147 | } else { | ||
148 | warping_Q16 = 0; | ||
149 | } | ||
150 | |||
151 | /********************************************/ | ||
152 | /* Compute noise shaping AR coefs and gains */ | ||
153 | /********************************************/ | ||
154 | ALLOC( x_windowed, psEnc->sCmn.shapeWinLength, opus_int16 ); | ||
155 | for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { | ||
156 | /* Apply window: sine slope followed by flat part followed by cosine slope */ | ||
157 | opus_int shift, slope_part, flat_part; | ||
158 | flat_part = psEnc->sCmn.fs_kHz * 3; | ||
159 | slope_part = silk_RSHIFT( psEnc->sCmn.shapeWinLength - flat_part, 1 ); | ||
160 | |||
161 | silk_apply_sine_window( x_windowed, x_ptr, 1, slope_part ); | ||
162 | shift = slope_part; | ||
163 | silk_memcpy( x_windowed + shift, x_ptr + shift, flat_part * sizeof(opus_int16) ); | ||
164 | shift += flat_part; | ||
165 | silk_apply_sine_window( x_windowed + shift, x_ptr + shift, 2, slope_part ); | ||
166 | |||
167 | /* Update pointer: next LPC analysis block */ | ||
168 | x_ptr += psEnc->sCmn.subfr_length; | ||
169 | |||
170 | if( psEnc->sCmn.warping_Q16 > 0 ) { | ||
171 | /* Calculate warped auto correlation */ | ||
172 | silk_warped_autocorrelation_FIX( auto_corr, &scale, x_windowed, warping_Q16, psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder, arch ); | ||
173 | } else { | ||
174 | /* Calculate regular auto correlation */ | ||
175 | silk_autocorr( auto_corr, &scale, x_windowed, psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder + 1, arch ); | ||
176 | } | ||
177 | |||
178 | /* Add white noise, as a fraction of energy */ | ||
179 | auto_corr[0] = silk_ADD32( auto_corr[0], silk_max_32( silk_SMULWB( silk_RSHIFT( auto_corr[ 0 ], 4 ), | ||
180 | SILK_FIX_CONST( SHAPE_WHITE_NOISE_FRACTION, 20 ) ), 1 ) ); | ||
181 | |||
182 | /* Calculate the reflection coefficients using schur */ | ||
183 | nrg = silk_schur64( refl_coef_Q16, auto_corr, psEnc->sCmn.shapingLPCOrder ); | ||
184 | silk_assert( nrg >= 0 ); | ||
185 | |||
186 | /* Convert reflection coefficients to prediction coefficients */ | ||
187 | silk_k2a_Q16( AR2_Q24, refl_coef_Q16, psEnc->sCmn.shapingLPCOrder ); | ||
188 | |||
189 | Qnrg = -scale; /* range: -12...30*/ | ||
190 | silk_assert( Qnrg >= -12 ); | ||
191 | silk_assert( Qnrg <= 30 ); | ||
192 | |||
193 | /* Make sure that Qnrg is an even number */ | ||
194 | if( Qnrg & 1 ) { | ||
195 | Qnrg -= 1; | ||
196 | nrg >>= 1; | ||
197 | } | ||
198 | |||
199 | tmp32 = silk_SQRT_APPROX( nrg ); | ||
200 | Qnrg >>= 1; /* range: -6...15*/ | ||
201 | |||
202 | psEncCtrl->Gains_Q16[ k ] = (silk_LSHIFT32( silk_LIMIT( (tmp32), silk_RSHIFT32( silk_int32_MIN, (16 - Qnrg) ), \ | ||
203 | silk_RSHIFT32( silk_int32_MAX, (16 - Qnrg) ) ), (16 - Qnrg) )); | ||
204 | |||
205 | if( psEnc->sCmn.warping_Q16 > 0 ) { | ||
206 | /* Adjust gain for warping */ | ||
207 | gain_mult_Q16 = warped_gain( AR2_Q24, warping_Q16, psEnc->sCmn.shapingLPCOrder ); | ||
208 | silk_assert( psEncCtrl->Gains_Q16[ k ] >= 0 ); | ||
209 | if ( silk_SMULWW( silk_RSHIFT_ROUND( psEncCtrl->Gains_Q16[ k ], 1 ), gain_mult_Q16 ) >= ( silk_int32_MAX >> 1 ) ) { | ||
210 | psEncCtrl->Gains_Q16[ k ] = silk_int32_MAX; | ||
211 | } else { | ||
212 | psEncCtrl->Gains_Q16[ k ] = silk_SMULWW( psEncCtrl->Gains_Q16[ k ], gain_mult_Q16 ); | ||
213 | } | ||
214 | } | ||
215 | |||
216 | /* Bandwidth expansion for synthesis filter shaping */ | ||
217 | silk_bwexpander_32( AR2_Q24, psEnc->sCmn.shapingLPCOrder, BWExp2_Q16 ); | ||
218 | |||
219 | /* Compute noise shaping filter coefficients */ | ||
220 | silk_memcpy( AR1_Q24, AR2_Q24, psEnc->sCmn.shapingLPCOrder * sizeof( opus_int32 ) ); | ||
221 | |||
222 | /* Bandwidth expansion for analysis filter shaping */ | ||
223 | silk_assert( BWExp1_Q16 <= SILK_FIX_CONST( 1.0, 16 ) ); | ||
224 | silk_bwexpander_32( AR1_Q24, psEnc->sCmn.shapingLPCOrder, BWExp1_Q16 ); | ||
225 | |||
226 | /* Ratio of prediction gains, in energy domain */ | ||
227 | pre_nrg_Q30 = silk_LPC_inverse_pred_gain_Q24( AR2_Q24, psEnc->sCmn.shapingLPCOrder, arch ); | ||
228 | nrg = silk_LPC_inverse_pred_gain_Q24( AR1_Q24, psEnc->sCmn.shapingLPCOrder, arch ); | ||
229 | |||
230 | /*psEncCtrl->GainsPre[ k ] = 1.0f - 0.7f * ( 1.0f - pre_nrg / nrg ) = 0.3f + 0.7f * pre_nrg / nrg;*/ | ||
231 | pre_nrg_Q30 = silk_LSHIFT32( silk_SMULWB( pre_nrg_Q30, SILK_FIX_CONST( 0.7, 15 ) ), 1 ); | ||
232 | psEncCtrl->GainsPre_Q14[ k ] = ( opus_int ) SILK_FIX_CONST( 0.3, 14 ) + silk_DIV32_varQ( pre_nrg_Q30, nrg, 14 ); | ||
233 | |||
234 | /* Convert to monic warped prediction coefficients and limit absolute values */ | ||
235 | limit_warped_coefs( AR2_Q24, AR1_Q24, warping_Q16, SILK_FIX_CONST( 3.999, 24 ), psEnc->sCmn.shapingLPCOrder ); | ||
236 | |||
237 | /* Convert from Q24 to Q13 and store in int16 */ | ||
238 | for( i = 0; i < psEnc->sCmn.shapingLPCOrder; i++ ) { | ||
239 | psEncCtrl->AR1_Q13[ k * MAX_SHAPE_LPC_ORDER + i ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( AR1_Q24[ i ], 11 ) ); | ||
240 | psEncCtrl->AR2_Q13[ k * MAX_SHAPE_LPC_ORDER + i ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( AR2_Q24[ i ], 11 ) ); | ||
241 | } | ||
242 | } | ||
243 | |||
244 | /*****************/ | ||
245 | /* Gain tweaking */ | ||
246 | /*****************/ | ||
247 | /* Increase gains during low speech activity and put lower limit on gains */ | ||
248 | gain_mult_Q16 = silk_log2lin( -silk_SMLAWB( -SILK_FIX_CONST( 16.0, 7 ), SNR_adj_dB_Q7, SILK_FIX_CONST( 0.16, 16 ) ) ); | ||
249 | gain_add_Q16 = silk_log2lin( silk_SMLAWB( SILK_FIX_CONST( 16.0, 7 ), SILK_FIX_CONST( MIN_QGAIN_DB, 7 ), SILK_FIX_CONST( 0.16, 16 ) ) ); | ||
250 | silk_assert( gain_mult_Q16 > 0 ); | ||
251 | for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { | ||
252 | psEncCtrl->Gains_Q16[ k ] = silk_SMULWW( psEncCtrl->Gains_Q16[ k ], gain_mult_Q16 ); | ||
253 | silk_assert( psEncCtrl->Gains_Q16[ k ] >= 0 ); | ||
254 | psEncCtrl->Gains_Q16[ k ] = silk_ADD_POS_SAT32( psEncCtrl->Gains_Q16[ k ], gain_add_Q16 ); | ||
255 | } | ||
256 | |||
257 | gain_mult_Q16 = SILK_FIX_CONST( 1.0, 16 ) + silk_RSHIFT_ROUND( silk_MLA( SILK_FIX_CONST( INPUT_TILT, 26 ), | ||
258 | psEncCtrl->coding_quality_Q14, SILK_FIX_CONST( HIGH_RATE_INPUT_TILT, 12 ) ), 10 ); | ||
259 | for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { | ||
260 | psEncCtrl->GainsPre_Q14[ k ] = silk_SMULWB( gain_mult_Q16, psEncCtrl->GainsPre_Q14[ k ] ); | ||
261 | } | ||
262 | |||
263 | /************************************************/ | ||
264 | /* Control low-frequency shaping and noise tilt */ | ||
265 | /************************************************/ | ||
266 | /* Less low frequency shaping for noisy inputs */ | ||
267 | strength_Q16 = silk_MUL( SILK_FIX_CONST( LOW_FREQ_SHAPING, 4 ), silk_SMLAWB( SILK_FIX_CONST( 1.0, 12 ), | ||
268 | SILK_FIX_CONST( LOW_QUALITY_LOW_FREQ_SHAPING_DECR, 13 ), psEnc->sCmn.input_quality_bands_Q15[ 0 ] - SILK_FIX_CONST( 1.0, 15 ) ) ); | ||
269 | strength_Q16 = silk_RSHIFT( silk_MUL( strength_Q16, psEnc->sCmn.speech_activity_Q8 ), 8 ); | ||
270 | if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { | ||
271 | /* Reduce low frequencies quantization noise for periodic signals, depending on pitch lag */ | ||
272 | /*f = 400; freqz([1, -0.98 + 2e-4 * f], [1, -0.97 + 7e-4 * f], 2^12, Fs); axis([0, 1000, -10, 1])*/ | ||
273 | opus_int fs_kHz_inv = silk_DIV32_16( SILK_FIX_CONST( 0.2, 14 ), psEnc->sCmn.fs_kHz ); | ||
274 | for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { | ||
275 | b_Q14 = fs_kHz_inv + silk_DIV32_16( SILK_FIX_CONST( 3.0, 14 ), psEncCtrl->pitchL[ k ] ); | ||
276 | /* Pack two coefficients in one int32 */ | ||
277 | psEncCtrl->LF_shp_Q14[ k ] = silk_LSHIFT( SILK_FIX_CONST( 1.0, 14 ) - b_Q14 - silk_SMULWB( strength_Q16, b_Q14 ), 16 ); | ||
278 | psEncCtrl->LF_shp_Q14[ k ] |= (opus_uint16)( b_Q14 - SILK_FIX_CONST( 1.0, 14 ) ); | ||
279 | } | ||
280 | silk_assert( SILK_FIX_CONST( HARM_HP_NOISE_COEF, 24 ) < SILK_FIX_CONST( 0.5, 24 ) ); /* Guarantees that second argument to SMULWB() is within range of an opus_int16*/ | ||
281 | Tilt_Q16 = - SILK_FIX_CONST( HP_NOISE_COEF, 16 ) - | ||
282 | silk_SMULWB( SILK_FIX_CONST( 1.0, 16 ) - SILK_FIX_CONST( HP_NOISE_COEF, 16 ), | ||
283 | silk_SMULWB( SILK_FIX_CONST( HARM_HP_NOISE_COEF, 24 ), psEnc->sCmn.speech_activity_Q8 ) ); | ||
284 | } else { | ||
285 | b_Q14 = silk_DIV32_16( 21299, psEnc->sCmn.fs_kHz ); /* 1.3_Q0 = 21299_Q14*/ | ||
286 | /* Pack two coefficients in one int32 */ | ||
287 | psEncCtrl->LF_shp_Q14[ 0 ] = silk_LSHIFT( SILK_FIX_CONST( 1.0, 14 ) - b_Q14 - | ||
288 | silk_SMULWB( strength_Q16, silk_SMULWB( SILK_FIX_CONST( 0.6, 16 ), b_Q14 ) ), 16 ); | ||
289 | psEncCtrl->LF_shp_Q14[ 0 ] |= (opus_uint16)( b_Q14 - SILK_FIX_CONST( 1.0, 14 ) ); | ||
290 | for( k = 1; k < psEnc->sCmn.nb_subfr; k++ ) { | ||
291 | psEncCtrl->LF_shp_Q14[ k ] = psEncCtrl->LF_shp_Q14[ 0 ]; | ||
292 | } | ||
293 | Tilt_Q16 = -SILK_FIX_CONST( HP_NOISE_COEF, 16 ); | ||
294 | } | ||
295 | |||
296 | /****************************/ | ||
297 | /* HARMONIC SHAPING CONTROL */ | ||
298 | /****************************/ | ||
299 | /* Control boosting of harmonic frequencies */ | ||
300 | HarmBoost_Q16 = silk_SMULWB( silk_SMULWB( SILK_FIX_CONST( 1.0, 17 ) - silk_LSHIFT( psEncCtrl->coding_quality_Q14, 3 ), | ||
301 | psEnc->LTPCorr_Q15 ), SILK_FIX_CONST( LOW_RATE_HARMONIC_BOOST, 16 ) ); | ||
302 | |||
303 | /* More harmonic boost for noisy input signals */ | ||
304 | HarmBoost_Q16 = silk_SMLAWB( HarmBoost_Q16, | ||
305 | SILK_FIX_CONST( 1.0, 16 ) - silk_LSHIFT( psEncCtrl->input_quality_Q14, 2 ), SILK_FIX_CONST( LOW_INPUT_QUALITY_HARMONIC_BOOST, 16 ) ); | ||
306 | |||
307 | if( USE_HARM_SHAPING && psEnc->sCmn.indices.signalType == TYPE_VOICED ) { | ||
308 | /* More harmonic noise shaping for high bitrates or noisy input */ | ||
309 | HarmShapeGain_Q16 = silk_SMLAWB( SILK_FIX_CONST( HARMONIC_SHAPING, 16 ), | ||
310 | SILK_FIX_CONST( 1.0, 16 ) - silk_SMULWB( SILK_FIX_CONST( 1.0, 18 ) - silk_LSHIFT( psEncCtrl->coding_quality_Q14, 4 ), | ||
311 | psEncCtrl->input_quality_Q14 ), SILK_FIX_CONST( HIGH_RATE_OR_LOW_QUALITY_HARMONIC_SHAPING, 16 ) ); | ||
312 | |||
313 | /* Less harmonic noise shaping for less periodic signals */ | ||
314 | HarmShapeGain_Q16 = silk_SMULWB( silk_LSHIFT( HarmShapeGain_Q16, 1 ), | ||
315 | silk_SQRT_APPROX( silk_LSHIFT( psEnc->LTPCorr_Q15, 15 ) ) ); | ||
316 | } else { | ||
317 | HarmShapeGain_Q16 = 0; | ||
318 | } | ||
319 | |||
320 | /*************************/ | ||
321 | /* Smooth over subframes */ | ||
322 | /*************************/ | ||
323 | for( k = 0; k < MAX_NB_SUBFR; k++ ) { | ||
324 | psShapeSt->HarmBoost_smth_Q16 = | ||
325 | silk_SMLAWB( psShapeSt->HarmBoost_smth_Q16, HarmBoost_Q16 - psShapeSt->HarmBoost_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) ); | ||
326 | psShapeSt->HarmShapeGain_smth_Q16 = | ||
327 | silk_SMLAWB( psShapeSt->HarmShapeGain_smth_Q16, HarmShapeGain_Q16 - psShapeSt->HarmShapeGain_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) ); | ||
328 | psShapeSt->Tilt_smth_Q16 = | ||
329 | silk_SMLAWB( psShapeSt->Tilt_smth_Q16, Tilt_Q16 - psShapeSt->Tilt_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) ); | ||
330 | |||
331 | psEncCtrl->HarmBoost_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psShapeSt->HarmBoost_smth_Q16, 2 ); | ||
332 | psEncCtrl->HarmShapeGain_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psShapeSt->HarmShapeGain_smth_Q16, 2 ); | ||
333 | psEncCtrl->Tilt_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psShapeSt->Tilt_smth_Q16, 2 ); | ||
334 | } | ||
335 | RESTORE_STACK; | ||
336 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/fixed/mips/prefilter_FIX_mipsr1.h b/lib/rbcodec/codecs/libopus/silk/fixed/mips/prefilter_FIX_mipsr1.h new file mode 100644 index 0000000000..21b256885f --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/fixed/mips/prefilter_FIX_mipsr1.h | |||
@@ -0,0 +1,184 @@ | |||
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 | #ifndef __PREFILTER_FIX_MIPSR1_H__ | ||
28 | #define __PREFILTER_FIX_MIPSR1_H__ | ||
29 | |||
30 | #ifdef HAVE_CONFIG_H | ||
31 | #include "config.h" | ||
32 | #endif | ||
33 | |||
34 | #include "main_FIX.h" | ||
35 | #include "stack_alloc.h" | ||
36 | #include "tuning_parameters.h" | ||
37 | |||
38 | #define OVERRIDE_silk_warped_LPC_analysis_filter_FIX | ||
39 | void silk_warped_LPC_analysis_filter_FIX( | ||
40 | opus_int32 state[], /* I/O State [order + 1] */ | ||
41 | opus_int32 res_Q2[], /* O Residual signal [length] */ | ||
42 | const opus_int16 coef_Q13[], /* I Coefficients [order] */ | ||
43 | const opus_int16 input[], /* I Input signal [length] */ | ||
44 | const opus_int16 lambda_Q16, /* I Warping factor */ | ||
45 | const opus_int length, /* I Length of input signal */ | ||
46 | const opus_int order, /* I Filter order (even) */ | ||
47 | int arch | ||
48 | ) | ||
49 | { | ||
50 | opus_int n, i; | ||
51 | opus_int32 acc_Q11, acc_Q22, tmp1, tmp2, tmp3, tmp4; | ||
52 | opus_int32 state_cur, state_next; | ||
53 | |||
54 | (void)arch; | ||
55 | |||
56 | /* Order must be even */ | ||
57 | /* Length must be even */ | ||
58 | |||
59 | silk_assert( ( order & 1 ) == 0 ); | ||
60 | silk_assert( ( length & 1 ) == 0 ); | ||
61 | |||
62 | for( n = 0; n < length; n+=2 ) { | ||
63 | /* Output of lowpass section */ | ||
64 | tmp2 = silk_SMLAWB( state[ 0 ], state[ 1 ], lambda_Q16 ); | ||
65 | state_cur = silk_LSHIFT( input[ n ], 14 ); | ||
66 | /* Output of allpass section */ | ||
67 | tmp1 = silk_SMLAWB( state[ 1 ], state[ 2 ] - tmp2, lambda_Q16 ); | ||
68 | state_next = tmp2; | ||
69 | acc_Q11 = silk_RSHIFT( order, 1 ); | ||
70 | acc_Q11 = silk_SMLAWB( acc_Q11, tmp2, coef_Q13[ 0 ] ); | ||
71 | |||
72 | |||
73 | /* Output of lowpass section */ | ||
74 | tmp4 = silk_SMLAWB( state_cur, state_next, lambda_Q16 ); | ||
75 | state[ 0 ] = silk_LSHIFT( input[ n+1 ], 14 ); | ||
76 | /* Output of allpass section */ | ||
77 | tmp3 = silk_SMLAWB( state_next, tmp1 - tmp4, lambda_Q16 ); | ||
78 | state[ 1 ] = tmp4; | ||
79 | acc_Q22 = silk_RSHIFT( order, 1 ); | ||
80 | acc_Q22 = silk_SMLAWB( acc_Q22, tmp4, coef_Q13[ 0 ] ); | ||
81 | |||
82 | /* Loop over allpass sections */ | ||
83 | for( i = 2; i < order; i += 2 ) { | ||
84 | /* Output of allpass section */ | ||
85 | tmp2 = silk_SMLAWB( state[ i ], state[ i + 1 ] - tmp1, lambda_Q16 ); | ||
86 | state_cur = tmp1; | ||
87 | acc_Q11 = silk_SMLAWB( acc_Q11, tmp1, coef_Q13[ i - 1 ] ); | ||
88 | /* Output of allpass section */ | ||
89 | tmp1 = silk_SMLAWB( state[ i + 1 ], state[ i + 2 ] - tmp2, lambda_Q16 ); | ||
90 | state_next = tmp2; | ||
91 | acc_Q11 = silk_SMLAWB( acc_Q11, tmp2, coef_Q13[ i ] ); | ||
92 | |||
93 | |||
94 | /* Output of allpass section */ | ||
95 | tmp4 = silk_SMLAWB( state_cur, state_next - tmp3, lambda_Q16 ); | ||
96 | state[ i ] = tmp3; | ||
97 | acc_Q22 = silk_SMLAWB( acc_Q22, tmp3, coef_Q13[ i - 1 ] ); | ||
98 | /* Output of allpass section */ | ||
99 | tmp3 = silk_SMLAWB( state_next, tmp1 - tmp4, lambda_Q16 ); | ||
100 | state[ i + 1 ] = tmp4; | ||
101 | acc_Q22 = silk_SMLAWB( acc_Q22, tmp4, coef_Q13[ i ] ); | ||
102 | } | ||
103 | acc_Q11 = silk_SMLAWB( acc_Q11, tmp1, coef_Q13[ order - 1 ] ); | ||
104 | res_Q2[ n ] = silk_LSHIFT( (opus_int32)input[ n ], 2 ) - silk_RSHIFT_ROUND( acc_Q11, 9 ); | ||
105 | |||
106 | state[ order ] = tmp3; | ||
107 | acc_Q22 = silk_SMLAWB( acc_Q22, tmp3, coef_Q13[ order - 1 ] ); | ||
108 | res_Q2[ n+1 ] = silk_LSHIFT( (opus_int32)input[ n+1 ], 2 ) - silk_RSHIFT_ROUND( acc_Q22, 9 ); | ||
109 | } | ||
110 | } | ||
111 | |||
112 | |||
113 | |||
114 | /* Prefilter for finding Quantizer input signal */ | ||
115 | #define OVERRIDE_silk_prefilt_FIX | ||
116 | static inline void silk_prefilt_FIX( | ||
117 | silk_prefilter_state_FIX *P, /* I/O state */ | ||
118 | opus_int32 st_res_Q12[], /* I short term residual signal */ | ||
119 | opus_int32 xw_Q3[], /* O prefiltered signal */ | ||
120 | opus_int32 HarmShapeFIRPacked_Q12, /* I Harmonic shaping coeficients */ | ||
121 | opus_int Tilt_Q14, /* I Tilt shaping coeficient */ | ||
122 | opus_int32 LF_shp_Q14, /* I Low-frequancy shaping coeficients */ | ||
123 | opus_int lag, /* I Lag for harmonic shaping */ | ||
124 | opus_int length /* I Length of signals */ | ||
125 | ) | ||
126 | { | ||
127 | opus_int i, idx, LTP_shp_buf_idx; | ||
128 | opus_int32 n_LTP_Q12, n_Tilt_Q10, n_LF_Q10; | ||
129 | opus_int32 sLF_MA_shp_Q12, sLF_AR_shp_Q12; | ||
130 | opus_int16 *LTP_shp_buf; | ||
131 | |||
132 | /* To speed up use temp variables instead of using the struct */ | ||
133 | LTP_shp_buf = P->sLTP_shp; | ||
134 | LTP_shp_buf_idx = P->sLTP_shp_buf_idx; | ||
135 | sLF_AR_shp_Q12 = P->sLF_AR_shp_Q12; | ||
136 | sLF_MA_shp_Q12 = P->sLF_MA_shp_Q12; | ||
137 | |||
138 | if( lag > 0 ) { | ||
139 | for( i = 0; i < length; i++ ) { | ||
140 | /* unrolled loop */ | ||
141 | silk_assert( HARM_SHAPE_FIR_TAPS == 3 ); | ||
142 | idx = lag + LTP_shp_buf_idx; | ||
143 | n_LTP_Q12 = silk_SMULBB( LTP_shp_buf[ ( idx - HARM_SHAPE_FIR_TAPS / 2 - 1) & LTP_MASK ], HarmShapeFIRPacked_Q12 ); | ||
144 | n_LTP_Q12 = silk_SMLABT( n_LTP_Q12, LTP_shp_buf[ ( idx - HARM_SHAPE_FIR_TAPS / 2 ) & LTP_MASK ], HarmShapeFIRPacked_Q12 ); | ||
145 | n_LTP_Q12 = silk_SMLABB( n_LTP_Q12, LTP_shp_buf[ ( idx - HARM_SHAPE_FIR_TAPS / 2 + 1) & LTP_MASK ], HarmShapeFIRPacked_Q12 ); | ||
146 | |||
147 | n_Tilt_Q10 = silk_SMULWB( sLF_AR_shp_Q12, Tilt_Q14 ); | ||
148 | n_LF_Q10 = silk_SMLAWB( silk_SMULWT( sLF_AR_shp_Q12, LF_shp_Q14 ), sLF_MA_shp_Q12, LF_shp_Q14 ); | ||
149 | |||
150 | sLF_AR_shp_Q12 = silk_SUB32( st_res_Q12[ i ], silk_LSHIFT( n_Tilt_Q10, 2 ) ); | ||
151 | sLF_MA_shp_Q12 = silk_SUB32( sLF_AR_shp_Q12, silk_LSHIFT( n_LF_Q10, 2 ) ); | ||
152 | |||
153 | LTP_shp_buf_idx = ( LTP_shp_buf_idx - 1 ) & LTP_MASK; | ||
154 | LTP_shp_buf[ LTP_shp_buf_idx ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( sLF_MA_shp_Q12, 12 ) ); | ||
155 | |||
156 | xw_Q3[i] = silk_RSHIFT_ROUND( silk_SUB32( sLF_MA_shp_Q12, n_LTP_Q12 ), 9 ); | ||
157 | } | ||
158 | } | ||
159 | else | ||
160 | { | ||
161 | for( i = 0; i < length; i++ ) { | ||
162 | |||
163 | n_LTP_Q12 = 0; | ||
164 | |||
165 | n_Tilt_Q10 = silk_SMULWB( sLF_AR_shp_Q12, Tilt_Q14 ); | ||
166 | n_LF_Q10 = silk_SMLAWB( silk_SMULWT( sLF_AR_shp_Q12, LF_shp_Q14 ), sLF_MA_shp_Q12, LF_shp_Q14 ); | ||
167 | |||
168 | sLF_AR_shp_Q12 = silk_SUB32( st_res_Q12[ i ], silk_LSHIFT( n_Tilt_Q10, 2 ) ); | ||
169 | sLF_MA_shp_Q12 = silk_SUB32( sLF_AR_shp_Q12, silk_LSHIFT( n_LF_Q10, 2 ) ); | ||
170 | |||
171 | LTP_shp_buf_idx = ( LTP_shp_buf_idx - 1 ) & LTP_MASK; | ||
172 | LTP_shp_buf[ LTP_shp_buf_idx ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( sLF_MA_shp_Q12, 12 ) ); | ||
173 | |||
174 | xw_Q3[i] = silk_RSHIFT_ROUND( sLF_MA_shp_Q12, 9 ); | ||
175 | } | ||
176 | } | ||
177 | |||
178 | /* Copy temp variable back to state */ | ||
179 | P->sLF_AR_shp_Q12 = sLF_AR_shp_Q12; | ||
180 | P->sLF_MA_shp_Q12 = sLF_MA_shp_Q12; | ||
181 | P->sLTP_shp_buf_idx = LTP_shp_buf_idx; | ||
182 | } | ||
183 | |||
184 | #endif /* __PREFILTER_FIX_MIPSR1_H__ */ | ||
diff --git a/lib/rbcodec/codecs/libopus/silk/fixed/mips/warped_autocorrelation_FIX_mipsr1.h b/lib/rbcodec/codecs/libopus/silk/fixed/mips/warped_autocorrelation_FIX_mipsr1.h new file mode 100644 index 0000000000..fcbd96c88d --- /dev/null +++ b/lib/rbcodec/codecs/libopus/silk/fixed/mips/warped_autocorrelation_FIX_mipsr1.h | |||
@@ -0,0 +1,166 @@ | |||
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 __WARPED_AUTOCORRELATION_FIX_MIPSR1_H__ | ||
29 | #define __WARPED_AUTOCORRELATION_FIX_MIPSR1_H__ | ||
30 | |||
31 | #ifdef HAVE_CONFIG_H | ||
32 | #include "config.h" | ||
33 | #endif | ||
34 | |||
35 | #include "main_FIX.h" | ||
36 | |||
37 | #undef QC | ||
38 | #define QC 10 | ||
39 | |||
40 | #undef QS | ||
41 | #define QS 14 | ||
42 | |||
43 | /* Autocorrelations for a warped frequency axis */ | ||
44 | #define OVERRIDE_silk_warped_autocorrelation_FIX | ||
45 | void silk_warped_autocorrelation_FIX( | ||
46 | opus_int32 *corr, /* O Result [order + 1] */ | ||
47 | opus_int *scale, /* O Scaling of the correlation vector */ | ||
48 | const opus_int16 *input, /* I Input data to correlate */ | ||
49 | const opus_int warping_Q16, /* I Warping coefficient */ | ||
50 | const opus_int length, /* I Length of input */ | ||
51 | const opus_int order, /* I Correlation order (even) */ | ||
52 | int arch /* I Run-time architecture */ | ||
53 | ) | ||
54 | { | ||
55 | opus_int n, i, lsh; | ||
56 | opus_int32 tmp1_QS=0, tmp2_QS=0, tmp3_QS=0, tmp4_QS=0, tmp5_QS=0, tmp6_QS=0, tmp7_QS=0, tmp8_QS=0, start_1=0, start_2=0, start_3=0; | ||
57 | opus_int32 state_QS[ MAX_SHAPE_LPC_ORDER + 1 ] = { 0 }; | ||
58 | opus_int64 corr_QC[ MAX_SHAPE_LPC_ORDER + 1 ] = { 0 }; | ||
59 | opus_int64 temp64; | ||
60 | |||
61 | opus_int32 val; | ||
62 | val = 2 * QS - QC; | ||
63 | |||
64 | /* Order must be even */ | ||
65 | silk_assert( ( order & 1 ) == 0 ); | ||
66 | silk_assert( 2 * QS - QC >= 0 ); | ||
67 | |||
68 | /* Loop over samples */ | ||
69 | for( n = 0; n < length; n=n+4 ) { | ||
70 | |||
71 | tmp1_QS = silk_LSHIFT32( (opus_int32)input[ n ], QS ); | ||
72 | start_1 = tmp1_QS; | ||
73 | tmp3_QS = silk_LSHIFT32( (opus_int32)input[ n+1], QS ); | ||
74 | start_2 = tmp3_QS; | ||
75 | tmp5_QS = silk_LSHIFT32( (opus_int32)input[ n+2], QS ); | ||
76 | start_3 = tmp5_QS; | ||
77 | tmp7_QS = silk_LSHIFT32( (opus_int32)input[ n+3], QS ); | ||
78 | |||
79 | /* Loop over allpass sections */ | ||
80 | for( i = 0; i < order; i += 2 ) { | ||
81 | /* Output of allpass section */ | ||
82 | tmp2_QS = silk_SMLAWB( state_QS[ i ], state_QS[ i + 1 ] - tmp1_QS, warping_Q16 ); | ||
83 | corr_QC[ i ] = __builtin_mips_madd( corr_QC[ i ], tmp1_QS, start_1); | ||
84 | |||
85 | tmp4_QS = silk_SMLAWB( tmp1_QS, tmp2_QS - tmp3_QS, warping_Q16 ); | ||
86 | corr_QC[ i ] = __builtin_mips_madd( corr_QC[ i ], tmp3_QS, start_2); | ||
87 | |||
88 | tmp6_QS = silk_SMLAWB( tmp3_QS, tmp4_QS - tmp5_QS, warping_Q16 ); | ||
89 | corr_QC[ i ] = __builtin_mips_madd( corr_QC[ i ], tmp5_QS, start_3); | ||
90 | |||
91 | tmp8_QS = silk_SMLAWB( tmp5_QS, tmp6_QS - tmp7_QS, warping_Q16 ); | ||
92 | state_QS[ i ] = tmp7_QS; | ||
93 | corr_QC[ i ] = __builtin_mips_madd( corr_QC[ i ], tmp7_QS, state_QS[0]); | ||
94 | |||
95 | /* Output of allpass section */ | ||
96 | tmp1_QS = silk_SMLAWB( state_QS[ i + 1 ], state_QS[ i + 2 ] - tmp2_QS, warping_Q16 ); | ||
97 | corr_QC[ i+1 ] = __builtin_mips_madd( corr_QC[ i+1 ], tmp2_QS, start_1); | ||
98 | |||
99 | tmp3_QS = silk_SMLAWB( tmp2_QS, tmp1_QS - tmp4_QS, warping_Q16 ); | ||
100 | corr_QC[ i+1 ] = __builtin_mips_madd( corr_QC[ i+1 ], tmp4_QS, start_2); | ||
101 | |||
102 | tmp5_QS = silk_SMLAWB( tmp4_QS, tmp3_QS - tmp6_QS, warping_Q16 ); | ||
103 | corr_QC[ i+1 ] = __builtin_mips_madd( corr_QC[ i+1 ], tmp6_QS, start_3); | ||
104 | |||
105 | tmp7_QS = silk_SMLAWB( tmp6_QS, tmp5_QS - tmp8_QS, warping_Q16 ); | ||
106 | state_QS[ i + 1 ] = tmp8_QS; | ||
107 | corr_QC[ i+1 ] = __builtin_mips_madd( corr_QC[ i+1 ], tmp8_QS, state_QS[ 0 ]); | ||
108 | |||
109 | } | ||
110 | state_QS[ order ] = tmp7_QS; | ||
111 | |||
112 | corr_QC[ order ] = __builtin_mips_madd( corr_QC[ order ], tmp1_QS, start_1); | ||
113 | corr_QC[ order ] = __builtin_mips_madd( corr_QC[ order ], tmp3_QS, start_2); | ||
114 | corr_QC[ order ] = __builtin_mips_madd( corr_QC[ order ], tmp5_QS, start_3); | ||
115 | corr_QC[ order ] = __builtin_mips_madd( corr_QC[ order ], tmp7_QS, state_QS[ 0 ]); | ||
116 | } | ||
117 | |||
118 | for(;n< length; n++ ) { | ||
119 | |||
120 | tmp1_QS = silk_LSHIFT32( (opus_int32)input[ n ], QS ); | ||
121 | |||
122 | /* Loop over allpass sections */ | ||
123 | for( i = 0; i < order; i += 2 ) { | ||
124 | |||
125 | /* Output of allpass section */ | ||
126 | tmp2_QS = silk_SMLAWB( state_QS[ i ], state_QS[ i + 1 ] - tmp1_QS, warping_Q16 ); | ||
127 | state_QS[ i ] = tmp1_QS; | ||
128 | corr_QC[ i ] = __builtin_mips_madd( corr_QC[ i ], tmp1_QS, state_QS[ 0 ]); | ||
129 | |||
130 | /* Output of allpass section */ | ||
131 | tmp1_QS = silk_SMLAWB( state_QS[ i + 1 ], state_QS[ i + 2 ] - tmp2_QS, warping_Q16 ); | ||
132 | state_QS[ i + 1 ] = tmp2_QS; | ||
133 | corr_QC[ i+1 ] = __builtin_mips_madd( corr_QC[ i+1 ], tmp2_QS, state_QS[ 0 ]); | ||
134 | } | ||
135 | state_QS[ order ] = tmp1_QS; | ||
136 | corr_QC[ order ] = __builtin_mips_madd( corr_QC[ order ], tmp1_QS, state_QS[ 0 ]); | ||
137 | } | ||
138 | |||
139 | temp64 = corr_QC[ 0 ]; | ||
140 | temp64 = __builtin_mips_shilo(temp64, val); | ||
141 | |||
142 | lsh = silk_CLZ64( temp64 ) - 35; | ||
143 | lsh = silk_LIMIT( lsh, -12 - QC, 30 - QC ); | ||
144 | *scale = -( QC + lsh ); | ||
145 | silk_assert( *scale >= -30 && *scale <= 12 ); | ||
146 | if( lsh >= 0 ) { | ||
147 | for( i = 0; i < order + 1; i++ ) { | ||
148 | temp64 = corr_QC[ i ]; | ||
149 | //temp64 = __builtin_mips_shilo(temp64, val); | ||
150 | temp64 = (val >= 0) ? (temp64 >> val) : (temp64 << -val); | ||
151 | corr[ i ] = (opus_int32)silk_CHECK_FIT32( __builtin_mips_shilo( temp64, -lsh ) ); | ||
152 | } | ||
153 | } else { | ||
154 | for( i = 0; i < order + 1; i++ ) { | ||
155 | temp64 = corr_QC[ i ]; | ||
156 | //temp64 = __builtin_mips_shilo(temp64, val); | ||
157 | temp64 = (val >= 0) ? (temp64 >> val) : (temp64 << -val); | ||
158 | corr[ i ] = (opus_int32)silk_CHECK_FIT32( __builtin_mips_shilo( temp64, -lsh ) ); | ||
159 | } | ||
160 | } | ||
161 | |||
162 | corr_QC[ 0 ] = __builtin_mips_shilo(corr_QC[ 0 ], val); | ||
163 | |||
164 | silk_assert( corr_QC[ 0 ] >= 0 ); /* If breaking, decrease QC*/ | ||
165 | } | ||
166 | #endif /* __WARPED_AUTOCORRELATION_FIX_MIPSR1_H__ */ | ||