ref: 0dbd0ca3e63064cf5108d716f96e4bbbe21c160d
parent: acc7a6c78b266e3ef0e1f91ee405af92a0989dec
author: Koen Vos <[email protected]>
date: Fri Oct 28 17:05:22 EDT 2011
Fixes two SILK PLC issues - Calling the decoder for FEC when there's no LBRR should no longer crash - There should no longer be an issue with the PLC on frame size switching
--- a/silk/PLC.c
+++ b/silk/PLC.c
@@ -54,6 +54,8 @@
)
{
psDec->sPLC.pitchL_Q8 = silk_RSHIFT( psDec->frame_length, 1 );
+ psDec->sPLC.prevGain_Q16[ 0 ] = SILK_FIX_CONST( 1, 16 );
+ psDec->sPLC.prevGain_Q16[ 1 ] = SILK_FIX_CONST( 1, 16 );
}
void silk_PLC(
@@ -155,8 +157,11 @@
silk_memcpy( psPLC->prevLPC_Q12, psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order * sizeof( opus_int16 ) );
psPLC->prevLTP_scale_Q14 = psDecCtrl->LTP_scale_Q14;
- /* Save Gains */
- silk_memcpy( psPLC->prevGain_Q16, psDecCtrl->Gains_Q16, psDec->nb_subfr * sizeof( opus_int32 ) );
+ /* Save last two gains */
+ silk_memcpy( psPLC->prevGain_Q16, &psDecCtrl->Gains_Q16[ psDec->nb_subfr - 2 ], 2 * sizeof( opus_int32 ) );
+
+ psPLC->subfr_length = psDec->subfr_length;
+ psPLC->nb_subfr = psDec->nb_subfr;
}
static inline void silk_PLC_conceal(
@@ -182,23 +187,23 @@
/* Find random noise component */
/* Scale previous excitation signal */
exc_buf_ptr = exc_buf;
- for( k = psDec->nb_subfr - 2; k < psDec->nb_subfr; k++ ) {
- for( i = 0; i < psDec->subfr_length; i++ ) {
+ for( k = 0; k < 2; k++ ) {
+ for( i = 0; i < psPLC->subfr_length; i++ ) {
exc_buf_ptr[ i ] = ( opus_int16 )silk_RSHIFT(
- silk_SMULWW( psDec->exc_Q10[ i + k * psDec->subfr_length ], psPLC->prevGain_Q16[ k ] ), 10 );
+ silk_SMULWW( psDec->exc_Q10[ i + ( k + psPLC->nb_subfr - 2 ) * psPLC->subfr_length ], psPLC->prevGain_Q16[ k ] ), 10 );
}
- exc_buf_ptr += psDec->subfr_length;
+ exc_buf_ptr += psPLC->subfr_length;
}
/* Find the subframe with lowest energy of the last two and use that as random noise generator */
- silk_sum_sqr_shift( &energy1, &shift1, exc_buf, psDec->subfr_length );
- silk_sum_sqr_shift( &energy2, &shift2, &exc_buf[ psDec->subfr_length ], psDec->subfr_length );
+ silk_sum_sqr_shift( &energy1, &shift1, exc_buf, psPLC->subfr_length );
+ silk_sum_sqr_shift( &energy2, &shift2, &exc_buf[ psDec->subfr_length ], psPLC->subfr_length );
if( silk_RSHIFT( energy1, shift2 ) < silk_RSHIFT( energy2, shift1 ) ) {
/* First sub-frame has lowest energy */
- rand_ptr = &psDec->exc_Q10[ silk_max_int( 0, psDec->frame_length - psDec->subfr_length - RAND_BUF_SIZE ) ];
+ rand_ptr = &psDec->exc_Q10[ silk_max_int( 0, ( psPLC->nb_subfr - 1 ) * psPLC->subfr_length - RAND_BUF_SIZE ) ];
} else {
/* Second sub-frame has lowest energy */
- rand_ptr = &psDec->exc_Q10[ silk_max_int( 0, psDec->frame_length - RAND_BUF_SIZE ) ];
+ rand_ptr = &psDec->exc_Q10[ silk_max_int( 0, psPLC->nb_subfr * psPLC->subfr_length - RAND_BUF_SIZE ) ];
}
/* Setup Gain to random noise component */
@@ -253,7 +258,7 @@
silk_assert( idx > 0 );
silk_LPC_analysis_filter( &sLTP[ idx ], &psDec->outBuf[ idx ], A_Q12, psDec->ltp_mem_length - idx, psDec->LPC_order );
/* Scale LTP state */
- inv_gain_Q16 = silk_INVERSE32_varQ( psPLC->prevGain_Q16[ psDec->nb_subfr - 1 ], 32 );
+ inv_gain_Q16 = silk_INVERSE32_varQ( psPLC->prevGain_Q16[ 1 ], 32 );
inv_gain_Q16 = silk_min( inv_gain_Q16, silk_int16_MAX );
inv_gain_Q30 = silk_LSHIFT( inv_gain_Q16, 14 );
for( i = idx + psDec->LPC_order; i < psDec->ltp_mem_length; i++ ) {
@@ -326,7 +331,7 @@
sLPC_Q14_ptr[ MAX_LPC_ORDER + i ] = silk_ADD_LSHIFT32( sLPC_Q14_ptr[ MAX_LPC_ORDER + i ], LPC_pred_Q10, 4 );
/* Scale with Gain */
- frame[ i ] = ( opus_int16 )silk_SAT16( silk_RSHIFT_ROUND( silk_SMULWW( sLPC_Q14_ptr[ MAX_LPC_ORDER + i ], psPLC->prevGain_Q16[ psDec->nb_subfr - 1 ] ), 14 ) );
+ frame[ i ] = ( opus_int16 )silk_SAT16( silk_RSHIFT_ROUND( silk_SMULWW( sLPC_Q14_ptr[ MAX_LPC_ORDER + i ], psPLC->prevGain_Q16[ 1 ] ), 14 ) );
}
/* Save LPC state */
@@ -342,7 +347,7 @@
}
}
-/* Glues concealed frames with new good recieved frames */
+/* Glues concealed frames with new good recieved frames */
void silk_PLC_glue_frames(
silk_decoder_state *psDec, /* I/O decoder state */
opus_int16 frame[], /* I/O signal */
--- a/silk/create_init_destroy.c
+++ /dev/null
@@ -1,56 +1,0 @@
-/***********************************************************************
-Copyright (c) 2006-2011, Skype Limited. All rights reserved.
-Redistribution and use in source and binary forms, with or without
-modification, (subject to the limitations in the disclaimer below)
-are permitted provided that the following conditions are met:
-- Redistributions of source code must retain the above copyright notice,
-this list of conditions and the following disclaimer.
-- Redistributions in binary form must reproduce the above copyright
-notice, this list of conditions and the following disclaimer in the
-documentation and/or other materials provided with the distribution.
-- Neither the name of Skype Limited, nor the names of specific
-contributors, may be used to endorse or promote products derived from
-this software without specific prior written permission.
-NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
-BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
-CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
-USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-***********************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "main.h"
-
-/************************/
-/* Init Decoder State */
-/************************/
-opus_int silk_init_decoder(
- silk_decoder_state *psDec /* I/O Decoder state pointer */
-)
-{
- /* Clear the entire encoder state, except anything copied */
- silk_memset( psDec, 0, sizeof( silk_decoder_state ) );
-
- /* Used to deactivate LSF interpolation */
- psDec->first_frame_after_reset = 1;
- psDec->prev_inv_gain_Q16 = 65536;
-
- /* Reset CNG state */
- silk_CNG_Reset( psDec );
-
- /* Reset PLC state */
- silk_PLC_Reset( psDec );
-
- return(0);
-}
-
--- /dev/null
+++ b/silk/init_decoder.c
@@ -1,0 +1,56 @@
+/***********************************************************************
+Copyright (c) 2006-2011, Skype Limited. All rights reserved.
+Redistribution and use in source and binary forms, with or without
+modification, (subject to the limitations in the disclaimer below)
+are permitted provided that the following conditions are met:
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+- Neither the name of Skype Limited, nor the names of specific
+contributors, may be used to endorse or promote products derived from
+this software without specific prior written permission.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "main.h"
+
+/************************/
+/* Init Decoder State */
+/************************/
+opus_int silk_init_decoder(
+ silk_decoder_state *psDec /* I/O Decoder state pointer */
+)
+{
+ /* Clear the entire encoder state, except anything copied */
+ silk_memset( psDec, 0, sizeof( silk_decoder_state ) );
+
+ /* Used to deactivate LSF interpolation */
+ psDec->first_frame_after_reset = 1;
+ psDec->prev_inv_gain_Q16 = 65536;
+
+ /* Reset CNG state */
+ silk_CNG_Reset( psDec );
+
+ /* Reset PLC state */
+ silk_PLC_Reset( psDec );
+
+ return(0);
+}
+
--- a/silk/silk_common.vcxproj
+++ b/silk/silk_common.vcxproj
@@ -97,7 +97,6 @@
<ClCompile Include="control_audio_bandwidth.c" />
<ClCompile Include="control_codec.c" />
<ClCompile Include="control_SNR.c" />
- <ClCompile Include="create_init_destroy.c" />
<ClCompile Include="debug.c" />
<ClCompile Include="decoder_set_fs.c" />
<ClCompile Include="decode_core.c" />
@@ -112,6 +111,7 @@
<ClCompile Include="enc_API.c" />
<ClCompile Include="gain_quant.c" />
<ClCompile Include="HP_variable_cutoff.c" />
+ <ClCompile Include="init_decoder.c" />
<ClCompile Include="init_encoder.c" />
<ClCompile Include="inner_prod_aligned.c" />
<ClCompile Include="interpolate.c" />
--- a/silk/silk_common.vcxproj.filters
+++ b/silk/silk_common.vcxproj.filters
@@ -51,9 +51,6 @@
<ClCompile Include="control_SNR.c">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="create_init_destroy.c">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="debug.c">
<Filter>Source Files</Filter>
</ClCompile>
@@ -244,6 +241,9 @@
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="VQ_WMat_EC.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="init_decoder.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
--- a/silk/structs.h
+++ b/silk/structs.h
@@ -237,8 +237,10 @@
opus_int32 conc_energy;
opus_int conc_energy_shift;
opus_int16 prevLTP_scale_Q14;
- opus_int32 prevGain_Q16[ MAX_NB_SUBFR ];
+ opus_int32 prevGain_Q16[ 2 ];
opus_int fs_kHz;
+ opus_int nb_subfr;
+ opus_int subfr_length;
} silk_PLC_struct;
/* Struct for CNG */