Fixing DTX for fixed-point too, updating project files
[opus.git] / src_FIX / SKP_Silk_control_codec_FIX.c
index 5c92427..b092460 100644 (file)
@@ -55,7 +55,7 @@ SKP_int SKP_Silk_control_encoder_FIX(
 {\r
     SKP_int   fs_kHz, ret = 0;\r
 \r
-    if( psEnc->sCmn.controlled_since_last_payload != 0 ) {\r
+    if( psEnc->sCmn.controlled_since_last_payload != 0 && psEnc->sCmn.prefillFlag == 0 ) {\r
         if( psEnc->sCmn.API_fs_Hz != psEnc->sCmn.prev_API_fs_Hz && psEnc->sCmn.fs_kHz > 0 ) {\r
             /* Change in API sampling rate in the middle of encoding a packet */\r
             ret += SKP_Silk_setup_resamplers( psEnc, psEnc->sCmn.fs_kHz );\r
@@ -176,9 +176,10 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
             ( PacketSize_ms !=  60 ) ) {\r
             ret = SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED;\r
         }\r
-        if( PacketSize_ms == 10 ) {\r
+        if( PacketSize_ms <= 10 ) {\r
             psEnc->sCmn.nFramesPerPacket = 1;\r
-            psEnc->sCmn.nb_subfr = MAX_NB_SUBFR >> 1;\r
+            psEnc->sCmn.nb_subfr = PacketSize_ms == 10 ? 2 : 1;\r
+            psEnc->sCmn.frame_length = SKP_SMULBB( PacketSize_ms, fs_kHz );\r
             psEnc->sCmn.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz );\r
             if( psEnc->sCmn.fs_kHz == 8 ) {\r
                 psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_NB_iCDF;\r
@@ -188,6 +189,7 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
         } else {\r
             psEnc->sCmn.nFramesPerPacket = SKP_DIV32_16( PacketSize_ms, MAX_FRAME_LENGTH_MS );\r
             psEnc->sCmn.nb_subfr = MAX_NB_SUBFR;\r
+            psEnc->sCmn.frame_length = SKP_SMULBB( 20, fs_kHz );\r
             psEnc->sCmn.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz );\r
             if( psEnc->sCmn.fs_kHz == 8 ) {\r
                 psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_NB_iCDF;\r
@@ -195,10 +197,13 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
                 psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_iCDF; \r
             }\r
         }\r
-        psEnc->sCmn.PacketSize_ms = PacketSize_ms;\r
+        psEnc->sCmn.PacketSize_ms  = PacketSize_ms;\r
+        psEnc->sCmn.TargetRate_bps = 0;         /* trigger new SNR computation */\r
     }\r
 \r
     /* Set internal sampling frequency */\r
+    SKP_assert( fs_kHz == 8 || fs_kHz == 12 || fs_kHz == 16 );\r
+    SKP_assert( psEnc->sCmn.nb_subfr == 2 || psEnc->sCmn.nb_subfr == 4 );\r
     if( psEnc->sCmn.fs_kHz != fs_kHz ) {\r
         /* reset part of the state */\r
         SKP_memset( &psEnc->sShape,               0, sizeof( SKP_Silk_shape_state_FIX ) );\r
@@ -220,42 +225,34 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
 \r
         psEnc->sCmn.fs_kHz = fs_kHz;\r
         if( psEnc->sCmn.fs_kHz == 8 ) {\r
-            psEnc->sCmn.predictLPCOrder = MIN_LPC_ORDER;\r
-            psEnc->sCmn.psNLSF_CB[ 0 ]  = &SKP_Silk_NLSF_CB0_10;\r
-            psEnc->sCmn.psNLSF_CB[ 1 ]  = &SKP_Silk_NLSF_CB1_10;\r
-            if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ){\r
+            if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) {\r
                 psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_NB_iCDF; \r
-            } else if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR / 2 ){\r
-                psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_NB_iCDF;\r
             } else {\r
-                /* Unsupported number of frames */\r
-                SKP_assert( 0 );\r
+                psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_NB_iCDF;\r
             }\r
         } else {\r
-            psEnc->sCmn.predictLPCOrder = MAX_LPC_ORDER;\r
-            psEnc->sCmn.psNLSF_CB[ 0 ]  = &SKP_Silk_NLSF_CB0_16;\r
-            psEnc->sCmn.psNLSF_CB[ 1 ]  = &SKP_Silk_NLSF_CB1_16;\r
-            if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ){\r
+            if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) {\r
                 psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_iCDF; \r
-            } else if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR / 2 ){\r
-                psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_iCDF;\r
             } else {\r
-                /* Unsupported number of frames */\r
-                SKP_assert( 0 );\r
+                psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_iCDF;\r
             }\r
         }\r
+        if( psEnc->sCmn.fs_kHz == 8 || psEnc->sCmn.fs_kHz == 12 ) {\r
+            psEnc->sCmn.predictLPCOrder = MIN_LPC_ORDER;\r
+            psEnc->sCmn.psNLSF_CB  = &SKP_Silk_NLSF_CB_NB_MB;\r
+        } else {\r
+            psEnc->sCmn.predictLPCOrder = MAX_LPC_ORDER;\r
+            psEnc->sCmn.psNLSF_CB  = &SKP_Silk_NLSF_CB_WB;\r
+        }\r
         psEnc->sCmn.subfr_length   = SUB_FRAME_LENGTH_MS * fs_kHz;\r
         psEnc->sCmn.frame_length   = SKP_SMULBB( psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr );\r
         psEnc->sCmn.ltp_mem_length = SKP_SMULBB( LTP_MEM_LENGTH_MS, fs_kHz ); \r
         psEnc->sCmn.la_pitch       = SKP_SMULBB( LA_PITCH_MS, fs_kHz );\r
         psEnc->sCmn.max_pitch_lag  = SKP_SMULBB( 18, fs_kHz );\r
-        if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ){\r
+        if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) {\r
             psEnc->sCmn.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz );\r
-        } else if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR / 2 ){\r
-            psEnc->sCmn.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz );\r
         } else {\r
-            /* Unsupported number of frames */\r
-            SKP_assert( 0 );\r
+            psEnc->sCmn.pitch_LPC_win_length = SKP_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz );\r
         }\r
         if( psEnc->sCmn.fs_kHz == 16 ) {\r
             psEnc->sCmn.mu_LTP_Q9 = SKP_FIX_CONST( MU_LTP_QUANT_WB, 9 );\r
@@ -263,12 +260,9 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
         } else if( psEnc->sCmn.fs_kHz == 12 ) {\r
             psEnc->sCmn.mu_LTP_Q9 = SKP_FIX_CONST( MU_LTP_QUANT_MB, 9 );\r
             psEnc->sCmn.pitch_lag_low_bits_iCDF = SKP_Silk_uniform6_iCDF;\r
-        } else if( psEnc->sCmn.fs_kHz == 8 ) {\r
+        } else {\r
             psEnc->sCmn.mu_LTP_Q9 = SKP_FIX_CONST( MU_LTP_QUANT_NB, 9 );\r
             psEnc->sCmn.pitch_lag_low_bits_iCDF = SKP_Silk_uniform4_iCDF;\r
-        } else {\r
-            /* unsupported sampling rate */\r
-            SKP_assert( 0 );\r
         }\r
     }\r
 \r