Update SILK code using the CELT range coder
[opus.git] / src_common / SKP_Silk_main.h
similarity index 78%
rename from src/SKP_Silk_main.h
rename to src_common/SKP_Silk_main.h
index d5b0a73..eddcddc 100644 (file)
@@ -33,6 +33,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "SKP_Silk_structs.h"\r
 #include "SKP_Silk_tables.h"\r
 #include "SKP_Silk_PLC.h"\r
+#include "SKP_debug.h"\r
+#include "entenc.h"\r
+#include "entdec.h"\r
 \r
 #ifdef __cplusplus\r
 extern "C"\r
@@ -42,7 +45,7 @@ extern "C"
 /* Encodes signs of excitation */\r
 void SKP_Silk_encode_signs(\r
     SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */\r
-    const SKP_int               q[],                /* I    pulse signal                                */\r
+    const SKP_int8              q[],                /* I    pulse signal                                */\r
     const SKP_int               length,             /* I    length of input                             */\r
     const SKP_int               sigtype,            /* I    Signal type                                 */\r
     const SKP_int               QuantOffsetType,    /* I    Quantization offset type                    */\r
@@ -68,7 +71,7 @@ void SKP_Silk_encode_pulses(
     SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */\r
     const SKP_int               sigtype,            /* I    Sigtype                                     */\r
     const SKP_int               QuantOffsetType,    /* I    QuantOffsetType                             */\r
-    const SKP_int               q[],                /* I    quantization indices                        */\r
+    SKP_int8                    q[],                /* I    quantization indices                        */\r
     const SKP_int               frame_length        /* I    Frame length                                */\r
 );\r
 \r
@@ -95,6 +98,13 @@ void SKP_Silk_range_encoder(
     const SKP_uint16            prob[]              /* I    cumulative density functions                */\r
 );\r
     \r
+/* Range encoder for one symbol, with uniform PDF*/\r
+void SKP_Silk_range_encode_uniform(\r
+    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */\r
+    const SKP_int                   data,               /* I    uncompressed data                           */\r
+    const SKP_int                   N                   /* I    number of possible outcomes                 */\r
+);\r
+\r
 /* Range encoder for multiple symbols */\r
 void SKP_Silk_range_encoder_multi(\r
     SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */\r
@@ -111,6 +121,13 @@ void SKP_Silk_range_decoder(
     SKP_int                     probIx              /* I    initial (middle) entry of cdf               */\r
 );\r
 \r
+/* Range decoder for one symbol, with uniform PDF*/\r
+void SKP_Silk_range_decode_uniform(\r
+    SKP_int                         data[],             /* O    uncompressed data                           */\r
+    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */\r
+    const SKP_int                   N                   /* I    number of possible outcomes                 */\r
+);\r
+\r
 /* Range decoder for multiple symbols */\r
 void SKP_Silk_range_decoder_multi(\r
     SKP_int                     data[],             /* O    uncompressed data                [nSymbols] */\r
@@ -133,14 +150,15 @@ void SKP_Silk_range_dec_init(
 );\r
 \r
 /* Determine length of bitstream */\r
-SKP_int SKP_Silk_range_coder_get_length(            /* O    returns number of BITS in stream            */\r
-    const SKP_Silk_range_coder_state    *psRC,      /* I    compressed data structure                   */\r
+SKP_int SKP_Silk_range_encoder_get_length(          /* O    returns number of BITS in stream            */\r
+    SKP_Silk_range_coder_state          *psRC,      /* I    compressed data structure                   */\r
     SKP_int                             *nBytes     /* O    number of BYTES in stream                   */\r
 );\r
 \r
-/* Write decodable stream to buffer, and determine its length */\r
-void SKP_Silk_range_enc_wrap_up(\r
-    SKP_Silk_range_coder_state  *psRC               /* I/O  compressed data structure                   */\r
+/* Determine length of bitstream */\r
+SKP_int SKP_Silk_range_decoder_get_length(          /* O    returns number of BITS in stream            */\r
+    SKP_Silk_range_coder_state          *psRC,      /* I    compressed data structure                   */\r
+    SKP_int                             *nBytes     /* O    number of BYTES in stream                   */\r
 );\r
 \r
 /* Check that any remaining bits in the last byte are set to 1 */\r
@@ -150,18 +168,20 @@ void SKP_Silk_range_coder_check_after_decoding(
 \r
 /* Gain scalar quantization with hysteresis, uniform on log scale */\r
 void SKP_Silk_gains_quant(\r
-    SKP_int                     ind[ NB_SUBFR ],        /* O    gain indices                            */\r
-    SKP_int32                   gain_Q16[ NB_SUBFR ],   /* I/O  gains (quantized out)                   */\r
-    SKP_int                     *prev_ind,              /* I/O  last index in previous frame            */\r
-    const SKP_int               conditional             /* I    first gain is delta coded if 1          */\r
+    SKP_int                         ind[ MAX_NB_SUBFR ],        /* O    gain indices                            */\r
+    SKP_int32                       gain_Q16[ MAX_NB_SUBFR ],   /* I/O  gains (quantized out)                   */\r
+    SKP_int                         *prev_ind,                  /* I/O  last index in previous frame            */\r
+    const SKP_int                   conditional,                /* I    first gain is delta coded if 1          */\r
+    const SKP_int                   nb_subfr                    /* I    number of subframes                     */\r
 );\r
 \r
 /* Gains scalar dequantization, uniform on log scale */\r
 void SKP_Silk_gains_dequant(\r
-    SKP_int32                   gain_Q16[ NB_SUBFR ],   /* O    quantized gains                         */\r
-    const SKP_int               ind[ NB_SUBFR ],        /* I    gain indices                            */\r
-    SKP_int                     *prev_ind,              /* I/O  last index in previous frame            */\r
-    const SKP_int               conditional             /* I    first gain is delta coded if 1          */\r
+    SKP_int32                       gain_Q16[ MAX_NB_SUBFR ],   /* O    quantized gains                         */\r
+    const SKP_int                   ind[ MAX_NB_SUBFR ],        /* I    gain indices                            */\r
+    SKP_int                         *prev_ind,                  /* I/O  last index in previous frame            */\r
+    const SKP_int                   conditional,                /* I    first gain is delta coded if 1          */\r
+    const SKP_int                   nb_subfr                    /* I    number of subframes                     */\r
 );\r
 \r
 /* Convert NLSF parameters to stable AR prediction filter coefficients */\r
@@ -188,15 +208,15 @@ void SKP_Silk_NSQ(
     SKP_Silk_encoder_control        *psEncCtrlC,                                /* I    Encoder Control                     */\r
     SKP_Silk_nsq_state              *NSQ,                                       /* I/O  NSQ state                           */\r
     const SKP_int16                 x[],                                        /* I    prefiltered input signal            */\r
-    SKP_int                         q[],                                        /* O    quantized qulse signal              */\r
+    SKP_int8                        q[],                                        /* O    quantized qulse signal              */\r
     const SKP_int                   LSFInterpFactor_Q2,                         /* I    LSF interpolation factor in Q2      */\r
     const SKP_int16                 PredCoef_Q12[ 2 * MAX_LPC_ORDER ],          /* I    Short term prediction coefficients  */\r
-    const SKP_int16                 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],        /* I    Long term prediction coefficients   */\r
-    const SKP_int16                 AR2_Q13[ NB_SUBFR * SHAPE_LPC_ORDER_MAX ],  /* I                                        */\r
-    const SKP_int                   HarmShapeGain_Q14[ NB_SUBFR ],              /* I                                        */\r
-    const SKP_int                   Tilt_Q14[ NB_SUBFR ],                       /* I    Spectral tilt                       */\r
-    const SKP_int32                 LF_shp_Q14[ NB_SUBFR ],                     /* I                                        */\r
-    const SKP_int32                 Gains_Q16[ NB_SUBFR ],                      /* I                                        */\r
+    const SKP_int16                 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ],        /* I    Long term prediction coefficients   */\r
+    const SKP_int16                 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ],  /* I                                    */\r
+    const SKP_int                   HarmShapeGain_Q14[ MAX_NB_SUBFR ],              /* I                                    */\r
+    const SKP_int                   Tilt_Q14[ MAX_NB_SUBFR ],                       /* I    Spectral tilt                   */\r
+    const SKP_int32                 LF_shp_Q14[ MAX_NB_SUBFR ],                     /* I                                    */\r
+    const SKP_int32                 Gains_Q16[ MAX_NB_SUBFR ],                      /* I                                    */\r
     const SKP_int                   Lambda_Q10,                                 /* I                                        */\r
     const SKP_int                   LTP_scale_Q14                               /* I    LTP state scaling                   */\r
 );\r
@@ -207,15 +227,15 @@ void SKP_Silk_NSQ_del_dec(
     SKP_Silk_encoder_control        *psEncCtrlC,                                /* I    Encoder Control                     */\r
     SKP_Silk_nsq_state              *NSQ,                                       /* I/O  NSQ state                           */\r
     const SKP_int16                 x[],                                        /* I    Prefiltered input signal            */\r
-    SKP_int                         q[],                                        /* O    Quantized pulse signal              */\r
+    SKP_int8                        q[],                                        /* O    Quantized pulse signal              */\r
     const SKP_int                   LSFInterpFactor_Q2,                         /* I    LSF interpolation factor in Q2      */\r
     const SKP_int16                 PredCoef_Q12[ 2 * MAX_LPC_ORDER ],          /* I    Prediction coefs                    */\r
-    const SKP_int16                 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ],        /* I    LT prediction coefs                 */\r
-    const SKP_int16                 AR2_Q13[ NB_SUBFR * SHAPE_LPC_ORDER_MAX ],  /* I                                        */\r
-    const SKP_int                   HarmShapeGain_Q14[ NB_SUBFR ],              /* I                                        */\r
-    const SKP_int                   Tilt_Q14[ NB_SUBFR ],                       /* I    Spectral tilt                       */\r
-    const SKP_int32                 LF_shp_Q14[ NB_SUBFR ],                     /* I                                        */\r
-    const SKP_int32                 Gains_Q16[ NB_SUBFR ],                      /* I                                        */\r
+    const SKP_int16                 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ],        /* I    LT prediction coefs                 */\r
+    const SKP_int16                 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ],  /* I                                        */\r
+    const SKP_int                   HarmShapeGain_Q14[ MAX_NB_SUBFR ],              /* I                                        */\r
+    const SKP_int                   Tilt_Q14[ MAX_NB_SUBFR ],                       /* I    Spectral tilt                       */\r
+    const SKP_int32                 LF_shp_Q14[ MAX_NB_SUBFR ],                     /* I                                        */\r
+    const SKP_int32                 Gains_Q16[ MAX_NB_SUBFR ],                      /* I                                        */\r
     const SKP_int                   Lambda_Q10,                                 /* I                                        */\r
     const SKP_int                   LTP_scale_Q14                               /* I    LTP state scaling                   */\r
 );\r
@@ -238,11 +258,11 @@ void SKP_Silk_VAD_GetNoiseLevels(
 SKP_int SKP_Silk_VAD_GetSA_Q8(                                  /* O    Return value, 0 if success      */\r
     SKP_Silk_VAD_state          *psSilk_VAD,                    /* I/O  Silk VAD state                  */\r
     SKP_int                     *pSA_Q8,                        /* O    Speech activity level in Q8     */\r
-    SKP_int                     *pSNR_dB_Q7,                    /* O    SNR for current frame in Q7     */\r
     SKP_int                     pQuality_Q15[ VAD_N_BANDS ],    /* O    Smoothed SNR for each band      */\r
     SKP_int                     *pTilt_Q15,                     /* O    current frame's frequency tilt  */\r
     const SKP_int16             pIn[],                          /* I    PCM input       [framelength]   */\r
-    const SKP_int               framelength                     /* I    Input frame length              */\r
+    const SKP_int               framelength,                    /* I    Input frame length              */\r
+    const SKP_int               fs_kHz                          /* I    Input frame sample frequency    */\r
 );\r
 \r
 /* Detect signal in 8 - 12 khz range */\r
@@ -281,8 +301,9 @@ SKP_int SKP_Silk_init_decoder(
 \r
 /* Set decoder sampling rate */\r
 void SKP_Silk_decoder_set_fs(\r
-    SKP_Silk_decoder_state      *psDec,             /* I/O  Decoder state pointer                       */\r
-    SKP_int                     fs_kHz              /* I    Sampling frequency (kHz)                    */\r
+    SKP_Silk_decoder_state          *psDec,             /* I/O  Decoder state pointer                       */\r
+    SKP_int                         fs_kHz,             /* I    Sampling frequency (kHz)                    */\r
+    SKP_int                         nb_subfr            /* I    Number of subframes                         */\r
 );\r
 \r
 /****************/\r
@@ -298,14 +319,6 @@ SKP_int SKP_Silk_decode_frame(
     SKP_int                     *decBytes           /* O    Used bytes to decode this frame             */\r
 );\r
 \r
-/* Decode parameters from payload */\r
-void SKP_Silk_decode_parameters(\r
-    SKP_Silk_decoder_state      *psDec,             /* I/O  State                                       */\r
-    SKP_Silk_decoder_control    *psDecCtrl,         /* I/O  Decoder control                             */\r
-    SKP_int                     q[],                /* O    Excitation signal                           */\r
-    const SKP_int               fullDecoding        /* I    Flag to tell if only arithmetic decoding    */\r
-);\r
-\r
 /* Decode indices from payload v4 Bitstream */\r
 void SKP_Silk_decode_indices_v4(\r
     SKP_Silk_decoder_state      *psDec              /* I/O  State                                       */\r
@@ -365,14 +378,6 @@ void SKP_Silk_CNG(
 );\r
 \r
 /* Encoding of various parameters */\r
-void SKP_Silk_encode_parameters(\r
-    SKP_Silk_encoder_state      *psEncC,            /* I/O  Encoder state                               */\r
-    SKP_Silk_encoder_control    *psEncCtrlC,        /* I/O  Encoder control                             */\r
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */\r
-    const SKP_int               *q                  /* I    Quantization indices                        */\r
-);\r
-\r
-/* Encoding of various parameters */\r
 void SKP_Silk_encode_parameters_v4(\r
     SKP_Silk_encoder_state      *psEncC,            /* I/O  Encoder state                               */\r
     SKP_Silk_encoder_control    *psEncCtrlC,        /* I/O  Encoder control                             */\r
@@ -395,7 +400,7 @@ void SKP_Silk_LBRR_reset(
 /* Predict number of bytes used to encode q */\r
 SKP_int SKP_Silk_pulses_to_bytes( /* O  Return value, predicted number of bytes used to encode q */ \r
     SKP_Silk_encoder_state      *psEncC,            /* I/O  Encoder State*/\r
-    SKP_int                     q[]                 /* I     Pulse signal */\r
+    SKP_int8                    q[]                 /* I     Pulse signal */\r
 );\r
 \r
 #ifdef __cplusplus\r