Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: opus/silk/decode_core.c

Issue 11196031: Add copy of opus library in deps/third_party. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « opus/silk/dec_API.c ('k') | opus/silk/decode_frame.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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.h"
33
34 /**********************************************************/
35 /* Core decoder. Performs inverse NSQ operation LTP + LPC */
36 /**********************************************************/
37 void silk_decode_core(
38 silk_decoder_state *psDec, /* I/O Decoder state */
39 silk_decoder_control *psDecCtrl, /* I Decoder control */
40 opus_int16 xq[], /* O Decoded speech */
41 const opus_int pulses[ MAX_FRAME_LENGTH ] /* I Pulse si gnal */
42 )
43 {
44 opus_int i, k, lag = 0, start_idx, sLTP_buf_idx, NLSF_interpolation_flag, signalType;
45 opus_int16 *A_Q12, *B_Q14, *pxq, A_Q12_tmp[ MAX_LPC_ORDER ];
46 opus_int16 sLTP[ MAX_FRAME_LENGTH ];
47 opus_int32 sLTP_Q15[ 2 * MAX_FRAME_LENGTH ];
48 opus_int32 LTP_pred_Q13, LPC_pred_Q10, Gain_Q10, inv_gain_Q31, gain_adj_Q16, rand_seed, offset_Q10;
49 opus_int32 *pred_lag_ptr, *pexc_Q14, *pres_Q14;
50 opus_int32 res_Q14[ MAX_SUB_FRAME_LENGTH ];
51 opus_int32 sLPC_Q14[ MAX_SUB_FRAME_LENGTH + MAX_LPC_ORDER ];
52
53 silk_assert( psDec->prev_gain_Q16 != 0 );
54
55 offset_Q10 = silk_Quantization_Offsets_Q10[ psDec->indices.signalType >> 1 ] [ psDec->indices.quantOffsetType ];
56
57 if( psDec->indices.NLSFInterpCoef_Q2 < 1 << 2 ) {
58 NLSF_interpolation_flag = 1;
59 } else {
60 NLSF_interpolation_flag = 0;
61 }
62
63 /* Decode excitation */
64 rand_seed = psDec->indices.Seed;
65 for( i = 0; i < psDec->frame_length; i++ ) {
66 rand_seed = silk_RAND( rand_seed );
67 psDec->exc_Q14[ i ] = silk_LSHIFT( (opus_int32)pulses[ i ], 14 );
68 if( psDec->exc_Q14[ i ] > 0 ) {
69 psDec->exc_Q14[ i ] -= QUANT_LEVEL_ADJUST_Q10 << 4;
70 } else
71 if( psDec->exc_Q14[ i ] < 0 ) {
72 psDec->exc_Q14[ i ] += QUANT_LEVEL_ADJUST_Q10 << 4;
73 }
74 psDec->exc_Q14[ i ] += offset_Q10 << 4;
75 if( rand_seed < 0 ) {
76 psDec->exc_Q14[ i ] = -psDec->exc_Q14[ i ];
77 }
78
79 rand_seed = silk_ADD32_ovflw( rand_seed, pulses[ i ] );
80 }
81
82 /* Copy LPC state */
83 silk_memcpy( sLPC_Q14, psDec->sLPC_Q14_buf, MAX_LPC_ORDER * sizeof( opus_int 32 ) );
84
85 pexc_Q14 = psDec->exc_Q14;
86 pxq = xq;
87 sLTP_buf_idx = psDec->ltp_mem_length;
88 /* Loop over subframes */
89 for( k = 0; k < psDec->nb_subfr; k++ ) {
90 pres_Q14 = res_Q14;
91 A_Q12 = psDecCtrl->PredCoef_Q12[ k >> 1 ];
92
93 /* Preload LPC coeficients to array on stack. Gives small performance ga in */
94 silk_memcpy( A_Q12_tmp, A_Q12, psDec->LPC_order * sizeof( opus_int16 ) ) ;
95 B_Q14 = &psDecCtrl->LTPCoef_Q14[ k * LTP_ORDER ];
96 signalType = psDec->indices.signalType;
97
98 Gain_Q10 = silk_RSHIFT( psDecCtrl->Gains_Q16[ k ], 6 );
99 inv_gain_Q31 = silk_INVERSE32_varQ( psDecCtrl->Gains_Q16[ k ], 47 );
100
101 /* Calculate gain adjustment factor */
102 if( psDecCtrl->Gains_Q16[ k ] != psDec->prev_gain_Q16 ) {
103 gain_adj_Q16 = silk_DIV32_varQ( psDec->prev_gain_Q16, psDecCtrl->Ga ins_Q16[ k ], 16 );
104
105 /* Scale short term state */
106 for( i = 0; i < MAX_LPC_ORDER; i++ ) {
107 sLPC_Q14[ i ] = silk_SMULWW( gain_adj_Q16, sLPC_Q14[ i ] );
108 }
109 } else {
110 gain_adj_Q16 = (opus_int32)1 << 16;
111 }
112
113 /* Save inv_gain */
114 silk_assert( inv_gain_Q31 != 0 );
115 psDec->prev_gain_Q16 = psDecCtrl->Gains_Q16[ k ];
116
117 /* Avoid abrupt transition from voiced PLC to unvoiced normal decoding * /
118 if( psDec->lossCnt && psDec->prevSignalType == TYPE_VOICED &&
119 psDec->indices.signalType != TYPE_VOICED && k < MAX_NB_SUBFR/2 ) {
120
121 silk_memset( B_Q14, 0, LTP_ORDER * sizeof( opus_int16 ) );
122 B_Q14[ LTP_ORDER/2 ] = SILK_FIX_CONST( 0.25, 14 );
123
124 signalType = TYPE_VOICED;
125 psDecCtrl->pitchL[ k ] = psDec->lagPrev;
126 }
127
128 if( signalType == TYPE_VOICED ) {
129 /* Voiced */
130 lag = psDecCtrl->pitchL[ k ];
131
132 /* Re-whitening */
133 if( k == 0 || ( k == 2 && NLSF_interpolation_flag ) ) {
134 /* Rewhiten with new A coefs */
135 start_idx = psDec->ltp_mem_length - lag - psDec->LPC_order - LTP _ORDER / 2;
136 silk_assert( start_idx > 0 );
137
138 if( k == 2 ) {
139 silk_memcpy( &psDec->outBuf[ psDec->ltp_mem_length ], xq, 2 * psDec->subfr_length * sizeof( opus_int16 ) );
140 }
141
142 silk_LPC_analysis_filter( &sLTP[ start_idx ], &psDec->outBuf[ st art_idx + k * psDec->subfr_length ],
143 A_Q12, psDec->ltp_mem_length - start_idx, psDec->LPC_order ) ;
144
145 /* After rewhitening the LTP state is unscaled */
146 if( k == 0 ) {
147 /* Do LTP downscaling to reduce inter-packet dependency */
148 inv_gain_Q31 = silk_LSHIFT( silk_SMULWB( inv_gain_Q31, psDec Ctrl->LTP_scale_Q14 ), 2 );
149 }
150 for( i = 0; i < lag + LTP_ORDER/2; i++ ) {
151 sLTP_Q15[ sLTP_buf_idx - i - 1 ] = silk_SMULWB( inv_gain_Q31 , sLTP[ psDec->ltp_mem_length - i - 1 ] );
152 }
153 } else {
154 /* Update LTP state when Gain changes */
155 if( gain_adj_Q16 != (opus_int32)1 << 16 ) {
156 for( i = 0; i < lag + LTP_ORDER/2; i++ ) {
157 sLTP_Q15[ sLTP_buf_idx - i - 1 ] = silk_SMULWW( gain_adj _Q16, sLTP_Q15[ sLTP_buf_idx - i - 1 ] );
158 }
159 }
160 }
161 }
162
163 /* Long-term prediction */
164 if( signalType == TYPE_VOICED ) {
165 /* Set up pointer */
166 pred_lag_ptr = &sLTP_Q15[ sLTP_buf_idx - lag + LTP_ORDER / 2 ];
167 for( i = 0; i < psDec->subfr_length; i++ ) {
168 /* Unrolled loop */
169 /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */
170 LTP_pred_Q13 = 2;
171 LTP_pred_Q13 = silk_SMLAWB( LTP_pred_Q13, pred_lag_ptr[ 0 ], B_ Q14[ 0 ] );
172 LTP_pred_Q13 = silk_SMLAWB( LTP_pred_Q13, pred_lag_ptr[ -1 ], B_ Q14[ 1 ] );
173 LTP_pred_Q13 = silk_SMLAWB( LTP_pred_Q13, pred_lag_ptr[ -2 ], B_ Q14[ 2 ] );
174 LTP_pred_Q13 = silk_SMLAWB( LTP_pred_Q13, pred_lag_ptr[ -3 ], B_ Q14[ 3 ] );
175 LTP_pred_Q13 = silk_SMLAWB( LTP_pred_Q13, pred_lag_ptr[ -4 ], B_ Q14[ 4 ] );
176 pred_lag_ptr++;
177
178 /* Generate LPC excitation */
179 pres_Q14[ i ] = silk_ADD_LSHIFT32( pexc_Q14[ i ], LTP_pred_Q13, 1 );
180
181 /* Update states */
182 sLTP_Q15[ sLTP_buf_idx ] = silk_LSHIFT( pres_Q14[ i ], 1 );
183 sLTP_buf_idx++;
184 }
185 } else {
186 pres_Q14 = pexc_Q14;
187 }
188
189 for( i = 0; i < psDec->subfr_length; i++ ) {
190 /* Short-term prediction */
191 silk_assert( psDec->LPC_order == 10 || psDec->LPC_order == 16 );
192 /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */
193 LPC_pred_Q10 = silk_RSHIFT( psDec->LPC_order, 1 );
194 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 1 ], A_Q12_tmp[ 0 ] );
195 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 2 ], A_Q12_tmp[ 1 ] );
196 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 3 ], A_Q12_tmp[ 2 ] );
197 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 4 ], A_Q12_tmp[ 3 ] );
198 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 5 ], A_Q12_tmp[ 4 ] );
199 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 6 ], A_Q12_tmp[ 5 ] );
200 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 7 ], A_Q12_tmp[ 6 ] );
201 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 8 ], A_Q12_tmp[ 7 ] );
202 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 9 ], A_Q12_tmp[ 8 ] );
203 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDER + i - 10 ], A_Q12_tmp[ 9 ] );
204 if( psDec->LPC_order == 16 ) {
205 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDE R + i - 11 ], A_Q12_tmp[ 10 ] );
206 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDE R + i - 12 ], A_Q12_tmp[ 11 ] );
207 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDE R + i - 13 ], A_Q12_tmp[ 12 ] );
208 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDE R + i - 14 ], A_Q12_tmp[ 13 ] );
209 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDE R + i - 15 ], A_Q12_tmp[ 14 ] );
210 LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, sLPC_Q14[ MAX_LPC_ORDE R + i - 16 ], A_Q12_tmp[ 15 ] );
211 }
212
213 /* Add prediction to LPC excitation */
214 sLPC_Q14[ MAX_LPC_ORDER + i ] = silk_ADD_LSHIFT32( pres_Q14[ i ], LP C_pred_Q10, 4 );
215
216 /* Scale with gain */
217 pxq[ i ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( silk_SMULWW( s LPC_Q14[ MAX_LPC_ORDER + i ], Gain_Q10 ), 8 ) );
218 }
219
220 /* DEBUG_STORE_DATA( dec.pcm, pxq, psDec->subfr_length * sizeof( opus_in t16 ) ) */
221
222 /* Update LPC filter state */
223 silk_memcpy( sLPC_Q14, &sLPC_Q14[ psDec->subfr_length ], MAX_LPC_ORDER * sizeof( opus_int32 ) );
224 pexc_Q14 += psDec->subfr_length;
225 pxq += psDec->subfr_length;
226 }
227
228 /* Save LPC state */
229 silk_memcpy( psDec->sLPC_Q14_buf, sLPC_Q14, MAX_LPC_ORDER * sizeof( opus_int 32 ) );
230 }
OLDNEW
« no previous file with comments | « opus/silk/dec_API.c ('k') | opus/silk/decode_frame.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698