diff options
author | Nils Wallménius <nils@rockbox.org> | 2014-01-19 16:31:59 +0100 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2014-07-13 11:12:40 +0200 |
commit | 9b7ec42403073ee887efc531c153e6b1b6c15bab (patch) | |
tree | 07e72fe9d817c65a6fede22955344a870842d5e6 /lib/rbcodec/codecs/libopus/silk/dec_API.c | |
parent | e557951c94c1efa769900257e466900f0ffeb53b (diff) | |
download | rockbox-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/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 */ |