| OLD | NEW |
| 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 12 matching lines...) Expand all Loading... |
| 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 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 | 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 | 34 |
| 34 /************************/ | 35 /************************/ |
| 35 /* Decoder Super Struct */ | 36 /* Decoder Super Struct */ |
| 36 /************************/ | 37 /************************/ |
| 37 typedef struct { | 38 typedef struct { |
| 38 silk_decoder_state channel_state[ DECODER_NUM_CHANNELS ]; | 39 silk_decoder_state channel_state[ DECODER_NUM_CHANNELS ]; |
| 39 stereo_dec_state sStereo; | 40 stereo_dec_state sStereo; |
| 40 opus_int nChannelsAPI; | 41 opus_int nChannelsAPI; |
| 41 opus_int nChannelsInternal; | 42 opus_int nChannelsInternal; |
| 42 opus_int prev_decode_only_middle; | 43 opus_int prev_decode_only_middle; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 silk_DecControlStruct* decControl, /* I/O Control Structur
e */ | 79 silk_DecControlStruct* decControl, /* I/O Control Structur
e */ |
| 79 opus_int lostFlag, /* I 0: no loss, 1 lo
ss, 2 decode fec */ | 80 opus_int lostFlag, /* I 0: no loss, 1 lo
ss, 2 decode fec */ |
| 80 opus_int newPacketFlag, /* I Indicates first
decoder call for this packet */ | 81 opus_int newPacketFlag, /* I Indicates first
decoder call for this packet */ |
| 81 ec_dec *psRangeDec, /* I/O Compressor data
structure */ | 82 ec_dec *psRangeDec, /* I/O Compressor data
structure */ |
| 82 opus_int16 *samplesOut, /* O Decoded output s
peech vector */ | 83 opus_int16 *samplesOut, /* O Decoded output s
peech vector */ |
| 83 opus_int32 *nSamplesOut /* O Number of sample
s decoded */ | 84 opus_int32 *nSamplesOut /* O Number of sample
s decoded */ |
| 84 ) | 85 ) |
| 85 { | 86 { |
| 86 opus_int i, n, decode_only_middle = 0, ret = SILK_NO_ERROR; | 87 opus_int i, n, decode_only_middle = 0, ret = SILK_NO_ERROR; |
| 87 opus_int32 nSamplesOutDec, LBRR_symbol; | 88 opus_int32 nSamplesOutDec, LBRR_symbol; |
| 88 opus_int16 samplesOut1_tmp[ 2 ][ MAX_FS_KHZ * MAX_FRAME_LENGTH_MS + 2 ]; | 89 opus_int16 *samplesOut1_tmp[ 2 ]; |
| 89 opus_int16 samplesOut2_tmp[ MAX_API_FS_KHZ * MAX_FRAME_LENGTH_MS ]; | 90 VARDECL( opus_int16, samplesOut1_tmp_storage ); |
| 91 VARDECL( opus_int16, samplesOut2_tmp ); |
| 90 opus_int32 MS_pred_Q13[ 2 ] = { 0 }; | 92 opus_int32 MS_pred_Q13[ 2 ] = { 0 }; |
| 91 opus_int16 *resample_out_ptr; | 93 opus_int16 *resample_out_ptr; |
| 92 silk_decoder *psDec = ( silk_decoder * )decState; | 94 silk_decoder *psDec = ( silk_decoder * )decState; |
| 93 silk_decoder_state *channel_state = psDec->channel_state; | 95 silk_decoder_state *channel_state = psDec->channel_state; |
| 94 opus_int has_side; | 96 opus_int has_side; |
| 95 opus_int stereo_to_mono; | 97 opus_int stereo_to_mono; |
| 98 SAVE_STACK; |
| 96 | 99 |
| 97 /**********************************/ | 100 /**********************************/ |
| 98 /* Test if first frame in payload */ | 101 /* Test if first frame in payload */ |
| 99 /**********************************/ | 102 /**********************************/ |
| 100 if( newPacketFlag ) { | 103 if( newPacketFlag ) { |
| 101 for( n = 0; n < decControl->nChannelsInternal; n++ ) { | 104 for( n = 0; n < decControl->nChannelsInternal; n++ ) { |
| 102 channel_state[ n ].nFramesDecoded = 0; /* Used to count frames in p
acket */ | 105 channel_state[ n ].nFramesDecoded = 0; /* Used to count frames in p
acket */ |
| 103 } | 106 } |
| 104 } | 107 } |
| 105 | 108 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 125 channel_state[ n ].nFramesPerPacket = 1; | 128 channel_state[ n ].nFramesPerPacket = 1; |
| 126 channel_state[ n ].nb_subfr = 4; | 129 channel_state[ n ].nb_subfr = 4; |
| 127 } else if( decControl->payloadSize_ms == 40 ) { | 130 } else if( decControl->payloadSize_ms == 40 ) { |
| 128 channel_state[ n ].nFramesPerPacket = 2; | 131 channel_state[ n ].nFramesPerPacket = 2; |
| 129 channel_state[ n ].nb_subfr = 4; | 132 channel_state[ n ].nb_subfr = 4; |
| 130 } else if( decControl->payloadSize_ms == 60 ) { | 133 } else if( decControl->payloadSize_ms == 60 ) { |
| 131 channel_state[ n ].nFramesPerPacket = 3; | 134 channel_state[ n ].nFramesPerPacket = 3; |
| 132 channel_state[ n ].nb_subfr = 4; | 135 channel_state[ n ].nb_subfr = 4; |
| 133 } else { | 136 } else { |
| 134 silk_assert( 0 ); | 137 silk_assert( 0 ); |
| 138 RESTORE_STACK; |
| 135 return SILK_DEC_INVALID_FRAME_SIZE; | 139 return SILK_DEC_INVALID_FRAME_SIZE; |
| 136 } | 140 } |
| 137 fs_kHz_dec = ( decControl->internalSampleRate >> 10 ) + 1; | 141 fs_kHz_dec = ( decControl->internalSampleRate >> 10 ) + 1; |
| 138 if( fs_kHz_dec != 8 && fs_kHz_dec != 12 && fs_kHz_dec != 16 ) { | 142 if( fs_kHz_dec != 8 && fs_kHz_dec != 12 && fs_kHz_dec != 16 ) { |
| 139 silk_assert( 0 ); | 143 silk_assert( 0 ); |
| 144 RESTORE_STACK; |
| 140 return SILK_DEC_INVALID_SAMPLING_FREQUENCY; | 145 return SILK_DEC_INVALID_SAMPLING_FREQUENCY; |
| 141 } | 146 } |
| 142 ret += silk_decoder_set_fs( &channel_state[ n ], fs_kHz_dec, decCont
rol->API_sampleRate ); | 147 ret += silk_decoder_set_fs( &channel_state[ n ], fs_kHz_dec, decCont
rol->API_sampleRate ); |
| 143 } | 148 } |
| 144 } | 149 } |
| 145 | 150 |
| 146 if( decControl->nChannelsAPI == 2 && decControl->nChannelsInternal == 2 && (
psDec->nChannelsAPI == 1 || psDec->nChannelsInternal == 1 ) ) { | 151 if( decControl->nChannelsAPI == 2 && decControl->nChannelsInternal == 2 && (
psDec->nChannelsAPI == 1 || psDec->nChannelsInternal == 1 ) ) { |
| 147 silk_memset( psDec->sStereo.pred_prev_Q13, 0, sizeof( psDec->sStereo.pre
d_prev_Q13 ) ); | 152 silk_memset( psDec->sStereo.pred_prev_Q13, 0, sizeof( psDec->sStereo.pre
d_prev_Q13 ) ); |
| 148 silk_memset( psDec->sStereo.sSide, 0, sizeof( psDec->sStereo.sSide ) ); | 153 silk_memset( psDec->sStereo.sSide, 0, sizeof( psDec->sStereo.sSide ) ); |
| 149 silk_memcpy( &channel_state[ 1 ].resampler_state, &channel_state[ 0 ].re
sampler_state, sizeof( silk_resampler_state_struct ) ); | 154 silk_memcpy( &channel_state[ 1 ].resampler_state, &channel_state[ 0 ].re
sampler_state, sizeof( silk_resampler_state_struct ) ); |
| 150 } | 155 } |
| 151 psDec->nChannelsAPI = decControl->nChannelsAPI; | 156 psDec->nChannelsAPI = decControl->nChannelsAPI; |
| 152 psDec->nChannelsInternal = decControl->nChannelsInternal; | 157 psDec->nChannelsInternal = decControl->nChannelsInternal; |
| 153 | 158 |
| 154 if( decControl->API_sampleRate > (opus_int32)MAX_API_FS_KHZ * 1000 || decCon
trol->API_sampleRate < 8000 ) { | 159 if( decControl->API_sampleRate > (opus_int32)MAX_API_FS_KHZ * 1000 || decCon
trol->API_sampleRate < 8000 ) { |
| 155 ret = SILK_DEC_INVALID_SAMPLING_FREQUENCY; | 160 ret = SILK_DEC_INVALID_SAMPLING_FREQUENCY; |
| 161 RESTORE_STACK; |
| 156 return( ret ); | 162 return( ret ); |
| 157 } | 163 } |
| 158 | 164 |
| 159 if( lostFlag != FLAG_PACKET_LOST && channel_state[ 0 ].nFramesDecoded == 0 )
{ | 165 if( lostFlag != FLAG_PACKET_LOST && channel_state[ 0 ].nFramesDecoded == 0 )
{ |
| 160 /* First decoder call for this payload */ | 166 /* First decoder call for this payload */ |
| 161 /* Decode VAD flags and LBRR flag */ | 167 /* Decode VAD flags and LBRR flag */ |
| 162 for( n = 0; n < decControl->nChannelsInternal; n++ ) { | 168 for( n = 0; n < decControl->nChannelsInternal; n++ ) { |
| 163 for( i = 0; i < channel_state[ n ].nFramesPerPacket; i++ ) { | 169 for( i = 0; i < channel_state[ n ].nFramesPerPacket; i++ ) { |
| 164 channel_state[ n ].VAD_flags[ i ] = ec_dec_bit_logp(psRangeDec,
1); | 170 channel_state[ n ].VAD_flags[ i ] = ec_dec_bit_logp(psRangeDec,
1); |
| 165 } | 171 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 /* Reset side channel decoder prediction memory for first frame with side co
ding */ | 239 /* Reset side channel decoder prediction memory for first frame with side co
ding */ |
| 234 if( decControl->nChannelsInternal == 2 && decode_only_middle == 0 && psDec->
prev_decode_only_middle == 1 ) { | 240 if( decControl->nChannelsInternal == 2 && decode_only_middle == 0 && psDec->
prev_decode_only_middle == 1 ) { |
| 235 silk_memset( psDec->channel_state[ 1 ].outBuf, 0, sizeof(psDec->channel_
state[ 1 ].outBuf) ); | 241 silk_memset( psDec->channel_state[ 1 ].outBuf, 0, sizeof(psDec->channel_
state[ 1 ].outBuf) ); |
| 236 silk_memset( psDec->channel_state[ 1 ].sLPC_Q14_buf, 0, sizeof(psDec->ch
annel_state[ 1 ].sLPC_Q14_buf) ); | 242 silk_memset( psDec->channel_state[ 1 ].sLPC_Q14_buf, 0, sizeof(psDec->ch
annel_state[ 1 ].sLPC_Q14_buf) ); |
| 237 psDec->channel_state[ 1 ].lagPrev = 100; | 243 psDec->channel_state[ 1 ].lagPrev = 100; |
| 238 psDec->channel_state[ 1 ].LastGainIndex = 10; | 244 psDec->channel_state[ 1 ].LastGainIndex = 10; |
| 239 psDec->channel_state[ 1 ].prevSignalType = TYPE_NO_VOICE_ACTIVITY; | 245 psDec->channel_state[ 1 ].prevSignalType = TYPE_NO_VOICE_ACTIVITY; |
| 240 psDec->channel_state[ 1 ].first_frame_after_reset = 1; | 246 psDec->channel_state[ 1 ].first_frame_after_reset = 1; |
| 241 } | 247 } |
| 242 | 248 |
| 249 ALLOC( samplesOut1_tmp_storage, |
| 250 decControl->nChannelsInternal*( |
| 251 channel_state[ 0 ].frame_length + 2 ), |
| 252 opus_int16 ); |
| 253 samplesOut1_tmp[ 0 ] = samplesOut1_tmp_storage; |
| 254 samplesOut1_tmp[ 1 ] = samplesOut1_tmp_storage |
| 255 + channel_state[ 0 ].frame_length + 2; |
| 256 |
| 243 if( lostFlag == FLAG_DECODE_NORMAL ) { | 257 if( lostFlag == FLAG_DECODE_NORMAL ) { |
| 244 has_side = !decode_only_middle; | 258 has_side = !decode_only_middle; |
| 245 } else { | 259 } else { |
| 246 has_side = !psDec->prev_decode_only_middle | 260 has_side = !psDec->prev_decode_only_middle |
| 247 || (decControl->nChannelsInternal == 2 && lostFlag == FLAG_DECODE_
LBRR && channel_state[1].LBRR_flags[ channel_state[1].nFramesDecoded ] == 1 ); | 261 || (decControl->nChannelsInternal == 2 && lostFlag == FLAG_DECODE_
LBRR && channel_state[1].LBRR_flags[ channel_state[1].nFramesDecoded ] == 1 ); |
| 248 } | 262 } |
| 249 /* Call decoder for one frame */ | 263 /* Call decoder for one frame */ |
| 250 for( n = 0; n < decControl->nChannelsInternal; n++ ) { | 264 for( n = 0; n < decControl->nChannelsInternal; n++ ) { |
| 251 if( n == 0 || has_side ) { | 265 if( n == 0 || has_side ) { |
| 252 opus_int FrameIndex; | 266 opus_int FrameIndex; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 278 } else { | 292 } else { |
| 279 /* Buffering */ | 293 /* Buffering */ |
| 280 silk_memcpy( samplesOut1_tmp[ 0 ], psDec->sStereo.sMid, 2 * sizeof( opus
_int16 ) ); | 294 silk_memcpy( samplesOut1_tmp[ 0 ], psDec->sStereo.sMid, 2 * sizeof( opus
_int16 ) ); |
| 281 silk_memcpy( psDec->sStereo.sMid, &samplesOut1_tmp[ 0 ][ nSamplesOutDec
], 2 * sizeof( opus_int16 ) ); | 295 silk_memcpy( psDec->sStereo.sMid, &samplesOut1_tmp[ 0 ][ nSamplesOutDec
], 2 * sizeof( opus_int16 ) ); |
| 282 } | 296 } |
| 283 | 297 |
| 284 /* Number of output samples */ | 298 /* Number of output samples */ |
| 285 *nSamplesOut = silk_DIV32( nSamplesOutDec * decControl->API_sampleRate, silk
_SMULBB( channel_state[ 0 ].fs_kHz, 1000 ) ); | 299 *nSamplesOut = silk_DIV32( nSamplesOutDec * decControl->API_sampleRate, silk
_SMULBB( channel_state[ 0 ].fs_kHz, 1000 ) ); |
| 286 | 300 |
| 287 /* Set up pointers to temp buffers */ | 301 /* Set up pointers to temp buffers */ |
| 302 ALLOC( samplesOut2_tmp, |
| 303 decControl->nChannelsAPI == 2 ? *nSamplesOut : 0, opus_int16 ); |
| 288 if( decControl->nChannelsAPI == 2 ) { | 304 if( decControl->nChannelsAPI == 2 ) { |
| 289 resample_out_ptr = samplesOut2_tmp; | 305 resample_out_ptr = samplesOut2_tmp; |
| 290 } else { | 306 } else { |
| 291 resample_out_ptr = samplesOut; | 307 resample_out_ptr = samplesOut; |
| 292 } | 308 } |
| 293 | 309 |
| 294 for( n = 0; n < silk_min( decControl->nChannelsAPI, decControl->nChannelsInt
ernal ); n++ ) { | 310 for( n = 0; n < silk_min( decControl->nChannelsAPI, decControl->nChannelsInt
ernal ); n++ ) { |
| 295 | 311 |
| 296 /* Resample decoded signal to API_sampleRate */ | 312 /* Resample decoded signal to API_sampleRate */ |
| 297 ret += silk_resampler( &channel_state[ n ].resampler_state, resample_out
_ptr, &samplesOut1_tmp[ n ][ 1 ], nSamplesOutDec ); | 313 ret += silk_resampler( &channel_state[ n ].resampler_state, resample_out
_ptr, &samplesOut1_tmp[ n ][ 1 ], nSamplesOutDec ); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 } | 346 } |
| 331 | 347 |
| 332 if( lostFlag == FLAG_PACKET_LOST ) { | 348 if( lostFlag == FLAG_PACKET_LOST ) { |
| 333 /* On packet loss, remove the gain clamping to prevent having the energy
"bounce back" | 349 /* On packet loss, remove the gain clamping to prevent having the energy
"bounce back" |
| 334 if we lose packets when the energy is going down */ | 350 if we lose packets when the energy is going down */ |
| 335 for ( i = 0; i < psDec->nChannelsInternal; i++ ) | 351 for ( i = 0; i < psDec->nChannelsInternal; i++ ) |
| 336 psDec->channel_state[ i ].LastGainIndex = 10; | 352 psDec->channel_state[ i ].LastGainIndex = 10; |
| 337 } else { | 353 } else { |
| 338 psDec->prev_decode_only_middle = decode_only_middle; | 354 psDec->prev_decode_only_middle = decode_only_middle; |
| 339 } | 355 } |
| 356 RESTORE_STACK; |
| 340 return ret; | 357 return ret; |
| 341 } | 358 } |
| 342 | 359 |
| 343 #if 0 | 360 #if 0 |
| 344 /* Getting table of contents for a packet */ | 361 /* Getting table of contents for a packet */ |
| 345 opus_int silk_get_TOC( | 362 opus_int silk_get_TOC( |
| 346 const opus_uint8 *payload, /* I Payload data
*/ | 363 const opus_uint8 *payload, /* I Payload data
*/ |
| 347 const opus_int nBytesIn, /* I Number of input
bytes */ | 364 const opus_int nBytesIn, /* I Number of input
bytes */ |
| 348 const opus_int nFramesPerPayload, /* I Number of SILK f
rames per payload */ | 365 const opus_int nFramesPerPayload, /* I Number of SILK f
rames per payload */ |
| 349 silk_TOC_struct *Silk_TOC /* O Type of content
*/ | 366 silk_TOC_struct *Silk_TOC /* O Type of content
*/ |
| (...skipping 16 matching lines...) Expand all Loading... |
| 366 Silk_TOC->inbandFECFlag = flags & 1; | 383 Silk_TOC->inbandFECFlag = flags & 1; |
| 367 for( i = nFramesPerPayload - 1; i >= 0 ; i-- ) { | 384 for( i = nFramesPerPayload - 1; i >= 0 ; i-- ) { |
| 368 flags = silk_RSHIFT( flags, 1 ); | 385 flags = silk_RSHIFT( flags, 1 ); |
| 369 Silk_TOC->VADFlags[ i ] = flags & 1; | 386 Silk_TOC->VADFlags[ i ] = flags & 1; |
| 370 Silk_TOC->VADFlag |= flags & 1; | 387 Silk_TOC->VADFlag |= flags & 1; |
| 371 } | 388 } |
| 372 | 389 |
| 373 return ret; | 390 return ret; |
| 374 } | 391 } |
| 375 #endif | 392 #endif |
| OLD | NEW |