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

Side by Side Diff: silk/dec_API.c

Issue 882843002: Update to opus-HEAD-66611f1. (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/opus.git@master
Patch Set: Add the contents of Makefile.mips back. Created 5 years, 10 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
« no previous file with comments | « silk/code_signs.c ('k') | silk/decode_core.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /*********************************************************************** 1 /***********************************************************************
2 Copyright (c) 2006-2011, Skype Limited. All rights reserved. 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3 Redistribution and use in source and binary forms, with or without 3 Redistribution and use in source and binary forms, with or without
4 modification, are permitted provided that the following conditions 4 modification, are permitted provided that the following conditions
5 are met: 5 are met:
6 - Redistributions of source code must retain the above copyright notice, 6 - Redistributions of source code must retain the above copyright notice,
7 this list of conditions and the following disclaimer. 7 this list of conditions and the following disclaimer.
8 - Redistributions in binary form must reproduce the above copyright 8 - Redistributions in binary form must reproduce the above copyright
9 notice, this list of conditions and the following disclaimer in the 9 notice, this list of conditions and the following disclaimer in the
10 documentation and/or other materials provided with the distribution. 10 documentation and/or other materials provided with the distribution.
(...skipping 13 matching lines...) Expand all
24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 POSSIBILITY OF SUCH DAMAGE. 25 POSSIBILITY OF SUCH DAMAGE.
26 ***********************************************************************/ 26 ***********************************************************************/
27 27
28 #ifdef HAVE_CONFIG_H 28 #ifdef HAVE_CONFIG_H
29 #include "config.h" 29 #include "config.h"
30 #endif 30 #endif
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 */
37 /************************/ 38 /************************/
38 typedef struct { 39 typedef struct {
39 silk_decoder_state channel_state[ DECODER_NUM_CHANNELS ]; 40 silk_decoder_state channel_state[ DECODER_NUM_CHANNELS ];
40 stereo_dec_state sStereo; 41 stereo_dec_state sStereo;
41 opus_int nChannelsAPI; 42 opus_int nChannelsAPI;
42 opus_int nChannelsInternal; 43 opus_int nChannelsInternal;
43 opus_int prev_decode_only_middle; 44 opus_int prev_decode_only_middle;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 78 }
78 79
79 /* Decode a frame */ 80 /* Decode a frame */
80 opus_int silk_Decode( /* O Returns error co de */ 81 opus_int silk_Decode( /* O Returns error co de */
81 void* decState, /* I/O State */ 82 void* decState, /* I/O State */
82 silk_DecControlStruct* decControl, /* I/O Control Structur e */ 83 silk_DecControlStruct* decControl, /* I/O Control Structur e */
83 opus_int lostFlag, /* I 0: no loss, 1 lo ss, 2 decode fec */ 84 opus_int lostFlag, /* I 0: no loss, 1 lo ss, 2 decode fec */
84 opus_int newPacketFlag, /* I Indicates first decoder call for this packet */ 85 opus_int newPacketFlag, /* I Indicates first decoder call for this packet */
85 ec_dec *psRangeDec, /* I/O Compressor data structure */ 86 ec_dec *psRangeDec, /* I/O Compressor data structure */
86 opus_int16 *samplesOut, /* O Decoded output s peech vector */ 87 opus_int16 *samplesOut, /* O Decoded output s peech vector */
87 opus_int32 *nSamplesOut /* O Number of sample s decoded */ 88 opus_int32 *nSamplesOut, /* O Number of sample s decoded */
89 int arch /* I Run-time archite cture */
88 ) 90 )
89 { 91 {
90 opus_int i, n, decode_only_middle = 0, ret = SILK_NO_ERROR; 92 opus_int i, n, decode_only_middle = 0, ret = SILK_NO_ERROR;
91 opus_int32 nSamplesOutDec, LBRR_symbol; 93 opus_int32 nSamplesOutDec, LBRR_symbol;
92 opus_int16 *samplesOut1_tmp[ 2 ]; 94 opus_int16 *samplesOut1_tmp[ 2 ];
93 VARDECL( opus_int16, samplesOut1_tmp_storage ); 95 VARDECL( opus_int16, samplesOut1_tmp_storage1 );
96 VARDECL( opus_int16, samplesOut1_tmp_storage2 );
94 VARDECL( opus_int16, samplesOut2_tmp ); 97 VARDECL( opus_int16, samplesOut2_tmp );
95 opus_int32 MS_pred_Q13[ 2 ] = { 0 }; 98 opus_int32 MS_pred_Q13[ 2 ] = { 0 };
96 opus_int16 *resample_out_ptr; 99 opus_int16 *resample_out_ptr;
97 silk_decoder *psDec = ( silk_decoder * )decState; 100 silk_decoder *psDec = ( silk_decoder * )decState;
98 silk_decoder_state *channel_state = psDec->channel_state; 101 silk_decoder_state *channel_state = psDec->channel_state;
99 opus_int has_side; 102 opus_int has_side;
100 opus_int stereo_to_mono; 103 opus_int stereo_to_mono;
104 int delay_stack_alloc;
101 SAVE_STACK; 105 SAVE_STACK;
102 106
103 silk_assert( decControl->nChannelsInternal == 1 || decControl->nChannelsInte rnal == 2 ); 107 silk_assert( decControl->nChannelsInternal == 1 || decControl->nChannelsInte rnal == 2 );
104 108
105 /**********************************/ 109 /**********************************/
106 /* Test if first frame in payload */ 110 /* Test if first frame in payload */
107 /**********************************/ 111 /**********************************/
108 if( newPacketFlag ) { 112 if( newPacketFlag ) {
109 for( n = 0; n < decControl->nChannelsInternal; n++ ) { 113 for( n = 0; n < decControl->nChannelsInternal; n++ ) {
110 channel_state[ n ].nFramesDecoded = 0; /* Used to count frames in p acket */ 114 channel_state[ n ].nFramesDecoded = 0; /* Used to count frames in p acket */
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } 193 }
190 } 194 }
191 } 195 }
192 } 196 }
193 197
194 if( lostFlag == FLAG_DECODE_NORMAL ) { 198 if( lostFlag == FLAG_DECODE_NORMAL ) {
195 /* Regular decoding: skip all LBRR data */ 199 /* Regular decoding: skip all LBRR data */
196 for( i = 0; i < channel_state[ 0 ].nFramesPerPacket; i++ ) { 200 for( i = 0; i < channel_state[ 0 ].nFramesPerPacket; i++ ) {
197 for( n = 0; n < decControl->nChannelsInternal; n++ ) { 201 for( n = 0; n < decControl->nChannelsInternal; n++ ) {
198 if( channel_state[ n ].LBRR_flags[ i ] ) { 202 if( channel_state[ n ].LBRR_flags[ i ] ) {
199 opus_int pulses[ MAX_FRAME_LENGTH ]; 203 opus_int16 pulses[ MAX_FRAME_LENGTH ];
200 opus_int condCoding; 204 opus_int condCoding;
201 205
202 if( decControl->nChannelsInternal == 2 && n == 0 ) { 206 if( decControl->nChannelsInternal == 2 && n == 0 ) {
203 silk_stereo_decode_pred( psRangeDec, MS_pred_Q13 ); 207 silk_stereo_decode_pred( psRangeDec, MS_pred_Q13 );
204 if( channel_state[ 1 ].LBRR_flags[ i ] == 0 ) { 208 if( channel_state[ 1 ].LBRR_flags[ i ] == 0 ) {
205 silk_stereo_decode_mid_only( psRangeDec, &decode _only_middle ); 209 silk_stereo_decode_mid_only( psRangeDec, &decode _only_middle );
206 } 210 }
207 } 211 }
208 /* Use conditional coding if previous frame available */ 212 /* Use conditional coding if previous frame available */
209 if( i > 0 && channel_state[ n ].LBRR_flags[ i - 1 ] ) { 213 if( i > 0 && channel_state[ n ].LBRR_flags[ i - 1 ] ) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 /* Reset side channel decoder prediction memory for first frame with side co ding */ 248 /* Reset side channel decoder prediction memory for first frame with side co ding */
245 if( decControl->nChannelsInternal == 2 && decode_only_middle == 0 && psDec-> prev_decode_only_middle == 1 ) { 249 if( decControl->nChannelsInternal == 2 && decode_only_middle == 0 && psDec-> prev_decode_only_middle == 1 ) {
246 silk_memset( psDec->channel_state[ 1 ].outBuf, 0, sizeof(psDec->channel_ state[ 1 ].outBuf) ); 250 silk_memset( psDec->channel_state[ 1 ].outBuf, 0, sizeof(psDec->channel_ state[ 1 ].outBuf) );
247 silk_memset( psDec->channel_state[ 1 ].sLPC_Q14_buf, 0, sizeof(psDec->ch annel_state[ 1 ].sLPC_Q14_buf) ); 251 silk_memset( psDec->channel_state[ 1 ].sLPC_Q14_buf, 0, sizeof(psDec->ch annel_state[ 1 ].sLPC_Q14_buf) );
248 psDec->channel_state[ 1 ].lagPrev = 100; 252 psDec->channel_state[ 1 ].lagPrev = 100;
249 psDec->channel_state[ 1 ].LastGainIndex = 10; 253 psDec->channel_state[ 1 ].LastGainIndex = 10;
250 psDec->channel_state[ 1 ].prevSignalType = TYPE_NO_VOICE_ACTIVITY; 254 psDec->channel_state[ 1 ].prevSignalType = TYPE_NO_VOICE_ACTIVITY;
251 psDec->channel_state[ 1 ].first_frame_after_reset = 1; 255 psDec->channel_state[ 1 ].first_frame_after_reset = 1;
252 } 256 }
253 257
254 ALLOC( samplesOut1_tmp_storage, 258 /* Check if the temp buffer fits into the output PCM buffer. If it fits,
255 decControl->nChannelsInternal*( 259 we can delay allocating the temp buffer until after the SILK peak stack
256 channel_state[ 0 ].frame_length + 2 ), 260 usage. We need to use a < and not a <= because of the two extra samples. */
261 delay_stack_alloc = decControl->internalSampleRate*decControl->nChannelsInte rnal
262 < decControl->API_sampleRate*decControl->nChannelsAPI;
263 ALLOC( samplesOut1_tmp_storage1, delay_stack_alloc ? ALLOC_NONE
264 : decControl->nChannelsInternal*(channel_state[ 0 ].frame_length + 2 ),
257 opus_int16 ); 265 opus_int16 );
258 samplesOut1_tmp[ 0 ] = samplesOut1_tmp_storage; 266 if ( delay_stack_alloc )
259 samplesOut1_tmp[ 1 ] = samplesOut1_tmp_storage 267 {
260 + channel_state[ 0 ].frame_length + 2; 268 samplesOut1_tmp[ 0 ] = samplesOut;
269 samplesOut1_tmp[ 1 ] = samplesOut + channel_state[ 0 ].frame_length + 2;
270 } else {
271 samplesOut1_tmp[ 0 ] = samplesOut1_tmp_storage1;
272 samplesOut1_tmp[ 1 ] = samplesOut1_tmp_storage1 + channel_state[ 0 ].fram e_length + 2;
273 }
261 274
262 if( lostFlag == FLAG_DECODE_NORMAL ) { 275 if( lostFlag == FLAG_DECODE_NORMAL ) {
263 has_side = !decode_only_middle; 276 has_side = !decode_only_middle;
264 } else { 277 } else {
265 has_side = !psDec->prev_decode_only_middle 278 has_side = !psDec->prev_decode_only_middle
266 || (decControl->nChannelsInternal == 2 && lostFlag == FLAG_DECODE_ LBRR && channel_state[1].LBRR_flags[ channel_state[1].nFramesDecoded ] == 1 ); 279 || (decControl->nChannelsInternal == 2 && lostFlag == FLAG_DECODE_ LBRR && channel_state[1].LBRR_flags[ channel_state[1].nFramesDecoded ] == 1 );
267 } 280 }
268 /* Call decoder for one frame */ 281 /* Call decoder for one frame */
269 for( n = 0; n < decControl->nChannelsInternal; n++ ) { 282 for( n = 0; n < decControl->nChannelsInternal; n++ ) {
270 if( n == 0 || has_side ) { 283 if( n == 0 || has_side ) {
271 opus_int FrameIndex; 284 opus_int FrameIndex;
272 opus_int condCoding; 285 opus_int condCoding;
273 286
274 FrameIndex = channel_state[ 0 ].nFramesDecoded - n; 287 FrameIndex = channel_state[ 0 ].nFramesDecoded - n;
275 /* Use independent coding if no previous frame available */ 288 /* Use independent coding if no previous frame available */
276 if( FrameIndex <= 0 ) { 289 if( FrameIndex <= 0 ) {
277 condCoding = CODE_INDEPENDENTLY; 290 condCoding = CODE_INDEPENDENTLY;
278 } else if( lostFlag == FLAG_DECODE_LBRR ) { 291 } else if( lostFlag == FLAG_DECODE_LBRR ) {
279 condCoding = channel_state[ n ].LBRR_flags[ FrameIndex - 1 ] ? C ODE_CONDITIONALLY : CODE_INDEPENDENTLY; 292 condCoding = channel_state[ n ].LBRR_flags[ FrameIndex - 1 ] ? C ODE_CONDITIONALLY : CODE_INDEPENDENTLY;
280 } else if( n > 0 && psDec->prev_decode_only_middle ) { 293 } else if( n > 0 && psDec->prev_decode_only_middle ) {
281 /* If we skipped a side frame in this packet, we don't 294 /* If we skipped a side frame in this packet, we don't
282 need LTP scaling; the LTP state is well-defined. */ 295 need LTP scaling; the LTP state is well-defined. */
283 condCoding = CODE_INDEPENDENTLY_NO_LTP_SCALING; 296 condCoding = CODE_INDEPENDENTLY_NO_LTP_SCALING;
284 } else { 297 } else {
285 condCoding = CODE_CONDITIONALLY; 298 condCoding = CODE_CONDITIONALLY;
286 } 299 }
287 ret += silk_decode_frame( &channel_state[ n ], psRangeDec, &samplesO ut1_tmp[ n ][ 2 ], &nSamplesOutDec, lostFlag, condCoding); 300 ret += silk_decode_frame( &channel_state[ n ], psRangeDec, &samplesO ut1_tmp[ n ][ 2 ], &nSamplesOutDec, lostFlag, condCoding, arch);
288 } else { 301 } else {
289 silk_memset( &samplesOut1_tmp[ n ][ 2 ], 0, nSamplesOutDec * sizeof( opus_int16 ) ); 302 silk_memset( &samplesOut1_tmp[ n ][ 2 ], 0, nSamplesOutDec * sizeof( opus_int16 ) );
290 } 303 }
291 channel_state[ n ].nFramesDecoded++; 304 channel_state[ n ].nFramesDecoded++;
292 } 305 }
293 306
294 if( decControl->nChannelsAPI == 2 && decControl->nChannelsInternal == 2 ) { 307 if( decControl->nChannelsAPI == 2 && decControl->nChannelsInternal == 2 ) {
295 /* Convert Mid/Side to Left/Right */ 308 /* Convert Mid/Side to Left/Right */
296 silk_stereo_MS_to_LR( &psDec->sStereo, samplesOut1_tmp[ 0 ], samplesOut1 _tmp[ 1 ], MS_pred_Q13, channel_state[ 0 ].fs_kHz, nSamplesOutDec ); 309 silk_stereo_MS_to_LR( &psDec->sStereo, samplesOut1_tmp[ 0 ], samplesOut1 _tmp[ 1 ], MS_pred_Q13, channel_state[ 0 ].fs_kHz, nSamplesOutDec );
297 } else { 310 } else {
298 /* Buffering */ 311 /* Buffering */
299 silk_memcpy( samplesOut1_tmp[ 0 ], psDec->sStereo.sMid, 2 * sizeof( opus _int16 ) ); 312 silk_memcpy( samplesOut1_tmp[ 0 ], psDec->sStereo.sMid, 2 * sizeof( opus _int16 ) );
300 silk_memcpy( psDec->sStereo.sMid, &samplesOut1_tmp[ 0 ][ nSamplesOutDec ], 2 * sizeof( opus_int16 ) ); 313 silk_memcpy( psDec->sStereo.sMid, &samplesOut1_tmp[ 0 ][ nSamplesOutDec ], 2 * sizeof( opus_int16 ) );
301 } 314 }
302 315
303 /* Number of output samples */ 316 /* Number of output samples */
304 *nSamplesOut = silk_DIV32( nSamplesOutDec * decControl->API_sampleRate, silk _SMULBB( channel_state[ 0 ].fs_kHz, 1000 ) ); 317 *nSamplesOut = silk_DIV32( nSamplesOutDec * decControl->API_sampleRate, silk _SMULBB( channel_state[ 0 ].fs_kHz, 1000 ) );
305 318
306 /* Set up pointers to temp buffers */ 319 /* Set up pointers to temp buffers */
307 ALLOC( samplesOut2_tmp, 320 ALLOC( samplesOut2_tmp,
308 decControl->nChannelsAPI == 2 ? *nSamplesOut : ALLOC_NONE, opus_int16 ); 321 decControl->nChannelsAPI == 2 ? *nSamplesOut : ALLOC_NONE, opus_int16 );
309 if( decControl->nChannelsAPI == 2 ) { 322 if( decControl->nChannelsAPI == 2 ) {
310 resample_out_ptr = samplesOut2_tmp; 323 resample_out_ptr = samplesOut2_tmp;
311 } else { 324 } else {
312 resample_out_ptr = samplesOut; 325 resample_out_ptr = samplesOut;
313 } 326 }
314 327
328 ALLOC( samplesOut1_tmp_storage2, delay_stack_alloc
329 ? decControl->nChannelsInternal*(channel_state[ 0 ].frame_length + 2 )
330 : ALLOC_NONE,
331 opus_int16 );
332 if ( delay_stack_alloc ) {
333 OPUS_COPY(samplesOut1_tmp_storage2, samplesOut, decControl->nChannelsInte rnal*(channel_state[ 0 ].frame_length + 2));
334 samplesOut1_tmp[ 0 ] = samplesOut1_tmp_storage2;
335 samplesOut1_tmp[ 1 ] = samplesOut1_tmp_storage2 + channel_state[ 0 ].fram e_length + 2;
336 }
315 for( n = 0; n < silk_min( decControl->nChannelsAPI, decControl->nChannelsInt ernal ); n++ ) { 337 for( n = 0; n < silk_min( decControl->nChannelsAPI, decControl->nChannelsInt ernal ); n++ ) {
316 338
317 /* Resample decoded signal to API_sampleRate */ 339 /* Resample decoded signal to API_sampleRate */
318 ret += silk_resampler( &channel_state[ n ].resampler_state, resample_out _ptr, &samplesOut1_tmp[ n ][ 1 ], nSamplesOutDec ); 340 ret += silk_resampler( &channel_state[ n ].resampler_state, resample_out _ptr, &samplesOut1_tmp[ n ][ 1 ], nSamplesOutDec );
319 341
320 /* Interleave if stereo output and stereo stream */ 342 /* Interleave if stereo output and stereo stream */
321 if( decControl->nChannelsAPI == 2 ) { 343 if( decControl->nChannelsAPI == 2 ) {
322 for( i = 0; i < *nSamplesOut; i++ ) { 344 for( i = 0; i < *nSamplesOut; i++ ) {
323 samplesOut[ n + 2 * i ] = resample_out_ptr[ i ]; 345 samplesOut[ n + 2 * i ] = resample_out_ptr[ i ];
324 } 346 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 Silk_TOC->inbandFECFlag = flags & 1; 410 Silk_TOC->inbandFECFlag = flags & 1;
389 for( i = nFramesPerPayload - 1; i >= 0 ; i-- ) { 411 for( i = nFramesPerPayload - 1; i >= 0 ; i-- ) {
390 flags = silk_RSHIFT( flags, 1 ); 412 flags = silk_RSHIFT( flags, 1 );
391 Silk_TOC->VADFlags[ i ] = flags & 1; 413 Silk_TOC->VADFlags[ i ] = flags & 1;
392 Silk_TOC->VADFlag |= flags & 1; 414 Silk_TOC->VADFlag |= flags & 1;
393 } 415 }
394 416
395 return ret; 417 return ret;
396 } 418 }
397 #endif 419 #endif
OLDNEW
« no previous file with comments | « silk/code_signs.c ('k') | silk/decode_core.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698