diff options
Diffstat (limited to 'lib/rbcodec/codecs/libopus/silk/dec_API.c')
-rw-r--r-- | lib/rbcodec/codecs/libopus/silk/dec_API.c | 37 |
1 files changed, 29 insertions, 8 deletions
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 */ |