summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libopus/silk
diff options
context:
space:
mode:
authorNils Wallménius <nils@rockbox.org>2014-01-19 16:31:59 +0100
committerNils Wallménius <nils@rockbox.org>2014-07-13 11:12:40 +0200
commit9b7ec42403073ee887efc531c153e6b1b6c15bab (patch)
tree07e72fe9d817c65a6fede22955344a870842d5e6 /lib/rbcodec/codecs/libopus/silk
parente557951c94c1efa769900257e466900f0ffeb53b (diff)
downloadrockbox-9b7ec42403073ee887efc531c153e6b1b6c15bab.tar.gz
rockbox-9b7ec42403073ee887efc531c153e6b1b6c15bab.zip
Sync to upstream libopus
Sync to commit bb4b6885a139644cf3ac14e7deda9f633ec2d93c This brings in a bunch of optimizations to decode speed and memory usage. Allocations are switched from using the pseudostack to using the real stack. Enabled hacks to reduce stack usage. This should fix crashes on sansa clip, although some files will not play due to failing allocations in the codec buffer. Speeds up decoding of the following test files: H300 (cf) C200 (arm7tdmi) ipod classic (arm9e) 16 kbps (silk) 14.28 MHz 4.00 MHz 2.61 MHz 64 kbps (celt) 4.09 MHz 8.08 MHz 6.24 MHz 128 kbps (celt) 1.93 MHz 8.83 MHz 6.53 MHz Change-Id: I851733a8a5824b61feb363a173091bc7e6629b58
Diffstat (limited to 'lib/rbcodec/codecs/libopus/silk')
-rw-r--r--lib/rbcodec/codecs/libopus/silk/CNG.c21
-rw-r--r--lib/rbcodec/codecs/libopus/silk/PLC.c53
-rw-r--r--lib/rbcodec/codecs/libopus/silk/SigProc_FIX.h5
-rw-r--r--lib/rbcodec/codecs/libopus/silk/code_signs.c4
-rw-r--r--lib/rbcodec/codecs/libopus/silk/dec_API.c37
-rw-r--r--lib/rbcodec/codecs/libopus/silk/decode_core.c7
-rw-r--r--lib/rbcodec/codecs/libopus/silk/decode_frame.c16
-rw-r--r--lib/rbcodec/codecs/libopus/silk/decode_pulses.c6
-rw-r--r--lib/rbcodec/codecs/libopus/silk/macros.h9
-rw-r--r--lib/rbcodec/codecs/libopus/silk/main.h8
-rw-r--r--lib/rbcodec/codecs/libopus/silk/resampler_private_IIR_FIR.c11
-rw-r--r--lib/rbcodec/codecs/libopus/silk/shell_coder.c8
-rw-r--r--lib/rbcodec/codecs/libopus/silk/sum_sqr_shift.c1
13 files changed, 122 insertions, 64 deletions
diff --git a/lib/rbcodec/codecs/libopus/silk/CNG.c b/lib/rbcodec/codecs/libopus/silk/CNG.c
index 8481d95dbe..bb30a7ccf2 100644
--- a/lib/rbcodec/codecs/libopus/silk/CNG.c
+++ b/lib/rbcodec/codecs/libopus/silk/CNG.c
@@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
34 34
35/* Generates excitation for CNG LPC synthesis */ 35/* Generates excitation for CNG LPC synthesis */
36static OPUS_INLINE void silk_CNG_exc( 36static OPUS_INLINE void silk_CNG_exc(
37 opus_int32 residual_Q10[], /* O CNG residual signal Q10 */ 37 opus_int32 exc_Q10[], /* O CNG excitation signal Q10 */
38 opus_int32 exc_buf_Q14[], /* I Random samples buffer Q10 */ 38 opus_int32 exc_buf_Q14[], /* I Random samples buffer Q10 */
39 opus_int32 Gain_Q16, /* I Gain to apply */ 39 opus_int32 Gain_Q16, /* I Gain to apply */
40 opus_int length, /* I Length */ 40 opus_int length, /* I Length */
@@ -55,7 +55,7 @@ static OPUS_INLINE void silk_CNG_exc(
55 idx = (opus_int)( silk_RSHIFT( seed, 24 ) & exc_mask ); 55 idx = (opus_int)( silk_RSHIFT( seed, 24 ) & exc_mask );
56 silk_assert( idx >= 0 ); 56 silk_assert( idx >= 0 );
57 silk_assert( idx <= CNG_BUF_MASK_MAX ); 57 silk_assert( idx <= CNG_BUF_MASK_MAX );
58 residual_Q10[ i ] = (opus_int16)silk_SAT16( silk_SMULWW( exc_buf_Q14[ idx ], Gain_Q16 >> 4 ) ); 58 exc_Q10[ i ] = (opus_int16)silk_SAT16( silk_SMULWW( exc_buf_Q14[ idx ], Gain_Q16 >> 4 ) );
59 } 59 }
60 *rand_seed = seed; 60 *rand_seed = seed;
61} 61}
@@ -85,7 +85,7 @@ void silk_CNG(
85) 85)
86{ 86{
87 opus_int i, subfr; 87 opus_int i, subfr;
88 opus_int32 sum_Q6, max_Gain_Q16; 88 opus_int32 sum_Q6, max_Gain_Q16, gain_Q16;
89 opus_int16 A_Q12[ MAX_LPC_ORDER ]; 89 opus_int16 A_Q12[ MAX_LPC_ORDER ];
90 silk_CNG_struct *psCNG = &psDec->sCNG; 90 silk_CNG_struct *psCNG = &psDec->sCNG;
91 SAVE_STACK; 91 SAVE_STACK;
@@ -125,11 +125,20 @@ void silk_CNG(
125 /* Add CNG when packet is lost or during DTX */ 125 /* Add CNG when packet is lost or during DTX */
126 if( psDec->lossCnt ) { 126 if( psDec->lossCnt ) {
127 VARDECL( opus_int32, CNG_sig_Q10 ); 127 VARDECL( opus_int32, CNG_sig_Q10 );
128
129 ALLOC( CNG_sig_Q10, length + MAX_LPC_ORDER, opus_int32 ); 128 ALLOC( CNG_sig_Q10, length + MAX_LPC_ORDER, opus_int32 );
130 129
131 /* Generate CNG excitation */ 130 /* Generate CNG excitation */
132 silk_CNG_exc( CNG_sig_Q10 + MAX_LPC_ORDER, psCNG->CNG_exc_buf_Q14, psCNG->CNG_smth_Gain_Q16, length, &psCNG->rand_seed ); 131 gain_Q16 = silk_SMULWW( psDec->sPLC.randScale_Q14, psDec->sPLC.prevGain_Q16[1] );
132 if( gain_Q16 >= (1 << 21) || psCNG->CNG_smth_Gain_Q16 > (1 << 23) ) {
133 gain_Q16 = silk_SMULTT( gain_Q16, gain_Q16 );
134 gain_Q16 = silk_SUB_LSHIFT32(silk_SMULTT( psCNG->CNG_smth_Gain_Q16, psCNG->CNG_smth_Gain_Q16 ), gain_Q16, 5 );
135 gain_Q16 = silk_LSHIFT32( silk_SQRT_APPROX( gain_Q16 ), 16 );
136 } else {
137 gain_Q16 = silk_SMULWW( gain_Q16, gain_Q16 );
138 gain_Q16 = silk_SUB_LSHIFT32(silk_SMULWW( psCNG->CNG_smth_Gain_Q16, psCNG->CNG_smth_Gain_Q16 ), gain_Q16, 5 );
139 gain_Q16 = silk_LSHIFT32( silk_SQRT_APPROX( gain_Q16 ), 8 );
140 }
141 silk_CNG_exc( CNG_sig_Q10 + MAX_LPC_ORDER, psCNG->CNG_exc_buf_Q14, gain_Q16, length, &psCNG->rand_seed );
133 142
134 /* Convert CNG NLSF to filter representation */ 143 /* Convert CNG NLSF to filter representation */
135 silk_NLSF2A( A_Q12, psCNG->CNG_smth_NLSF_Q15, psDec->LPC_order ); 144 silk_NLSF2A( A_Q12, psCNG->CNG_smth_NLSF_Q15, psDec->LPC_order );
@@ -162,7 +171,7 @@ void silk_CNG(
162 /* Update states */ 171 /* Update states */
163 CNG_sig_Q10[ MAX_LPC_ORDER + i ] = silk_ADD_LSHIFT( CNG_sig_Q10[ MAX_LPC_ORDER + i ], sum_Q6, 4 ); 172 CNG_sig_Q10[ MAX_LPC_ORDER + i ] = silk_ADD_LSHIFT( CNG_sig_Q10[ MAX_LPC_ORDER + i ], sum_Q6, 4 );
164 173
165 frame[ i ] = silk_ADD_SAT16( frame[ i ], silk_RSHIFT_ROUND( sum_Q6, 6 ) ); 174 frame[ i ] = silk_ADD_SAT16( frame[ i ], silk_RSHIFT_ROUND( CNG_sig_Q10[ MAX_LPC_ORDER + i ], 10 ) );
166 } 175 }
167 silk_memcpy( psCNG->CNG_synth_state, &CNG_sig_Q10[ length ], MAX_LPC_ORDER * sizeof( opus_int32 ) ); 176 silk_memcpy( psCNG->CNG_synth_state, &CNG_sig_Q10[ length ], MAX_LPC_ORDER * sizeof( opus_int32 ) );
168 } else { 177 } else {
diff --git a/lib/rbcodec/codecs/libopus/silk/PLC.c b/lib/rbcodec/codecs/libopus/silk/PLC.c
index 01f40014c4..8b0a8fe57d 100644
--- a/lib/rbcodec/codecs/libopus/silk/PLC.c
+++ b/lib/rbcodec/codecs/libopus/silk/PLC.c
@@ -165,6 +165,30 @@ static OPUS_INLINE void silk_PLC_update(
165 psPLC->nb_subfr = psDec->nb_subfr; 165 psPLC->nb_subfr = psDec->nb_subfr;
166} 166}
167 167
168static OPUS_INLINE void silk_PLC_energy(opus_int32 *energy1, opus_int *shift1, opus_int32 *energy2, opus_int *shift2,
169 const opus_int32 *exc_Q14, const opus_int32 *prevGain_Q10, int subfr_length, int nb_subfr)
170{
171 int i, k;
172 VARDECL( opus_int16, exc_buf );
173 opus_int16 *exc_buf_ptr;
174 SAVE_STACK;
175 ALLOC( exc_buf, 2*subfr_length, opus_int16 );
176 /* Find random noise component */
177 /* Scale previous excitation signal */
178 exc_buf_ptr = exc_buf;
179 for( k = 0; k < 2; k++ ) {
180 for( i = 0; i < subfr_length; i++ ) {
181 exc_buf_ptr[ i ] = (opus_int16)silk_SAT16( silk_RSHIFT(
182 silk_SMULWW( exc_Q14[ i + ( k + nb_subfr - 2 ) * subfr_length ], prevGain_Q10[ k ] ), 8 ) );
183 }
184 exc_buf_ptr += subfr_length;
185 }
186 /* Find the subframe with lowest energy of the last two and use that as random noise generator */
187 silk_sum_sqr_shift( energy1, shift1, exc_buf, subfr_length );
188 silk_sum_sqr_shift( energy2, shift2, &exc_buf[ subfr_length ], subfr_length );
189 RESTORE_STACK;
190}
191
168static OPUS_INLINE void silk_PLC_conceal( 192static OPUS_INLINE void silk_PLC_conceal(
169 silk_decoder_state *psDec, /* I/O Decoder state */ 193 silk_decoder_state *psDec, /* I/O Decoder state */
170 silk_decoder_control *psDecCtrl, /* I/O Decoder control */ 194 silk_decoder_control *psDecCtrl, /* I/O Decoder control */
@@ -177,19 +201,26 @@ static OPUS_INLINE void silk_PLC_conceal(
177 opus_int32 energy1, energy2, *rand_ptr, *pred_lag_ptr; 201 opus_int32 energy1, energy2, *rand_ptr, *pred_lag_ptr;
178 opus_int32 LPC_pred_Q10, LTP_pred_Q12; 202 opus_int32 LPC_pred_Q10, LTP_pred_Q12;
179 opus_int16 rand_scale_Q14; 203 opus_int16 rand_scale_Q14;
180 opus_int16 *B_Q14, *exc_buf_ptr; 204 opus_int16 *B_Q14;
181 opus_int32 *sLPC_Q14_ptr; 205 opus_int32 *sLPC_Q14_ptr;
182 VARDECL( opus_int16, exc_buf );
183 opus_int16 A_Q12[ MAX_LPC_ORDER ]; 206 opus_int16 A_Q12[ MAX_LPC_ORDER ];
207#ifdef SMALL_FOOTPRINT
208 opus_int16 *sLTP;
209#else
184 VARDECL( opus_int16, sLTP ); 210 VARDECL( opus_int16, sLTP );
211#endif
185 VARDECL( opus_int32, sLTP_Q14 ); 212 VARDECL( opus_int32, sLTP_Q14 );
186 silk_PLC_struct *psPLC = &psDec->sPLC; 213 silk_PLC_struct *psPLC = &psDec->sPLC;
187 opus_int32 prevGain_Q10[2]; 214 opus_int32 prevGain_Q10[2];
188 SAVE_STACK; 215 SAVE_STACK;
189 216
190 ALLOC( exc_buf, 2*psPLC->subfr_length, opus_int16 );
191 ALLOC( sLTP, psDec->ltp_mem_length, opus_int16 );
192 ALLOC( sLTP_Q14, psDec->ltp_mem_length + psDec->frame_length, opus_int32 ); 217 ALLOC( sLTP_Q14, psDec->ltp_mem_length + psDec->frame_length, opus_int32 );
218#ifdef SMALL_FOOTPRINT
219 /* Ugly hack that breaks aliasing rules to save stack: put sLTP at the very end of sLTP_Q14. */
220 sLTP = ((opus_int16*)&sLTP_Q14[psDec->ltp_mem_length + psDec->frame_length])-psDec->ltp_mem_length;
221#else
222 ALLOC( sLTP, psDec->ltp_mem_length, opus_int16 );
223#endif
193 224
194 prevGain_Q10[0] = silk_RSHIFT( psPLC->prevGain_Q16[ 0 ], 6); 225 prevGain_Q10[0] = silk_RSHIFT( psPLC->prevGain_Q16[ 0 ], 6);
195 prevGain_Q10[1] = silk_RSHIFT( psPLC->prevGain_Q16[ 1 ], 6); 226 prevGain_Q10[1] = silk_RSHIFT( psPLC->prevGain_Q16[ 1 ], 6);
@@ -198,19 +229,7 @@ static OPUS_INLINE void silk_PLC_conceal(
198 silk_memset( psPLC->prevLPC_Q12, 0, sizeof( psPLC->prevLPC_Q12 ) ); 229 silk_memset( psPLC->prevLPC_Q12, 0, sizeof( psPLC->prevLPC_Q12 ) );
199 } 230 }
200 231
201 /* Find random noise component */ 232 silk_PLC_energy(&energy1, &shift1, &energy2, &shift2, psDec->exc_Q14, prevGain_Q10, psDec->subfr_length, psDec->nb_subfr);
202 /* Scale previous excitation signal */
203 exc_buf_ptr = exc_buf;
204 for( k = 0; k < 2; k++ ) {
205 for( i = 0; i < psPLC->subfr_length; i++ ) {
206 exc_buf_ptr[ i ] = (opus_int16)silk_SAT16( silk_RSHIFT(
207 silk_SMULWW( psDec->exc_Q14[ i + ( k + psPLC->nb_subfr - 2 ) * psPLC->subfr_length ], prevGain_Q10[ k ] ), 8 ) );
208 }
209 exc_buf_ptr += psPLC->subfr_length;
210 }
211 /* Find the subframe with lowest energy of the last two and use that as random noise generator */
212 silk_sum_sqr_shift( &energy1, &shift1, exc_buf, psPLC->subfr_length );
213 silk_sum_sqr_shift( &energy2, &shift2, &exc_buf[ psPLC->subfr_length ], psPLC->subfr_length );
214 233
215 if( silk_RSHIFT( energy1, shift2 ) < silk_RSHIFT( energy2, shift1 ) ) { 234 if( silk_RSHIFT( energy1, shift2 ) < silk_RSHIFT( energy2, shift1 ) ) {
216 /* First sub-frame has lowest energy */ 235 /* First sub-frame has lowest energy */
diff --git a/lib/rbcodec/codecs/libopus/silk/SigProc_FIX.h b/lib/rbcodec/codecs/libopus/silk/SigProc_FIX.h
index 1b58057910..4be0985435 100644
--- a/lib/rbcodec/codecs/libopus/silk/SigProc_FIX.h
+++ b/lib/rbcodec/codecs/libopus/silk/SigProc_FIX.h
@@ -587,6 +587,11 @@ static OPUS_INLINE opus_int64 silk_max_64(opus_int64 a, opus_int64 b)
587#include "arm/SigProc_FIX_armv5e.h" 587#include "arm/SigProc_FIX_armv5e.h"
588#endif 588#endif
589 589
590#if defined(MIPSr1_ASM)
591#include "mips/sigproc_fix_mipsr1.h"
592#endif
593
594
590#ifdef __cplusplus 595#ifdef __cplusplus
591} 596}
592#endif 597#endif
diff --git a/lib/rbcodec/codecs/libopus/silk/code_signs.c b/lib/rbcodec/codecs/libopus/silk/code_signs.c
index 561043c739..6ac25cb389 100644
--- a/lib/rbcodec/codecs/libopus/silk/code_signs.c
+++ b/lib/rbcodec/codecs/libopus/silk/code_signs.c
@@ -76,7 +76,7 @@ void silk_encode_signs(
76/* Decodes signs of excitation */ 76/* Decodes signs of excitation */
77void silk_decode_signs( 77void silk_decode_signs(
78 ec_dec *psRangeDec, /* I/O Compressor data structure */ 78 ec_dec *psRangeDec, /* I/O Compressor data structure */
79 opus_int pulses[], /* I/O pulse signal */ 79 opus_int16 pulses[], /* I/O pulse signal */
80 opus_int length, /* I length of input */ 80 opus_int length, /* I length of input */
81 const opus_int signalType, /* I Signal type */ 81 const opus_int signalType, /* I Signal type */
82 const opus_int quantOffsetType, /* I Quantization offset type */ 82 const opus_int quantOffsetType, /* I Quantization offset type */
@@ -85,7 +85,7 @@ void silk_decode_signs(
85{ 85{
86 opus_int i, j, p; 86 opus_int i, j, p;
87 opus_uint8 icdf[ 2 ]; 87 opus_uint8 icdf[ 2 ];
88 opus_int *q_ptr; 88 opus_int16 *q_ptr;
89 const opus_uint8 *icdf_ptr; 89 const opus_uint8 *icdf_ptr;
90 90
91 icdf[ 1 ] = 0; 91 icdf[ 1 ] = 0;
diff --git a/lib/rbcodec/codecs/libopus/silk/dec_API.c b/lib/rbcodec/codecs/libopus/silk/dec_API.c
index 4cbcf71514..1087c6726a 100644
--- a/lib/rbcodec/codecs/libopus/silk/dec_API.c
+++ b/lib/rbcodec/codecs/libopus/silk/dec_API.c
@@ -31,6 +31,7 @@ POSSIBILITY OF SUCH DAMAGE.
31#include "API.h" 31#include "API.h"
32#include "main.h" 32#include "main.h"
33#include "stack_alloc.h" 33#include "stack_alloc.h"
34#include "os_support.h"
34 35
35/************************/ 36/************************/
36/* Decoder Super Struct */ 37/* Decoder Super Struct */
@@ -90,7 +91,8 @@ opus_int silk_Decode( /* O Returns error co
90 opus_int i, n, decode_only_middle = 0, ret = SILK_NO_ERROR; 91 opus_int i, n, decode_only_middle = 0, ret = SILK_NO_ERROR;
91 opus_int32 nSamplesOutDec, LBRR_symbol; 92 opus_int32 nSamplesOutDec, LBRR_symbol;
92 opus_int16 *samplesOut1_tmp[ 2 ]; 93 opus_int16 *samplesOut1_tmp[ 2 ];
93 VARDECL( opus_int16, samplesOut1_tmp_storage ); 94 VARDECL( opus_int16, samplesOut1_tmp_storage1 );
95 VARDECL( opus_int16, samplesOut1_tmp_storage2 );
94 VARDECL( opus_int16, samplesOut2_tmp ); 96 VARDECL( opus_int16, samplesOut2_tmp );
95 opus_int32 MS_pred_Q13[ 2 ] = { 0 }; 97 opus_int32 MS_pred_Q13[ 2 ] = { 0 };
96 opus_int16 *resample_out_ptr; 98 opus_int16 *resample_out_ptr;
@@ -98,6 +100,7 @@ opus_int silk_Decode( /* O Returns error co
98 silk_decoder_state *channel_state = psDec->channel_state; 100 silk_decoder_state *channel_state = psDec->channel_state;
99 opus_int has_side; 101 opus_int has_side;
100 opus_int stereo_to_mono; 102 opus_int stereo_to_mono;
103 int delay_stack_alloc;
101 SAVE_STACK; 104 SAVE_STACK;
102 105
103 silk_assert( decControl->nChannelsInternal == 1 || decControl->nChannelsInternal == 2 ); 106 silk_assert( decControl->nChannelsInternal == 1 || decControl->nChannelsInternal == 2 );
@@ -196,7 +199,7 @@ opus_int silk_Decode( /* O Returns error co
196 for( i = 0; i < channel_state[ 0 ].nFramesPerPacket; i++ ) { 199 for( i = 0; i < channel_state[ 0 ].nFramesPerPacket; i++ ) {
197 for( n = 0; n < decControl->nChannelsInternal; n++ ) { 200 for( n = 0; n < decControl->nChannelsInternal; n++ ) {
198 if( channel_state[ n ].LBRR_flags[ i ] ) { 201 if( channel_state[ n ].LBRR_flags[ i ] ) {
199 opus_int pulses[ MAX_FRAME_LENGTH ]; 202 opus_int16 pulses[ MAX_FRAME_LENGTH ];
200 opus_int condCoding; 203 opus_int condCoding;
201 204
202 if( decControl->nChannelsInternal == 2 && n == 0 ) { 205 if( decControl->nChannelsInternal == 2 && n == 0 ) {
@@ -251,13 +254,22 @@ opus_int silk_Decode( /* O Returns error co
251 psDec->channel_state[ 1 ].first_frame_after_reset = 1; 254 psDec->channel_state[ 1 ].first_frame_after_reset = 1;
252 } 255 }
253 256
254 ALLOC( samplesOut1_tmp_storage, 257 /* Check if the temp buffer fits into the output PCM buffer. If it fits,
255 decControl->nChannelsInternal*( 258 we can delay allocating the temp buffer until after the SILK peak stack
256 channel_state[ 0 ].frame_length + 2 ), 259 usage. We need to use a < and not a <= because of the two extra samples. */
260 delay_stack_alloc = decControl->internalSampleRate*decControl->nChannelsInternal
261 < decControl->API_sampleRate*decControl->nChannelsAPI;
262 ALLOC( samplesOut1_tmp_storage1, delay_stack_alloc ? ALLOC_NONE
263 : decControl->nChannelsInternal*(channel_state[ 0 ].frame_length + 2 ),
257 opus_int16 ); 264 opus_int16 );
258 samplesOut1_tmp[ 0 ] = samplesOut1_tmp_storage; 265 if ( delay_stack_alloc )
259 samplesOut1_tmp[ 1 ] = samplesOut1_tmp_storage 266 {
260 + channel_state[ 0 ].frame_length + 2; 267 samplesOut1_tmp[ 0 ] = samplesOut;
268 samplesOut1_tmp[ 1 ] = samplesOut + channel_state[ 0 ].frame_length + 2;
269 } else {
270 samplesOut1_tmp[ 0 ] = samplesOut1_tmp_storage1;
271 samplesOut1_tmp[ 1 ] = samplesOut1_tmp_storage1 + channel_state[ 0 ].frame_length + 2;
272 }
261 273
262 if( lostFlag == FLAG_DECODE_NORMAL ) { 274 if( lostFlag == FLAG_DECODE_NORMAL ) {
263 has_side = !decode_only_middle; 275 has_side = !decode_only_middle;
@@ -312,6 +324,15 @@ opus_int silk_Decode( /* O Returns error co
312 resample_out_ptr = samplesOut; 324 resample_out_ptr = samplesOut;
313 } 325 }
314 326
327 ALLOC( samplesOut1_tmp_storage2, delay_stack_alloc
328 ? decControl->nChannelsInternal*(channel_state[ 0 ].frame_length + 2 )
329 : ALLOC_NONE,
330 opus_int16 );
331 if ( delay_stack_alloc ) {
332 OPUS_COPY(samplesOut1_tmp_storage2, samplesOut, decControl->nChannelsInternal*(channel_state[ 0 ].frame_length + 2));
333 samplesOut1_tmp[ 0 ] = samplesOut1_tmp_storage2;
334 samplesOut1_tmp[ 1 ] = samplesOut1_tmp_storage2 + channel_state[ 0 ].frame_length + 2;
335 }
315 for( n = 0; n < silk_min( decControl->nChannelsAPI, decControl->nChannelsInternal ); n++ ) { 336 for( n = 0; n < silk_min( decControl->nChannelsAPI, decControl->nChannelsInternal ); n++ ) {
316 337
317 /* Resample decoded signal to API_sampleRate */ 338 /* Resample decoded signal to API_sampleRate */
diff --git a/lib/rbcodec/codecs/libopus/silk/decode_core.c b/lib/rbcodec/codecs/libopus/silk/decode_core.c
index 87fbd5de9f..af68b75da9 100644
--- a/lib/rbcodec/codecs/libopus/silk/decode_core.c
+++ b/lib/rbcodec/codecs/libopus/silk/decode_core.c
@@ -39,7 +39,7 @@ void silk_decode_core(
39 silk_decoder_state *psDec, /* I/O Decoder state */ 39 silk_decoder_state *psDec, /* I/O Decoder state */
40 silk_decoder_control *psDecCtrl, /* I Decoder control */ 40 silk_decoder_control *psDecCtrl, /* I Decoder control */
41 opus_int16 xq[], /* O Decoded speech */ 41 opus_int16 xq[], /* O Decoded speech */
42 const opus_int pulses[ MAX_FRAME_LENGTH ] /* I Pulse signal */ 42 const opus_int16 pulses[ MAX_FRAME_LENGTH ] /* I Pulse signal */
43) 43)
44{ 44{
45 opus_int i, k, lag = 0, start_idx, sLTP_buf_idx, NLSF_interpolation_flag, signalType; 45 opus_int i, k, lag = 0, start_idx, sLTP_buf_idx, NLSF_interpolation_flag, signalType;
@@ -49,7 +49,7 @@ void silk_decode_core(
49 opus_int32 LTP_pred_Q13, LPC_pred_Q10, Gain_Q10, inv_gain_Q31, gain_adj_Q16, rand_seed, offset_Q10; 49 opus_int32 LTP_pred_Q13, LPC_pred_Q10, Gain_Q10, inv_gain_Q31, gain_adj_Q16, rand_seed, offset_Q10;
50 opus_int32 *pred_lag_ptr, *pexc_Q14, *pres_Q14; 50 opus_int32 *pred_lag_ptr, *pexc_Q14, *pres_Q14;
51 VARDECL( opus_int32, res_Q14 ); 51 VARDECL( opus_int32, res_Q14 );
52/* VARDECL( opus_int32, sLPC_Q14 ); */ 52 VARDECL( opus_int32, sLPC_Q14 );
53 SAVE_STACK; 53 SAVE_STACK;
54 54
55 silk_assert( psDec->prev_gain_Q16 != 0 ); 55 silk_assert( psDec->prev_gain_Q16 != 0 );
@@ -57,8 +57,7 @@ void silk_decode_core(
57 ALLOC( sLTP, psDec->ltp_mem_length, opus_int16 ); 57 ALLOC( sLTP, psDec->ltp_mem_length, opus_int16 );
58 ALLOC( sLTP_Q15, psDec->ltp_mem_length + psDec->frame_length, opus_int32 ); 58 ALLOC( sLTP_Q15, psDec->ltp_mem_length + psDec->frame_length, opus_int32 );
59 ALLOC( res_Q14, psDec->subfr_length, opus_int32 ); 59 ALLOC( res_Q14, psDec->subfr_length, opus_int32 );
60/* ALLOC( sLPC_Q14, psDec->subfr_length + MAX_LPC_ORDER, opus_int32 ); */ 60 ALLOC( sLPC_Q14, psDec->subfr_length + MAX_LPC_ORDER, opus_int32 );
61 opus_int32 sLPC_Q14[psDec->subfr_length + MAX_LPC_ORDER]; /* worst case is 80 + 16 */
62 61
63 offset_Q10 = silk_Quantization_Offsets_Q10[ psDec->indices.signalType >> 1 ][ psDec->indices.quantOffsetType ]; 62 offset_Q10 = silk_Quantization_Offsets_Q10[ psDec->indices.signalType >> 1 ][ psDec->indices.quantOffsetType ];
64 63
diff --git a/lib/rbcodec/codecs/libopus/silk/decode_frame.c b/lib/rbcodec/codecs/libopus/silk/decode_frame.c
index abc00a3d54..6a7cffbbe0 100644
--- a/lib/rbcodec/codecs/libopus/silk/decode_frame.c
+++ b/lib/rbcodec/codecs/libopus/silk/decode_frame.c
@@ -47,13 +47,10 @@ opus_int silk_decode_frame(
47{ 47{
48 VARDECL( silk_decoder_control, psDecCtrl ); 48 VARDECL( silk_decoder_control, psDecCtrl );
49 opus_int L, mv_len, ret = 0; 49 opus_int L, mv_len, ret = 0;
50 VARDECL( opus_int, pulses );
51 SAVE_STACK; 50 SAVE_STACK;
52 51
53 L = psDec->frame_length; 52 L = psDec->frame_length;
54 ALLOC( psDecCtrl, 1, silk_decoder_control ); 53 ALLOC( psDecCtrl, 1, silk_decoder_control );
55 ALLOC( pulses, (L + SHELL_CODEC_FRAME_LENGTH - 1) &
56 ~(SHELL_CODEC_FRAME_LENGTH - 1), opus_int );
57 psDecCtrl->LTP_scale_Q14 = 0; 54 psDecCtrl->LTP_scale_Q14 = 0;
58 55
59 /* Safety checks */ 56 /* Safety checks */
@@ -62,6 +59,9 @@ opus_int silk_decode_frame(
62 if( lostFlag == FLAG_DECODE_NORMAL || 59 if( lostFlag == FLAG_DECODE_NORMAL ||
63 ( lostFlag == FLAG_DECODE_LBRR && psDec->LBRR_flags[ psDec->nFramesDecoded ] == 1 ) ) 60 ( lostFlag == FLAG_DECODE_LBRR && psDec->LBRR_flags[ psDec->nFramesDecoded ] == 1 ) )
64 { 61 {
62 VARDECL( opus_int16, pulses );
63 ALLOC( pulses, (L + SHELL_CODEC_FRAME_LENGTH - 1) &
64 ~(SHELL_CODEC_FRAME_LENGTH - 1), opus_int16 );
65 /*********************************************/ 65 /*********************************************/
66 /* Decode quantization indices of side info */ 66 /* Decode quantization indices of side info */
67 /*********************************************/ 67 /*********************************************/
@@ -107,16 +107,16 @@ opus_int silk_decode_frame(
107 silk_memmove( psDec->outBuf, &psDec->outBuf[ psDec->frame_length ], mv_len * sizeof(opus_int16) ); 107 silk_memmove( psDec->outBuf, &psDec->outBuf[ psDec->frame_length ], mv_len * sizeof(opus_int16) );
108 silk_memcpy( &psDec->outBuf[ mv_len ], pOut, psDec->frame_length * sizeof( opus_int16 ) ); 108 silk_memcpy( &psDec->outBuf[ mv_len ], pOut, psDec->frame_length * sizeof( opus_int16 ) );
109 109
110 /****************************************************************/
111 /* Ensure smooth connection of extrapolated and good frames */
112 /****************************************************************/
113 silk_PLC_glue_frames( psDec, pOut, L );
114
115 /************************************************/ 110 /************************************************/
116 /* Comfort noise generation / estimation */ 111 /* Comfort noise generation / estimation */
117 /************************************************/ 112 /************************************************/
118 silk_CNG( psDec, psDecCtrl, pOut, L ); 113 silk_CNG( psDec, psDecCtrl, pOut, L );
119 114
115 /****************************************************************/
116 /* Ensure smooth connection of extrapolated and good frames */
117 /****************************************************************/
118 silk_PLC_glue_frames( psDec, pOut, L );
119
120 /* Update some decoder state variables */ 120 /* Update some decoder state variables */
121 psDec->lagPrev = psDecCtrl->pitchL[ psDec->nb_subfr - 1 ]; 121 psDec->lagPrev = psDecCtrl->pitchL[ psDec->nb_subfr - 1 ];
122 122
diff --git a/lib/rbcodec/codecs/libopus/silk/decode_pulses.c b/lib/rbcodec/codecs/libopus/silk/decode_pulses.c
index e8a87c2ab7..1e14bc37b4 100644
--- a/lib/rbcodec/codecs/libopus/silk/decode_pulses.c
+++ b/lib/rbcodec/codecs/libopus/silk/decode_pulses.c
@@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
36/*********************************************/ 36/*********************************************/
37void silk_decode_pulses( 37void silk_decode_pulses(
38 ec_dec *psRangeDec, /* I/O Compressor data structure */ 38 ec_dec *psRangeDec, /* I/O Compressor data structure */
39 opus_int pulses[], /* O Excitation signal */ 39 opus_int16 pulses[], /* O Excitation signal */
40 const opus_int signalType, /* I Sigtype */ 40 const opus_int signalType, /* I Sigtype */
41 const opus_int quantOffsetType, /* I quantOffsetType */ 41 const opus_int quantOffsetType, /* I quantOffsetType */
42 const opus_int frame_length /* I Frame length */ 42 const opus_int frame_length /* I Frame length */
@@ -44,7 +44,7 @@ void silk_decode_pulses(
44{ 44{
45 opus_int i, j, k, iter, abs_q, nLS, RateLevelIndex; 45 opus_int i, j, k, iter, abs_q, nLS, RateLevelIndex;
46 opus_int sum_pulses[ MAX_NB_SHELL_BLOCKS ], nLshifts[ MAX_NB_SHELL_BLOCKS ]; 46 opus_int sum_pulses[ MAX_NB_SHELL_BLOCKS ], nLshifts[ MAX_NB_SHELL_BLOCKS ];
47 opus_int *pulses_ptr; 47 opus_int16 *pulses_ptr;
48 const opus_uint8 *cdf_ptr; 48 const opus_uint8 *cdf_ptr;
49 49
50 /*********************/ 50 /*********************/
@@ -84,7 +84,7 @@ void silk_decode_pulses(
84 if( sum_pulses[ i ] > 0 ) { 84 if( sum_pulses[ i ] > 0 ) {
85 silk_shell_decoder( &pulses[ silk_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], psRangeDec, sum_pulses[ i ] ); 85 silk_shell_decoder( &pulses[ silk_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], psRangeDec, sum_pulses[ i ] );
86 } else { 86 } else {
87 silk_memset( &pulses[ silk_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], 0, SHELL_CODEC_FRAME_LENGTH * sizeof( opus_int ) ); 87 silk_memset( &pulses[ silk_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], 0, SHELL_CODEC_FRAME_LENGTH * sizeof( pulses[0] ) );
88 } 88 }
89 } 89 }
90 90
diff --git a/lib/rbcodec/codecs/libopus/silk/macros.h b/lib/rbcodec/codecs/libopus/silk/macros.h
index 482dc3c6eb..05623b5df8 100644
--- a/lib/rbcodec/codecs/libopus/silk/macros.h
+++ b/lib/rbcodec/codecs/libopus/silk/macros.h
@@ -79,17 +79,24 @@ POSSIBILITY OF SUCH DAMAGE.
79 (( (a) & ((b)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a)-(b)) : \ 79 (( (a) & ((b)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a)-(b)) : \
80 ((((a)^0x80000000) & (b) & 0x80000000) ? silk_int32_MAX : (a)-(b)) ) 80 ((((a)^0x80000000) & (b) & 0x80000000) ? silk_int32_MAX : (a)-(b)) )
81 81
82#include "ecintrin.h" 82#if defined(MIPSr1_ASM)
83#include "mips/macros_mipsr1.h"
84#endif
83 85
86#include "ecintrin.h"
87#ifndef OVERRIDE_silk_CLZ16
84static OPUS_INLINE opus_int32 silk_CLZ16(opus_int16 in16) 88static OPUS_INLINE opus_int32 silk_CLZ16(opus_int16 in16)
85{ 89{
86 return 32 - EC_ILOG(in16<<16|0x8000); 90 return 32 - EC_ILOG(in16<<16|0x8000);
87} 91}
92#endif
88 93
94#ifndef OVERRIDE_silk_CLZ32
89static OPUS_INLINE opus_int32 silk_CLZ32(opus_int32 in32) 95static OPUS_INLINE opus_int32 silk_CLZ32(opus_int32 in32)
90{ 96{
91 return in32 ? 32 - EC_ILOG(in32) : 32; 97 return in32 ? 32 - EC_ILOG(in32) : 32;
92} 98}
99#endif
93 100
94/* Row based */ 101/* Row based */
95#define matrix_ptr(Matrix_base_adr, row, column, N) \ 102#define matrix_ptr(Matrix_base_adr, row, column, N) \
diff --git a/lib/rbcodec/codecs/libopus/silk/main.h b/lib/rbcodec/codecs/libopus/silk/main.h
index 2bdf89784d..77524f5b57 100644
--- a/lib/rbcodec/codecs/libopus/silk/main.h
+++ b/lib/rbcodec/codecs/libopus/silk/main.h
@@ -116,7 +116,7 @@ void silk_encode_signs(
116/* Decodes signs of excitation */ 116/* Decodes signs of excitation */
117void silk_decode_signs( 117void silk_decode_signs(
118 ec_dec *psRangeDec, /* I/O Compressor data structure */ 118 ec_dec *psRangeDec, /* I/O Compressor data structure */
119 opus_int pulses[], /* I/O pulse signal */ 119 opus_int16 pulses[], /* I/O pulse signal */
120 opus_int length, /* I length of input */ 120 opus_int length, /* I length of input */
121 const opus_int signalType, /* I Signal type */ 121 const opus_int signalType, /* I Signal type */
122 const opus_int quantOffsetType, /* I Quantization offset type */ 122 const opus_int quantOffsetType, /* I Quantization offset type */
@@ -161,7 +161,7 @@ void silk_shell_encoder(
161 161
162/* Shell decoder, operates on one shell code frame of 16 pulses */ 162/* Shell decoder, operates on one shell code frame of 16 pulses */
163void silk_shell_decoder( 163void silk_shell_decoder(
164 opus_int *pulses0, /* O data: nonnegative pulse amplitudes */ 164 opus_int16 *pulses0, /* O data: nonnegative pulse amplitudes */
165 ec_dec *psRangeDec, /* I/O Compressor data structure */ 165 ec_dec *psRangeDec, /* I/O Compressor data structure */
166 const opus_int pulses4 /* I number of pulses per pulse-subframe */ 166 const opus_int pulses4 /* I number of pulses per pulse-subframe */
167); 167);
@@ -397,13 +397,13 @@ void silk_decode_core(
397 silk_decoder_state *psDec, /* I/O Decoder state */ 397 silk_decoder_state *psDec, /* I/O Decoder state */
398 silk_decoder_control *psDecCtrl, /* I Decoder control */ 398 silk_decoder_control *psDecCtrl, /* I Decoder control */
399 opus_int16 xq[], /* O Decoded speech */ 399 opus_int16 xq[], /* O Decoded speech */
400 const opus_int pulses[ MAX_FRAME_LENGTH ] /* I Pulse signal */ 400 const opus_int16 pulses[ MAX_FRAME_LENGTH ] /* I Pulse signal */
401); 401);
402 402
403/* Decode quantization indices of excitation (Shell coding) */ 403/* Decode quantization indices of excitation (Shell coding) */
404void silk_decode_pulses( 404void silk_decode_pulses(
405 ec_dec *psRangeDec, /* I/O Compressor data structure */ 405 ec_dec *psRangeDec, /* I/O Compressor data structure */
406 opus_int pulses[], /* O Excitation signal */ 406 opus_int16 pulses[], /* O Excitation signal */
407 const opus_int signalType, /* I Sigtype */ 407 const opus_int signalType, /* I Sigtype */
408 const opus_int quantOffsetType, /* I quantOffsetType */ 408 const opus_int quantOffsetType, /* I quantOffsetType */
409 const opus_int frame_length /* I Frame length */ 409 const opus_int frame_length /* I Frame length */
diff --git a/lib/rbcodec/codecs/libopus/silk/resampler_private_IIR_FIR.c b/lib/rbcodec/codecs/libopus/silk/resampler_private_IIR_FIR.c
index c7b4f6ed5e..6b2b3a2e18 100644
--- a/lib/rbcodec/codecs/libopus/silk/resampler_private_IIR_FIR.c
+++ b/lib/rbcodec/codecs/libopus/silk/resampler_private_IIR_FIR.c
@@ -72,13 +72,10 @@ void silk_resampler_private_IIR_FIR(
72 silk_resampler_state_struct *S = (silk_resampler_state_struct *)SS; 72 silk_resampler_state_struct *S = (silk_resampler_state_struct *)SS;
73 opus_int32 nSamplesIn; 73 opus_int32 nSamplesIn;
74 opus_int32 max_index_Q16, index_increment_Q16; 74 opus_int32 max_index_Q16, index_increment_Q16;
75/* VARDECL( opus_int16, buf ); 75 VARDECL( opus_int16, buf );
76 SAVE_STACK; */ 76 SAVE_STACK;
77 77
78/* ALLOC( buf, 2 * S->batchSize + RESAMPLER_ORDER_FIR_12, opus_int16 ); */ 78 ALLOC( buf, 2 * S->batchSize + RESAMPLER_ORDER_FIR_12, opus_int16 );
79
80 /* worst case = 2*16*10+8 = 328 * 2 = 656bytes */
81 opus_int16 buf[2 * S->batchSize + RESAMPLER_ORDER_FIR_12];
82 79
83 /* Copy buffered samples to start of buffer */ 80 /* Copy buffered samples to start of buffer */
84 silk_memcpy( buf, S->sFIR.i16, RESAMPLER_ORDER_FIR_12 * sizeof( opus_int16 ) ); 81 silk_memcpy( buf, S->sFIR.i16, RESAMPLER_ORDER_FIR_12 * sizeof( opus_int16 ) );
@@ -106,5 +103,5 @@ void silk_resampler_private_IIR_FIR(
106 103
107 /* Copy last part of filtered signal to the state for the next call */ 104 /* Copy last part of filtered signal to the state for the next call */
108 silk_memcpy( S->sFIR.i16, &buf[ nSamplesIn << 1 ], RESAMPLER_ORDER_FIR_12 * sizeof( opus_int16 ) ); 105 silk_memcpy( S->sFIR.i16, &buf[ nSamplesIn << 1 ], RESAMPLER_ORDER_FIR_12 * sizeof( opus_int16 ) );
109/* RESTORE_STACK; */ 106 RESTORE_STACK;
110} 107}
diff --git a/lib/rbcodec/codecs/libopus/silk/shell_coder.c b/lib/rbcodec/codecs/libopus/silk/shell_coder.c
index 9d6e1bb366..d80dd51f9e 100644
--- a/lib/rbcodec/codecs/libopus/silk/shell_coder.c
+++ b/lib/rbcodec/codecs/libopus/silk/shell_coder.c
@@ -60,8 +60,8 @@ static OPUS_INLINE void encode_split(
60#endif 60#endif
61 61
62static OPUS_INLINE void decode_split( 62static OPUS_INLINE void decode_split(
63 opus_int *p_child1, /* O pulse amplitude of first child subframe */ 63 opus_int16 *p_child1, /* O pulse amplitude of first child subframe */
64 opus_int *p_child2, /* O pulse amplitude of second child subframe */ 64 opus_int16 *p_child2, /* O pulse amplitude of second child subframe */
65 ec_dec *psRangeDec, /* I/O Compressor data structure */ 65 ec_dec *psRangeDec, /* I/O Compressor data structure */
66 const opus_int p, /* I pulse amplitude of current subframe */ 66 const opus_int p, /* I pulse amplitude of current subframe */
67 const opus_uint8 *shell_table /* I table of shell cdfs */ 67 const opus_uint8 *shell_table /* I table of shell cdfs */
@@ -121,12 +121,12 @@ void silk_shell_encoder(
121 121
122/* Shell decoder, operates on one shell code frame of 16 pulses */ 122/* Shell decoder, operates on one shell code frame of 16 pulses */
123void silk_shell_decoder( 123void silk_shell_decoder(
124 opus_int *pulses0, /* O data: nonnegative pulse amplitudes */ 124 opus_int16 *pulses0, /* O data: nonnegative pulse amplitudes */
125 ec_dec *psRangeDec, /* I/O Compressor data structure */ 125 ec_dec *psRangeDec, /* I/O Compressor data structure */
126 const opus_int pulses4 /* I number of pulses per pulse-subframe */ 126 const opus_int pulses4 /* I number of pulses per pulse-subframe */
127) 127)
128{ 128{
129 opus_int pulses3[ 2 ], pulses2[ 4 ], pulses1[ 8 ]; 129 opus_int16 pulses3[ 2 ], pulses2[ 4 ], pulses1[ 8 ];
130 130
131 /* this function operates on one shell code frame of 16 pulses */ 131 /* this function operates on one shell code frame of 16 pulses */
132 silk_assert( SHELL_CODEC_FRAME_LENGTH == 16 ); 132 silk_assert( SHELL_CODEC_FRAME_LENGTH == 16 );
diff --git a/lib/rbcodec/codecs/libopus/silk/sum_sqr_shift.c b/lib/rbcodec/codecs/libopus/silk/sum_sqr_shift.c
index 12514c9917..129df191d8 100644
--- a/lib/rbcodec/codecs/libopus/silk/sum_sqr_shift.c
+++ b/lib/rbcodec/codecs/libopus/silk/sum_sqr_shift.c
@@ -53,6 +53,7 @@ void silk_sum_sqr_shift(
53 /* Scale down */ 53 /* Scale down */
54 nrg = (opus_int32)silk_RSHIFT_uint( (opus_uint32)nrg, 2 ); 54 nrg = (opus_int32)silk_RSHIFT_uint( (opus_uint32)nrg, 2 );
55 shft = 2; 55 shft = 2;
56 i+=2;
56 break; 57 break;
57 } 58 }
58 } 59 }