Squashed commit of the following:
authorKoen Vos <koen.vos@skype.net>
Wed, 27 Apr 2011 04:49:40 +0000 (00:49 -0400)
committerJean-Marc Valin <jean-marc.valin@usherbrooke.ca>
Wed, 27 Apr 2011 04:49:40 +0000 (00:49 -0400)
commit c44b37355295df2963daa724649ff1876b690488
Author: Jean-Marc Valin <jean-marc.valin@usherbrooke.ca>
Date:   Wed Apr 27 00:33:12 2011 -0400

    decoder size fix

commit 78f864e9ddacd94d03d717d79a6e606712e25edd
Author: Jean-Marc Valin <jean-marc.valin@usherbrooke.ca>
Date:   Tue Apr 26 23:26:14 2011 -0400

    Makefile fix

commit a0e884e463af88bcaa2f410ea8cc85e5bebd2c3b
Author: Jean-Marc Valin <jean-marc.valin@usherbrooke.ca>
Date:   Tue Apr 26 22:53:27 2011 -0400

    Making some progress

commit 9e30457f2199bba7b5e37bb577ff75dc85ba9306
Author: Koen Vos <koen.vos@skype.net>
Date:   Tue Apr 26 22:29:42 2011 -0400

    SILK update with stereo support

77 files changed:
Makefile.am
autogen.sh [changed mode: 0755->0644]
interface/SKP_Silk_SDK_API.h
interface/SKP_Silk_control.h
interface/SKP_Silk_errors.h
src_FIX/SKP_Silk_LTP_scale_ctrl_FIX.c
src_FIX/SKP_Silk_encode_frame_FIX.c
src_FIX/SKP_Silk_main_FIX.h
src_FIX/SKP_Silk_noise_shape_analysis_FIX.c
src_FIX/SKP_Silk_process_gains_FIX.c
src_FIX/SKP_Silk_structs_FIX.h
src_FIX/src_FIX.vcxproj
src_FIX/src_FIX.vcxproj.filters
src_FLP/SKP_Silk_LTP_scale_ctrl_FLP.c
src_FLP/SKP_Silk_control_codec_FLP.c [deleted file]
src_FLP/SKP_Silk_encode_frame_FLP.c
src_FLP/SKP_Silk_init_encoder_FLP.c [deleted file]
src_FLP/SKP_Silk_main_FLP.h
src_FLP/SKP_Silk_noise_shape_analysis_FLP.c
src_FLP/SKP_Silk_process_gains_FLP.c
src_FLP/SKP_Silk_structs_FLP.h
src_FLP/src_FLP.vcxproj
src_FLP/src_FLP.vcxproj.filters
src_SigProc_FIX/SKP_Silk_SigProc_FIX.h
src_SigProc_FIX/SKP_Silk_allpass_int.c [deleted file]
src_SigProc_FIX/SKP_Silk_autocorr.c
src_SigProc_FIX/SKP_Silk_debug.c
src_SigProc_FIX/SKP_Silk_inner_prod_aligned.c
src_SigProc_FIX/SKP_Silk_lowpass_int.c [deleted file]
src_SigProc_FIX/SKP_Silk_resampler_private_up2_HQ.c
src_SigProc_FIX/SKP_Silk_resampler_private_up4.c
src_SigProc_FIX/SKP_Silk_resampler_rom.h
src_SigProc_FIX/SKP_Silk_resampler_structs.h
src_SigProc_FIX/SKP_Silk_scale_vector.c
src_SigProc_FIX/SKP_Silk_schur64.c
src_SigProc_FIX/SKP_Silk_sum_sqr_shift.c
src_SigProc_FLP/SKP_Silk_SigProc_FLP.h
src_SigProc_FLP/SKP_Silk_sort_FLP.c
src_common/SKP_Silk_LBRR_embed.c [deleted file]
src_common/SKP_Silk_LP_variable_cutoff.c
src_common/SKP_Silk_NLSF_MSVQ_decode.c [deleted file]
src_common/SKP_Silk_NLSF_MSVQ_encode.c [deleted file]
src_common/SKP_Silk_NLSF_VQ_rate_distortion.c [deleted file]
src_common/SKP_Silk_NLSF_VQ_sum_error.c [deleted file]
src_common/SKP_Silk_PLC.c
src_common/SKP_Silk_PLC.h
src_common/SKP_Silk_check_control_input.c [new file with mode: 0644]
src_common/SKP_Silk_control_SNR.c [moved from src_SigProc_FIX/SKP_Silk_lowpass_short.c with 51% similarity]
src_common/SKP_Silk_control_audio_bandwidth.c
src_common/SKP_Silk_control_codec.c [moved from src_FIX/SKP_Silk_control_codec_FIX.c with 55% similarity]
src_common/SKP_Silk_dec_API.c
src_common/SKP_Silk_decode_frame.c
src_common/SKP_Silk_decode_indices.c
src_common/SKP_Silk_decoder_set_fs.c
src_common/SKP_Silk_define.h
src_common/SKP_Silk_enc_API.c
src_common/SKP_Silk_encode_indices.c
src_common/SKP_Silk_init_encoder.c [moved from src_FIX/SKP_Silk_init_encoder_FIX.c with 85% similarity]
src_common/SKP_Silk_main.h
src_common/SKP_Silk_process_NLSFs.c
src_common/SKP_Silk_setup.h [deleted file]
src_common/SKP_Silk_stereo_LR_to_MS.c [new file with mode: 0644]
src_common/SKP_Silk_stereo_MS_to_LR.c [new file with mode: 0644]
src_common/SKP_Silk_structs.h
src_common/SKP_Silk_tables.h
src_common/SKP_Silk_tables_NLSF_CB.h [deleted file]
src_common/SKP_Silk_tables_NLSF_CB0_10.c [deleted file]
src_common/SKP_Silk_tables_NLSF_CB0_16.c [deleted file]
src_common/SKP_Silk_tables_NLSF_CB1_10.c [deleted file]
src_common/SKP_Silk_tables_NLSF_CB1_16.c [deleted file]
src_common/SKP_Silk_tables_other.c
src_common/SKP_Silk_tuning_parameters.h
src_common/src_common.vcxproj
src_common/src_common.vcxproj.filters
test/Decoder.c [deleted file]
test/Encoder.c [deleted file]
test/signalCompare.c [deleted file]

index cd8082e..0ea06d7 100644 (file)
@@ -10,9 +10,6 @@ src_FLP/src_FLP.vcxproj \
 src_FLP/src_FLP.vcxproj.filters \
 src_common/src_common.vcxproj \
 src_common/src_common.vcxproj.filters \
-test/Encoder.c \
-test/Decoder.c \
-test/signalCompare.c \
 src_SigProc_FLP/src_SigProc_FLP.vcxproj \
 src_SigProc_FLP/src_SigProc_FLP.vcxproj.filters \
 src_SigProc_FIX/src_SigProc_FIX.vcxproj \
@@ -39,7 +36,6 @@ src_common/SKP_Silk_encode_indices.c \
 src_common/SKP_Silk_encode_pulses.c \
 src_common/SKP_Silk_gain_quant.c \
 src_common/SKP_Silk_interpolate.c \
-src_common/SKP_Silk_LBRR_embed.c \
 src_common/SKP_Silk_LP_variable_cutoff.c \
 src_common/SKP_Silk_NLSF2A_stable.c \
 src_common/SKP_Silk_NLSF_decode.c \
@@ -64,6 +60,12 @@ src_common/SKP_Silk_NLSF_VQ.c \
 src_common/SKP_Silk_NLSF_unpack.c \
 src_common/SKP_Silk_NLSF_del_dec_quant.c \
 src_common/SKP_Silk_process_NLSFs.c \
+src_common/SKP_Silk_stereo_LR_to_MS.c \
+src_common/SKP_Silk_stereo_MS_to_LR.c \
+src_common/SKP_Silk_control_SNR.c \
+src_common/SKP_Silk_init_encoder.c \
+src_common/SKP_Silk_control_codec.c \
+src_common/SKP_Silk_check_control_input.c \
 src_SigProc_FIX/SKP_Silk_A2NLSF.c \
 src_SigProc_FIX/SKP_Silk_ana_filt_bank_1.c \
 src_SigProc_FIX/SKP_Silk_apply_sine_window.c \
@@ -149,14 +151,12 @@ src_FIX/SKP_Silk_warped_autocorrelation_FIX.c
 else
 libSKP_SILK_SDK_la_SOURCES += \
 src_FLP/SKP_Silk_apply_sine_window_FLP.c \
-src_FLP/SKP_Silk_control_codec_FLP.c \
 src_FLP/SKP_Silk_corrMatrix_FLP.c \
 src_FLP/SKP_Silk_encode_frame_FLP.c \
 src_FLP/SKP_Silk_find_LPC_FLP.c \
 src_FLP/SKP_Silk_find_LTP_FLP.c \
 src_FLP/SKP_Silk_find_pitch_lags_FLP.c \
 src_FLP/SKP_Silk_find_pred_coefs_FLP.c \
-src_FLP/SKP_Silk_init_encoder_FLP.c \
 src_FLP/SKP_Silk_LPC_analysis_filter_FLP.c \
 src_FLP/SKP_Silk_LTP_analysis_filter_FLP.c \
 src_FLP/SKP_Silk_LTP_scale_ctrl_FLP.c \
@@ -185,7 +185,6 @@ src_common/SKP_Silk_PLC.h \
 src_common/SKP_Silk_structs.h \
 src_common/SKP_Silk_tables.h \
 src_common/SKP_Silk_tuning_parameters.h \
-src_common/SKP_Silk_setup.h \
 src_FIX/SKP_Silk_main_FIX.h \
 src_FIX/SKP_Silk_structs_FIX.h \
 src_FLP/SKP_Silk_assembler_FLP.h \
@@ -202,17 +201,4 @@ src_SigProc_FIX/SKP_Silk_resampler_structs.h \
 src_SigProc_FIX/SKP_Silk_SigProc_FIX.h \
 src_SigProc_FLP/SKP_Silk_SigProc_FLP.h
 
-bin_PROGRAMS = Encoder Decoder signalCompare
-Encoder_SOURCES = test/Encoder.c $(top_builddir)/interface/SKP_Silk_SDK_API.h
-Encoder_LDADD = $(lib_LTLIBRARIES) 
-Encoder_LDFLAGS = $(LIBS)
-
-Decoder_SOURCES = test/Decoder.c $(top_builddir)/interface/SKP_Silk_SDK_API.h
-Decoder_LDADD = $(lib_LTLIBRARIES) 
-Decoder_LDFLAGS = $(LIBS)
-
-signalCompare_SOURCES = test/signalCompare.c $(top_builddir)/interface/SKP_Silk_SDK_API.h
-signalCompare_LDADD = $(lib_LTLIBRARIES) 
-signalCompare_LDFLAGS = $(LIBS)
-
 LIBS = ../celt/libcelt/libcelt0.la
old mode 100755 (executable)
new mode 100644 (file)
index 166700b..fcbfc7f 100644 (file)
@@ -108,16 +108,6 @@ SKP_int SKP_Silk_SDK_InitDecoder(                       /* O:   Returns error co
     void                                *decState       /* I/O: State                                           */\r
 );\r
 \r
-/************************************************************************************************/\r
-/* Prefill LPC synthesis buffer, HP filter and upsampler. Input must be exactly 10 ms of audio. */\r
-/************************************************************************************************/\r
-SKP_int SKP_Silk_SDK_Decoder_prefill_buffers(           /* O:   Returns error code                              */\r
-    void*                               decState,       /* I/O: State                                           */\r
-    SKP_SILK_SDK_DecControlStruct*      decControl,     /* I/O: Control Structure                               */\r
-    const SKP_int16                     *samplesIn,     /* I:   Speech sample input vector  (10 ms)             */\r
-    SKP_int                             nSamplesIn      /* I:   Number of samples in input vector               */\r
-);\r
-\r
 /******************/\r
 /* Decode a frame */\r
 /******************/\r
@@ -127,7 +117,6 @@ SKP_int SKP_Silk_SDK_Decode(                            /* O:   Returns error co
     SKP_int                             lostFlag,       /* I:   0: no loss, 1 loss, 2 decode fec                */\r
     SKP_int                             newPacketFlag,  /* I:   Indicates first decoder call for this packet    */\r
     ec_dec                              *psRangeDec,    /* I/O  Compressor data structure                       */\r
-    const SKP_int                       nBytesIn,       /* I:   Number of input bytes                           */\r
     SKP_int16                           *samplesOut,    /* O:   Decoded output speech vector                    */\r
     SKP_int32                           *nSamplesOut    /* O:   Number of samples decoded                       */\r
 );\r
index 0e283fb..6d81af0 100644 (file)
@@ -35,10 +35,18 @@ extern "C"
 {\r
 #endif\r
 \r
+/* Decoder API flags */\r
+#define FLAG_DECODE_NORMAL                      0\r
+#define FLAG_PACKET_LOST                        1\r
+#define FLAG_DECODE_LBRR                        2\r
+\r
 /***********************************************/\r
 /* Structure for controlling encoder operation */\r
 /***********************************************/\r
 typedef struct {\r
+    /* I:   Number of channels; 1/2                                                         */\r
+    SKP_int32 nChannels;\r
+\r
     /* I:   Input signal sampling rate in Hertz; 8000/12000/16000/24000/32000/44100/48000   */\r
     SKP_int32 API_sampleRate;\r
 \r
@@ -77,6 +85,9 @@ typedef struct {
 /* Structure for controlling decoder operation and reading decoder status */\r
 /**************************************************************************/\r
 typedef struct {\r
+    /* I:   Number of channels; 1/2                                                         */\r
+    SKP_int32 nChannels;\r
+\r
     /* I:   Output signal sampling rate in Hertz; 8000/12000/16000/24000/32000/44100/48000  */\r
     SKP_int32 API_sampleRate;\r
 \r
index c751d9b..b7f194f 100644 (file)
@@ -72,6 +72,9 @@ extern "C"
 /* Internal encoder error */\r
 #define SKP_SILK_ENC_INTERNAL_ERROR                     -110\r
 \r
+/* Internal encoder error */\r
+#define SKP_SILK_ENC_INVALID_NUMBER_OF_CHANNELS_ERROR   -111\r
+\r
 /**************************/\r
 /* Decoder error messages */\r
 /**************************/\r
index 090e003..0851605 100644 (file)
@@ -27,53 +27,26 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 \r
 #include "SKP_Silk_main_FIX.h"\r
 \r
-#define NB_THRESHOLDS           11\r
-\r
-/* Table containing trained thresholds for LTP scaling */\r
-static const SKP_int16 LTPScaleThresholds_Q15[ NB_THRESHOLDS ] = \r
-{\r
-    31129, 26214, 16384, 13107, 9830, 6554,\r
-     4915,  3276,  2621,  2458,    0\r
-};\r
-\r
 void SKP_Silk_LTP_scale_ctrl_FIX(\r
     SKP_Silk_encoder_state_FIX      *psEnc,     /* I/O  encoder state FIX                           */\r
     SKP_Silk_encoder_control_FIX    *psEncCtrl  /* I/O  encoder control FIX                         */\r
 )\r
 {\r
     SKP_int round_loss;\r
-    SKP_int g_out_Q5, g_limit_Q15, thrld1_Q15, thrld2_Q15;\r
 \r
     /* 1st order high-pass filter */\r
-    psEnc->HPLTPredCodGain_Q7 = SKP_max_int( psEncCtrl->LTPredCodGain_Q7 - psEnc->prevLTPredCodGain_Q7, 0 ) \r
-        + SKP_RSHIFT_ROUND( psEnc->HPLTPredCodGain_Q7, 1 );\r
-    \r
+    psEnc->HPLTPredCodGain_Q7 = SKP_max_int( psEncCtrl->LTPredCodGain_Q7 - SKP_RSHIFT( psEnc->prevLTPredCodGain_Q7, 1 ), 0 ) \r
+        + SKP_RSHIFT( psEnc->HPLTPredCodGain_Q7, 1 );\r
     psEnc->prevLTPredCodGain_Q7 = psEncCtrl->LTPredCodGain_Q7;\r
 \r
-    /* combine input and filtered input */\r
-    g_out_Q5    = SKP_RSHIFT_ROUND( SKP_RSHIFT( psEncCtrl->LTPredCodGain_Q7, 1 ) + SKP_RSHIFT( psEnc->HPLTPredCodGain_Q7, 1 ), 3 );\r
-    g_limit_Q15 = SKP_Silk_sigm_Q15( g_out_Q5 - ( 3 << 5 ) );\r
-            \r
-    /* Default is minimum scaling */\r
-    psEnc->sCmn.indices.LTP_scaleIndex = 0;\r
-\r
-    /* Round the loss measure to whole pct */\r
-    round_loss = ( SKP_int )psEnc->sCmn.PacketLoss_perc;\r
-\r
     /* Only scale if first frame in packet */\r
     if( psEnc->sCmn.nFramesAnalyzed == 0 ) {\r
-        \r
-        round_loss += psEnc->sCmn.nFramesPerPacket - 1;\r
-        thrld1_Q15 = LTPScaleThresholds_Q15[ SKP_min_int( round_loss,     NB_THRESHOLDS - 1 ) ];\r
-        thrld2_Q15 = LTPScaleThresholds_Q15[ SKP_min_int( round_loss + 1, NB_THRESHOLDS - 1 ) ];\r
-    \r
-        if( g_limit_Q15 > thrld1_Q15 ) {\r
-            /* Maximum scaling */\r
-            psEnc->sCmn.indices.LTP_scaleIndex = 2;\r
-        } else if( g_limit_Q15 > thrld2_Q15 ) {\r
-            /* Medium scaling */\r
-            psEnc->sCmn.indices.LTP_scaleIndex = 1;\r
-        }\r
+        round_loss = psEnc->sCmn.PacketLoss_perc + psEnc->sCmn.nFramesPerPacket - 1;\r
+        psEnc->sCmn.indices.LTP_scaleIndex = (SKP_int8)SKP_LIMIT( \r
+            SKP_SMULWB( SKP_SMULBB( round_loss, psEnc->HPLTPredCodGain_Q7 ), SKP_FIX_CONST( 0.1, 9 ) ), 0, 2 );\r
+    } else {\r
+        /* Default is minimum scaling */\r
+        psEnc->sCmn.indices.LTP_scaleIndex = 0;\r
     }\r
     psEncCtrl->LTP_scale_Q14 = SKP_Silk_LTPScales_table_Q14[ psEnc->sCmn.indices.LTP_scaleIndex ];\r
 }\r
index 057d3b4..e9003fc 100644 (file)
@@ -38,8 +38,7 @@ SKP_int SKP_Silk_encode_frame_FIX(
 )\r
 {\r
     SKP_Silk_encoder_control_FIX sEncCtrl;\r
-    SKP_int     i, nBits, ret = 0;\r
-    SKP_uint8   flags;\r
+    SKP_int     ret = 0;\r
     SKP_int16   *x_frame, *res_pitch_frame;\r
     SKP_int16   xfw[ MAX_FRAME_LENGTH ];\r
     SKP_int16   res_pitch[ 2 * MAX_FRAME_LENGTH + LA_PITCH_MAX ];\r
@@ -65,14 +64,16 @@ TOC(VAD)
     /**************************************************/\r
     /* Convert speech activity into VAD and DTX flags */\r
     /**************************************************/\r
+    if( psEnc->sCmn.nFramesAnalyzed == 0 ) {\r
+        psEnc->sCmn.inDTX = psEnc->sCmn.useDTX;\r
+    }\r
     if( psEnc->sCmn.speech_activity_Q8 < SKP_FIX_CONST( SPEECH_ACTIVITY_DTX_THRES, 8 ) ) {\r
         psEnc->sCmn.indices.signalType = TYPE_NO_VOICE_ACTIVITY;\r
         psEnc->sCmn.noSpeechCounter++;\r
-        if( psEnc->sCmn.noSpeechCounter > NO_SPEECH_FRAMES_BEFORE_DTX ) {\r
-            psEnc->sCmn.inDTX = 1;\r
-        }\r
-        if( psEnc->sCmn.noSpeechCounter > MAX_CONSECUTIVE_DTX ) {\r
-            psEnc->sCmn.noSpeechCounter = 0;\r
+        if( psEnc->sCmn.noSpeechCounter < NB_SPEECH_FRAMES_BEFORE_DTX ) {\r
+            psEnc->sCmn.inDTX = 0;\r
+        } else if( psEnc->sCmn.noSpeechCounter > MAX_CONSECUTIVE_DTX + NB_SPEECH_FRAMES_BEFORE_DTX ) {\r
+            psEnc->sCmn.noSpeechCounter = NB_SPEECH_FRAMES_BEFORE_DTX;\r
             psEnc->sCmn.inDTX           = 0;\r
         }\r
         psEnc->sCmn.VAD_flags[ psEnc->sCmn.nFramesAnalyzed ] = 0;\r
@@ -83,24 +84,6 @@ TOC(VAD)
         psEnc->sCmn.VAD_flags[ psEnc->sCmn.nFramesAnalyzed ] = 1;\r
     }\r
 \r
-    if( psEnc->sCmn.nFramesAnalyzed == 0 && !psEnc->sCmn.prefillFlag && !( psEnc->sCmn.useDTX && psEnc->sCmn.inDTX ) ) {\r
-        /* Create space at start of payload for VAD and FEC flags */\r
-        SKP_uint8 iCDF[ 2 ] = { 0, 0 };\r
-        iCDF[ 0 ] = 256 - SKP_RSHIFT( 256, psEnc->sCmn.nFramesPerPacket + 1 );\r
-        ec_enc_icdf( psRangeEnc, 0, iCDF, 8 );\r
-\r
-        /* Encode any LBRR data from previous packet */\r
-        SKP_Silk_LBRR_embed( &psEnc->sCmn, psRangeEnc );\r
-\r
-        /* Reduce coding SNR depending on how many bits used by LBRR */\r
-        nBits = ec_tell( psRangeEnc );\r
-        psEnc->inBandFEC_SNR_comp_Q7 = SKP_DIV32_16( SKP_SMULBB( SKP_FIX_CONST( 6.0f, 7 ), nBits ), \r
-            SKP_SMULBB( psEnc->sCmn.nFramesPerPacket, psEnc->sCmn.frame_length ) );\r
-\r
-        /* Reset LBRR flags */\r
-        SKP_memset( psEnc->sCmn.LBRR_flags, 0, sizeof( psEnc->sCmn.LBRR_flags ) );\r
-    }\r
-\r
     /*******************************************/\r
     /* High-pass filtering of the input signal */\r
     /*******************************************/\r
@@ -108,10 +91,8 @@ TIC(HP_IN)
     SKP_Silk_HP_variable_cutoff( &psEnc->sCmn, x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.inputBuf, psEnc->sCmn.frame_length );\r
 TOC(HP_IN)\r
 \r
-#if SWITCH_TRANSITION_FILTERING\r
     /* Ensure smooth bandwidth transitions */\r
     SKP_Silk_LP_variable_cutoff( &psEnc->sCmn.sLP, x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.frame_length );\r
-#endif\r
     \r
     /*****************************************/\r
     /* Find pitch lags, initial LPC analysis */\r
@@ -179,7 +160,7 @@ TOC(NSQ)
     psEnc->sCmn.prevSignalType = psEnc->sCmn.indices.signalType;\r
 \r
     /* Exit without entropy coding */\r
-    if( psEnc->sCmn.prefillFlag || ( psEnc->sCmn.useDTX && psEnc->sCmn.inDTX ) ) {\r
+    if( psEnc->sCmn.prefillFlag ) {\r
         /* No payload */\r
         *pnBytesOut = 0;\r
         return ret;\r
@@ -201,36 +182,15 @@ TIC(ENCODE_PULSES)
 TOC(ENCODE_PULSES)\r
 \r
     /****************************************/\r
-    /* Simulate network buffer delay caused */\r
-    /* by exceeding TargetRate              */\r
-    /****************************************/\r
-    nBits = ec_tell( psRangeEnc );\r
-    psEnc->BufferedInChannel_ms += SKP_DIV32( SKP_SMULBB( 1000, nBits - psEnc->sCmn.prev_nBits ), psEnc->sCmn.TargetRate_bps );\r
-    psEnc->BufferedInChannel_ms -= psEnc->sCmn.PacketSize_ms;\r
-    psEnc->BufferedInChannel_ms  = SKP_LIMIT_int( psEnc->BufferedInChannel_ms, 0, 100 );\r
-    psEnc->sCmn.prev_nBits = nBits;\r
-    psEnc->sCmn.first_frame_after_reset = 0;\r
-\r
-    /****************************************/\r
     /* Finalize payload                     */\r
     /****************************************/\r
+    psEnc->sCmn.first_frame_after_reset = 0;\r
     if( ++psEnc->sCmn.nFramesAnalyzed >= psEnc->sCmn.nFramesPerPacket ) {\r
-        /* Insert VAD flags and FEC flag at beginning of bitstream */\r
-        flags = 0;\r
-        for( i = 0; i < psEnc->sCmn.nFramesPerPacket; i++ ) {\r
-            flags |= psEnc->sCmn.VAD_flags[i];\r
-            flags  = SKP_LSHIFT( flags, 1 );\r
-        }\r
-        flags |= psEnc->sCmn.LBRR_flag;\r
-        ec_enc_patch_initial_bits( psRangeEnc, flags, psEnc->sCmn.nFramesPerPacket + 1 );\r
-\r
         /* Payload size */\r
-        nBits = ec_tell( psRangeEnc );\r
-        *pnBytesOut = SKP_RSHIFT( nBits + 7, 3 );\r
+        *pnBytesOut = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );\r
 \r
         /* Reset the number of frames in payload buffer */\r
         psEnc->sCmn.nFramesAnalyzed = 0;\r
-        psEnc->sCmn.prev_nBits = 0;\r
     } else {\r
         /* No payload this time */\r
         *pnBytesOut = 0;\r
@@ -241,9 +201,9 @@ TOC(ENCODE_FRAME)
     {\r
         SKP_float tmp[ MAX_NB_SUBFR * LTP_ORDER ];\r
         int i;\r
-        DEBUG_STORE_DATA( xf.dat,                   x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.frame_length    * sizeof( SKP_int16 ) );\r
+        DEBUG_STORE_DATA( xf.dat,                   x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.frame_length * sizeof( SKP_int16 ) );\r
         DEBUG_STORE_DATA( xfw.dat,                  xfw,                            psEnc->sCmn.frame_length    * sizeof( SKP_int16 ) );\r
-        DEBUG_STORE_DATA( pitchL.dat,               sEncCtrl.pitchL,                psEnc->sCmn.nb_subfr            * sizeof( SKP_int ) );\r
+        DEBUG_STORE_DATA( pitchL.dat,               sEncCtrl.pitchL,                psEnc->sCmn.nb_subfr        * sizeof( SKP_int ) );\r
         for( i = 0; i < psEnc->sCmn.nb_subfr * LTP_ORDER; i++ ) {\r
             tmp[ i ] = (SKP_float)sEncCtrl.LTPCoef_Q14[ i ] / 16384.0f;\r
         }\r
@@ -263,17 +223,16 @@ TOC(ENCODE_FRAME)
             tmp[ i ] = (SKP_float)sEncCtrl.Gains_Q16[ i ] / 65536.0f;\r
         }\r
         DEBUG_STORE_DATA( gains.dat,                tmp,                            psEnc->sCmn.nb_subfr * sizeof( SKP_float ) );\r
-        DEBUG_STORE_DATA( gains_indices.dat,        &psEnc->sCmn.indices.GainsIndices,       psEnc->sCmn.nb_subfr * sizeof( SKP_int ) );\r
-        DEBUG_STORE_DATA( nBits.dat,                &nBits,                         sizeof( SKP_int ) );\r
+        DEBUG_STORE_DATA( gains_indices.dat,        &psEnc->sCmn.indices.GainsIndices, psEnc->sCmn.nb_subfr * sizeof( SKP_int ) );\r
         tmp[ 0 ] = (SKP_float)sEncCtrl.current_SNR_dB_Q7 / 128.0f;\r
         DEBUG_STORE_DATA( current_SNR_db.dat,       tmp,                            sizeof( SKP_float ) );\r
-        DEBUG_STORE_DATA( quantOffsetType.dat,      &psEnc->sCmn.indices.quantOffsetType,    sizeof( SKP_int ) );\r
+        DEBUG_STORE_DATA( quantOffsetType.dat,      &psEnc->sCmn.indices.quantOffsetType, sizeof( SKP_int ) );\r
         tmp[ 0 ] = (SKP_float)psEnc->sCmn.speech_activity_Q8 / 256.0f;\r
         DEBUG_STORE_DATA( speech_activity.dat,      tmp,                            sizeof( SKP_float ) );\r
         for( i = 0; i < VAD_N_BANDS; i++ ) {\r
             tmp[ i ] = (SKP_float)psEnc->sCmn.input_quality_bands_Q15[ i ] / 32768.0f;\r
         }\r
-        DEBUG_STORE_DATA( input_quality_bands.dat,  tmp,                            VAD_N_BANDS * sizeof( SKP_float ) );\r
+        DEBUG_STORE_DATA( input_quality_bands.dat,  tmp,                       VAD_N_BANDS * sizeof( SKP_float ) );\r
         DEBUG_STORE_DATA( signalType.dat,           &psEnc->sCmn.indices.signalType,         sizeof( SKP_int8) ); \r
         DEBUG_STORE_DATA( lag_index.dat,            &psEnc->sCmn.indices.lagIndex,           sizeof( SKP_int16 ) ); \r
         DEBUG_STORE_DATA( contour_index.dat,        &psEnc->sCmn.indices.contourIndex,       sizeof( SKP_int8 ) ); \r
@@ -336,7 +295,7 @@ void SKP_Silk_LBRR_encode_FIX(
                 psEncCtrl->Gains_Q16, psEncCtrl->pitchL, psEncCtrl->Lambda_Q10, psEncCtrl->LTP_scale_Q14 );\r
         }\r
 \r
-        /* Restore original Gains */\r
+        /* Restore original gains */\r
         SKP_memcpy( psEncCtrl->Gains_Q16, TempGains_Q16, psEnc->sCmn.nb_subfr * sizeof( SKP_int32 ) );\r
     }\r
 }\r
index e0b7871..5dba8e6 100644 (file)
@@ -30,6 +30,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 \r
 #include "SKP_Silk_SigProc_FIX.h"\r
 #include "SKP_Silk_structs_FIX.h"\r
+#include "SKP_Silk_control.h"\r
 #include "SKP_Silk_main.h"\r
 #include "SKP_Silk_PLC.h"\r
 #include "SKP_debug.h"\r
@@ -55,23 +56,21 @@ SKP_int SKP_Silk_encode_frame_FIX(
 \r
 /* Low Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode with lower bitrate           */\r
 void SKP_Silk_LBRR_encode_FIX(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,         /* I/O  Pointer to Silk FIX encoder state           */\r
-    SKP_Silk_encoder_control_FIX    *psEncCtrl,     /* I/O  Pointer to Silk FIX encoder control struct  */\r
-    const SKP_int16                 xfw[]           /* I    Input signal                                */\r
+    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk FIX encoder state           */\r
+    SKP_Silk_encoder_control_FIX    *psEncCtrl,         /* I/O  Pointer to Silk FIX encoder control struct  */\r
+    const SKP_int16                 xfw[]               /* I    Input signal                                */\r
 );\r
 \r
 /* Initializes the Silk encoder state */\r
-SKP_int SKP_Silk_init_encoder_FIX(\r
-    SKP_Silk_encoder_state_FIX  *psEnc              /* I/O  Pointer to Silk FIX encoder state           */\r
+SKP_int SKP_Silk_init_encoder(\r
+    SKP_Silk_encoder_state_FIX      *psEnc              /* I/O  Pointer to Silk FIX encoder state           */\r
 );\r
 \r
 /* Control the Silk encoder */\r
-SKP_int SKP_Silk_control_encoder_FIX( \r
-    SKP_Silk_encoder_state_FIX  *psEnc,                 /* I/O  Pointer to Silk encoder state           */\r
-    const SKP_int               PacketSize_ms,          /* I    Packet length (ms)                      */\r
-    const SKP_int32             TargetRate_bps,         /* I    Target max bitrate (bps)                */\r
-    const SKP_int               PacketLoss_perc,        /* I    Packet loss rate (in percent)           */\r
-    const SKP_int               Complexity              /* I    Complexity (0-10)                       */\r
+SKP_int SKP_Silk_control_encoder( \r
+    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O  Pointer to Silk encoder state           */\r
+    SKP_SILK_SDK_EncControlStruct   *encControl,        /* I:   Control structure                       */\r
+    const SKP_int32                 TargetRate_bps      /* I    Target max bitrate (bps)                */\r
 );\r
 \r
 /****************/\r
index e43e253..b8d804c 100644 (file)
@@ -158,27 +158,19 @@ void SKP_Silk_noise_shape_analysis_FIX(
     x_ptr = x - psEnc->sCmn.la_shape;\r
 \r
     /****************/\r
-    /* CONTROL SNR  */\r
-    /****************/\r
-    /* Reduce SNR_dB values if recent bitstream has exceeded TargetRate */\r
-    psEncCtrl->current_SNR_dB_Q7 = psEnc->SNR_dB_Q7 - SKP_SMULBB( psEnc->BufferedInChannel_ms, SKP_FIX_CONST( 0.1, 7 ) );\r
-\r
-    /* Reduce SNR_dB because of any inband FEC used */\r
-    psEncCtrl->current_SNR_dB_Q7 -= psEnc->inBandFEC_SNR_comp_Q7;\r
-\r
-    /****************/\r
     /* GAIN CONTROL */\r
     /****************/\r
+    SNR_adj_dB_Q7 = psEnc->sCmn.SNR_dB_Q7;\r
+\r
     /* Input quality is the average of the quality in the lowest two VAD bands */\r
     psEncCtrl->input_quality_Q14 = ( SKP_int )SKP_RSHIFT( ( SKP_int32 )psEnc->sCmn.input_quality_bands_Q15[ 0 ] \r
         + psEnc->sCmn.input_quality_bands_Q15[ 1 ], 2 );\r
 \r
     /* Coding quality level, between 0.0_Q0 and 1.0_Q0, but in Q14 */\r
-    psEncCtrl->coding_quality_Q14 = SKP_RSHIFT( SKP_Silk_sigm_Q15( SKP_RSHIFT_ROUND( psEncCtrl->current_SNR_dB_Q7 - \r
+    psEncCtrl->coding_quality_Q14 = SKP_RSHIFT( SKP_Silk_sigm_Q15( SKP_RSHIFT_ROUND( SNR_adj_dB_Q7 - \r
         SKP_FIX_CONST( 18.0, 7 ), 4 ) ), 1 );\r
 \r
     /* Reduce coding SNR during low speech activity */\r
-    SNR_adj_dB_Q7 = psEncCtrl->current_SNR_dB_Q7;\r
     if( psEnc->sCmn.useCBR == 0 ) {\r
         b_Q8 = SKP_FIX_CONST( 1.0, 8 ) - psEnc->sCmn.speech_activity_Q8;\r
         b_Q8 = SKP_SMULWB( SKP_LSHIFT( b_Q8, 8 ), b_Q8 );\r
@@ -193,7 +185,7 @@ void SKP_Silk_noise_shape_analysis_FIX(
     } else { \r
         /* For unvoiced signals and low-quality input, adjust the quality slower than SNR_dB setting */\r
         SNR_adj_dB_Q7 = SKP_SMLAWB( SNR_adj_dB_Q7, \r
-            SKP_SMLAWB( SKP_FIX_CONST( 6.0, 9 ), -SKP_FIX_CONST( 0.4, 18 ), psEncCtrl->current_SNR_dB_Q7 ),\r
+            SKP_SMLAWB( SKP_FIX_CONST( 6.0, 9 ), -SKP_FIX_CONST( 0.4, 18 ), psEnc->sCmn.SNR_dB_Q7 ),\r
             SKP_FIX_CONST( 1.0, 14 ) - psEncCtrl->input_quality_Q14 );\r
     }\r
 \r
index f8bb295..c11502b 100644 (file)
@@ -48,21 +48,18 @@ void SKP_Silk_process_gains_FIX(
     }\r
 \r
     /* Limit the quantized signal */\r
+    /* InvMaxSqrVal = pow( 2.0f, 0.33f * ( 21.0f - SNR_dB ) ) / subfr_length; */\r
     InvMaxSqrVal_Q16 = SKP_DIV32_16( SKP_Silk_log2lin( \r
-        SKP_SMULWB( SKP_FIX_CONST( 70.0, 7 ) - psEncCtrl->current_SNR_dB_Q7, SKP_FIX_CONST( 0.33, 16 ) ) ), psEnc->sCmn.subfr_length );\r
+        SKP_SMULWB( SKP_FIX_CONST( 21 + 16 / 0.33, 7 ) - psEnc->sCmn.SNR_dB_Q7, SKP_FIX_CONST( 0.33, 16 ) ) ), psEnc->sCmn.subfr_length );\r
 \r
     for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) {\r
         /* Soft limit on ratio residual energy and squared gains */\r
         ResNrg     = psEncCtrl->ResNrg[ k ];\r
         ResNrgPart = SKP_SMULWW( ResNrg, InvMaxSqrVal_Q16 );\r
         if( psEncCtrl->ResNrgQ[ k ] > 0 ) {\r
-            if( psEncCtrl->ResNrgQ[ k ] < 32 ) {\r
-                ResNrgPart = SKP_RSHIFT_ROUND( ResNrgPart, psEncCtrl->ResNrgQ[ k ] );\r
-            } else {\r
-                ResNrgPart = 0;\r
-            }\r
-        } else if( psEncCtrl->ResNrgQ[k] != 0 ) {\r
-            if( ResNrgPart > SKP_RSHIFT( SKP_int32_MAX, -psEncCtrl->ResNrgQ[ k ] ) ) {\r
+            ResNrgPart = SKP_RSHIFT_ROUND( ResNrgPart, psEncCtrl->ResNrgQ[ k ] );\r
+        } else {\r
+            if( ResNrgPart >= SKP_RSHIFT( SKP_int32_MAX, -psEncCtrl->ResNrgQ[ k ] ) ) {\r
                 ResNrgPart = SKP_int32_MAX;\r
             } else {\r
                 ResNrgPart = SKP_LSHIFT( ResNrgPart, -psEncCtrl->ResNrgQ[ k ] );\r
@@ -75,9 +72,11 @@ void SKP_Silk_process_gains_FIX(
             gain_squared = SKP_SMLAWW( SKP_LSHIFT( ResNrgPart, 16 ), gain, gain );\r
             SKP_assert( gain_squared > 0 );\r
             gain = SKP_Silk_SQRT_APPROX( gain_squared );                    /* Q8   */\r
+            gain = SKP_min( gain, SKP_int32_MAX >> 8 );\r
             psEncCtrl->Gains_Q16[ k ] = SKP_LSHIFT_SAT32( gain, 8 );        /* Q16  */\r
         } else {\r
             gain = SKP_Silk_SQRT_APPROX( gain_squared );                    /* Q0   */\r
+            gain = SKP_min( gain, SKP_int32_MAX >> 16 );\r
             psEncCtrl->Gains_Q16[ k ] = SKP_LSHIFT_SAT32( gain, 16 );       /* Q16  */\r
         }\r
     }\r
@@ -85,6 +84,7 @@ void SKP_Silk_process_gains_FIX(
     /* Noise shaping quantization */\r
     SKP_Silk_gains_quant( psEnc->sCmn.indices.GainsIndices, psEncCtrl->Gains_Q16, \r
         &psShapeSt->LastGainIndex, psEnc->sCmn.nFramesAnalyzed, psEnc->sCmn.nb_subfr );\r
+\r
     /* Set quantizer offset for voiced signals. Larger offset when LTP coding gain is low or tilt is high (ie low-pass) */\r
     if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) {\r
         if( psEncCtrl->LTPredCodGain_Q7 + SKP_RSHIFT( psEnc->sCmn.input_tilt_Q15, 8 ) > SKP_FIX_CONST( 1.0, 7 ) ) {\r
index 9f60477..f7e91d2 100644 (file)
@@ -72,15 +72,10 @@ typedef struct {
     /* Buffer for find pitch and noise shape analysis */\r
     SKP_DWORD_ALIGN SKP_int16 x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ];\r
     SKP_int                         LTPCorr_Q15;                    /* Normalized correlation from pitch lag estimator                      */\r
-    SKP_int32                       SNR_dB_Q7;                      /* Quality setting                                                      */\r
-    SKP_int                         BufferedInChannel_ms;           /* Simulated number of ms buffer because of exceeded TargetRate_bps     */\r
 \r
     /* Parameters For LTP scaling Control */\r
     SKP_int                         prevLTPredCodGain_Q7;\r
     SKP_int                         HPLTPredCodGain_Q7;\r
-\r
-    SKP_int32                       inBandFEC_SNR_comp_Q7;          /* Compensation to SNR_dB when using inband FEC Voiced                  */\r
-\r
 } SKP_Silk_encoder_state_FIX;\r
 \r
 /************************/\r
@@ -106,7 +101,6 @@ typedef struct {
     SKP_int     Lambda_Q10;\r
     SKP_int     input_quality_Q14;\r
     SKP_int     coding_quality_Q14;\r
-    SKP_int     current_SNR_dB_Q7;\r
 \r
     /* measures */\r
     SKP_int     sparseness_Q8;\r
index ece080e..3b885a4 100644 (file)
     <ClInclude Include="SKP_Silk_structs_FIX.h" />\r
   </ItemGroup>\r
   <ItemGroup>\r
-    <ClCompile Include="SKP_Silk_control_codec_FIX.c" />\r
     <ClCompile Include="SKP_Silk_corrMatrix_FIX.c" />\r
     <ClCompile Include="SKP_Silk_encode_frame_FIX.c" />\r
     <ClCompile Include="SKP_Silk_find_LPC_FIX.c" />\r
     <ClCompile Include="SKP_Silk_find_LTP_FIX.c" />\r
     <ClCompile Include="SKP_Silk_find_pitch_lags_FIX.c" />\r
     <ClCompile Include="SKP_Silk_find_pred_coefs_FIX.c" />\r
-    <ClCompile Include="SKP_Silk_init_encoder_FIX.c" />\r
     <ClCompile Include="SKP_Silk_LTP_analysis_filter_FIX.c" />\r
     <ClCompile Include="SKP_Silk_LTP_scale_ctrl_FIX.c" />\r
     <ClCompile Include="SKP_Silk_noise_shape_analysis_FIX.c" />\r
index 1718e61..d640244 100644 (file)
@@ -26,9 +26,6 @@
     </ClInclude>\r
   </ItemGroup>\r
   <ItemGroup>\r
-    <ClCompile Include="SKP_Silk_control_codec_FIX.c">\r
-      <Filter>Source Files</Filter>\r
-    </ClCompile>\r
     <ClCompile Include="SKP_Silk_corrMatrix_FIX.c">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
@@ -47,9 +44,6 @@
     <ClCompile Include="SKP_Silk_find_pred_coefs_FIX.c">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
-    <ClCompile Include="SKP_Silk_init_encoder_FIX.c">\r
-      <Filter>Source Files</Filter>\r
-    </ClCompile>\r
     <ClCompile Include="SKP_Silk_LTP_analysis_filter_FIX.c">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
index b94d2fe..4d9345d 100644 (file)
@@ -27,57 +27,26 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 \r
 #include "SKP_Silk_main_FLP.h"\r
 \r
-#define NB_THRESHOLDS           11\r
-\r
-/* Table containing trained thresholds for LTP scaling */\r
-static const SKP_float LTPScaleThresholds[ NB_THRESHOLDS ] = \r
-{\r
-    0.95f, 0.8f, 0.50f, 0.400f, 0.3f, 0.2f,\r
-    0.15f, 0.1f, 0.08f, 0.075f, 0.0f\r
-};\r
-\r
-\r
 void SKP_Silk_LTP_scale_ctrl_FLP(\r
     SKP_Silk_encoder_state_FLP      *psEnc,             /* I/O  Encoder state FLP                       */\r
     SKP_Silk_encoder_control_FLP    *psEncCtrl          /* I/O  Encoder control FLP                     */\r
 )\r
 {\r
-    SKP_int round_loss;\r
-    SKP_float g_out, g_limit, thrld1, thrld2;\r
+    SKP_int   round_loss;\r
 \r
     /* 1st order high-pass filter */\r
-    //g_HP(n) = g(n) - g(n-1) + 0.5 * g_HP(n-1);       // tune the 0.5: higher means longer impact of jump\r
-    psEnc->HPLTPredCodGain = SKP_max_float( psEncCtrl->LTPredCodGain - psEnc->prevLTPredCodGain, 0.0f ) \r
+    //g_HP(n) = g(n) - 0.5 * g(n-1) + 0.5 * g_HP(n-1);\r
+    psEnc->HPLTPredCodGain = SKP_max_float( psEncCtrl->LTPredCodGain - 0.5 * psEnc->prevLTPredCodGain, 0.0f ) \r
                             + 0.5f * psEnc->HPLTPredCodGain;\r
-    \r
     psEnc->prevLTPredCodGain = psEncCtrl->LTPredCodGain;\r
 \r
-    /* Combine input and filtered input */\r
-    g_out = 0.5f * psEncCtrl->LTPredCodGain + ( 1.0f - 0.5f ) * psEnc->HPLTPredCodGain;\r
-    g_limit = SKP_sigmoid( 0.5f * ( g_out - 6 ) );\r
-    \r
-    \r
-    /* Default is minimum scaling */\r
-    psEnc->sCmn.indices.LTP_scaleIndex = 0;\r
-\r
-    /* Round the loss measure to whole pct */\r
-    round_loss = ( SKP_int )( psEnc->sCmn.PacketLoss_perc );\r
-    round_loss = SKP_max( 0, round_loss );\r
-\r
     /* Only scale if first frame in packet */\r
-    if( psEnc->sCmn.nFramesAnalyzed == 0 ){\r
-        \r
-        round_loss += psEnc->sCmn.nFramesPerPacket - 1;\r
-        thrld1 = LTPScaleThresholds[ SKP_min_int( round_loss,     NB_THRESHOLDS - 1 ) ];\r
-        thrld2 = LTPScaleThresholds[ SKP_min_int( round_loss + 1, NB_THRESHOLDS - 1 ) ];\r
-    \r
-        if( g_limit > thrld1 ) {\r
-            /* High Scaling */\r
-            psEnc->sCmn.indices.LTP_scaleIndex = 2;\r
-        } else if( g_limit > thrld2 ) {\r
-            /* Middle Scaling */\r
-            psEnc->sCmn.indices.LTP_scaleIndex = 1;\r
-        }\r
+    if( psEnc->sCmn.nFramesAnalyzed == 0 ) {\r
+        round_loss = psEnc->sCmn.PacketLoss_perc + psEnc->sCmn.nFramesPerPacket;\r
+        psEnc->sCmn.indices.LTP_scaleIndex = (SKP_int8)SKP_LIMIT( round_loss * psEnc->HPLTPredCodGain * 0.1f, 0.0f, 2.0f );\r
+    } else {\r
+        /* Default is minimum scaling */\r
+        psEnc->sCmn.indices.LTP_scaleIndex = 0;\r
     }\r
-    psEncCtrl->LTP_scale = ( SKP_float)SKP_Silk_LTPScales_table_Q14[ psEnc->sCmn.indices.LTP_scaleIndex ] / 16384.0f;\r
+    psEncCtrl->LTP_scale = (SKP_float)SKP_Silk_LTPScales_table_Q14[ psEnc->sCmn.indices.LTP_scaleIndex ] / 16384.0f;\r
 }\r
diff --git a/src_FLP/SKP_Silk_control_codec_FLP.c b/src_FLP/SKP_Silk_control_codec_FLP.c
deleted file mode 100644 (file)
index 06b3fd2..0000000
+++ /dev/null
@@ -1,317 +0,0 @@
-/***********************************************************************\r
-Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
-Redistribution and use in source and binary forms, with or without \r
-modification, (subject to the limitations in the disclaimer below) \r
-are permitted provided that the following conditions are met:\r
-- Redistributions of source code must retain the above copyright notice,\r
-this list of conditions and the following disclaimer.\r
-- Redistributions in binary form must reproduce the above copyright \r
-notice, this list of conditions and the following disclaimer in the \r
-documentation and/or other materials provided with the distribution.\r
-- Neither the name of Skype Limited, nor the names of specific \r
-contributors, may be used to endorse or promote products derived from \r
-this software without specific prior written permission.\r
-NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
-BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
-CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
-FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
-COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
-USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-***********************************************************************/\r
-\r
-#include "SKP_Silk_main_FLP.h"\r
-#include "SKP_Silk_setup.h"\r
-\r
-SKP_INLINE SKP_int SKP_Silk_setup_resamplers(\r
-    SKP_Silk_encoder_state_FLP      *psEnc,             /* I/O  Pointer to Silk encoder state FLP       */\r
-    SKP_int                         fs_kHz              /* I    Internal sampling rate (kHz)            */\r
-);\r
-\r
-SKP_INLINE SKP_int SKP_Silk_setup_fs(\r
-    SKP_Silk_encoder_state_FLP      *psEnc,             /* I/O                      */\r
-    SKP_int                         fs_kHz,             /* I                        */\r
-    SKP_int                         PacketSize_ms       /* I                        */\r
-);\r
-\r
-SKP_INLINE SKP_int SKP_Silk_setup_rate(\r
-    SKP_Silk_encoder_state_FLP      *psEnc,             /* I/O  Pointer to Silk encoder state FLP       */\r
-    SKP_int32                       TargetRate_bps      /* I    Target max bitrate                      */\r
-);\r
-\r
-/* Control encoder */\r
-SKP_int SKP_Silk_control_encoder_FLP( \r
-    SKP_Silk_encoder_state_FLP  *psEnc,                 /* I/O  Pointer to Silk encoder state FLP       */\r
-    const SKP_int               PacketSize_ms,          /* I    Packet length (ms)                      */\r
-    const SKP_int32             TargetRate_bps,         /* I    Target max bitrate (bps)                */\r
-    const SKP_int               PacketLoss_perc,        /* I    Packet loss rate (in percent)           */\r
-    const SKP_int               Complexity              /* I    Complexity (0-10)                       */\r
-)\r
-{\r
-    SKP_int   fs_kHz, ret = 0;\r
-\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
-        }\r
-        return ret;\r
-    }\r
-\r
-    /* Beyond this point we know that there are no previously coded frames in the payload buffer */\r
-\r
-    /********************************************/\r
-    /* Determine internal sampling rate         */\r
-    /********************************************/\r
-    fs_kHz = SKP_Silk_control_audio_bandwidth( &psEnc->sCmn, TargetRate_bps );\r
-\r
-    /********************************************/\r
-    /* Prepare resampler and buffered data      */\r
-    /********************************************/\r
-    ret += SKP_Silk_setup_resamplers( psEnc, fs_kHz );\r
-\r
-    /********************************************/\r
-    /* Set internal sampling frequency          */\r
-    /********************************************/\r
-    ret += SKP_Silk_setup_fs( psEnc, fs_kHz, PacketSize_ms );\r
-\r
-    /********************************************/\r
-    /* Set encoding complexity                  */\r
-    /********************************************/\r
-    ret += SKP_Silk_setup_complexity( &psEnc->sCmn, Complexity );\r
-\r
-    /********************************************/\r
-    /* Set bitrate/coding quality               */\r
-    /********************************************/\r
-    ret += SKP_Silk_setup_rate( psEnc, TargetRate_bps );\r
-\r
-    /********************************************/\r
-    /* Set packet loss rate measured by farend  */\r
-    /********************************************/\r
-    if( ( PacketLoss_perc < 0 ) || ( PacketLoss_perc > 100 ) ) {\r
-        ret = SKP_SILK_ENC_INVALID_LOSS_RATE;\r
-    }\r
-    psEnc->sCmn.PacketLoss_perc = PacketLoss_perc;\r
-\r
-    /********************************************/\r
-    /* Set LBRR usage                           */\r
-    /********************************************/\r
-    ret += SKP_Silk_setup_LBRR( &psEnc->sCmn );\r
-\r
-    psEnc->sCmn.controlled_since_last_payload = 1;\r
-\r
-    return ret;\r
-}\r
-\r
-SKP_INLINE SKP_int SKP_Silk_setup_resamplers(\r
-    SKP_Silk_encoder_state_FLP      *psEnc,             /* I/O  Pointer to Silk encoder state FLP       */\r
-    SKP_int                         fs_kHz              /* I    External (API) sampling rate (Hz)       */\r
-)\r
-{\r
-    SKP_int ret = SKP_SILK_NO_ERROR;\r
-    \r
-    if( psEnc->sCmn.fs_kHz != fs_kHz || psEnc->sCmn.prev_API_fs_Hz != psEnc->sCmn.API_fs_Hz ) {\r
-\r
-        if( psEnc->sCmn.fs_kHz == 0 ) {\r
-            /* Initialize the resampler for enc_API.c preparing resampling from API_fs_Hz to fs_kHz */\r
-            ret += SKP_Silk_resampler_init( &psEnc->sCmn.resampler_state, psEnc->sCmn.API_fs_Hz, fs_kHz * 1000 );\r
-        } else {\r
-            /* Allocate space for worst case temporary upsampling, 8 to 48 kHz, so a factor 6 */\r
-            SKP_int16 x_buf_API_fs_Hz[ ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * ( MAX_API_FS_KHZ / 8 ) ];\r
-            SKP_int16 x_bufFIX[          2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ]; \r
-\r
-            SKP_int32 nSamples_temp = 2 * psEnc->sCmn.frame_length + LA_SHAPE_MS * psEnc->sCmn.fs_kHz;\r
-\r
-            SKP_float2short_array( x_bufFIX, psEnc->x_buf, nSamples_temp );\r
-\r
-            if( fs_kHz * 1000 < psEnc->sCmn.API_fs_Hz && psEnc->sCmn.fs_kHz != 0 ) {\r
-                /* Resample buffered data in x_buf to API_fs_Hz */\r
-\r
-                SKP_Silk_resampler_state_struct  temp_resampler_state;\r
-\r
-                /* Initialize resampler for temporary resampling of x_buf data to API_fs_Hz */\r
-                ret += SKP_Silk_resampler_init( &temp_resampler_state, psEnc->sCmn.fs_kHz * 1000, psEnc->sCmn.API_fs_Hz );\r
-\r
-                /* Temporary resampling of x_buf data to API_fs_Hz */\r
-                ret += SKP_Silk_resampler( &temp_resampler_state, x_buf_API_fs_Hz, x_bufFIX, nSamples_temp );\r
-\r
-                /* Calculate number of samples that has been temporarily upsampled */\r
-                nSamples_temp = SKP_DIV32_16( nSamples_temp * psEnc->sCmn.API_fs_Hz, psEnc->sCmn.fs_kHz * 1000 );\r
-\r
-                /* Initialize the resampler for enc_API.c preparing resampling from API_fs_Hz to fs_kHz */\r
-                ret += SKP_Silk_resampler_init( &psEnc->sCmn.resampler_state, psEnc->sCmn.API_fs_Hz, fs_kHz * 1000 );\r
-\r
-            } else {\r
-                /* Copy data */\r
-                SKP_memcpy( x_buf_API_fs_Hz, x_bufFIX, nSamples_temp * sizeof( SKP_int16 ) );\r
-            }\r
-\r
-            if( 1000 * fs_kHz != psEnc->sCmn.API_fs_Hz ) {\r
-                /* Correct resampler state (unless resampling by a factor 1) by resampling buffered data from API_fs_Hz to fs_kHz */\r
-                ret += SKP_Silk_resampler( &psEnc->sCmn.resampler_state, x_bufFIX, x_buf_API_fs_Hz, nSamples_temp );\r
-            }\r
-            SKP_short2float_array( psEnc->x_buf, x_bufFIX, ( 2 * MAX_FRAME_LENGTH_MS + LA_SHAPE_MS ) * fs_kHz );\r
-        }\r
-    }\r
-\r
-    psEnc->sCmn.prev_API_fs_Hz = psEnc->sCmn.API_fs_Hz;\r
-\r
-    return(ret);\r
-}\r
-\r
-SKP_INLINE SKP_int SKP_Silk_setup_fs(\r
-    SKP_Silk_encoder_state_FLP      *psEnc,             /* I/O                      */\r
-    SKP_int                         fs_kHz,             /* I                        */\r
-    SKP_int                         PacketSize_ms       /* I                        */\r
-)\r
-{\r
-    SKP_int ret = SKP_SILK_NO_ERROR;\r
-\r
-    /* Set packet size */\r
-    if( PacketSize_ms != psEnc->sCmn.PacketSize_ms ) {\r
-        if( ( PacketSize_ms !=  10 ) &&\r
-            ( PacketSize_ms !=  20 ) &&\r
-            ( PacketSize_ms !=  40 ) && \r
-            ( PacketSize_ms !=  60 ) ) {\r
-            ret = SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED;\r
-        }\r
-        if( PacketSize_ms <= 10 ) {\r
-            psEnc->sCmn.nFramesPerPacket = 1;\r
-            psEnc->sCmn.nb_subfr = PacketSize_ms == 10 ? 2 : 1;\r
-            psEnc->sCmn.frame_length = 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
-            } else {\r
-                psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_iCDF;\r
-            }\r
-        } 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 = 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
-            } else {\r
-                psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_iCDF; \r
-            }\r
-        }\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_FLP ) );\r
-        SKP_memset( &psEnc->sPrefilt,             0, sizeof( SKP_Silk_prefilter_state_FLP ) );\r
-        SKP_memset( &psEnc->sCmn.sNSQ,            0, sizeof( SKP_Silk_nsq_state ) );\r
-        SKP_memset( psEnc->sCmn.prev_NLSFq_Q15,   0, sizeof( psEnc->sCmn.prev_NLSFq_Q15 ) );\r
-        SKP_memset( &psEnc->sCmn.sLP.In_LP_State, 0, sizeof( psEnc->sCmn.sLP.In_LP_State ) );\r
-        psEnc->sCmn.inputBufIx                  = 0;\r
-        psEnc->sCmn.nFramesAnalyzed             = 0;\r
-        psEnc->sCmn.TargetRate_bps              = 0; /* Ensures that psEnc->SNR_dB is recomputed */\r
-\r
-        /* Initialize non-zero parameters */\r
-        psEnc->sCmn.prevLag                     = 100;\r
-        psEnc->sCmn.first_frame_after_reset     = 1;\r
-        psEnc->sPrefilt.lagPrev                 = 100;\r
-        psEnc->sShape.LastGainIndex             = 10;\r
-        psEnc->sCmn.sNSQ.lagPrev                = 100;\r
-        psEnc->sCmn.sNSQ.prev_inv_gain_Q16      = 65536;\r
-\r
-        psEnc->sCmn.fs_kHz = fs_kHz;\r
-        if( psEnc->sCmn.fs_kHz == 8 ) {\r
-            if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) {\r
-                psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_NB_iCDF; \r
-            } else {\r
-                psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_10_ms_NB_iCDF;\r
-            }\r
-        } else {\r
-            if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) {\r
-                psEnc->sCmn.pitch_contour_iCDF = SKP_Silk_pitch_contour_iCDF; \r
-            } else {\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   = psEnc->sCmn.subfr_length * psEnc->sCmn.nb_subfr;\r
-        psEnc->sCmn.ltp_mem_length = LTP_MEM_LENGTH_MS * fs_kHz; \r
-        psEnc->sCmn.la_pitch       = LA_PITCH_MS * fs_kHz;\r
-        psEnc->sCmn.max_pitch_lag = 18 * fs_kHz;\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 {\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
-            psEnc->sCmn.pitch_lag_low_bits_iCDF = SKP_Silk_uniform8_iCDF;\r
-        } 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 {\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
-        }\r
-    }\r
-\r
-    /* Check that settings are valid */\r
-    SKP_assert( ( psEnc->sCmn.subfr_length * psEnc->sCmn.nb_subfr ) == psEnc->sCmn.frame_length );\r
\r
-    return( ret );\r
-}\r
-\r
-SKP_INLINE SKP_int SKP_Silk_setup_rate(\r
-    SKP_Silk_encoder_state_FLP      *psEnc,             /* I/O  Pointer to Silk encoder state FLP       */\r
-    SKP_int32                       TargetRate_bps      /* I    Target max bitrate                      */\r
-)\r
-{\r
-    SKP_int k, ret = SKP_SILK_NO_ERROR;\r
-    SKP_float frac;\r
-    const SKP_int32 *rateTable;\r
-\r
-    /* Set bitrate/coding quality */\r
-    if( TargetRate_bps != psEnc->sCmn.TargetRate_bps ) {\r
-        psEnc->sCmn.TargetRate_bps = TargetRate_bps;\r
-\r
-        /* If new TargetRate_bps, translate to SNR_dB value */\r
-        if( psEnc->sCmn.fs_kHz == 8 ) {\r
-            rateTable = TargetRate_table_NB;\r
-        } else if( psEnc->sCmn.fs_kHz == 12 ) {\r
-            rateTable = TargetRate_table_MB;\r
-        } else if( psEnc->sCmn.fs_kHz == 16 ) {\r
-            rateTable = TargetRate_table_WB;\r
-        } else {\r
-            SKP_assert( 0 );\r
-        }\r
-        /* Reduce bitrate for 10 ms modes in these calculations */\r
-        if( psEnc->sCmn.nb_subfr == 2 ) {\r
-            TargetRate_bps -= REDUCE_BITRATE_10_MS_BPS;\r
-        }\r
-        for( k = 1; k < TARGET_RATE_TAB_SZ; k++ ) {\r
-            /* Find bitrate interval in table and interpolate */\r
-            if( TargetRate_bps <= rateTable[ k ] ) {\r
-                frac = (SKP_float)( TargetRate_bps - rateTable[ k - 1 ] ) / \r
-                       (SKP_float)( rateTable[ k ] - rateTable[ k - 1 ] );\r
-                psEnc->SNR_dB = 0.5f * ( SNR_table_Q1[ k - 1 ] + frac * ( SNR_table_Q1[ k ] - SNR_table_Q1[ k - 1 ] ) );\r
-                break;\r
-            }\r
-        }\r
-    }\r
-    return( ret );\r
-}\r
index 2bc74a6..43b5283 100644 (file)
@@ -38,8 +38,7 @@ SKP_int SKP_Silk_encode_frame_FLP(
 )\r
 {\r
     SKP_Silk_encoder_control_FLP sEncCtrl;\r
-    SKP_int     i, nBits, ret = 0;\r
-    SKP_uint8   flags;\r
+    SKP_int     i, ret = 0;\r
     SKP_float   *x_frame, *res_pitch_frame;\r
     SKP_int16   pIn_HP[ MAX_FRAME_LENGTH ];\r
     SKP_float   xfw[ MAX_FRAME_LENGTH ];\r
@@ -66,42 +65,26 @@ TOC(VAD)
     /**************************************************/\r
     /* Convert speech activity into VAD and DTX flags */\r
     /**************************************************/\r
+    if( psEnc->sCmn.nFramesAnalyzed == 0 ) {\r
+        psEnc->sCmn.inDTX = psEnc->sCmn.useDTX;\r
+    }\r
     if( psEnc->sCmn.speech_activity_Q8 < SKP_FIX_CONST( SPEECH_ACTIVITY_DTX_THRES, 8 ) ) {\r
         psEnc->sCmn.indices.signalType = TYPE_NO_VOICE_ACTIVITY;\r
         psEnc->sCmn.noSpeechCounter++;\r
-        if( psEnc->sCmn.noSpeechCounter > NO_SPEECH_FRAMES_BEFORE_DTX ) {\r
-            psEnc->sCmn.inDTX = 1;\r
-        }\r
-        if( psEnc->sCmn.noSpeechCounter > MAX_CONSECUTIVE_DTX ) {\r
-            psEnc->sCmn.noSpeechCounter = 0;\r
+        if( psEnc->sCmn.noSpeechCounter < NB_SPEECH_FRAMES_BEFORE_DTX ) {\r
+            psEnc->sCmn.inDTX = 0;\r
+        } else if( psEnc->sCmn.noSpeechCounter > MAX_CONSECUTIVE_DTX + NB_SPEECH_FRAMES_BEFORE_DTX ) {\r
+            psEnc->sCmn.noSpeechCounter = NB_SPEECH_FRAMES_BEFORE_DTX;\r
             psEnc->sCmn.inDTX           = 0;\r
         }\r
         psEnc->sCmn.VAD_flags[ psEnc->sCmn.nFramesAnalyzed ] = 0;\r
     } else {\r
-        psEnc->sCmn.noSpeechCounter = 0;\r
-        psEnc->sCmn.inDTX           = 0;\r
+        psEnc->sCmn.noSpeechCounter    = 0;\r
+        psEnc->sCmn.inDTX              = 0;\r
         psEnc->sCmn.indices.signalType = TYPE_UNVOICED;\r
         psEnc->sCmn.VAD_flags[ psEnc->sCmn.nFramesAnalyzed ] = 1;\r
     }\r
 \r
-    if( psEnc->sCmn.nFramesAnalyzed == 0 && !psEnc->sCmn.prefillFlag && !( psEnc->sCmn.useDTX && psEnc->sCmn.inDTX ) ) {\r
-        /* Create space at start of payload for VAD and FEC flags */\r
-        SKP_uint8 iCDF[ 2 ] = { 0, 0 };\r
-        iCDF[ 0 ] = 256 - SKP_RSHIFT( 256, psEnc->sCmn.nFramesPerPacket + 1 );\r
-        ec_enc_icdf( psRangeEnc, 0, iCDF, 8 );\r
-\r
-        /* Encode any LBRR data from previous packet */\r
-        SKP_Silk_LBRR_embed( &psEnc->sCmn, psRangeEnc );\r
-\r
-        /* Reduce coding SNR depending on how many bits used by LBRR */\r
-        nBits = ec_tell( psRangeEnc );\r
-        psEnc->inBandFEC_SNR_comp = ( 6.0f * nBits ) / \r
-            ( psEnc->sCmn.nFramesPerPacket * psEnc->sCmn.frame_length );\r
-\r
-        /* Reset LBRR flags */\r
-        SKP_memset( psEnc->sCmn.LBRR_flags, 0, sizeof( psEnc->sCmn.LBRR_flags ) );\r
-    }\r
-\r
     /*******************************************/\r
     /* High-pass filtering of the input signal */\r
     /*******************************************/\r
@@ -109,10 +92,8 @@ TIC(HP_IN)
     SKP_Silk_HP_variable_cutoff( &psEnc->sCmn, pIn_HP, psEnc->sCmn.inputBuf, psEnc->sCmn.frame_length );\r
 TOC(HP_IN)\r
 \r
-#if SWITCH_TRANSITION_FILTERING\r
     /* Ensure smooth bandwidth transitions */\r
     SKP_Silk_LP_variable_cutoff( &psEnc->sCmn.sLP, pIn_HP, psEnc->sCmn.frame_length );\r
-#endif\r
 \r
     /*******************************************/\r
     /* Copy new frame to front of input buffer */\r
@@ -182,7 +163,7 @@ TOC(NSQ)
     psEnc->sCmn.prevSignalType = psEnc->sCmn.indices.signalType;\r
 \r
     /* Exit without entropy coding */\r
-    if( psEnc->sCmn.prefillFlag || ( psEnc->sCmn.useDTX && psEnc->sCmn.inDTX ) ) {\r
+    if( psEnc->sCmn.prefillFlag ) {\r
         /* No payload */\r
         *pnBytesOut = 0;\r
         return ret;\r
@@ -204,36 +185,15 @@ TIC(ENCODE_PULSES)
 TOC(ENCODE_PULSES)\r
 \r
     /****************************************/\r
-    /* Simulate network buffer delay caused */\r
-    /* by exceeding TargetRate              */\r
-    /****************************************/\r
-    nBits = ec_tell( psRangeEnc );\r
-    psEnc->BufferedInChannel_ms += 1000.0f * ( nBits - psEnc->sCmn.prev_nBits ) / psEnc->sCmn.TargetRate_bps;\r
-    psEnc->BufferedInChannel_ms -= psEnc->sCmn.nb_subfr * SUB_FRAME_LENGTH_MS;\r
-    psEnc->BufferedInChannel_ms  = SKP_LIMIT_float( psEnc->BufferedInChannel_ms, 0.0f, 100.0f );\r
-    psEnc->sCmn.prev_nBits = nBits;\r
-    psEnc->sCmn.first_frame_after_reset = 0;\r
-\r
-    /****************************************/\r
     /* Finalize payload                     */\r
     /****************************************/\r
+    psEnc->sCmn.first_frame_after_reset = 0;\r
     if( ++psEnc->sCmn.nFramesAnalyzed >= psEnc->sCmn.nFramesPerPacket ) {\r
-        /* Insert VAD flags and FEC flag at beginning of bitstream */\r
-        flags = 0;\r
-        for( i = 0; i < psEnc->sCmn.nFramesPerPacket; i++ ) {\r
-            flags |= psEnc->sCmn.VAD_flags[i];\r
-            flags  = SKP_LSHIFT( flags, 1 );\r
-        }\r
-        flags |= psEnc->sCmn.LBRR_flag;\r
-        ec_enc_patch_initial_bits( psRangeEnc, flags, psEnc->sCmn.nFramesPerPacket + 1 );\r
-\r
         /* Payload size */\r
-        nBits = ec_tell( psRangeEnc );\r
-        *pnBytesOut = SKP_RSHIFT( nBits + 7, 3 );\r
+        *pnBytesOut = SKP_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );\r
 \r
         /* Reset the number of frames in payload buffer */\r
         psEnc->sCmn.nFramesAnalyzed = 0;\r
-        psEnc->sCmn.prev_nBits = 0;\r
     } else {\r
         /* No payload this time */\r
         *pnBytesOut = 0;\r
@@ -248,8 +208,6 @@ TOC(ENCODE_FRAME)
     DEBUG_STORE_DATA( LTPcorr.dat,              &psEnc->LTPCorr,                                                sizeof( SKP_float ) );\r
     DEBUG_STORE_DATA( gains.dat,                sEncCtrl.Gains,                          psEnc->sCmn.nb_subfr * sizeof( SKP_float ) );\r
     DEBUG_STORE_DATA( gains_indices.dat,        &psEnc->sCmn.indices.GainsIndices,       psEnc->sCmn.nb_subfr * sizeof( SKP_int8  ) );\r
-    DEBUG_STORE_DATA( nBits.dat,                &nBits,                                                         sizeof( SKP_int   ) );\r
-    DEBUG_STORE_DATA( current_SNR_db.dat,       &sEncCtrl.current_SNR_dB,                                       sizeof( SKP_float ) );\r
     DEBUG_STORE_DATA( quantOffsetType.dat,      &psEnc->sCmn.indices.quantOffsetType,                           sizeof( SKP_int8  ) );\r
     DEBUG_STORE_DATA( speech_activity_q8.dat,   &psEnc->sCmn.speech_activity_Q8,                                sizeof( SKP_int   ) );\r
     DEBUG_STORE_DATA( signalType.dat,           &psEnc->sCmn.indices.signalType,                                sizeof( SKP_int8  ) ); \r
@@ -289,7 +247,6 @@ void SKP_Silk_LBRR_encode_FLP(
         /* Save original gains */\r
         SKP_memcpy( TempGains, psEncCtrl->Gains, psEnc->sCmn.nb_subfr * sizeof( SKP_float ) );\r
 \r
-\r
         if( psEnc->sCmn.nFramesAnalyzed == 0 || psEnc->sCmn.LBRR_flags[ psEnc->sCmn.nFramesAnalyzed - 1 ] == 0 ) {\r
             /* First frame in packet or previous frame not LBRR coded */\r
             psEnc->sCmn.LBRRprevLastGainIndex = psEnc->sShape.LastGainIndex;\r
@@ -314,7 +271,7 @@ void SKP_Silk_LBRR_encode_FLP(
         SKP_Silk_NSQ_wrapper_FLP( psEnc, psEncCtrl, psIndices_LBRR, &sNSQ_LBRR, \r
             psEnc->sCmn.pulses_LBRR[ psEnc->sCmn.nFramesAnalyzed ], xfw );\r
 \r
-        /* Restore original Gains */\r
+        /* Restore original gains */\r
         SKP_memcpy( psEncCtrl->Gains, TempGains, psEnc->sCmn.nb_subfr * sizeof( SKP_float ) );\r
     }\r
 }\r
diff --git a/src_FLP/SKP_Silk_init_encoder_FLP.c b/src_FLP/SKP_Silk_init_encoder_FLP.c
deleted file mode 100644 (file)
index 1a444d0..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/***********************************************************************\r
-Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
-Redistribution and use in source and binary forms, with or without \r
-modification, (subject to the limitations in the disclaimer below) \r
-are permitted provided that the following conditions are met:\r
-- Redistributions of source code must retain the above copyright notice,\r
-this list of conditions and the following disclaimer.\r
-- Redistributions in binary form must reproduce the above copyright \r
-notice, this list of conditions and the following disclaimer in the \r
-documentation and/or other materials provided with the distribution.\r
-- Neither the name of Skype Limited, nor the names of specific \r
-contributors, may be used to endorse or promote products derived from \r
-this software without specific prior written permission.\r
-NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
-BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
-CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
-FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
-COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
-USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-***********************************************************************/\r
-\r
-#include <stdlib.h>\r
-#include "SKP_Silk_main_FLP.h"\r
-\r
-/*********************************/\r
-/* Initialize Silk Encoder state */\r
-/*********************************/\r
-SKP_int SKP_Silk_init_encoder_FLP(\r
-    SKP_Silk_encoder_state_FLP      *psEnc              /* I/O  Encoder state FLP                       */\r
-) {\r
-    SKP_int ret = 0;\r
-\r
-    /* Clear the entire encoder state */\r
-    SKP_memset( psEnc, 0, sizeof( SKP_Silk_encoder_state_FLP ) );\r
-\r
-    psEnc->sCmn.variable_HP_smth1_Q15 = 200844; /* = SKP_Silk_log2(70)_Q0; */\r
-    psEnc->sCmn.variable_HP_smth2_Q15 = 200844; /* = SKP_Silk_log2(70)_Q0; */\r
-\r
-    /* Used to deactivate e.g. LSF interpolation and fluctuation reduction */\r
-    psEnc->sCmn.first_frame_after_reset = 1;\r
-\r
-    /* Initialize Silk VAD */\r
-    ret += SKP_Silk_VAD_Init( &psEnc->sCmn.sVAD );\r
-\r
-    return( ret );\r
-}\r
index dda5bf8..4447a8a 100644 (file)
@@ -36,9 +36,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "SKP_debug.h"\r
 #include "entenc.h"\r
 \r
-/* uncomment to compile without SSE optimizations */\r
-//#undef SKP_USE_SSE\r
-\r
 #ifdef __cplusplus\r
 extern "C"\r
 {\r
@@ -63,17 +60,15 @@ void SKP_Silk_LBRR_encode_FLP(
 );\r
 \r
 /* Initializes the Silk encoder state */\r
-SKP_int SKP_Silk_init_encoder_FLP(\r
+SKP_int SKP_Silk_init_encoder(\r
     SKP_Silk_encoder_state_FLP      *psEnc              /* I/O  Encoder state FLP                       */\r
 );\r
 \r
 /* Control the Silk encoder */\r
-SKP_int SKP_Silk_control_encoder_FLP( \r
-    SKP_Silk_encoder_state_FLP  *psEnc,                 /* I/O  Pointer to Silk encoder state FLP       */\r
-    const SKP_int               PacketSize_ms,          /* I    Packet length (ms)                      */\r
-    const SKP_int32             TargetRate_bps,         /* I    Target max bitrate (bps)                */\r
-    const SKP_int               PacketLoss_perc,        /* I    Packet loss rate (in percent)           */\r
-    const SKP_int               Complexity              /* I    Complexity (0-10)                       */\r
+SKP_int SKP_Silk_control_encoder( \r
+    SKP_Silk_encoder_state_FLP      *psEnc,             /* I/O  Pointer to Silk encoder state FLP       */\r
+    SKP_SILK_SDK_EncControlStruct   *encControl,        /* I:   Control structure                       */\r
+    const SKP_int32                 TargetRate_bps      /* I    Target max bitrate (bps)                */\r
 );\r
 \r
 /****************/\r
index 001c3ac..05f98fa 100644 (file)
@@ -139,24 +139,16 @@ void SKP_Silk_noise_shape_analysis_FLP(
     x_ptr = x - psEnc->sCmn.la_shape;\r
 \r
     /****************/\r
-    /* CONTROL SNR  */\r
-    /****************/\r
-    /* Reduce SNR_dB values if recent bitstream has exceeded TargetRate */\r
-    psEncCtrl->current_SNR_dB = psEnc->SNR_dB - 0.1f * psEnc->BufferedInChannel_ms;\r
-\r
-    /* Reduce SNR_dB because of any inband FEC used */\r
-    psEncCtrl->current_SNR_dB -= psEnc->inBandFEC_SNR_comp;\r
-\r
-    /****************/\r
     /* GAIN CONTROL */\r
     /****************/\r
+    SNR_adj_dB = psEnc->sCmn.SNR_dB_Q7 * ( 1 / 128.0f );\r
+\r
     /* Input quality is the average of the quality in the lowest two VAD bands */\r
     psEncCtrl->input_quality = 0.5f * ( psEnc->sCmn.input_quality_bands_Q15[ 0 ] + psEnc->sCmn.input_quality_bands_Q15[ 1 ] ) * ( 1.0f / 32768.0f );\r
 \r
     /* Coding quality level, between 0.0 and 1.0 */\r
-    psEncCtrl->coding_quality = SKP_sigmoid( 0.25f * ( psEncCtrl->current_SNR_dB - 18.0f ) );\r
+    psEncCtrl->coding_quality = SKP_sigmoid( 0.25f * ( SNR_adj_dB - 18.0f ) );\r
 \r
-    SNR_adj_dB = psEncCtrl->current_SNR_dB;\r
     if( psEnc->sCmn.useCBR == 0 ) {\r
         /* Reduce coding SNR during low speech activity */\r
         b = 1.0f - psEnc->sCmn.speech_activity_Q8 * ( 1.0f /  256.0f );\r
@@ -168,7 +160,7 @@ void SKP_Silk_noise_shape_analysis_FLP(
         SNR_adj_dB += HARM_SNR_INCR_dB * psEnc->LTPCorr;\r
     } else { \r
         /* For unvoiced signals and low-quality input, adjust the quality slower than SNR_dB setting */\r
-        SNR_adj_dB += ( -0.4f * psEncCtrl->current_SNR_dB + 6.0f ) * ( 1.0f - psEncCtrl->input_quality );\r
+        SNR_adj_dB += ( -0.4f * psEnc->sCmn.SNR_dB_Q7 * ( 1 / 128.0f ) + 6.0f ) * ( 1.0f - psEncCtrl->input_quality );\r
     }\r
 \r
     /*************************/\r
index 7090933..4f0a208 100644 (file)
@@ -48,7 +48,7 @@ void SKP_Silk_process_gains_FLP(
     }\r
 \r
     /* Limit the quantized signal */\r
-    InvMaxSqrVal = ( SKP_float )( pow( 2.0f, 0.33f * ( 21.0f - psEncCtrl->current_SNR_dB ) ) / psEnc->sCmn.subfr_length );\r
+    InvMaxSqrVal = ( SKP_float )( pow( 2.0f, 0.33f * ( 21.0f - psEnc->sCmn.SNR_dB_Q7 * ( 1 / 128.0f ) ) ) / psEnc->sCmn.subfr_length );\r
 \r
     for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) {\r
         /* Soft limit on ratio residual energy and squared gains */\r
index 8dbf734..2b57a02 100644 (file)
@@ -30,6 +30,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 \r
 #include "SKP_Silk_typedef.h"\r
 #include "SKP_Silk_main.h"\r
+#include "SKP_Silk_structs.h"\r
 \r
 #ifdef __cplusplus\r
 extern "C"\r
@@ -71,17 +72,12 @@ typedef struct {
     /* Buffer for find pitch and noise shape analysis */\r
     SKP_float                           x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ];/* Buffer for find pitch and noise shape analysis */\r
     SKP_float                           LTPCorr;                    /* Normalized correlation from pitch lag estimator */\r
-    SKP_float                           SNR_dB;                     /* Quality setting */\r
-    SKP_float                           BufferedInChannel_ms;       /* Simulated number of ms buffer in channel because of exceeded TargetRate_bps */\r
 \r
     /* Parameters for LTP scaling control */\r
     SKP_float                           prevLTPredCodGain;\r
     SKP_float                           HPLTPredCodGain;\r
-\r
-    SKP_float                           inBandFEC_SNR_comp;         /* Compensation to SNR_DB when using inband FEC Voiced */\r
 } SKP_Silk_encoder_state_FLP;\r
 \r
-\r
 /************************/\r
 /* Encoder control FLP  */\r
 /************************/\r
@@ -105,7 +101,6 @@ typedef struct {
        SKP_float                                       Lambda;\r
        SKP_float                                       input_quality;\r
        SKP_float                                       coding_quality;\r
-       SKP_float                                       current_SNR_dB;\r
 \r
        /* Measures */\r
        SKP_float                                       sparseness;\r
index 576fe4f..6310247 100644 (file)
   </ItemGroup>\r
   <ItemGroup>\r
     <ClCompile Include="SKP_Silk_apply_sine_window_FLP.c" />\r
-    <ClCompile Include="SKP_Silk_control_codec_FLP.c" />\r
     <ClCompile Include="SKP_Silk_corrMatrix_FLP.c" />\r
     <ClCompile Include="SKP_Silk_encode_frame_FLP.c" />\r
     <ClCompile Include="SKP_Silk_find_LPC_FLP.c" />\r
     <ClCompile Include="SKP_Silk_find_LTP_FLP.c" />\r
     <ClCompile Include="SKP_Silk_find_pitch_lags_FLP.c" />\r
     <ClCompile Include="SKP_Silk_find_pred_coefs_FLP.c" />\r
-    <ClCompile Include="SKP_Silk_init_encoder_FLP.c" />\r
     <ClCompile Include="SKP_Silk_LPC_analysis_filter_FLP.c" />\r
     <ClCompile Include="SKP_Silk_LTP_analysis_filter_FLP.c" />\r
     <ClCompile Include="SKP_Silk_LTP_scale_ctrl_FLP.c" />\r
index d55e607..92d93ea 100644 (file)
@@ -32,9 +32,6 @@
     <ClCompile Include="SKP_Silk_apply_sine_window_FLP.c">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
-    <ClCompile Include="SKP_Silk_control_codec_FLP.c">\r
-      <Filter>Source Files</Filter>\r
-    </ClCompile>\r
     <ClCompile Include="SKP_Silk_corrMatrix_FLP.c">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
@@ -53,9 +50,6 @@
     <ClCompile Include="SKP_Silk_find_pred_coefs_FLP.c">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
-    <ClCompile Include="SKP_Silk_init_encoder_FLP.c">\r
-      <Filter>Source Files</Filter>\r
-    </ClCompile>\r
     <ClCompile Include="SKP_Silk_LPC_analysis_filter_FLP.c">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
index bfa8449..56782b3 100644 (file)
@@ -399,13 +399,6 @@ void SKP_Silk_burg_modified(
     const SKP_int        D                   /* I   order                                                           */\r
 );\r
 \r
-/* Multiply a vector by a constant */\r
-void SKP_Silk_scale_vector16_Q14( \r
-    SKP_int16            *data1, \r
-    SKP_int              gain_Q14,           /* Gain in Q14 */ \r
-    SKP_int              dataSize\r
-);\r
-\r
 /* Copy and multiply a vector by a constant */\r
 void SKP_Silk_scale_copy_vector16( \r
     SKP_int16            *data_out, \r
@@ -414,19 +407,6 @@ void SKP_Silk_scale_copy_vector16(
     const SKP_int        dataSize            /* I:   length        */\r
 );\r
 \r
-void SKP_Silk_scale_vector32_16_Q14( \r
-    SKP_int32            *data1,             /* I/O: Q0/Q0         */\r
-    SKP_int              gain_Q14,           /* I:   Q14           */\r
-    SKP_int              dataSize            /* I:   length        */\r
-);\r
-\r
-/* Multiply a vector by a constant, does not saturate output data */\r
-void SKP_Silk_scale_vector32_Q16( \r
-    SKP_int32            *data1,             /* I/O: Q0/Q0         */\r
-    SKP_int32            gain_Q16,           /* I:   gain in Q16 ( SKP_int16_MIN <= gain_Q16 <= SKP_int16_MAX + 65536 ) */\r
-    const SKP_int        dataSize            /* I:   length        */\r
-);\r
-\r
 /* Some for the LTP related function requires Q26 to work.*/\r
 void SKP_Silk_scale_vector32_Q26_lshift_18( \r
     SKP_int32            *data1,             /* I/O: Q0/Q18        */\r
@@ -439,30 +419,25 @@ void SKP_Silk_scale_vector32_Q26_lshift_18(
 /********************************************************************/\r
 \r
 /*    return sum(inVec1[i]*inVec2[i])    */\r
-/*    inVec1 and inVec2 should be increasing ordered, and starting address should be 4 byte aligned. (a factor of 4)*/\r
 SKP_int32 SKP_Silk_inner_prod_aligned(\r
-    const SKP_int16* const inVec1,           /* I   input vector 1    */ \r
-    const SKP_int16* const inVec2,           /* I   input vector 2    */\r
-    const SKP_int          len               /* I   vector lengths    */\r
+    const SKP_int16 *const  inVec1,     /*    I input vector 1    */\r
+    const SKP_int16 *const  inVec2,     /*    I input vector 2    */\r
+    const SKP_int           len         /*    I vector lengths    */\r
 );\r
 \r
-SKP_int32 SKP_Silk_inner_prod16_aligned_sat(\r
-    const SKP_int16* const inVec1,           /* I   input vector 1  */\r
-    const SKP_int16* const inVec2,           /* I   input vector 2  */\r
-    const SKP_int          len               /* I   vector lengths  */\r
-);\r
-\r
-SKP_int64 SKP_Silk_inner_prod_aligned_64(\r
-    const SKP_int32        *inVec1,          /* I   input vector 1    */\r
-    const SKP_int32        *inVec2,          /* I   input vector 2    */\r
-    const SKP_int          len               /* I   vector lengths    */\r
+SKP_int32 SKP_Silk_inner_prod_aligned_scale(\r
+    const SKP_int16 *const  inVec1,     /*    I input vector 1          */\r
+    const SKP_int16 *const  inVec2,     /*    I input vector 2          */\r
+    const SKP_int           scale,      /*    I number of bits to shift */\r
+    const SKP_int           len         /*    I vector lengths          */\r
 );\r
 \r
 SKP_int64 SKP_Silk_inner_prod16_aligned_64(\r
-    const SKP_int16        *inVec1,          /* I   input vector 1    */\r
-    const SKP_int16        *inVec2,          /* I   input vector 2    */\r
-    const SKP_int          len               /* I   vector lengths    */\r
+    const SKP_int16         *inVec1,    /*    I input vector 1    */ \r
+    const SKP_int16         *inVec2,    /*    I input vector 2    */\r
+    const SKP_int           len         /*    I vector lengths    */\r
 );\r
+\r
 /********************************************************************/\r
 /*                                MACROS                            */\r
 /********************************************************************/\r
diff --git a/src_SigProc_FIX/SKP_Silk_allpass_int.c b/src_SigProc_FIX/SKP_Silk_allpass_int.c
deleted file mode 100644 (file)
index bc2f7ce..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/***********************************************************************\r
-Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
-Redistribution and use in source and binary forms, with or without \r
-modification, (subject to the limitations in the disclaimer below) \r
-are permitted provided that the following conditions are met:\r
-- Redistributions of source code must retain the above copyright notice,\r
-this list of conditions and the following disclaimer.\r
-- Redistributions in binary form must reproduce the above copyright \r
-notice, this list of conditions and the following disclaimer in the \r
-documentation and/or other materials provided with the distribution.\r
-- Neither the name of Skype Limited, nor the names of specific \r
-contributors, may be used to endorse or promote products derived from \r
-this software without specific prior written permission.\r
-NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
-BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
-CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
-FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
-COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
-USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-***********************************************************************/\r
-\r
-/*                                                                        *\r
- * SKP_Silk_allpass_int.c                                               *\r
- *                                                                        *\r
- * First-order allpass filter with                                        *\r
- * transfer function:                                                     *\r
- *                                                                        *\r
- *         A + Z^(-1)                                                     *\r
- * H(z) = ------------                                                    *\r
- *        1 + A*Z^(-1)                                                    *\r
- *                                                                        *\r
- * Implemented using minimum multiplier filter design.                    *\r
- *                                                                        *\r
- * Reference: http://www.univ.trieste.it/~ramponi/teaching/               *\r
- * DSP/materiale/Ch6(2).pdf                                               *\r
- *                                                                        *\r
- * Copyright 2007 (c), Skype Limited                                      *\r
- * Date: 070525                                                           *\r
- *                                                                        */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-\r
-/* First-order allpass filter */\r
-void SKP_Silk_allpass_int(\r
-    const SKP_int32      *in,    /* I:    Q25 input signal [len]               */\r
-    SKP_int32            *S,     /* I/O:  Q25 state [1]                         */\r
-    SKP_int              A,      /* I:    Q15 coefficient    (0 <= A < 32768)  */\r
-    SKP_int32            *out,   /* O:    Q25 output signal [len]              */\r
-    const SKP_int32      len     /* I:    Number of samples                    */\r
-)\r
-{\r
-    SKP_int32    Y2, X2, S0;\r
-    SKP_int        k;\r
-\r
-    S0 = S[ 0 ];\r
-    for( k = len - 1; k >= 0; k-- ) {\r
-        Y2         = *in - S0;\r
-        X2         = ( Y2 >> 15 ) * A + ( ( ( Y2 & 0x00007FFF ) * A ) >> 15 );\r
-        ( *out++ ) = S0 + X2;\r
-        S0         = ( *in++ ) + X2;\r
-    }\r
-    S[ 0 ] = S0;\r
-}\r
index f7862b8..c7f8b29 100644 (file)
@@ -25,15 +25,6 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
 ***********************************************************************/\r
 \r
-/*                                                                      *\r
- * SKP_Silk_autocorr.c                                                *\r
- *                                                                      *\r
- * Calculates the autocorrelation                                       *\r
- * The result has 29 non-zero bits for the first correlation, to leave  *\r
- * some    room for adding white noise fractions etc.                   *\r
- *                                                                      *\r
- * Copyright 2008 (c), Skype Limited                                    *\r
- *                                                                      */\r
 #include "SKP_Silk_SigProc_FIX.h"\r
 \r
 /* Compute autocorrelation */\r
index 2e3f691..c8c9b60 100644 (file)
@@ -37,6 +37,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "SKP_debug.h"\r
 #include "../src_SigProc_FIX/SKP_Silk_SigProc_FIX.h"\r
 \r
+#if SKP_TIC_TOC\r
+\r
 #ifdef _WIN32\r
 \r
 #if (defined(_WIN32) || defined(_WINCE)) \r
@@ -65,8 +67,6 @@ unsigned long GetHighResolutionTime(void) /* O: time in usec*/
 }\r
 #endif\r
 \r
-#if SKP_TIC_TOC\r
-\r
 int           SKP_Timer_nTimers = 0;\r
 int           SKP_Timer_depth_ctr = 0;\r
 char          SKP_Timer_tags[SKP_NUM_TIMERS_MAX][SKP_NUM_TIMERS_MAX_TAG_LEN];\r
index 98025c7..cc0364f 100644 (file)
@@ -34,9 +34,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 /*        * only when len>6, memory access can be reduced by half.              */\r
 \r
 SKP_int32 SKP_Silk_inner_prod_aligned(\r
-    const SKP_int16* const inVec1,  /*    I input vector 1    */\r
-    const SKP_int16* const inVec2,  /*    I input vector 2    */\r
-    const SKP_int             len   /*    I vector lengths    */\r
+    const SKP_int16 *const  inVec1,     /*    I input vector 1    */\r
+    const SKP_int16 *const  inVec2,     /*    I input vector 2    */\r
+    const SKP_int           len         /*    I vector lengths    */\r
 )\r
 {\r
     SKP_int   i; \r
@@ -47,23 +47,25 @@ SKP_int32 SKP_Silk_inner_prod_aligned(
     return sum;\r
 }\r
 \r
-SKP_int64 SKP_Silk_inner_prod_aligned_64(\r
-    const SKP_int32 *inVec1,        /*    I input vector 1    */ \r
-    const SKP_int32 *inVec2,        /*    I input vector 2    */\r
-    const SKP_int   len             /*    I vector lengths    */\r
+SKP_int32 SKP_Silk_inner_prod_aligned_scale(\r
+    const SKP_int16 *const  inVec1,     /*    I input vector 1          */\r
+    const SKP_int16 *const  inVec2,     /*    I input vector 2          */\r
+    const SKP_int           scale,      /*    I number of bits to shift */\r
+    const SKP_int           len         /*    I vector lengths          */\r
 )\r
 {\r
     SKP_int   i; \r
-    SKP_int64 sum = 0;\r
+    SKP_int32 sum = 0;\r
     for( i = 0; i < len; i++ ) {\r
-        sum = SKP_SMLAL( sum, inVec1[ i ], inVec2[ i ] );\r
+        sum = SKP_ADD_RSHIFT32( sum, SKP_SMULBB( inVec1[ i ], inVec2[ i ] ), scale );\r
     }\r
     return sum;\r
 }\r
+\r
 SKP_int64 SKP_Silk_inner_prod16_aligned_64(\r
-    const SKP_int16 *inVec1,        /*    I input vector 1    */ \r
-    const SKP_int16 *inVec2,        /*    I input vector 2    */\r
-    const SKP_int   len             /*    I vector lengths    */\r
+    const SKP_int16         *inVec1,    /*    I input vector 1    */ \r
+    const SKP_int16         *inVec2,    /*    I input vector 2    */\r
+    const SKP_int           len         /*    I vector lengths    */\r
 )\r
 {\r
     SKP_int   i; \r
@@ -73,17 +75,3 @@ SKP_int64 SKP_Silk_inner_prod16_aligned_64(
     }\r
     return sum;\r
 }\r
-\r
-SKP_int32 SKP_Silk_inner_prod16_aligned_sat(\r
-    const SKP_int16* const inVec1,  /*    I input vector 1  */ \r
-    const SKP_int16* const inVec2,  /*    I input vector 2  */\r
-    const SKP_int    len            /*    I vector lengths  */ \r
-)\r
-{\r
-    SKP_int   i; \r
-    SKP_int32 sum = 0;\r
-    for( i = 0; i < len; i++ ) {\r
-        sum = SKP_ADD_SAT32( sum, SKP_SMULBB( inVec1[ i ], inVec2[ i ] ) );\r
-    }\r
-    return sum;\r
-}\r
diff --git a/src_SigProc_FIX/SKP_Silk_lowpass_int.c b/src_SigProc_FIX/SKP_Silk_lowpass_int.c
deleted file mode 100644 (file)
index ac25455..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/***********************************************************************\r
-Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
-Redistribution and use in source and binary forms, with or without \r
-modification, (subject to the limitations in the disclaimer below) \r
-are permitted provided that the following conditions are met:\r
-- Redistributions of source code must retain the above copyright notice,\r
-this list of conditions and the following disclaimer.\r
-- Redistributions in binary form must reproduce the above copyright \r
-notice, this list of conditions and the following disclaimer in the \r
-documentation and/or other materials provided with the distribution.\r
-- Neither the name of Skype Limited, nor the names of specific \r
-contributors, may be used to endorse or promote products derived from \r
-this software without specific prior written permission.\r
-NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
-BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
-CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
-FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
-COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
-USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-***********************************************************************/\r
-\r
-/*                                                                      *\r
- * SKP_Silk_lowpass_int.c                                             *\r
- *                                                                      *\r
- * First order low-pass filter, with input as SKP_int32, running at     *\r
- * 48 kHz                                                               *\r
- *                                                                      *\r
- * Copyright 2006 (c), Skype Limited                                    *\r
- * Date: 060221                                                         *\r
- *                                                                      */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
-\r
-/* First order low-pass filter, with input as SKP_int32, running at 48 kHz        */\r
-void SKP_Silk_lowpass_int(\r
-    const SKP_int32      *in,            /* I:    Q25 48 kHz signal; length = len */\r
-    SKP_int32            *S,             /* I/O: Q25 state; length = 1            */\r
-    SKP_int32            *out,           /* O:    Q25 48 kHz signal; length = len */\r
-    const SKP_int32      len             /* I:    Number of samples               */\r
-)\r
-{\r
-    SKP_int        k;\r
-    SKP_int32    in_tmp, out_tmp, state;\r
-    \r
-    state = S[ 0 ];\r
-    for( k = len; k > 0; k-- ) {    \r
-        in_tmp  = *in++;\r
-        in_tmp -= SKP_RSHIFT( in_tmp, 2 );              /* multiply by 0.75 */\r
-        out_tmp = state + in_tmp;                       /* zero at nyquist  */\r
-        state   = in_tmp - SKP_RSHIFT( out_tmp, 1 );    /* pole             */\r
-        *out++  = out_tmp;\r
-    }\r
-    S[ 0 ] = state;\r
-}\r
-\r
-\r
index afb4a12..b161f92 100644 (file)
@@ -25,14 +25,6 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
 ***********************************************************************/\r
 \r
-/*                                                                      *\r
- * SKP_Silk_resampler_private_up2_HQ.c                                *\r
- *                                                                      *\r
- * Upsample by a factor 2, high quality                                 *\r
- *                                                                      *\r
- * Copyright 2010 (c), Skype Limited                                    *\r
- *                                                                      */\r
-\r
 #include "SKP_Silk_SigProc_FIX.h"\r
 #include "SKP_Silk_resampler_private.h"\r
 \r
index 9c63d40..c099893 100644 (file)
@@ -25,18 +25,10 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
 ***********************************************************************/\r
 \r
-/*                                                                      *\r
- * SKP_Silk_resampler_private_up4.c                                   *\r
- *                                                                      *\r
- * Upsample by a factor 4, low quality                                  *\r
- *                                                                      *\r
- * Copyright 2010 (c), Skype Limited                                    *\r
- *                                                                      */\r
-\r
 #include "SKP_Silk_SigProc_FIX.h"\r
 #include "SKP_Silk_resampler_private.h"\r
 \r
-/* Upsample by a factor 4, Note: very low quality, only use with output sampling rates above 96 kHz. */\r
+/* Upsample by a factor 4, Note: low quality, only use with output sampling rates above 96 kHz. */\r
 void SKP_Silk_resampler_private_up4(\r
     SKP_int32                       *S,             /* I/O: State vector [ 2 ]                      */\r
     SKP_int16                       *out,           /* O:   Output signal [ 4 * len ]               */\r
index e08f83a..e541f50 100644 (file)
@@ -25,18 +25,6 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
 ***********************************************************************/\r
 \r
-/*                                                                      *\r
- * File Name:    SKP_Silk_resample_rom.h                              *\r
- *                                                                      *\r
- * Description: Header file for FIR resampling of                       *\r
- *                32 and 44 kHz input                                   *\r
- *                                                                      *\r
- * Copyright 2007 (c), Skype Limited                                    *\r
- * All rights reserved.                                                 *\r
- *                                                                      *\r
- * Date: 070807                                                         *\r
- *                                                                      */\r
-\r
 #ifndef _SKP_SILK_FIX_RESAMPLER_ROM_H_\r
 #define _SKP_SILK_FIX_RESAMPLER_ROM_H_\r
 \r
index e4513e3..292422b 100644 (file)
@@ -43,7 +43,7 @@ extern "C" {
 #endif\r
 \r
 /* Flag to enable support for input/output sampling rates above 48 kHz. Turn off for embedded devices */\r
-#define RESAMPLER_SUPPORT_ABOVE_48KHZ                   1\r
+#define RESAMPLER_SUPPORT_ABOVE_48KHZ                    1\r
 \r
 #define SKP_Silk_RESAMPLER_MAX_FIR_ORDER                 16\r
 #define SKP_Silk_RESAMPLER_MAX_IIR_ORDER                 6\r
index a3615e7..a673418 100644 (file)
@@ -28,25 +28,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "SKP_Silk_SigProc_FIX.h"\r
 \r
 /* Multiply a vector by a constant */\r
-void SKP_Silk_scale_vector16_Q14( \r
-    SKP_int16           *data1, \r
-    SKP_int             gain_Q14,       /* Gain in Q14 */ \r
-    SKP_int             dataSize\r
-)\r
-{\r
-    SKP_int   i;\r
-    SKP_int32 gain_Q16;\r
-\r
-    SKP_assert( gain_Q14 <   32768 );\r
-    SKP_assert( gain_Q14 >= -32768 );\r
-\r
-    gain_Q16 = SKP_LSHIFT( gain_Q14, 2 );\r
-    for( i = 0; i < dataSize; i ++ ) {\r
-        data1[ i ] = SKP_SMULWB( gain_Q16, data1[ i ] );\r
-    }\r
-}\r
-\r
-/* Multiply a vector by a constant */\r
 void SKP_Silk_scale_vector32_Q26_lshift_18( \r
     SKP_int32           *data1,                     /* (I/O): Q0/Q18        */\r
     SKP_int32           gain_Q26,                   /* (I):   Q26           */\r
@@ -59,49 +40,3 @@ void SKP_Silk_scale_vector32_Q26_lshift_18(
         data1[ i ] = (SKP_int32)SKP_CHECK_FIT32( SKP_RSHIFT64( SKP_SMULL( data1[ i ], gain_Q26 ), 8 ) );// OUTPUT: Q18\r
     }\r
 }\r
-\r
-/* Multiply a vector by a constant */\r
-void SKP_Silk_scale_vector32_16_Q14( \r
-    SKP_int32           *data1,                     /* (I/O): Q0/Q0         */\r
-    SKP_int             gain_Q14,                   /* (I):   Q14           */\r
-    SKP_int             dataSize                    /* (I):   length        */\r
-)\r
-{\r
-    SKP_int  i, gain_Q16;\r
-\r
-    if( gain_Q14 < ( SKP_int16_MAX >> 2 ) ) {\r
-        gain_Q16 = SKP_LSHIFT( gain_Q14, 2 );\r
-        for( i = 0; i < dataSize; i++ ) {\r
-            data1[ i ] = SKP_SMULWB( data1[ i ], gain_Q16 );\r
-        }\r
-    } else {\r
-        SKP_assert( gain_Q14 >= SKP_int16_MIN );\r
-        for( i = 0; i < dataSize; i++ ) {\r
-            data1[ i ] = SKP_LSHIFT( SKP_SMULWB( data1[ i ], gain_Q14 ), 2 );\r
-        }\r
-    }\r
-}\r
-\r
-/* Multiply a vector by a constant, does not saturate output data */\r
-void SKP_Silk_scale_vector32_Q16( \r
-    SKP_int32           *data1,                     /* (I/O): Q0/Q0         */\r
-    SKP_int32           gain_Q16,                   /* (I):   gain in Q16 ( SKP_int16_MIN <= gain_Q16 <= SKP_int16_MAX + 65536 ) */\r
-    const SKP_int       dataSize                    /* (I):   length        */\r
-)\r
-{\r
-    SKP_int     i;\r
-\r
-    SKP_assert( gain_Q16 <= SKP_int16_MAX + 65536 );\r
-    SKP_assert( gain_Q16 >= SKP_int16_MIN );\r
-\r
-    if( gain_Q16 > SKP_int16_MAX ) {\r
-        gain_Q16 -= 65536;\r
-        for( i = 0; i < dataSize; i++ ) {\r
-            data1[ i ] = SKP_SMLAWB( data1[ i ], data1[ i ], gain_Q16 );\r
-        }\r
-    } else {\r
-        for( i = 0; i < dataSize; i++ ) {\r
-            data1[ i ] = SKP_SMULWB( data1[ i ], gain_Q16 );\r
-        }\r
-    }\r
-}\r
index 891b59a..f2cc70a 100644 (file)
@@ -25,20 +25,11 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
 ***********************************************************************/\r
 \r
-/*                                                                      *\r
- * SKP_Silk_schur64.c                                                 *\r
- *                                                                      *\r
- * Calculates the reflection coefficients from the correlation sequence *\r
- * using extra precision                                                *\r
- *                                                                      *\r
- * Copyright 2008 (c), Skype Limited                                    *\r
- * Date: 080103                                                         *\r
- *                                                                      */\r
 #include "SKP_Silk_SigProc_FIX.h"\r
 \r
 /* Slower than schur(), but more accurate.                              */\r
 /* Uses SMULL(), available on armv4                                     */ \r
-SKP_int32 SKP_Silk_schur64(                    /* O:    Returns residual energy                     */\r
+SKP_int32 SKP_Silk_schur64(                      /* O:    Returns residual energy                     */\r
     SKP_int32            rc_Q16[],               /* O:    Reflection coefficients [order] Q16         */\r
     const SKP_int32      c[],                    /* I:    Correlations [order+1]                      */\r
     SKP_int32            order                   /* I:    Prediction order                            */\r
index a7cd691..d1848ef 100644 (file)
@@ -25,15 +25,8 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
 ***********************************************************************/\r
 \r
-/*                                                                      *\r
- * SKP_Silk_sum_sqr_shift.c                                           *\r
- *                                                                      *\r
- * compute number of bits to right shift the sum of squares of a vector *\r
- * of int16s to make it fit in an int32                                 *\r
- *                                                                      *\r
- * Copyright 2006-2008 (c), Skype Limited                               *\r
- *                                                                      */\r
 #include "SKP_Silk_SigProc_FIX.h"\r
+\r
 /* Compute number of bits to right shift the sum of squares of a vector */\r
 /* of int16s to make it fit in an int32                                 */\r
 void SKP_Silk_sum_sqr_shift(\r
@@ -44,24 +37,14 @@ void SKP_Silk_sum_sqr_shift(
 )\r
 {\r
     SKP_int   i, shft;\r
-    SKP_int32 in32, nrg_tmp, nrg;\r
+    SKP_int32 nrg_tmp, nrg;\r
 \r
-    if( (SKP_int32)( (SKP_int_ptr_size)x & 2 ) != 0 ) {\r
-        /* Input is not 4-byte aligned */\r
-        nrg = SKP_SMULBB( x[ 0 ], x[ 0 ] );\r
-        i = 1;\r
-    } else {\r
-        nrg = 0;\r
-        i   = 0;\r
-    }\r
+    nrg  = 0;\r
     shft = 0;\r
     len--;\r
-    while( i < len ) {\r
-        /* Load two values at once */\r
-        in32 = *( (SKP_int32 *)&x[ i ] );\r
-        nrg = SKP_SMLABB_ovflw( nrg, in32, in32 );\r
-        nrg = SKP_SMLATT_ovflw( nrg, in32, in32 );\r
-        i += 2;\r
+    for( i = 0; i < len; i += 2 ) {\r
+        nrg = SKP_SMLABB_ovflw( nrg, x[ i ], x[ i ] );\r
+        nrg = SKP_SMLABB_ovflw( nrg, x[ i + 1 ], x[ i + 1 ] );\r
         if( nrg < 0 ) {\r
             /* Scale down */\r
             nrg = (SKP_int32)SKP_RSHIFT_uint( (SKP_uint32)nrg, 2 );\r
@@ -70,10 +53,8 @@ void SKP_Silk_sum_sqr_shift(
         }\r
     }\r
     for( ; i < len; i += 2 ) {\r
-        /* Load two values at once */\r
-        in32 = *( (SKP_int32 *)&x[ i ] );\r
-        nrg_tmp = SKP_SMULBB( in32, in32 );\r
-        nrg_tmp = SKP_SMLATT_ovflw( nrg_tmp, in32, in32 );\r
+        nrg_tmp = SKP_SMULBB( x[ i ], x[ i ] );\r
+        nrg_tmp = SKP_SMLABB_ovflw( nrg_tmp, x[ i + 1 ], x[ i + 1 ] );\r
         nrg = (SKP_int32)SKP_ADD_RSHIFT_uint( nrg, (SKP_uint32)nrg_tmp, shft );\r
         if( nrg < 0 ) {\r
             /* Scale down */\r
index 9c37d69..97067bd 100644 (file)
@@ -113,13 +113,6 @@ void SKP_Silk_insertion_sort_decreasing_FLP(
     const SKP_int        K              /* I:    Number of correctly sorted positions    */\r
 );\r
 \r
-void SKP_Silk_insertion_sort_increasing_FLP(\r
-    SKP_float            *a,            /* I/O:  Unsorted / Sorted vector                */\r
-    SKP_int              *index,        /* O:    Index vector for the sorted elements    */\r
-    const SKP_int        L,             /* I:    Vector length                           */\r
-    const SKP_int        K              /* I:    Number of correctly sorted positions    */\r
-);\r
-\r
 /* Compute reflection coefficients from input signal */\r
 SKP_float SKP_Silk_burg_modified_FLP(       /* O    returns residual energy                                         */\r
     SKP_float           A[],                /* O    prediction coefficients (length order)                          */\r
index fa592de..20d3f7d 100644 (file)
@@ -32,52 +32,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "SKP_Silk_typedef.h"\r
 #include "SKP_Silk_SigProc_FLP.h"\r
 \r
-void SKP_Silk_insertion_sort_increasing_FLP(\r
-    SKP_float            *a,          /* I/O:  Unsorted / Sorted vector                */\r
-    SKP_int              *index,      /* O:    Index vector for the sorted elements    */\r
-    const SKP_int        L,           /* I:    Vector length                           */\r
-    const SKP_int        K            /* I:    Number of correctly sorted positions    */\r
-)\r
-{\r
-    SKP_float value;\r
-    SKP_int   i, j;\r
-\r
-    /* Safety checks */\r
-    SKP_assert( K >  0 );\r
-    SKP_assert( L >  0 );\r
-    SKP_assert( L >= K );\r
-\r
-    /* Write start indices in index vector */\r
-    for( i = 0; i < K; i++ ) {\r
-        index[ i ] = i;\r
-    }\r
-\r
-    /* Sort vector elements by value, increasing order */\r
-    for( i = 1; i < K; i++ ) {\r
-        value = a[ i ];\r
-        for( j = i - 1; ( j >= 0 ) && ( value < a[ j ] ); j-- ) {\r
-            a[ j + 1 ]     = a[ j ];     /* Shift value */\r
-            index[ j + 1 ] = index[ j ]; /* Shift index */\r
-        }\r
-        a[ j + 1 ]     = value; /* Write value */\r
-        index[ j + 1 ] = i;     /* Write index */\r
-    }\r
-\r
-    /* If less than L values are asked check the remaining values,      */\r
-    /* but only spend CPU to ensure that the K first values are correct */\r
-    for( i = K; i < L; i++ ) {\r
-        value = a[ i ];\r
-        if( value < a[ K - 1 ] ) {\r
-            for( j = K - 2; ( j >= 0 ) && ( value < a[ j ] ); j-- ) {\r
-                a[ j + 1 ]     = a[ j ];     /* Shift value */\r
-                index[ j + 1 ] = index[ j ]; /* Shift index */\r
-            }\r
-            a[ j + 1 ]     = value; /* Write value */\r
-            index[ j + 1 ] = i;        /* Write index */\r
-        }\r
-    }\r
-}\r
-\r
 void SKP_Silk_insertion_sort_decreasing_FLP(\r
     SKP_float            *a,          /* I/O:  Unsorted / Sorted vector                */\r
     SKP_int              *index,      /* O:    Index vector for the sorted elements    */\r
@@ -123,25 +77,3 @@ void SKP_Silk_insertion_sort_decreasing_FLP(
         }\r
     }\r
 }\r
-\r
-void SKP_Silk_insertion_sort_increasing_all_values_FLP(\r
-    SKP_float            *a,          /* I/O:  Unsorted / Sorted vector                */\r
-    const SKP_int        L            /* I:    Vector length                           */\r
-)\r
-{\r
-    SKP_float value;\r
-    SKP_int   i, j;\r
-\r
-    /* Safety checks */\r
-    SKP_assert( L >  0 );\r
-\r
-    /* Sort vector elements by value, increasing order */\r
-    for( i = 1; i < L; i++ ) {\r
-        value = a[ i ];\r
-        for( j = i - 1; ( j >= 0 ) && ( value < a[ j ] ); j-- ) {    \r
-            a[ j + 1 ] = a[ j ]; /* Shift value */\r
-        }\r
-        a[ j + 1 ] = value; /* Write value */\r
-    }\r
-}\r
-\r
diff --git a/src_common/SKP_Silk_LBRR_embed.c b/src_common/SKP_Silk_LBRR_embed.c
deleted file mode 100644 (file)
index c5080d1..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/***********************************************************************\r
-Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
-Redistribution and use in source and binary forms, with or without \r
-modification, (subject to the limitations in the disclaimer below) \r
-are permitted provided that the following conditions are met:\r
-- Redistributions of source code must retain the above copyright notice,\r
-this list of conditions and the following disclaimer.\r
-- Redistributions in binary form must reproduce the above copyright \r
-notice, this list of conditions and the following disclaimer in the \r
-documentation and/or other materials provided with the distribution.\r
-- Neither the name of Skype Limited, nor the names of specific \r
-contributors, may be used to endorse or promote products derived from \r
-this software without specific prior written permission.\r
-NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
-BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
-CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
-FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
-COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
-USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-***********************************************************************/\r
-\r
-#include "SKP_Silk_main.h"\r
-\r
-/*******************************************/\r
-/* Encode LBRR side info and excitation    */\r
-/*******************************************/\r
-void SKP_Silk_LBRR_embed(\r
-    SKP_Silk_encoder_state      *psEncC,            /* I/O  Encoder state                               */\r
-    ec_enc                      *psRangeEnc         /* I/O  Compressor data structure                   */\r
-)\r
-{\r
-    SKP_int   i;\r
-    SKP_int32 LBRR_symbol;\r
-\r
-    /* Encode LBRR flags */\r
-    LBRR_symbol = 0;\r
-    for( i = 0; i < psEncC->nFramesPerPacket; i++ ) {\r
-        LBRR_symbol |= SKP_LSHIFT( psEncC->LBRR_flags[ i ], i );\r
-    }\r
-    psEncC->LBRR_flag = LBRR_symbol > 0 ? 1 : 0;\r
-    if( LBRR_symbol && psEncC->nFramesPerPacket > 1 ) {\r
-        ec_enc_icdf( psRangeEnc, LBRR_symbol - 1, SKP_Silk_LBRR_flags_iCDF_ptr[ psEncC->nFramesPerPacket - 2 ], 8 );\r
-    }\r
-\r
-    /* Code indices and excitation signals */\r
-    for( i = 0; i < psEncC->nFramesPerPacket; i++ ) {\r
-        if( psEncC->LBRR_flags[ i ] ) {\r
-            SKP_Silk_encode_indices( psEncC, psRangeEnc, i, 1 );\r
-            SKP_Silk_encode_pulses( psRangeEnc, psEncC->indices_LBRR[i].signalType, \r
-                psEncC->indices_LBRR[i].quantOffsetType, psEncC->pulses_LBRR[ i ], psEncC->frame_length );\r
-        }\r
-    }\r
-}\r
index 57c5939..f95bbc9 100644 (file)
@@ -34,9 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */\r
 #include "SKP_Silk_main.h"\r
 \r
-#if SWITCH_TRANSITION_FILTERING\r
-\r
-/* Helper function, that interpolates the filter taps */\r
+/* Helper function, interpolates the filter taps */\r
 SKP_INLINE void SKP_Silk_LP_interpolate_filter_taps( \r
     SKP_int32           B_Q28[ TRANSITION_NB ], \r
     SKP_int32           A_Q28[ TRANSITION_NA ],\r
@@ -133,4 +131,3 @@ void SKP_Silk_LP_variable_cutoff(
         SKP_Silk_biquad_alt( signal, B_Q28, A_Q28, psLP->In_LP_State, signal, frame_length );\r
     }\r
 }\r
-#endif\r
diff --git a/src_common/SKP_Silk_NLSF_MSVQ_decode.c b/src_common/SKP_Silk_NLSF_MSVQ_decode.c
deleted file mode 100644 (file)
index a48448f..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-/***********************************************************************\r
-Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
-Redistribution and use in source and binary forms, with or without \r
-modification, (subject to the limitations in the disclaimer below) \r
-are permitted provided that the following conditions are met:\r
-- Redistributions of source code must retain the above copyright notice,\r
-this list of conditions and the following disclaimer.\r
-- Redistributions in binary form must reproduce the above copyright \r
-notice, this list of conditions and the following disclaimer in the \r
-documentation and/or other materials provided with the distribution.\r
-- Neither the name of Skype Limited, nor the names of specific \r
-contributors, may be used to endorse or promote products derived from \r
-this software without specific prior written permission.\r
-NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
-BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
-CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
-FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
-COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
-USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-***********************************************************************/\r
-\r
-#include "SKP_Silk_main.h"\r
-\r
-/* NLSF vector decoder */\r
-void SKP_Silk_NLSF_MSVQ_decode(\r
-    SKP_int                         *pNLSF_Q15,     /* O    Pointer to decoded output vector [LPC_ORDER x 1]    */\r
-    const SKP_Silk_NLSF_CB_struct   *psNLSF_CB,     /* I    Pointer to NLSF codebook struct                     */\r
-    const SKP_int8                  *NLSFIndices,   /* I    Pointer to NLSF indices          [nStages x 1]      */\r
-    const SKP_int                   LPC_order       /* I    LPC order used                                      */\r
-) \r
-{\r
-    const SKP_int8 *pCB_element;\r
-          SKP_int   i, s;\r
-          SKP_int   pNLSF_Q8[ MAX_LPC_ORDER ];\r
-\r
-    /* Check that index is within valid range */\r
-    SKP_assert( 0 <= NLSFIndices[ 0 ] && NLSFIndices[ 0 ] < psNLSF_CB->CBStages[ 0 ].nVectors );\r
-\r
-    /* Point to the first vector element */\r
-    pCB_element = &psNLSF_CB->CBStages[ 0 ].CB_NLSF_Q8[ SKP_SMULBB( (SKP_int16)NLSFIndices[ 0 ], LPC_order ) ];\r
-\r
-    /* Initialize with the codebook vector from stage 0 */\r
-    for( i = 0; i < LPC_order; i++ ) {\r
-        pNLSF_Q8[ i ] = SKP_LSHIFT( ( SKP_int )pCB_element[ i ], NLSF_Q_DOMAIN_STAGE_2_TO_LAST - NLSF_Q_DOMAIN_STAGE_0 );\r
-    }\r
-          \r
-    if( LPC_order == 16 ) {\r
-        for( s = 1; s < psNLSF_CB->nStages; s++ ) {\r
-            /* Check that each index is within valid range */\r
-            SKP_assert( 0 <= NLSFIndices[ s ] && NLSFIndices[ s ] < psNLSF_CB->CBStages[ s ].nVectors );\r
-\r
-            /* Point to the first vector element */\r
-            pCB_element = &psNLSF_CB->CBStages[ s ].CB_NLSF_Q8[ 16 * (SKP_int16)NLSFIndices[ s ] ];\r
-\r
-            /* Add the codebook vector from the current stage */\r
-            pNLSF_Q8[  0 ] += ( SKP_int )pCB_element[  0 ];\r
-            pNLSF_Q8[  1 ] += ( SKP_int )pCB_element[  1 ];\r
-            pNLSF_Q8[  2 ] += ( SKP_int )pCB_element[  2 ];\r
-            pNLSF_Q8[  3 ] += ( SKP_int )pCB_element[  3 ];\r
-            pNLSF_Q8[  4 ] += ( SKP_int )pCB_element[  4 ];\r
-            pNLSF_Q8[  5 ] += ( SKP_int )pCB_element[  5 ];\r
-            pNLSF_Q8[  6 ] += ( SKP_int )pCB_element[  6 ];\r
-            pNLSF_Q8[  7 ] += ( SKP_int )pCB_element[  7 ];\r
-            pNLSF_Q8[  8 ] += ( SKP_int )pCB_element[  8 ];\r
-            pNLSF_Q8[  9 ] += ( SKP_int )pCB_element[  9 ];\r
-            pNLSF_Q8[ 10 ] += ( SKP_int )pCB_element[ 10 ];\r
-            pNLSF_Q8[ 11 ] += ( SKP_int )pCB_element[ 11 ];\r
-            pNLSF_Q8[ 12 ] += ( SKP_int )pCB_element[ 12 ];\r
-            pNLSF_Q8[ 13 ] += ( SKP_int )pCB_element[ 13 ];\r
-            pNLSF_Q8[ 14 ] += ( SKP_int )pCB_element[ 14 ];\r
-            pNLSF_Q8[ 15 ] += ( SKP_int )pCB_element[ 15 ];\r
-        }\r
-    } else {\r
-        SKP_assert( LPC_order == 10 );\r
-        for( s = 1; s < psNLSF_CB->nStages; s++ ) {\r
-            /* Point to the first vector element */\r
-            pCB_element = &psNLSF_CB->CBStages[ s ].CB_NLSF_Q8[ SKP_SMULBB( (SKP_int16)NLSFIndices[ s ], LPC_order ) ];\r
-\r
-            /* Add the codebook vector from the current stage */\r
-            pNLSF_Q8[  0 ] += ( SKP_int )pCB_element[  0 ];\r
-            pNLSF_Q8[  1 ] += ( SKP_int )pCB_element[  1 ];\r
-            pNLSF_Q8[  2 ] += ( SKP_int )pCB_element[  2 ];\r
-            pNLSF_Q8[  3 ] += ( SKP_int )pCB_element[  3 ];\r
-            pNLSF_Q8[  4 ] += ( SKP_int )pCB_element[  4 ];\r
-            pNLSF_Q8[  5 ] += ( SKP_int )pCB_element[  5 ];\r
-            pNLSF_Q8[  6 ] += ( SKP_int )pCB_element[  6 ];\r
-            pNLSF_Q8[  7 ] += ( SKP_int )pCB_element[  7 ];\r
-            pNLSF_Q8[  8 ] += ( SKP_int )pCB_element[  8 ];\r
-            pNLSF_Q8[  9 ] += ( SKP_int )pCB_element[  9 ];\r
-        }\r
-    }\r
-\r
-    /* Add 1/2 in Q15 */\r
-    for( i = 0; i < LPC_order; i++ ) {\r
-        pNLSF_Q15[ i ] = SKP_LSHIFT16( pNLSF_Q8[ i ], 15 - NLSF_Q_DOMAIN_STAGE_2_TO_LAST ) + SKP_FIX_CONST( 0.5f, 15 );\r
-    }\r
-\r
-    /* NLSF stabilization */\r
-    SKP_Silk_NLSF_stabilize( pNLSF_Q15, psNLSF_CB->NDeltaMin_Q15, LPC_order );\r
-}\r
diff --git a/src_common/SKP_Silk_NLSF_MSVQ_encode.c b/src_common/SKP_Silk_NLSF_MSVQ_encode.c
deleted file mode 100644 (file)
index 343e1fd..0000000
+++ /dev/null
@@ -1,238 +0,0 @@
-/***********************************************************************\r
-Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
-Redistribution and use in source and binary forms, with or without \r
-modification, (subject to the limitations in the disclaimer below) \r
-are permitted provided that the following conditions are met:\r
-- Redistributions of source code must retain the above copyright notice,\r
-this list of conditions and the following disclaimer.\r
-- Redistributions in binary form must reproduce the above copyright \r
-notice, this list of conditions and the following disclaimer in the \r
-documentation and/or other materials provided with the distribution.\r
-- Neither the name of Skype Limited, nor the names of specific \r
-contributors, may be used to endorse or promote products derived from \r
-this software without specific prior written permission.\r
-NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
-BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
-CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
-FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
-COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
-USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-***********************************************************************/\r
-\r
-#include "SKP_Silk_main.h"\r
-\r
-/***********************/\r
-/* NLSF vector encoder */\r
-/***********************/\r
-void SKP_Silk_NLSF_MSVQ_encode(\r
-          SKP_int8                  *NLSFIndices,           /* O    Codebook path vector [ CB_STAGES ]      */\r
-          SKP_int                   *pNLSF_Q15,             /* I/O  Quantized NLSF vector [ LPC_ORDER ]     */\r
-    const SKP_Silk_NLSF_CB_struct   *psNLSF_CB,             /* I    Codebook object                         */\r
-    const SKP_int                   *pNLSF_q_Q15_prev,      /* I    Prev. quantized NLSF vector [LPC_ORDER] */\r
-    const SKP_int                   *pW_Q5,                 /* I    NLSF weight vector [ LPC_ORDER ]        */\r
-    const SKP_int                   NLSF_mu_Q15,            /* I    Rate weight for the RD optimization     */\r
-    const SKP_int                   NLSF_mu_fluc_red_Q16,   /* I    Fluctuation reduction error weight      */\r
-    const SKP_int                   NLSF_MSVQ_Survivors,    /* I    Max survivors from each stage           */\r
-    const SKP_int                   LPC_order,              /* I    LPC order                               */\r
-    const SKP_int                   deactivate_fluc_red     /* I    Deactivate fluctuation reduction        */\r
-)\r
-{\r
-    SKP_int     i, s, k, cur_survivors = 0, prev_survivors, min_survivors, input_index, cb_index, bestIndex;\r
-    SKP_int32   rateDistThreshold_Q18;\r
-#if( NLSF_MSVQ_FLUCTUATION_REDUCTION == 1 )\r
-    SKP_int32   se_Q15, wsse_Q20, bestRateDist_Q20;\r
-#endif\r
-\r
-    SKP_int32   pRateDist_Q18[  NLSF_MSVQ_TREE_SEARCH_MAX_VECTORS_EVALUATED ];\r
-    SKP_int32   pRate_Q4[       MAX_NLSF_MSVQ_SURVIVORS ];\r
-    SKP_int32   pRate_new_Q4[   MAX_NLSF_MSVQ_SURVIVORS ];\r
-    SKP_int     pTempIndices[   MAX_NLSF_MSVQ_SURVIVORS ];\r
-    SKP_int8    pPath[          MAX_NLSF_MSVQ_SURVIVORS * NLSF_MSVQ_MAX_CB_STAGES ];\r
-    SKP_int8    pPath_new[      MAX_NLSF_MSVQ_SURVIVORS * NLSF_MSVQ_MAX_CB_STAGES ];\r
-    SKP_int16   pRes_Q15[       MAX_NLSF_MSVQ_SURVIVORS * MAX_LPC_ORDER ];\r
-    SKP_int16   pRes_new_Q15[   MAX_NLSF_MSVQ_SURVIVORS * MAX_LPC_ORDER ];\r
-\r
-    const SKP_int16 *pConstInt16;\r
-          SKP_int16 *pInt16;\r
-    const SKP_int8  *pConstInt8;\r
-          SKP_int8  *pInt8;\r
-    const SKP_int8  *pCB_element;\r
-    const SKP_Silk_NLSF_CBS *pCurrentCBStage;\r
-\r
-    SKP_assert( NLSF_MSVQ_Survivors <= MAX_NLSF_MSVQ_SURVIVORS );\r
-\r
-#ifdef SAVE_ALL_INTERNAL_DATA\r
-    DEBUG_STORE_DATA( NLSF.dat,    pNLSF_Q15,    LPC_order * sizeof( SKP_int   ) );\r
-    DEBUG_STORE_DATA( WNLSF.dat,   pW_Q5,        LPC_order * sizeof( SKP_int   ) );\r
-    DEBUG_STORE_DATA( NLSF_mu.dat, &NLSF_mu_Q15,             sizeof( SKP_int32 ) );\r
-#endif\r
-\r
-    /****************************************************/\r
-    /* Tree search for the multi-stage vector quantizer */\r
-    /****************************************************/\r
-\r
-    /* Clear accumulated rates */\r
-    SKP_memset( pRate_Q4, 0, NLSF_MSVQ_Survivors * sizeof( SKP_int32 ) );\r
-\r
-    /* Subtract 1/2 from NLSF input vector to create initial residual */\r
-    for( i = 0; i < LPC_order; i++ ) {\r
-        pRes_Q15[ i ] = pNLSF_Q15[ i ] - SKP_FIX_CONST( 0.5f, 15 );\r
-    }\r
-\r
-    /* Set first stage values */\r
-    prev_survivors = 1;\r
-\r
-    /* Minimum number of survivors */\r
-    min_survivors = NLSF_MSVQ_Survivors / 2;\r
-\r
-    /* Loop over all stages */\r
-    for( s = 0; s < psNLSF_CB->nStages; s++ ) {\r
-\r
-        /* Set a pointer to the current stage codebook */\r
-        pCurrentCBStage = &psNLSF_CB->CBStages[ s ];\r
-\r
-        /* Calculate the number of survivors in the current stage */\r
-        cur_survivors = SKP_min_32( NLSF_MSVQ_Survivors, SKP_SMULBB( prev_survivors, pCurrentCBStage->nVectors ) );\r
-\r
-#if( NLSF_MSVQ_FLUCTUATION_REDUCTION == 0 )\r
-        /* Find a single best survivor in the last stage, if we */\r
-        /* do not need candidates for fluctuation reduction     */\r
-        if( s == psNLSF_CB->nStages - 1 ) {\r
-            cur_survivors = 1;\r
-        }\r
-#endif\r
-\r
-        /* Nearest neighbor clustering for multiple input data vectors */\r
-        SKP_Silk_NLSF_VQ_rate_distortion( pRateDist_Q18, pCurrentCBStage, pRes_Q15, pW_Q5, \r
-            pRate_Q4, NLSF_mu_Q15, prev_survivors, s, LPC_order );\r
-\r
-        /* Sort the rate-distortion errors */\r
-        SKP_Silk_insertion_sort_increasing( pRateDist_Q18, pTempIndices, \r
-            prev_survivors * pCurrentCBStage->nVectors, cur_survivors );\r
-\r
-        /* Discard survivors with rate-distortion values too far above the best one */\r
-        if( pRateDist_Q18[ 0 ] < SKP_int32_MAX / MAX_NLSF_MSVQ_SURVIVORS ) {\r
-            rateDistThreshold_Q18 = SKP_SMLAWB( pRateDist_Q18[ 0 ], \r
-                SKP_MUL( NLSF_MSVQ_Survivors, pRateDist_Q18[ 0 ] ), SKP_FIX_CONST( NLSF_MSVQ_SURV_MAX_REL_RD, 16 ) );\r
-            while( pRateDist_Q18[ cur_survivors - 1 ] > rateDistThreshold_Q18 && cur_survivors > min_survivors ) {\r
-                cur_survivors--;\r
-            }\r
-        }\r
-        /* Update accumulated codebook contributions for the 'cur_survivors' best codebook indices */\r
-        for( k = 0; k < cur_survivors; k++ ) { \r
-            if( s > 0 ) {\r
-                /* Find the indices of the input and the codebook vector */\r
-                if( pCurrentCBStage->nVectors == 8 ) {\r
-                    input_index = SKP_RSHIFT( pTempIndices[ k ], 3 );\r
-                    cb_index    = pTempIndices[ k ] & 7;\r
-                } else {\r
-                    input_index = SKP_DIV32_16( pTempIndices[ k ], pCurrentCBStage->nVectors );  \r
-                    cb_index    = pTempIndices[ k ] - SKP_SMULBB( input_index, pCurrentCBStage->nVectors );\r
-                }\r
-            } else {\r
-                /* Find the indices of the input and the codebook vector */\r
-                input_index = 0;\r
-                cb_index    = pTempIndices[ k ];\r
-            }\r
-\r
-            /* Subtract new contribution from the previous residual vector for each of 'cur_survivors' */\r
-            pConstInt16 = &pRes_Q15[ SKP_SMULBB( input_index, LPC_order ) ];\r
-            pCB_element = &pCurrentCBStage->CB_NLSF_Q8[ SKP_SMULBB( cb_index, LPC_order ) ];\r
-            pInt16      = &pRes_new_Q15[ SKP_SMULBB( k, LPC_order ) ];\r
-            for( i = 0; i < LPC_order; i++ ) {\r
-                pInt16[ i ] = pConstInt16[ i ] - SKP_LSHIFT16( ( SKP_int16 )pCB_element[ i ], 7 );\r
-            }\r
-\r
-            /* Update accumulated rate for stage 1 to the current */\r
-            pRate_new_Q4[ k ] = pRate_Q4[ input_index ] + pCurrentCBStage->Rates_Q4[ cb_index ];\r
-\r
-            /* Copy paths from previous matrix, starting with the best path */\r
-            pConstInt8 = &pPath[ SKP_SMULBB( input_index, psNLSF_CB->nStages ) ];\r
-            pInt8      = &pPath_new[ SKP_SMULBB( k, psNLSF_CB->nStages ) ];\r
-            for( i = 0; i < s; i++ ) {\r
-                pInt8[ i ] = pConstInt8[ i ];\r
-            }\r
-            /* Write the current stage indices for the 'cur_survivors' to the best path matrix */\r
-            pInt8[ s ] = (SKP_int8)cb_index;\r
-        }\r
-\r
-        if( s < psNLSF_CB->nStages - 1 ) {\r
-            /* Copy NLSF residual matrix for next stage */\r
-            SKP_memcpy( pRes_Q15, pRes_new_Q15, SKP_SMULBB( cur_survivors, LPC_order ) * sizeof( SKP_int16 ) );\r
-\r
-            /* Copy rate vector for next stage */\r
-            SKP_memcpy( pRate_Q4, pRate_new_Q4, cur_survivors * sizeof( SKP_int32 ) );\r
-\r
-            /* Copy best path matrix for next stage */\r
-            SKP_memcpy( pPath, pPath_new, SKP_SMULBB( cur_survivors, psNLSF_CB->nStages ) * sizeof( SKP_int8) );\r
-        }\r
-\r
-        prev_survivors = cur_survivors;\r
-    }\r
-\r
-    /* (Preliminary) index of the best survivor, later to be decoded */\r
-    bestIndex = 0;\r
-\r
-#if( NLSF_MSVQ_FLUCTUATION_REDUCTION == 1 )\r
-    /******************************/\r
-    /* NLSF fluctuation reduction */\r
-    /******************************/\r
-    if( deactivate_fluc_red != 1 ) {\r
-    \r
-        /* Search among all survivors, now taking also weighted fluctuation errors into account */\r
-        bestRateDist_Q20 = SKP_int32_MAX;\r
-        for( s = 0; s < cur_survivors; s++ ) {\r
-            /* Decode survivor to compare with previous quantized NLSF vector */\r
-            SKP_Silk_NLSF_MSVQ_decode( pNLSF_Q15, psNLSF_CB, &pPath_new[ SKP_SMULBB( s, psNLSF_CB->nStages ) ], LPC_order );\r
-\r
-            /* Compare decoded NLSF vector with the previously quantized vector */ \r
-            wsse_Q20 = 0;\r
-            for( i = 0; i < LPC_order; i += 2 ) {\r
-                /* Compute weighted squared quantization error for index i */\r
-                se_Q15 = pNLSF_Q15[ i ] - pNLSF_q_Q15_prev[ i ]; // range: [ -32767 : 32767 ]\r
-                wsse_Q20 = SKP_SMLAWB( wsse_Q20, SKP_SMULBB( se_Q15, se_Q15 ), pW_Q5[ i ] );\r
-\r
-                /* Compute weighted squared quantization error for index i + 1 */\r
-                se_Q15 = pNLSF_Q15[ i + 1 ] - pNLSF_q_Q15_prev[ i + 1 ]; // range: [ -32767 : 32767 ]\r
-                wsse_Q20 = SKP_SMLAWB( wsse_Q20, SKP_SMULBB( se_Q15, se_Q15 ), pW_Q5[ i + 1 ] );\r
-            }\r
-            SKP_assert( wsse_Q20 >= 0 );\r
-\r
-            /* Add the fluctuation reduction penalty to the rate distortion error */\r
-            wsse_Q20 = SKP_ADD_POS_SAT32( pRateDist_Q18[ s ], SKP_SMULWB( wsse_Q20, NLSF_mu_fluc_red_Q16 ) );\r
-\r
-            /* Keep index of best survivor */\r
-            if( wsse_Q20 < bestRateDist_Q20 ) {\r
-                bestRateDist_Q20 = wsse_Q20;\r
-                bestIndex = s;\r
-            }\r
-        }\r
-    }\r
-#endif\r
-\r
-    /* Copy best path to output argument */\r
-    SKP_memcpy( NLSFIndices, &pPath_new[ SKP_SMULBB( bestIndex, psNLSF_CB->nStages ) ], psNLSF_CB->nStages * sizeof( SKP_int8 ) );\r
-\r
-    /* Decode and stabilize the best survivor */\r
-    SKP_Silk_NLSF_MSVQ_decode( pNLSF_Q15, psNLSF_CB, NLSFIndices, LPC_order );\r
-\r
-#ifdef SAVE_ALL_INTERNAL_DATA\r
-    {\r
-        SKP_float rateBPF_LSF;\r
-        SKP_float NLSF_coef;\r
-\r
-        rateBPF_LSF = (SKP_float)pRate_new_Q5[ bestIndex ] / 32.0f; // Q5 -> Q0\r
-        DEBUG_STORE_DATA( rateBPF_LSF.dat, &rateBPF_LSF, sizeof( SKP_float ));\r
-        for( i = 0; i < LPC_order; i++ ) {\r
-            NLSF_coef = ( (SKP_float)pNLSF_Q15[ i ] ) * ( 1.0f / 32768.0f );\r
-            DEBUG_STORE_DATA( NLSFq.dat, &NLSF_coef, sizeof( SKP_float ) );\r
-        }\r
-    }\r
-#endif\r
-}\r
diff --git a/src_common/SKP_Silk_NLSF_VQ_rate_distortion.c b/src_common/SKP_Silk_NLSF_VQ_rate_distortion.c
deleted file mode 100644 (file)
index 7b16fd5..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/***********************************************************************\r
-Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
-Redistribution and use in source and binary forms, with or without \r
-modification, (subject to the limitations in the disclaimer below) \r
-are permitted provided that the following conditions are met:\r
-- Redistributions of source code must retain the above copyright notice,\r
-this list of conditions and the following disclaimer.\r
-- Redistributions in binary form must reproduce the above copyright \r
-notice, this list of conditions and the following disclaimer in the \r
-documentation and/or other materials provided with the distribution.\r
-- Neither the name of Skype Limited, nor the names of specific \r
-contributors, may be used to endorse or promote products derived from \r
-this software without specific prior written permission.\r
-NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
-BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
-CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
-FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
-COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
-USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-***********************************************************************/\r
-\r
-#include "SKP_Silk_main.h"\r
-\r
-/* Rate-Distortion calculations for multiple input data vectors */\r
-void SKP_Silk_NLSF_VQ_rate_distortion(\r
-    SKP_int32                       *pRD_Q19,           /* O    Rate-distortion values [psNLSF_CBS->nVectors*N] */\r
-    const SKP_Silk_NLSF_CBS         *psNLSF_CBS,        /* I    NLSF codebook stage struct                      */\r
-    const SKP_int16                 *in_Q15,            /* I    Input vectors to be quantized                   */\r
-    const SKP_int                   *w_Q5,              /* I    Weight vector                                   */\r
-    const SKP_int32                 *rate_acc_Q4,       /* I    Accumulated rates from previous stage           */\r
-    const SKP_int                   mu_Q15,             /* I    Weight between weighted error and rate          */\r
-    const SKP_int                   N,                  /* I    Number of input vectors to be quantized         */\r
-    const SKP_int                   stage,              /* I    Stage number                                */\r
-    const SKP_int                   LPC_order           /* I    LPC order                                       */\r
-)\r
-{\r
-    SKP_int   i, n;\r
-    SKP_int32 *pRD_vec_Q19;\r
-\r
-    /* Compute weighted quantization errors for all input vectors over one codebook stage */\r
-    SKP_Silk_NLSF_VQ_sum_error( pRD_Q19, in_Q15, w_Q5, psNLSF_CBS->CB_NLSF_Q8, \r
-        N, psNLSF_CBS->nVectors, stage, LPC_order );\r
-\r
-    /* Loop over input vectors */\r
-    pRD_vec_Q19 = pRD_Q19;\r
-    for( n = 0; n < N; n++ ) {\r
-        /* Add rate cost to error for each codebook vector */\r
-        for( i = 0; i < psNLSF_CBS->nVectors; i++ ) {\r
-            SKP_assert( rate_acc_Q4[ n ] + SKP_LSHIFT32( ( SKP_int32 )psNLSF_CBS->Rates_Q4[ i ], 1 ) >= 0 );\r
-            SKP_assert( rate_acc_Q4[ n ] + SKP_LSHIFT32( ( SKP_int32 )psNLSF_CBS->Rates_Q4[ i ], 1 ) <= SKP_int16_MAX );\r
-            pRD_vec_Q19[ i ] = SKP_SMLABB( pRD_vec_Q19[ i ], rate_acc_Q4[ n ] + psNLSF_CBS->Rates_Q4[ i ], mu_Q15 );\r
-            SKP_assert( pRD_vec_Q19[ i ] >= 0 );\r
-        }\r
-        pRD_vec_Q19 += psNLSF_CBS->nVectors;\r
-    }\r
-}\r
diff --git a/src_common/SKP_Silk_NLSF_VQ_sum_error.c b/src_common/SKP_Silk_NLSF_VQ_sum_error.c
deleted file mode 100644 (file)
index bb52c51..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/***********************************************************************\r
-Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
-Redistribution and use in source and binary forms, with or without \r
-modification, (subject to the limitations in the disclaimer below) \r
-are permitted provided that the following conditions are met:\r
-- Redistributions of source code must retain the above copyright notice,\r
-this list of conditions and the following disclaimer.\r
-- Redistributions in binary form must reproduce the above copyright \r
-notice, this list of conditions and the following disclaimer in the \r
-documentation and/or other materials provided with the distribution.\r
-- Neither the name of Skype Limited, nor the names of specific \r
-contributors, may be used to endorse or promote products derived from \r
-this software without specific prior written permission.\r
-NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
-BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
-CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
-FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
-COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
-USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-***********************************************************************/\r
-\r
-#include "SKP_Silk_main.h"\r
-\r
-/* Compute weighted quantization errors for an LPC_order element input vector, over one codebook stage */\r
-void SKP_Silk_NLSF_VQ_sum_error(\r
-    SKP_int32                       *err_Q19,           /* O    Weighted quantization errors  [N*K]         */\r
-    const SKP_int16                 *in_Q15,            /* I    Input vectors to be quantized [N*LPC_order] */\r
-    const SKP_int                   *w_Q5,              /* I    Weighting vectors             [LPC_order]   */\r
-    const SKP_int8                  *pCB_Q8,            /* I    Codebook vectors              [K*LPC_order] */\r
-    const SKP_int                   N,                  /* I    Number of input vectors                     */\r
-    const SKP_int                   K,                  /* I    Number of codebook vectors                  */\r
-    const SKP_int                   stage,              /* I    Stage number                                */\r
-    const SKP_int                   LPC_order           /* I    Number of LPCs                              */\r
-)\r
-{\r
-    SKP_int        i, n, m;\r
-    SKP_int32      diff_Q15, sum_error, Wtmp_Q5;\r
-    SKP_int32      Wcpy_Q5[ MAX_LPC_ORDER / 2 ];\r
-    const SKP_int8 *cb_vec_Q8;\r
-\r
-    SKP_assert( LPC_order <= 16 );\r
-    SKP_assert( ( LPC_order & 1 ) == 0 );\r
-\r
-    /* Copy to local stack and pack two weights per int32 */\r
-    for( m = 0; m < SKP_RSHIFT( LPC_order, 1 ); m++ ) {\r
-        Wcpy_Q5[ m ] = w_Q5[ 2 * m ] | SKP_LSHIFT( ( SKP_int32 )w_Q5[ 2 * m + 1 ], 16 );\r
-    }\r
-\r
-    if( stage == 0 ) {\r
-        /* Loop over input vectors */\r
-        for( n = 0; n < N; n++ ) {\r
-            /* Loop over codebook */\r
-            cb_vec_Q8 = pCB_Q8;\r
-            for( i = 0; i < K; i++ ) {\r
-                sum_error = 0;\r
-                for( m = 0; m < LPC_order; m += 2 ) {\r
-                    /* Get two weights packed in an int32 */\r
-                    Wtmp_Q5 = Wcpy_Q5[ m >> 1 ];\r
-\r
-                    /* Compute weighted squared quantization error for index m */\r
-                    diff_Q15 = in_Q15[ m ] - SKP_LSHIFT16( ( SKP_int16 )( *cb_vec_Q8++ ), 15 - NLSF_Q_DOMAIN_STAGE_0 ); // range: [ -32767 : 32767 ]\r
-                    sum_error = SKP_SMLAWB( sum_error, SKP_SMULBB( diff_Q15, diff_Q15 ), Wtmp_Q5 );\r
-\r
-                    /* Compute weighted squared quantization error for index m + 1 */\r
-                    diff_Q15 = in_Q15[m + 1] - SKP_LSHIFT16( ( SKP_int16 )( *cb_vec_Q8++ ), 15 - NLSF_Q_DOMAIN_STAGE_0 ); // range: [ -32767 : 32767 ]\r
-                    sum_error = SKP_SMLAWT( sum_error, SKP_SMULBB( diff_Q15, diff_Q15 ), Wtmp_Q5 );\r
-                }\r
-                SKP_assert( sum_error >= 0 );\r
-                err_Q19[ i ] = sum_error;\r
-            }\r
-            err_Q19 += K;\r
-            in_Q15 += LPC_order;\r
-        }\r
-    } else {\r
-        /* Loop over input vectors */\r
-        for( n = 0; n < N; n++ ) {\r
-            /* Loop over codebook */\r
-            cb_vec_Q8 = pCB_Q8;\r
-            for( i = 0; i < K; i++ ) {\r
-                sum_error = 0;\r
-                for( m = 0; m < LPC_order; m += 2 ) {\r
-                    /* Get two weights packed in an int32 */\r
-                    Wtmp_Q5 = Wcpy_Q5[ m >> 1 ];\r
-\r
-                    /* Compute weighted squared quantization error for index m */\r
-                    diff_Q15 = in_Q15[ m ] - SKP_LSHIFT16( ( SKP_int16 )( *cb_vec_Q8++ ), 15 - NLSF_Q_DOMAIN_STAGE_2_TO_LAST ); // range: [ -32767 : 32767 ]\r
-                    sum_error = SKP_SMLAWB( sum_error, SKP_SMULBB( diff_Q15, diff_Q15 ), Wtmp_Q5 );\r
-\r
-                    /* Compute weighted squared quantization error for index m + 1 */\r
-                    diff_Q15 = in_Q15[m + 1] - SKP_LSHIFT16( ( SKP_int16 )( *cb_vec_Q8++ ), 15 - NLSF_Q_DOMAIN_STAGE_2_TO_LAST ); // range: [ -32767 : 32767 ]\r
-                    sum_error = SKP_SMLAWT( sum_error, SKP_SMULBB( diff_Q15, diff_Q15 ), Wtmp_Q5 );\r
-                }\r
-                SKP_assert( sum_error >= 0 );\r
-                err_Q19[ i ] = sum_error;\r
-            }\r
-            err_Q19 += K;\r
-            in_Q15 += LPC_order;\r
-        }\r
-    }\r
-}\r
-\r
index a99ebf8..c10e420 100644 (file)
@@ -167,7 +167,7 @@ void SKP_Silk_PLC_conceal(
     SKP_memmove( psDec->sLTP_Q16, &psDec->sLTP_Q16[ psDec->frame_length ], psDec->ltp_mem_length * sizeof( SKP_int32 ) );\r
 \r
     /* LPC concealment. Apply BWE to previous LPC */\r
-    SKP_Silk_bwexpander( psPLC->prevLPC_Q12, psDec->LPC_order, BWE_COEF_Q16 );\r
+    SKP_Silk_bwexpander( psPLC->prevLPC_Q12, psDec->LPC_order, SKP_FIX_CONST( BWE_COEF, 16 ) );\r
 \r
     /* Find random noise component */\r
     /* Scale previous excitation signal */\r
@@ -205,7 +205,7 @@ void SKP_Silk_PLC_conceal(
 \r
     /* First Lost frame */\r
     if( psDec->lossCnt == 0 ) {\r
-        rand_scale_Q14 = (1 << 14 );\r
+        rand_scale_Q14 = 1 << 14;\r
     \r
         /* Reduce random noise Gain for voiced frames */\r
         if( psDec->prevSignalType == TYPE_VOICED ) {\r
@@ -220,8 +220,8 @@ void SKP_Silk_PLC_conceal(
             \r
             SKP_Silk_LPC_inverse_pred_gain( &invGain_Q30, psPLC->prevLPC_Q12, psDec->LPC_order );\r
             \r
-            down_scale_Q30 = SKP_min_32( SKP_RSHIFT( ( 1 << 30 ), LOG2_INV_LPC_GAIN_HIGH_THRES ), invGain_Q30 );\r
-            down_scale_Q30 = SKP_max_32( SKP_RSHIFT( ( 1 << 30 ), LOG2_INV_LPC_GAIN_LOW_THRES ), down_scale_Q30 );\r
+            down_scale_Q30 = SKP_min_32( SKP_RSHIFT( 1 << 30, LOG2_INV_LPC_GAIN_HIGH_THRES ), invGain_Q30 );\r
+            down_scale_Q30 = SKP_max_32( SKP_RSHIFT( 1 << 30, LOG2_INV_LPC_GAIN_LOW_THRES ), down_scale_Q30 );\r
             down_scale_Q30 = SKP_LSHIFT( down_scale_Q30, LOG2_INV_LPC_GAIN_HIGH_THRES );\r
             \r
             rand_Gain_Q15 = SKP_RSHIFT( SKP_SMULWB( down_scale_Q30, rand_Gain_Q15 ), 14 );\r
@@ -360,7 +360,7 @@ void SKP_Silk_PLC_glue_frames(
             /* Fade in the energy difference */\r
             if( energy > psPLC->conc_energy ) {\r
                 SKP_int32 frac_Q24, LZ;\r
-                SKP_int32 gain_Q12, slope_Q12;\r
+                SKP_int32 gain_Q16, slope_Q16;\r
 \r
                 LZ = SKP_Silk_CLZ32( psPLC->conc_energy );\r
                 LZ = LZ - 1;\r
@@ -369,13 +369,17 @@ void SKP_Silk_PLC_glue_frames(
                 \r
                 frac_Q24 = SKP_DIV32( psPLC->conc_energy, SKP_max( energy, 1 ) );\r
                 \r
-                gain_Q12 = SKP_Silk_SQRT_APPROX( frac_Q24 );\r
-                slope_Q12 = SKP_DIV32_16( ( 1 << 12 ) - gain_Q12, length );\r
+                gain_Q16 = SKP_LSHIFT( SKP_Silk_SQRT_APPROX( frac_Q24 ), 4 );\r
+                slope_Q16 = SKP_DIV32_16( ( 1 << 16 ) - gain_Q16, length );\r
+                               /* Make slope 4x steeper to avoid missing onsets after DTX */\r
+                slope_Q16 = SKP_LSHIFT( slope_Q16, 2 );\r
 \r
                 for( i = 0; i < length; i++ ) {\r
-                    signal[ i ] = SKP_RSHIFT( SKP_MUL( gain_Q12, signal[ i ] ), 12 );\r
-                    gain_Q12 += slope_Q12;\r
-                    gain_Q12 = SKP_min( gain_Q12, ( 1 << 12 ) );\r
+                    signal[ i ] = SKP_SMULWB( gain_Q16, signal[ i ] );\r
+                    gain_Q16 += slope_Q16;\r
+                    if( gain_Q16 > 1 << 16 ) {\r
+                        break;\r
+                    }\r
                 }\r
             }\r
         }\r
index d23f994..97fc901 100644 (file)
@@ -30,7 +30,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 \r
 #include "SKP_Silk_main.h"\r
 \r
-#define BWE_COEF_Q16                    64880           /* 0.99 in Q16                      */\r
+#define BWE_COEF                        0.99\r
 #define V_PITCH_GAIN_START_MIN_Q14      11469           /* 0.7 in Q14                       */\r
 #define V_PITCH_GAIN_START_MAX_Q14      15565           /* 0.95 in Q14                      */\r
 #define MAX_PITCH_LAG_MS                18\r
diff --git a/src_common/SKP_Silk_check_control_input.c b/src_common/SKP_Silk_check_control_input.c
new file mode 100644 (file)
index 0000000..cbdafc6
--- /dev/null
@@ -0,0 +1,89 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+#include "SKP_Silk_main.h"\r
+#include "SKP_Silk_control.h"\r
+#include "SKP_Silk_errors.h"\r
+\r
+/* Check encoder control struct */\r
+SKP_int check_control_input( \r
+    SKP_SILK_SDK_EncControlStruct        *encControl     /* I:   Control structure                               */\r
+)\r
+{\r
+    SKP_assert( encControl != NULL );\r
+\r
+    if( ( ( encControl->API_sampleRate        !=  8000 ) &&\r
+          ( encControl->API_sampleRate        != 12000 ) &&\r
+          ( encControl->API_sampleRate        != 16000 ) &&\r
+          ( encControl->API_sampleRate        != 24000 ) && \r
+          ( encControl->API_sampleRate        != 32000 ) &&\r
+          ( encControl->API_sampleRate        != 44100 ) &&\r
+          ( encControl->API_sampleRate        != 48000 ) ) ||\r
+        ( ( encControl->maxInternalSampleRate !=  8000 ) &&\r
+          ( encControl->maxInternalSampleRate != 12000 ) &&\r
+          ( encControl->maxInternalSampleRate != 16000 ) ) ||\r
+        ( ( encControl->minInternalSampleRate !=  8000 ) &&\r
+          ( encControl->minInternalSampleRate != 12000 ) &&\r
+          ( encControl->minInternalSampleRate != 16000 ) ) ||\r
+          ( encControl->minInternalSampleRate > encControl->maxInternalSampleRate ) ) {\r
+        SKP_assert( 0 );\r
+        return SKP_SILK_ENC_FS_NOT_SUPPORTED;\r
+    }\r
+    if( encControl->payloadSize_ms != 10 && \r
+        encControl->payloadSize_ms != 20 && \r
+        encControl->payloadSize_ms != 40 && \r
+        encControl->payloadSize_ms != 60 ) {\r
+        SKP_assert( 0 );\r
+        return SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED;\r
+    }\r
+    if( encControl->packetLossPercentage < 0 || encControl->packetLossPercentage > 100 ) {\r
+        SKP_assert( 0 );\r
+        return SKP_SILK_ENC_INVALID_LOSS_RATE;\r
+    }\r
+    if( encControl->useDTX < 0 || encControl->useDTX > 1 ) {\r
+        SKP_assert( 0 );\r
+        return SKP_SILK_ENC_INVALID_DTX_SETTING;\r
+    }\r
+       if( encControl->useCBR < 0 || encControl->useCBR > 1 ) {\r
+        SKP_assert( 0 );\r
+        return SKP_SILK_ENC_INVALID_CBR_SETTING;\r
+    }\r
+       if( encControl->useInBandFEC < 0 || encControl->useInBandFEC > 1 ) {\r
+        SKP_assert( 0 );\r
+        return SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING;\r
+    }\r
+    if( encControl->nChannels < 1 || encControl->nChannels > ENCODER_NUM_CHANNELS ) {\r
+        SKP_assert( 0 );\r
+        return SKP_SILK_ENC_INVALID_NUMBER_OF_CHANNELS_ERROR;\r
+    }\r
+    if( encControl->complexity < 0 || encControl->complexity > 10 ) {\r
+        SKP_assert( 0 );\r
+        return SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING;\r
+    }\r
+\r
+    return SKP_SILK_NO_ERROR;\r
+}\r
similarity index 51%
rename from src_SigProc_FIX/SKP_Silk_lowpass_short.c
rename to src_common/SKP_Silk_control_SNR.c
index 058822d..81618c2 100644 (file)
@@ -25,37 +25,50 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
 ***********************************************************************/\r
 \r
-/*                                                                      *\r
- * SKP_Silk_lowpass_short.c                                           *\r
- *                                                                      *\r
- * First order low-pass filter, with input as SKP_int16, running at     *\r
- * 48 kHz                                                               *\r
- *                                                                      *\r
- * Copyright 2006 (c), Skype Limited                                    *\r
- * Date: 060221                                                         *\r
- *                                                                      */\r
-#include "SKP_Silk_SigProc_FIX.h"\r
+#include "SKP_Silk_main.h"\r
+#include "SKP_Silk_tuning_parameters.h"\r
 \r
-\r
-/* First order low-pass filter, with input as SKP_int16, running at 48 kHz   */\r
-void SKP_Silk_lowpass_short(\r
-    const SKP_int16          *in,        /* I:   Q15 48 kHz signal; [len]    */\r
-    SKP_int32                *S,         /* I/O: Q25 state; length = 1       */\r
-    SKP_int32                *out,       /* O:   Q25 48 kHz signal; [len]    */\r
-    const SKP_int32          len         /* O:   Signal length               */\r
+/* Control SNR of redidual quantizer */\r
+SKP_int SKP_Silk_control_SNR(\r
+    SKP_Silk_encoder_state      *psEncC,            /* I/O  Pointer to Silk encoder state               */\r
+    SKP_int32                   TargetRate_bps      /* I    Target max bitrate (bps)                    */\r
 )\r
 {\r
-    SKP_int        k;\r
-    SKP_int32    in_tmp, out_tmp, state;\r
-    \r
-    state = S[ 0 ];\r
-    for( k = 0; k < len; k++ ) {    \r
-        in_tmp   = SKP_MUL( 768, (SKP_int32)in[k] );    /* multiply by 0.75, going from Q15 to Q25 */\r
-        out_tmp  = state + in_tmp;                      /* zero at nyquist                         */\r
-        state    = in_tmp - SKP_RSHIFT( out_tmp, 1 );   /* pole                                    */\r
-        out[ k ] = out_tmp;\r
-    }\r
-    S[ 0 ] = state;\r
-}\r
+    SKP_int k, ret = SKP_SILK_NO_ERROR;\r
+    SKP_int32 frac_Q6;\r
+    const SKP_int32 *rateTable;\r
+\r
+    /* Set bitrate/coding quality */\r
+    TargetRate_bps = SKP_LIMIT( TargetRate_bps, MIN_TARGET_RATE_BPS, MAX_TARGET_RATE_BPS );\r
+    if( TargetRate_bps != psEncC->TargetRate_bps ) {\r
+        psEncC->TargetRate_bps = TargetRate_bps;\r
 \r
+        /* If new TargetRate_bps, translate to SNR_dB value */\r
+        if( psEncC->fs_kHz == 8 ) {\r
+            rateTable = TargetRate_table_NB;\r
+        } else if( psEncC->fs_kHz == 12 ) {\r
+            rateTable = TargetRate_table_MB;\r
+        } else if( psEncC->fs_kHz == 16 ) {\r
+            rateTable = TargetRate_table_WB;\r
+        } else {\r
+            SKP_assert( 0 );\r
+        }\r
 \r
+        /* Reduce bitrate for 10 ms modes in these calculations */\r
+        if( psEncC->nb_subfr == 2 ) {\r
+            TargetRate_bps -= REDUCE_BITRATE_10_MS_BPS;\r
+        }\r
+\r
+        /* Find bitrate interval in table and interpolate */\r
+        for( k = 1; k < TARGET_RATE_TAB_SZ; k++ ) {\r
+            if( TargetRate_bps <= rateTable[ k ] ) {\r
+                frac_Q6 = SKP_DIV32( SKP_LSHIFT( TargetRate_bps - rateTable[ k - 1 ], 6 ), \r
+                                                 rateTable[ k ] - rateTable[ k - 1 ] );\r
+                psEncC->SNR_dB_Q7 = SKP_LSHIFT( SNR_table_Q1[ k - 1 ], 6 ) + SKP_MUL( frac_Q6, SNR_table_Q1[ k ] - SNR_table_Q1[ k - 1 ] );\r
+                break;\r
+            }\r
+        }\r
+    }\r
+\r
+    return ret;\r
+}\r
index 552fe07..20a1eea 100644 (file)
@@ -34,42 +34,45 @@ SKP_int SKP_Silk_control_audio_bandwidth(
     SKP_int32                   TargetRate_bps      /* I    Target max bitrate (bps)                    */\r
 )\r
 {\r
-    SKP_int fs_kHz;\r
-\r
-    fs_kHz = psEncC->fs_kHz;\r
-\r
+    SKP_int   fs_kHz;\r
+    SKP_int32 fs_Hz;\r
+    \r
     /* Reduce bitrate for 10 ms modes in these calculations */\r
     if( psEncC->nb_subfr == 2 ) {\r
         TargetRate_bps -= REDUCE_BITRATE_10_MS_BPS;\r
     }\r
 \r
-    if( fs_kHz == 0 ) {\r
+    fs_kHz = psEncC->fs_kHz;\r
+    fs_Hz = SKP_SMULBB( fs_kHz, 1000 );\r
+    if( fs_Hz == 0 ) {\r
         /* Encoder has just been initialized */\r
         if( TargetRate_bps >= WB2MB_BITRATE_BPS ) {\r
-            fs_kHz = 16;\r
+            fs_Hz = 16000;\r
         } else if( TargetRate_bps >= MB2NB_BITRATE_BPS ) {\r
-            fs_kHz = 12;\r
+            fs_Hz = 12000;\r
         } else {\r
-            fs_kHz = 8;\r
+            fs_Hz = 8000;\r
         }\r
         /* Make sure internal rate is not higher than external rate or maximum allowed, or lower than minimum allowed */\r
-        fs_kHz = SKP_min( fs_kHz, SKP_DIV32_16( psEncC->API_fs_Hz, 1000 ) );\r
-        fs_kHz = SKP_min( fs_kHz, psEncC->maxInternal_fs_kHz );\r
-        fs_kHz = SKP_max( fs_kHz, psEncC->minInternal_fs_kHz );\r
-    } else if( SKP_SMULBB( fs_kHz, 1000 ) > psEncC->API_fs_Hz || fs_kHz > psEncC->maxInternal_fs_kHz || fs_kHz < psEncC->minInternal_fs_kHz ) {\r
+        fs_Hz = SKP_min( fs_Hz, psEncC->API_fs_Hz );\r
+        fs_Hz = SKP_min( fs_Hz, psEncC->maxInternal_fs_Hz );\r
+        fs_Hz = SKP_max( fs_Hz, psEncC->minInternal_fs_Hz );\r
+        fs_kHz = SKP_DIV32_16( fs_Hz, 1000 );\r
+    } else if( fs_Hz > psEncC->API_fs_Hz || fs_Hz > psEncC->maxInternal_fs_Hz || fs_Hz < psEncC->minInternal_fs_Hz ) {\r
         /* Make sure internal rate is not higher than external rate or maximum allowed, or lower than minimum allowed */\r
-        fs_kHz = SKP_DIV32_16( psEncC->API_fs_Hz, 1000 );\r
-        fs_kHz = SKP_min( fs_kHz, psEncC->maxInternal_fs_kHz );\r
-        fs_kHz = SKP_max( fs_kHz, psEncC->minInternal_fs_kHz );\r
+        fs_Hz = psEncC->API_fs_Hz;\r
+        fs_Hz = SKP_min( fs_Hz, psEncC->maxInternal_fs_Hz );\r
+        fs_Hz = SKP_max( fs_Hz, psEncC->minInternal_fs_Hz );\r
+        fs_kHz = SKP_DIV32_16( fs_Hz, 1000 );\r
     } else {\r
         /* State machine for the internal sampling rate switching */\r
-        if( psEncC->API_fs_Hz > 8000 && psEncC->prevSignalType == TYPE_NO_VOICE_ACTIVITY ) { /* Low speech activity */\r
+        if( psEncC->API_fs_Hz > 8000 && psEncC->prevSignalType == TYPE_NO_VOICE_ACTIVITY ) {\r
             /* Check if we should switch down */\r
-            if( ( psEncC->fs_kHz == 12 && TargetRate_bps < MB2NB_BITRATE_BPS && psEncC->minInternal_fs_kHz <=  8 ) ||\r
-                ( psEncC->fs_kHz == 16 && TargetRate_bps < WB2MB_BITRATE_BPS && psEncC->minInternal_fs_kHz <= 12 ) ) \r
+            if( ( psEncC->fs_kHz == 12 && TargetRate_bps < MB2NB_BITRATE_BPS && psEncC->minInternal_fs_Hz <=  8000 ) ||\r
+                ( psEncC->fs_kHz == 16 && TargetRate_bps < WB2MB_BITRATE_BPS && psEncC->minInternal_fs_Hz <= 12000 ) ) \r
             {\r
                 /* Switch down */\r
-                if( SWITCH_TRANSITION_FILTERING && psEncC->sLP.mode == 0 ) {\r
+                if( psEncC->sLP.mode == 0 ) {\r
                     /* New transition */\r
                     psEncC->sLP.transition_frame_no = TRANSITION_FRAMES;\r
 \r
@@ -88,11 +91,11 @@ SKP_int SKP_Silk_control_audio_bandwidth(
                 } \r
             } \r
             else\r
-            if( ( psEncC->fs_kHz ==  8 && TargetRate_bps > NB2MB_BITRATE_BPS && psEncC->maxInternal_fs_kHz >= 12 && psEncC->API_fs_Hz >= 12000 ) ||\r
-                ( psEncC->fs_kHz == 12 && TargetRate_bps > MB2WB_BITRATE_BPS && psEncC->maxInternal_fs_kHz >= 16 && psEncC->API_fs_Hz >= 16000 ) ) \r
+            if( ( psEncC->fs_kHz ==  8 && TargetRate_bps > NB2MB_BITRATE_BPS && psEncC->maxInternal_fs_Hz >= 12000 && psEncC->API_fs_Hz >= 12000 ) ||\r
+                ( psEncC->fs_kHz == 12 && TargetRate_bps > MB2WB_BITRATE_BPS && psEncC->maxInternal_fs_Hz >= 16000 && psEncC->API_fs_Hz >= 16000 ) ) \r
             {\r
                 /* Switch up */\r
-                if( SWITCH_TRANSITION_FILTERING && psEncC->sLP.mode == 0 ) {\r
+                if( psEncC->sLP.mode == 0 ) {\r
                     /* Switch to a higher sample frequency */\r
                     fs_kHz = psEncC->fs_kHz == 8 ? 12 : 16;\r
 \r
similarity index 55%
rename from src_FIX/SKP_Silk_control_codec_FIX.c
rename to src_common/SKP_Silk_control_codec.c
index b092460..c497e19 100644 (file)
@@ -25,36 +25,53 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
 ***********************************************************************/\r
 \r
+#include "SKP_Silk_tuning_parameters.h"\r
+#if FIXED_POINT\r
 #include "SKP_Silk_main_FIX.h"\r
-#include "SKP_Silk_setup.h"\r
-\r
-SKP_INLINE SKP_int SKP_Silk_setup_resamplers(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O                      */\r
+#define SKP_Silk_encoder_state_Fxx      SKP_Silk_encoder_state_FIX\r
+#else\r
+#include "SKP_Silk_main_FLP.h"\r
+#define SKP_Silk_encoder_state_Fxx      SKP_Silk_encoder_state_FLP\r
+#endif\r
+\r
+SKP_int SKP_Silk_setup_resamplers(\r
+    SKP_Silk_encoder_state_Fxx      *psEnc,             /* I/O                      */\r
     SKP_int                         fs_kHz              /* I                        */\r
 );\r
 \r
-SKP_INLINE SKP_int SKP_Silk_setup_fs(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O                      */\r
+SKP_int SKP_Silk_setup_fs(\r
+    SKP_Silk_encoder_state_Fxx      *psEnc,             /* I/O                      */\r
     SKP_int                         fs_kHz,             /* I                        */\r
     SKP_int                         PacketSize_ms       /* I                        */\r
 );\r
 \r
-SKP_INLINE SKP_int SKP_Silk_setup_rate(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O                      */\r
-    SKP_int32                       TargetRate_bps      /* I                        */\r
+SKP_int SKP_Silk_setup_complexity(\r
+    SKP_Silk_encoder_state          *psEncC,            /* I/O                      */\r
+    SKP_int                         Complexity          /* I                        */\r
+);\r
+\r
+static SKP_int SKP_Silk_setup_LBRR(\r
+    SKP_Silk_encoder_state          *psEncC,            /* I/O                      */\r
+    const SKP_int32                 TargetRate_bps      /* I                        */\r
 );\r
 \r
-/* Control encoder SNR */\r
-SKP_int SKP_Silk_control_encoder_FIX( \r
-    SKP_Silk_encoder_state_FIX  *psEnc,                 /* I/O  Pointer to Silk encoder state           */\r
-    const SKP_int               PacketSize_ms,          /* I    Packet length (ms)                      */\r
-    const SKP_int32             TargetRate_bps,         /* I    Target max bitrate (bps)                */\r
-    const SKP_int               PacketLoss_perc,        /* I    Packet loss rate (in percent)           */\r
-    const SKP_int               Complexity              /* I    Complexity (0-10)                       */\r
+\r
+/* Control encoder */\r
+SKP_int SKP_Silk_control_encoder( \r
+    SKP_Silk_encoder_state_Fxx      *psEnc,             /* I/O  Pointer to Silk encoder state           */\r
+    SKP_SILK_SDK_EncControlStruct   *encControl,        /* I:   Control structure                       */\r
+    const SKP_int32                 TargetRate_bps      /* I    Target max bitrate (bps)                */\r
 )\r
 {\r
     SKP_int   fs_kHz, ret = 0;\r
 \r
+    psEnc->sCmn.useDTX            = encControl->useDTX;\r
+    psEnc->sCmn.useCBR            = encControl->useCBR;\r
+    psEnc->sCmn.API_fs_Hz         = encControl->API_sampleRate;\r
+    psEnc->sCmn.maxInternal_fs_Hz = encControl->maxInternalSampleRate;\r
+    psEnc->sCmn.minInternal_fs_Hz = encControl->minInternalSampleRate;\r
+    psEnc->sCmn.useInBandFEC      = encControl->useInBandFEC;\r
+\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
@@ -78,53 +95,55 @@ SKP_int SKP_Silk_control_encoder_FIX(
     /********************************************/\r
     /* Set internal sampling frequency          */\r
     /********************************************/\r
-    ret += SKP_Silk_setup_fs( psEnc, fs_kHz, PacketSize_ms );\r
+    ret += SKP_Silk_setup_fs( psEnc, fs_kHz, encControl->payloadSize_ms );\r
 \r
     /********************************************/\r
     /* Set encoding complexity                  */\r
     /********************************************/\r
-    ret += SKP_Silk_setup_complexity( &psEnc->sCmn, Complexity );\r
-\r
-    /********************************************/\r
-    /* Set bitrate/coding quality               */\r
-    /********************************************/\r
-    ret += SKP_Silk_setup_rate( psEnc, TargetRate_bps );\r
+    ret += SKP_Silk_setup_complexity( &psEnc->sCmn, encControl->complexity  );\r
 \r
     /********************************************/\r
     /* Set packet loss rate measured by farend  */\r
     /********************************************/\r
-    if( ( PacketLoss_perc < 0 ) || ( PacketLoss_perc > 100 ) ) {\r
-        ret = SKP_SILK_ENC_INVALID_LOSS_RATE;\r
-    }\r
-    psEnc->sCmn.PacketLoss_perc = PacketLoss_perc;\r
+    psEnc->sCmn.PacketLoss_perc = encControl->packetLossPercentage;\r
 \r
     /********************************************/\r
     /* Set LBRR usage                           */\r
     /********************************************/\r
-    ret += SKP_Silk_setup_LBRR( &psEnc->sCmn );\r
+    ret += SKP_Silk_setup_LBRR( &psEnc->sCmn, TargetRate_bps );\r
 \r
     psEnc->sCmn.controlled_since_last_payload = 1;\r
 \r
     return ret;\r
 }\r
 \r
-SKP_INLINE SKP_int SKP_Silk_setup_resamplers(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O                      */\r
+SKP_int SKP_Silk_setup_resamplers(\r
+    SKP_Silk_encoder_state_Fxx      *psEnc,             /* I/O                      */\r
     SKP_int                         fs_kHz              /* I                        */\r
 )\r
 {\r
-    SKP_int ret = SKP_SILK_NO_ERROR;\r
+    SKP_int   ret = SKP_SILK_NO_ERROR;\r
+    SKP_int32 nSamples_temp;\r
     \r
-    if( psEnc->sCmn.fs_kHz != fs_kHz || psEnc->sCmn.prev_API_fs_Hz != psEnc->sCmn.API_fs_Hz ) {\r
-\r
+    if( psEnc->sCmn.fs_kHz != fs_kHz || psEnc->sCmn.prev_API_fs_Hz != psEnc->sCmn.API_fs_Hz ) \r
+    {\r
         if( psEnc->sCmn.fs_kHz == 0 ) {\r
             /* Initialize the resampler for enc_API.c preparing resampling from API_fs_Hz to fs_kHz */\r
             ret += SKP_Silk_resampler_init( &psEnc->sCmn.resampler_state, psEnc->sCmn.API_fs_Hz, fs_kHz * 1000 );\r
         } else {\r
             /* Allocate space for worst case temporary upsampling, 8 to 48 kHz, so a factor 6 */\r
             SKP_int16 x_buf_API_fs_Hz[ ( 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ) * ( MAX_API_FS_KHZ / 8 ) ];\r
+#if FIXED_POINT\r
+            SKP_int16 *x_bufFIX = psEnc->x_buf;\r
+#else\r
+            SKP_int16 x_bufFIX[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ]; \r
+#endif\r
+\r
+            nSamples_temp = SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + LA_SHAPE_MS * psEnc->sCmn.fs_kHz;\r
 \r
-            SKP_int32 nSamples_temp = SKP_LSHIFT( psEnc->sCmn.frame_length, 1 ) + LA_SHAPE_MS * psEnc->sCmn.fs_kHz;\r
+#if !FIXED_POINT\r
+            SKP_float2short_array( x_bufFIX, psEnc->x_buf, nSamples_temp );\r
+#endif\r
 \r
             if( SKP_SMULBB( fs_kHz, 1000 ) < psEnc->sCmn.API_fs_Hz && psEnc->sCmn.fs_kHz != 0 ) {\r
                 /* Resample buffered data in x_buf to API_fs_Hz */\r
@@ -135,7 +154,7 @@ SKP_INLINE SKP_int SKP_Silk_setup_resamplers(
                 ret += SKP_Silk_resampler_init( &temp_resampler_state, SKP_SMULBB( psEnc->sCmn.fs_kHz, 1000 ), psEnc->sCmn.API_fs_Hz );\r
 \r
                 /* Temporary resampling of x_buf data to API_fs_Hz */\r
-                ret += SKP_Silk_resampler( &temp_resampler_state, x_buf_API_fs_Hz, psEnc->x_buf, nSamples_temp );\r
+                ret += SKP_Silk_resampler( &temp_resampler_state, x_buf_API_fs_Hz, x_bufFIX, nSamples_temp );\r
 \r
                 /* Calculate number of samples that has been temporarily upsampled */\r
                 nSamples_temp = SKP_DIV32_16( nSamples_temp * psEnc->sCmn.API_fs_Hz, SKP_SMULBB( psEnc->sCmn.fs_kHz, 1000 ) );\r
@@ -145,23 +164,26 @@ SKP_INLINE SKP_int SKP_Silk_setup_resamplers(
 \r
             } else {\r
                 /* Copy data */\r
-                SKP_memcpy( x_buf_API_fs_Hz, psEnc->x_buf, nSamples_temp * sizeof( SKP_int16 ) );\r
+                SKP_memcpy( x_buf_API_fs_Hz, x_bufFIX, nSamples_temp * sizeof( SKP_int16 ) );\r
             }\r
 \r
             if( 1000 * fs_kHz != psEnc->sCmn.API_fs_Hz ) {\r
                 /* Correct resampler state (unless resampling by a factor 1) by resampling buffered data from API_fs_Hz to fs_kHz */\r
-                ret += SKP_Silk_resampler( &psEnc->sCmn.resampler_state, psEnc->x_buf, x_buf_API_fs_Hz, nSamples_temp );\r
+                ret += SKP_Silk_resampler( &psEnc->sCmn.resampler_state, x_bufFIX, x_buf_API_fs_Hz, nSamples_temp );\r
             }\r
+#if !FIXED_POINT\r
+            SKP_short2float_array( psEnc->x_buf, x_bufFIX, ( 2 * MAX_FRAME_LENGTH_MS + LA_SHAPE_MS ) * fs_kHz );\r
+#endif\r
         }\r
     }\r
 \r
     psEnc->sCmn.prev_API_fs_Hz = psEnc->sCmn.API_fs_Hz;\r
 \r
-    return(ret);\r
+    return ret;\r
 }\r
 \r
-SKP_INLINE SKP_int SKP_Silk_setup_fs(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O                      */\r
+SKP_int SKP_Silk_setup_fs(\r
+    SKP_Silk_encoder_state_Fxx      *psEnc,             /* I/O                      */\r
     SKP_int                         fs_kHz,             /* I                        */\r
     SKP_int                         PacketSize_ms       /* I                        */\r
 )\r
@@ -206,14 +228,19 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
     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
+#if FIXED_POINT\r
         SKP_memset( &psEnc->sShape,               0, sizeof( SKP_Silk_shape_state_FIX ) );\r
         SKP_memset( &psEnc->sPrefilt,             0, sizeof( SKP_Silk_prefilter_state_FIX ) );\r
+#else\r
+        SKP_memset( &psEnc->sShape,               0, sizeof( SKP_Silk_shape_state_FLP ) );\r
+        SKP_memset( &psEnc->sPrefilt,             0, sizeof( SKP_Silk_prefilter_state_FLP ) );\r
+#endif\r
         SKP_memset( &psEnc->sCmn.sNSQ,            0, sizeof( SKP_Silk_nsq_state ) );\r
         SKP_memset( psEnc->sCmn.prev_NLSFq_Q15,   0, sizeof( psEnc->sCmn.prev_NLSFq_Q15 ) );\r
         SKP_memset( &psEnc->sCmn.sLP.In_LP_State, 0, sizeof( psEnc->sCmn.sLP.In_LP_State ) );\r
         psEnc->sCmn.inputBufIx                  = 0;\r
         psEnc->sCmn.nFramesAnalyzed             = 0;\r
-        psEnc->sCmn.TargetRate_bps              = 0; /* Ensures that psEnc->SNR_dB is recomputed */\r
+        psEnc->sCmn.TargetRate_bps              = 0;     /* trigger new SNR computation */\r
 \r
         /* Initialize non-zero parameters */\r
         psEnc->sCmn.prevLag                     = 100;\r
@@ -269,45 +296,115 @@ SKP_INLINE SKP_int SKP_Silk_setup_fs(
     /* Check that settings are valid */\r
     SKP_assert( ( psEnc->sCmn.subfr_length * psEnc->sCmn.nb_subfr ) == psEnc->sCmn.frame_length );\r
  \r
-    return( ret );\r
+    return ret;\r
 }\r
 \r
-SKP_INLINE SKP_int SKP_Silk_setup_rate(\r
-    SKP_Silk_encoder_state_FIX      *psEnc,             /* I/O                      */\r
-    SKP_int32                       TargetRate_bps      /* I                        */\r
+SKP_int SKP_Silk_setup_complexity(\r
+    SKP_Silk_encoder_state          *psEncC,            /* I/O                      */\r
+    SKP_int                         Complexity          /* I                        */\r
 )\r
 {\r
-    SKP_int k, ret = SKP_SILK_NO_ERROR;\r
-    SKP_int32 frac_Q6;\r
-    const SKP_int32 *rateTable;\r
+    SKP_int ret = 0;\r
+\r
+    /* Set encoding complexity */\r
+    SKP_assert( Complexity >= 0 && Complexity <= 10 );\r
+    if( Complexity < 2 ) {\r
+        psEncC->pitchEstimationComplexity       = SKP_Silk_PE_MIN_COMPLEX;\r
+        psEncC->pitchEstimationThreshold_Q16    = SKP_FIX_CONST( 0.8, 16 );\r
+        psEncC->pitchEstimationLPCOrder         = 6;\r
+        psEncC->shapingLPCOrder                 = 8;\r
+        psEncC->la_shape                        = 3 * psEncC->fs_kHz;\r
+        psEncC->nStatesDelayedDecision          = 1;\r
+        psEncC->useInterpolatedNLSFs            = 0;\r
+        psEncC->LTPQuantLowComplexity           = 1;\r
+        psEncC->NLSF_MSVQ_Survivors             = 2;\r
+        psEncC->warping_Q16                     = 0;\r
+    } else if( Complexity < 4 ) {\r
+        psEncC->pitchEstimationComplexity       = SKP_Silk_PE_MID_COMPLEX;\r
+        psEncC->pitchEstimationThreshold_Q16    = SKP_FIX_CONST( 0.76, 16 );\r
+        psEncC->pitchEstimationLPCOrder         = 8;\r
+        psEncC->shapingLPCOrder                 = 10;\r
+        psEncC->la_shape                        = 5 * psEncC->fs_kHz;\r
+        psEncC->nStatesDelayedDecision          = 1;\r
+        psEncC->useInterpolatedNLSFs            = 1;\r
+        psEncC->LTPQuantLowComplexity           = 0;\r
+        psEncC->NLSF_MSVQ_Survivors             = 4;\r
+        psEncC->warping_Q16                     = 0;\r
+    } else if( Complexity < 6 ) {\r
+        psEncC->pitchEstimationComplexity       = SKP_Silk_PE_MID_COMPLEX;\r
+        psEncC->pitchEstimationThreshold_Q16    = SKP_FIX_CONST( 0.74, 16 );\r
+        psEncC->pitchEstimationLPCOrder         = 10;\r
+        psEncC->shapingLPCOrder                 = 12;\r
+        psEncC->la_shape                        = 5 * psEncC->fs_kHz;\r
+        psEncC->nStatesDelayedDecision          = 2;\r
+        psEncC->useInterpolatedNLSFs            = 0;\r
+        psEncC->LTPQuantLowComplexity           = 0;\r
+        psEncC->NLSF_MSVQ_Survivors             = 6;\r
+        psEncC->warping_Q16                     = psEncC->fs_kHz * SKP_FIX_CONST( WARPING_MULTIPLIER, 16 );\r
+    } else if( Complexity < 8 ) {\r
+        psEncC->pitchEstimationComplexity       = SKP_Silk_PE_MID_COMPLEX;\r
+        psEncC->pitchEstimationThreshold_Q16    = SKP_FIX_CONST( 0.72, 16 );\r
+        psEncC->pitchEstimationLPCOrder         = 12;\r
+        psEncC->shapingLPCOrder                 = 14;\r
+        psEncC->la_shape                        = 5 * psEncC->fs_kHz;\r
+        psEncC->nStatesDelayedDecision          = 3;\r
+        psEncC->useInterpolatedNLSFs            = 0;\r
+        psEncC->LTPQuantLowComplexity           = 0;\r
+        psEncC->NLSF_MSVQ_Survivors             = 8;\r
+        psEncC->warping_Q16                     = psEncC->fs_kHz * SKP_FIX_CONST( WARPING_MULTIPLIER, 16 );\r
+    } else {\r
+        psEncC->pitchEstimationComplexity       = SKP_Silk_PE_MAX_COMPLEX;\r
+        psEncC->pitchEstimationThreshold_Q16    = SKP_FIX_CONST( 0.7, 16 );\r
+        psEncC->pitchEstimationLPCOrder         = 16;\r
+        psEncC->shapingLPCOrder                 = 16;\r
+        psEncC->la_shape                        = 5 * psEncC->fs_kHz;\r
+        psEncC->nStatesDelayedDecision          = MAX_DEL_DEC_STATES;\r
+        psEncC->useInterpolatedNLSFs            = 1;\r
+        psEncC->LTPQuantLowComplexity           = 0;\r
+        psEncC->NLSF_MSVQ_Survivors             = 16;\r
+        psEncC->warping_Q16                     = psEncC->fs_kHz * SKP_FIX_CONST( WARPING_MULTIPLIER, 16 );\r
+    }\r
 \r
-    /* Set bitrate/coding quality */\r
-    if( TargetRate_bps != psEnc->sCmn.TargetRate_bps ) {\r
-        psEnc->sCmn.TargetRate_bps = TargetRate_bps;\r
+    /* Do not allow higher pitch estimation LPC order than predict LPC order */\r
+    psEncC->pitchEstimationLPCOrder = SKP_min_int( psEncC->pitchEstimationLPCOrder, psEncC->predictLPCOrder );\r
+    psEncC->shapeWinLength          = SUB_FRAME_LENGTH_MS * psEncC->fs_kHz + 2 * psEncC->la_shape;\r
 \r
-        /* If new TargetRate_bps, translate to SNR_dB value */\r
-        if( psEnc->sCmn.fs_kHz == 8 ) {\r
-            rateTable = TargetRate_table_NB;\r
-        } else if( psEnc->sCmn.fs_kHz == 12 ) {\r
-            rateTable = TargetRate_table_MB;\r
-        } else if( psEnc->sCmn.fs_kHz == 16 ) {\r
-            rateTable = TargetRate_table_WB;\r
-        } else {\r
-            SKP_assert( 0 );\r
-        }\r
-        /* Reduce bitrate for 10 ms modes in these calculations */\r
-        if( psEnc->sCmn.nb_subfr == 2 ) {\r
-            TargetRate_bps -= REDUCE_BITRATE_10_MS_BPS;\r
-        }\r
-        for( k = 1; k < TARGET_RATE_TAB_SZ; k++ ) {\r
-            /* Find bitrate interval in table and interpolate */\r
-            if( TargetRate_bps <= rateTable[ k ] ) {\r
-                frac_Q6 = SKP_DIV32( SKP_LSHIFT( TargetRate_bps - rateTable[ k - 1 ], 6 ), \r
-                                                 rateTable[ k ] - rateTable[ k - 1 ] );\r
-                psEnc->SNR_dB_Q7 = SKP_LSHIFT( SNR_table_Q1[ k - 1 ], 6 ) + SKP_MUL( frac_Q6, SNR_table_Q1[ k ] - SNR_table_Q1[ k - 1 ] );\r
-                break;\r
-            }\r
-        }\r
+    SKP_assert( psEncC->pitchEstimationLPCOrder <= MAX_FIND_PITCH_LPC_ORDER );\r
+    SKP_assert( psEncC->shapingLPCOrder         <= MAX_SHAPE_LPC_ORDER      );\r
+    SKP_assert( psEncC->nStatesDelayedDecision  <= MAX_DEL_DEC_STATES       );\r
+    SKP_assert( psEncC->warping_Q16             <= 32767                    );\r
+    SKP_assert( psEncC->la_shape                <= LA_SHAPE_MAX             );\r
+    SKP_assert( psEncC->shapeWinLength          <= SHAPE_LPC_WIN_MAX        );\r
+    SKP_assert( psEncC->NLSF_MSVQ_Survivors     <= NLSF_VQ_MAX_SURVIVORS    );\r
+\r
+    return ret;\r
+}\r
+\r
+SKP_INLINE SKP_int SKP_Silk_setup_LBRR(\r
+    SKP_Silk_encoder_state          *psEncC,            /* I/O                      */\r
+    const SKP_int32                 TargetRate_bps      /* I                        */\r
+)\r
+{\r
+    SKP_int   ret = SKP_SILK_NO_ERROR;\r
+    SKP_int32 LBRRRate_thres_bps;\r
+\r
+    SKP_assert( psEncC->fs_kHz == 8 || psEncC->fs_kHz == 12 || psEncC->fs_kHz == 16 );\r
+    if( psEncC->fs_kHz == 8 ) {\r
+        LBRRRate_thres_bps = LBRR_NB_MIN_RATE_BPS;\r
+    } else if( psEncC->fs_kHz == 12 ) {\r
+        LBRRRate_thres_bps = LBRR_MB_MIN_RATE_BPS;\r
+    } else {\r
+        LBRRRate_thres_bps = LBRR_WB_MIN_RATE_BPS;\r
     }\r
-    return( ret );\r
+\r
+    LBRRRate_thres_bps = SKP_RSHIFT( SKP_SMULBB( LBRRRate_thres_bps, 7 - psEncC->PacketLoss_perc ), 2 );\r
+    if( psEncC->useInBandFEC && TargetRate_bps >= LBRRRate_thres_bps && psEncC->PacketLoss_perc > 0 ) {\r
+        /* Set gain increase / rate reduction for LBRR usage */\r
+        psEncC->LBRR_GainIncreases = SKP_max_int( 7 - SKP_SMULWB( psEncC->PacketLoss_perc, SKP_FIX_CONST( 0.4, 16 ) ), 2 );\r
+        psEncC->LBRR_enabled = 1;\r
+    } else {\r
+        psEncC->LBRR_enabled = 0;\r
+    }\r
+\r
+    return ret;\r
 }\r
index ce03b9e..7d046f4 100644 (file)
@@ -31,6 +31,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "SKP_Silk_SDK_API.h"\r
 #include "SKP_Silk_main.h"\r
 \r
+/* Decoder Super Struct */\r
+typedef struct {\r
+    SKP_Silk_decoder_state          channel_state[ DECODER_NUM_CHANNELS ];\r
+    stereo_state                    sStereo;\r
+    SKP_int                         nChannels;\r
+} SKP_Silk_decoder;\r
+\r
+\r
 /*********************/\r
 /* Decoder functions */\r
 /*********************/\r
@@ -39,7 +47,7 @@ SKP_int SKP_Silk_SDK_Get_Decoder_Size( SKP_int32 *decSizeBytes )
 {\r
     SKP_int ret = SKP_SILK_NO_ERROR;\r
 \r
-    *decSizeBytes = sizeof( SKP_Silk_decoder_state );\r
+    *decSizeBytes = sizeof( SKP_Silk_decoder );\r
 \r
     return ret;\r
 }\r
@@ -49,61 +57,13 @@ SKP_int SKP_Silk_SDK_InitDecoder(
     void* decState                                      /* I/O: State                                          */\r
 )\r
 {\r
-    SKP_int ret = SKP_SILK_NO_ERROR;\r
-    SKP_Silk_decoder_state *struc;\r
-\r
-    struc = (SKP_Silk_decoder_state *)decState;\r
+    SKP_int n, ret = SKP_SILK_NO_ERROR;\r
+    SKP_Silk_decoder_state *channel_state = ((SKP_Silk_decoder *)decState)->channel_state;\r
 \r
-    ret  = SKP_Silk_init_decoder( struc );\r
-\r
-    return ret;\r
-}\r
-\r
-/* Prefill LPC synthesis buffer, HP filter and upsampler. Input must be exactly 10 ms of audio. */\r
-SKP_int SKP_Silk_SDK_Decoder_prefill_buffers(           /* O:   Returns error code                              */\r
-    void*                               decState,       /* I/O: State                                           */\r
-    SKP_SILK_SDK_DecControlStruct*      decControl,     /* I/O: Control Structure                               */\r
-    const SKP_int16                     *samplesIn,     /* I:   Speech sample input vector  (10 ms)             */\r
-    SKP_int                             nSamplesIn      /* I:   Number of samples in input vector               */\r
-)\r
-{\r
-    SKP_int   i, nSamples, ret = 0;\r
-    SKP_Silk_decoder_state *psDec = ( SKP_Silk_decoder_state *)decState;\r
-    SKP_Silk_resampler_state_struct resampler_state;\r
-    SKP_int16 buf[ 10 * MAX_FS_KHZ ];\r
-    SKP_int16 buf_out[ 10 * MAX_API_FS_KHZ ];\r
-    const SKP_int16 *in_ptr;\r
-\r
-    /* Compute some numbers at API sampling rate */\r
-    if( nSamplesIn != SKP_DIV32_16( decControl->API_sampleRate, 100 ) ) {\r
-        return -1;\r
+    for( n = 0; n < DECODER_NUM_CHANNELS; n++ ) {\r
+        ret  = SKP_Silk_init_decoder( &channel_state[ n ] );\r
     }\r
 \r
-    /* Resample input if necessary */\r
-    if( decControl->API_sampleRate != SKP_SMULBB( 1000, psDec->fs_kHz ) ) { \r
-        ret += SKP_Silk_resampler_init( &resampler_state, decControl->API_sampleRate, SKP_SMULBB( 1000, psDec->fs_kHz ) );\r
-        ret += SKP_Silk_resampler( &resampler_state, buf, samplesIn, nSamplesIn );\r
-        in_ptr = buf;\r
-        nSamples = SKP_SMULBB( 10, psDec->fs_kHz );\r
-    } else {\r
-        in_ptr = samplesIn;\r
-        nSamples = nSamplesIn;\r
-    }\r
-\r
-    /* Set synthesis filter state */\r
-    for( i = 0; i < psDec->LPC_order; i++ ) {\r
-        psDec->sLPC_Q14[ MAX_LPC_ORDER - i ] = SKP_LSHIFT( SKP_SMULWB( psDec->prev_inv_gain_Q16, in_ptr[ nSamples - i ] ), 14 );\r
-    }\r
-\r
-    /* HP filter */\r
-    SKP_Silk_biquad_alt( in_ptr, psDec->HP_B, psDec->HP_A, psDec->HPState, buf, nSamples );\r
-\r
-    /* Output upsampler */\r
-    SKP_Silk_resampler( &psDec->resampler_state, buf_out, buf, nSamples );\r
-\r
-    /* Avoid using LSF interpolation or pitch prediction in first next frame */\r
-    psDec->first_frame_after_reset = 1;\r
-\r
     return ret;\r
 }\r
 \r
@@ -111,89 +71,182 @@ SKP_int SKP_Silk_SDK_Decoder_prefill_buffers(           /* O:   Returns error co
 SKP_int SKP_Silk_SDK_Decode(\r
     void*                               decState,       /* I/O: State                                           */\r
     SKP_SILK_SDK_DecControlStruct*      decControl,     /* I/O: Control Structure                               */\r
-    SKP_int                             lostFlag,       /* I:   0: no loss, 1 loss, 2 decode fec                */\r
+    SKP_int                             lostFlag,       /* I:   0: no loss, 1 loss, 2 decode FEC                */\r
     SKP_int                             newPacketFlag,  /* I:   Indicates first decoder call for this packet    */\r
     ec_dec                              *psRangeDec,    /* I/O  Compressor data structure                       */\r
-    const SKP_int                       nBytesIn,       /* I:   Number of input bytes                           */\r
     SKP_int16                           *samplesOut,    /* O:   Decoded output speech vector                    */\r
     SKP_int32                           *nSamplesOut    /* O:   Number of samples decoded                       */\r
 )\r
 {\r
-    SKP_int ret = SKP_SILK_NO_ERROR, prev_fs_kHz;\r
-    SKP_Silk_decoder_state *psDec;\r
-\r
-    psDec = (SKP_Silk_decoder_state *)decState;\r
+    SKP_int   i, n, prev_fs_kHz, doResample, flags, nFlags, MS_predictorIx, ret = SKP_SILK_NO_ERROR;\r
+    SKP_int32 nSamplesOutDec, LBRR_symbol;\r
+    SKP_int16 samplesOut1_tmp[ 2 * MAX_FS_KHZ * MAX_FRAME_LENGTH_MS ];\r
+    SKP_int16 samplesOut2_tmp[ MAX_API_FS_KHZ * MAX_FRAME_LENGTH_MS ];\r
+    SKP_int16 *dec_out_ptr, *resample_out_ptr;\r
+    SKP_Silk_decoder *psDec = ( SKP_Silk_decoder * )decState;\r
+    SKP_Silk_decoder_state *channel_state = psDec->channel_state;\r
 \r
     /**********************************/\r
     /* Test if first frame in payload */\r
     /**********************************/\r
     if( newPacketFlag ) {\r
-        /* First Frame in Payload */\r
-        psDec->nFramesDecoded = 0;  /* Used to count frames in packet */\r
+        for( n = 0; n < decControl->nChannels; n++ ) {\r
+            channel_state[ n ].nFramesDecoded = 0;  /* Used to count frames in packet */\r
+        }\r
     }\r
 \r
     /* Save previous sample frequency */\r
-    prev_fs_kHz = psDec->fs_kHz;\r
-\r
-    if( psDec->nFramesDecoded == 0 ) {\r
-        SKP_int fs_kHz_dec;\r
-        if( decControl->payloadSize_ms == 10 ) {\r
-            psDec->nFramesPerPacket = 1;\r
-            psDec->nb_subfr = 2;\r
-        } else if( decControl->payloadSize_ms == 20 ) {\r
-            psDec->nFramesPerPacket = 1;\r
-            psDec->nb_subfr = 4;\r
-        } else if( decControl->payloadSize_ms == 40 ) {\r
-            psDec->nFramesPerPacket = 2;\r
-            psDec->nb_subfr = 4;\r
-        } else if( decControl->payloadSize_ms == 60 ) {\r
-            psDec->nFramesPerPacket = 3;\r
-            psDec->nb_subfr = 4;\r
-        } else {\r
-            SKP_assert( 0 );\r
-            return SKP_SILK_DEC_INVALID_FRAME_SIZE;\r
-        } \r
-        fs_kHz_dec = ( decControl->internalSampleRate >> 10 ) + 1;\r
-        if( fs_kHz_dec != 8 && fs_kHz_dec != 12 && fs_kHz_dec != 16 ) {\r
-            SKP_assert( 0 );\r
-            return SKP_SILK_DEC_INVALID_SAMPLING_FREQUENCY;\r
+    prev_fs_kHz = channel_state[ 0 ].fs_kHz;\r
+\r
+    if( decControl->nChannels > psDec->nChannels ) {\r
+        /* Mono -> Stereo transition: init state of second channel and stereo state */\r
+        SKP_memset( &psDec->sStereo, 0, sizeof( psDec->sStereo ) );\r
+        ret += SKP_Silk_init_decoder( &channel_state[ 1 ] );\r
+    }\r
+    psDec->nChannels = decControl->nChannels;\r
+\r
+    for( n = 0; n < decControl->nChannels; n++ ) {\r
+        if( channel_state[ n ].nFramesDecoded == 0 ) {\r
+            SKP_int fs_kHz_dec;\r
+            if( decControl->payloadSize_ms == 10 ) {\r
+                channel_state[ n ].nFramesPerPacket = 1;\r
+                channel_state[ n ].nb_subfr = 2;\r
+            } else if( decControl->payloadSize_ms == 20 ) {\r
+                channel_state[ n ].nFramesPerPacket = 1;\r
+                channel_state[ n ].nb_subfr = 4;\r
+            } else if( decControl->payloadSize_ms == 40 ) {\r
+                channel_state[ n ].nFramesPerPacket = 2;\r
+                channel_state[ n ].nb_subfr = 4;\r
+            } else if( decControl->payloadSize_ms == 60 ) {\r
+                channel_state[ n ].nFramesPerPacket = 3;\r
+                channel_state[ n ].nb_subfr = 4;\r
+            } else {\r
+                SKP_assert( 0 );\r
+                return SKP_SILK_DEC_INVALID_FRAME_SIZE;\r
+            } \r
+            fs_kHz_dec = ( decControl->internalSampleRate >> 10 ) + 1;\r
+            if( fs_kHz_dec != 8 && fs_kHz_dec != 12 && fs_kHz_dec != 16 ) {\r
+                SKP_assert( 0 );\r
+                return SKP_SILK_DEC_INVALID_SAMPLING_FREQUENCY;\r
+            }\r
+            SKP_Silk_decoder_set_fs( &channel_state[ n ], fs_kHz_dec );\r
         }\r
-        SKP_Silk_decoder_set_fs( psDec, fs_kHz_dec );\r
     }\r
     \r
-    /* Call decoder for one frame */\r
-    ret += SKP_Silk_decode_frame( psDec, psRangeDec, samplesOut, nSamplesOut, nBytesIn, lostFlag );\r
-    \r
     if( decControl->API_sampleRate > MAX_API_FS_KHZ * 1000 || decControl->API_sampleRate < 8000 ) {\r
         ret = SKP_SILK_DEC_INVALID_SAMPLING_FREQUENCY;\r
         return( ret );\r
     }\r
 \r
-    /* Resample if needed */\r
-    if( SKP_SMULBB( psDec->fs_kHz, 1000 ) != decControl->API_sampleRate ) { \r
-        SKP_int16 samplesOut_tmp[ MAX_API_FS_KHZ * MAX_FRAME_LENGTH_MS ];\r
-        SKP_assert( psDec->fs_kHz <= MAX_API_FS_KHZ );\r
+    doResample = SKP_SMULBB( channel_state[ 0 ].fs_kHz, 1000 ) != decControl->API_sampleRate;\r
+\r
+    /* Set up pointers to temp buffers */\r
+    if( doResample || decControl->nChannels == 2 ) { \r
+        dec_out_ptr = samplesOut1_tmp;\r
+    } else {\r
+        dec_out_ptr = samplesOut;\r
+    }\r
+    if( decControl->nChannels == 2 ) {\r
+        resample_out_ptr = samplesOut2_tmp;\r
+    } else {\r
+        resample_out_ptr = samplesOut;\r
+    }\r
 \r
-        /* Copy to a tmp buffer as the resampling writes to samplesOut */\r
-        SKP_memcpy( samplesOut_tmp, samplesOut, *nSamplesOut * sizeof( SKP_int16 ) );\r
+    if( lostFlag != FLAG_PACKET_LOST && channel_state[ 0 ].nFramesDecoded == 0 ) {\r
+        /* First decoder call for this payload */\r
+        nFlags = SKP_SMULBB( decControl->nChannels, channel_state[ 0 ].nFramesPerPacket + 1 );\r
+        flags = SKP_RSHIFT( psRangeDec->buf[ 0 ], 8 - nFlags ) & ( SKP_LSHIFT( 1, nFlags ) - 1 );\r
+        for( i = 0; i < nFlags; i++ ) {\r
+            ec_dec_icdf( psRangeDec, SKP_Silk_uniform2_iCDF, 8 );\r
+        }\r
+        /* Decode VAD flags and LBRR flag */\r
+        for( n = decControl->nChannels - 1; n >= 0; n-- ) {\r
+            channel_state[ n ].LBRR_flag = flags & 1;\r
+            flags = SKP_RSHIFT( flags, 1 );\r
+            for( i = channel_state[ n ].nFramesPerPacket - 1; i >= 0 ; i-- ) {\r
+                channel_state[ n ].VAD_flags[ i ] = flags & 1;\r
+                flags = SKP_RSHIFT( flags, 1 );\r
+            }\r
+        }       \r
+        /* Decode LBRR flags */\r
+        for( n = 0; n < decControl->nChannels; n++ ) {\r
+            SKP_memset( channel_state[ n ].LBRR_flags, 0, sizeof( channel_state[ n ].LBRR_flags ) );\r
+            if( channel_state[ n ].LBRR_flag ) {\r
+                if( channel_state[ n ].nFramesPerPacket == 1 ) {\r
+                    channel_state[ n ].LBRR_flags[ 0 ] = 1;\r
+                } else {\r
+                    LBRR_symbol = ec_dec_icdf( psRangeDec, SKP_Silk_LBRR_flags_iCDF_ptr[ channel_state[ n ].nFramesPerPacket - 2 ], 8 ) + 1;\r
+                    for( i = 0; i < channel_state[ n ].nFramesPerPacket; i++ ) {\r
+                        channel_state[ n ].LBRR_flags[ i ] = SKP_RSHIFT( LBRR_symbol, i ) & 1;\r
+                    }\r
+                }\r
+            }\r
+        }\r
 \r
-        /* (Re-)initialize resampler state when switching internal sampling frequency */\r
-        if( prev_fs_kHz != psDec->fs_kHz || psDec->prev_API_sampleRate != decControl->API_sampleRate ) {\r
-            ret = SKP_Silk_resampler_init( &psDec->resampler_state, SKP_SMULBB( psDec->fs_kHz, 1000 ), decControl->API_sampleRate );\r
+        if( lostFlag == FLAG_DECODE_NORMAL ) {\r
+            /* Regular decoding: skip all LBRR data */\r
+            for( i = 0; i < channel_state[ 0 ].nFramesPerPacket; i++ ) {\r
+                for( n = 0; n < decControl->nChannels; n++ ) {\r
+                    if( channel_state[ n ].LBRR_flags[ i ] ) {\r
+                        SKP_int pulses[ MAX_FRAME_LENGTH ];\r
+                        SKP_Silk_decode_indices( &channel_state[ n ], psRangeDec, i, 1 );\r
+                        SKP_Silk_decode_pulses( psRangeDec, pulses, channel_state[ n ].indices.signalType, \r
+                            channel_state[ n ].indices.quantOffsetType, channel_state[ n ].frame_length );\r
+                    }\r
+                }\r
+            }\r
         }\r
+    }\r
+\r
+    /* Get MS predictor index */\r
+    if( decControl->nChannels == 2 ) {\r
+        MS_predictorIx = ec_dec_icdf( psRangeDec, SKP_Silk_stereo_predictor_iCDF, 8 );\r
+    }\r
+\r
+    /* Call decoder for one frame */\r
+    for( n = 0; n < decControl->nChannels; n++ ) {\r
+        ret += SKP_Silk_decode_frame( &channel_state[ n ], psRangeDec, &dec_out_ptr[ n * MAX_FS_KHZ * MAX_FRAME_LENGTH_MS ], &nSamplesOutDec, lostFlag );\r
+    }\r
 \r
-        /* Resample the output to API_sampleRate */\r
-        ret += SKP_Silk_resampler( &psDec->resampler_state, samplesOut, samplesOut_tmp, *nSamplesOut );\r
+    /* Convert Mid/Side to Left/Right */\r
+    if( decControl->nChannels == 2 ) {\r
+        SKP_Silk_stereo_MS_to_LR( &psDec->sStereo, dec_out_ptr, &dec_out_ptr[ MAX_FS_KHZ * MAX_FRAME_LENGTH_MS ], MS_predictorIx, channel_state[ 0 ].fs_kHz, nSamplesOutDec );\r
+    }\r
 \r
-        /* Update the number of output samples */\r
-        *nSamplesOut = SKP_DIV32( ( SKP_int32 )*nSamplesOut * decControl->API_sampleRate, SKP_SMULBB( psDec->fs_kHz, 1000 ) );\r
+    /* Number of output samples */\r
+    if( doResample ) {\r
+        *nSamplesOut = SKP_DIV32( nSamplesOutDec * decControl->API_sampleRate, SKP_SMULBB( channel_state[ 0 ].fs_kHz, 1000 ) );\r
+    } else {\r
+        *nSamplesOut = nSamplesOutDec;\r
     }\r
 \r
-    psDec->prev_API_sampleRate = decControl->API_sampleRate;\r
+    for( n = 0; n < decControl->nChannels; n++ ) {\r
+        /* Resample if needed */\r
+        if( doResample ) {\r
+            /* Initialize resampler when switching internal or external sampling frequency */\r
+            if( prev_fs_kHz != channel_state[ n ].fs_kHz || channel_state[ n ].prev_API_sampleRate != decControl->API_sampleRate ) {\r
+                ret = SKP_Silk_resampler_init( &channel_state[ n ].resampler_state, SKP_SMULBB( channel_state[ n ].fs_kHz, 1000 ), decControl->API_sampleRate );\r
+            }\r
+\r
+            /* Resample the output to API_sampleRate */\r
+            ret += SKP_Silk_resampler( &channel_state[ n ].resampler_state, resample_out_ptr, &dec_out_ptr[ n * MAX_FS_KHZ * MAX_FRAME_LENGTH_MS ], nSamplesOutDec );\r
+        } else {\r
+            resample_out_ptr = &dec_out_ptr[ n * MAX_FS_KHZ * MAX_FRAME_LENGTH_MS ];\r
+        }\r
+\r
+        /* Interleave if needed */\r
+        if( decControl->nChannels == 2 ) {\r
+            for( i = 0; i < *nSamplesOut; i++ ) {\r
+                samplesOut[ n + 2 * i ] = resample_out_ptr[ i ];\r
+            }\r
+        }\r
+        \r
+        channel_state[ n ].prev_API_sampleRate = decControl->API_sampleRate;\r
+    }\r
 \r
-    /* Copy all parameters that are needed out of internal structure to the control stucture */\r
-    decControl->frameSize                 = ( SKP_int )*nSamplesOut;\r
-    decControl->framesPerPayload          = ( SKP_int )psDec->nFramesPerPacket;\r
+    /* Copy parameters to control stucture */\r
+    decControl->frameSize        = ( SKP_int )*nSamplesOut;\r
+    decControl->framesPerPayload = ( SKP_int )channel_state[ n ].nFramesPerPacket;\r
 \r
     return ret;\r
 }\r
@@ -217,6 +270,7 @@ SKP_int SKP_Silk_SDK_get_TOC(
 \r
     SKP_memset( Silk_TOC, 0, sizeof( Silk_TOC ) );\r
 \r
+    /* For stereo, extract the flags for the mid channel */\r
     flags = SKP_RSHIFT( payload[ 0 ], 7 - nFramesPerPayload ) & ( SKP_LSHIFT( 1, nFramesPerPayload + 1 ) - 1 );\r
 \r
     Silk_TOC->inbandFECFlag = flags & 1;\r
index b090450..0db27f8 100644 (file)
@@ -28,10 +28,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "SKP_Silk_main.h"\r
 #include "SKP_Silk_PLC.h"\r
 \r
-#define DECODE_NORMAL       0\r
-#define PACKET_LOST         1\r
-#define DECODE_LBRR         2\r
-\r
 /****************/\r
 /* Decode frame */\r
 /****************/\r
@@ -40,14 +36,11 @@ SKP_int SKP_Silk_decode_frame(
     ec_dec                      *psRangeDec,        /* I/O  Compressor data structure                   */\r
     SKP_int16                   pOut[],             /* O    Pointer to output speech frame              */\r
     SKP_int32                   *pN,                /* O    Pointer to size of output frame             */\r
-    const SKP_int               nBytes,             /* I    Payload length                              */\r
     SKP_int                     lostFlag            /* I    0: no loss, 1 loss, 2 decode fec            */\r
 )\r
 {\r
     SKP_Silk_decoder_control sDecCtrl;\r
-    SKP_int         i, L, mv_len, ret = 0;\r
-    SKP_int8        flags;\r
-    SKP_int32       LBRR_symbol;\r
+    SKP_int         L, mv_len, ret = 0;\r
     SKP_int         pulses[ MAX_FRAME_LENGTH ];\r
 \r
 TIC(DECODE_FRAME)\r
@@ -58,56 +51,9 @@ TIC(DECODE_FRAME)
     /* Safety checks */\r
     SKP_assert( L > 0 && L <= MAX_FRAME_LENGTH );\r
 \r
-    /********************************************/\r
-    /* Decode Frame if packet is not lost       */\r
-    /********************************************/\r
-    if( lostFlag != PACKET_LOST && psDec->nFramesDecoded == 0 ) {\r
-        /* First decoder call for this payload */\r
-        /* Decode VAD flags and LBRR flag */\r
-        flags = SKP_RSHIFT( psRangeDec->buf[ 0 ], 7 - psDec->nFramesPerPacket ) & \r
-            ( SKP_LSHIFT( 1, psDec->nFramesPerPacket + 1 ) - 1 );\r
-        psDec->LBRR_flag = flags & 1;\r
-        for( i = psDec->nFramesPerPacket - 1; i >= 0 ; i-- ) {\r
-            flags = SKP_RSHIFT( flags, 1 );\r
-            psDec->VAD_flags[ i ] = flags & 1;\r
-        }\r
-        for( i = 0; i < psDec->nFramesPerPacket + 1; i++ ) {\r
-            ec_dec_icdf( psRangeDec, SKP_Silk_uniform2_iCDF, 8 );\r
-        }\r
-       \r
-        /* Decode LBRR flags */\r
-        SKP_memset( psDec->LBRR_flags, 0, sizeof( psDec->LBRR_flags ) );\r
-        if( psDec->LBRR_flag ) {\r
-            if( psDec->nFramesPerPacket == 1 ) {\r
-                psDec->LBRR_flags[ 0 ] = 1;\r
-            } else {\r
-                LBRR_symbol = ec_dec_icdf( psRangeDec, SKP_Silk_LBRR_flags_iCDF_ptr[ psDec->nFramesPerPacket - 2 ], 8 ) + 1;\r
-                for( i = 0; i < psDec->nFramesPerPacket; i++ ) {\r
-                    psDec->LBRR_flags[ i ] = SKP_RSHIFT( LBRR_symbol, i ) & 1;\r
-                }\r
-            }\r
-        }\r
-\r
-        if( lostFlag == DECODE_NORMAL ) {\r
-            /* Regular decoding: skip all LBRR data */\r
-            for( i = 0; i < psDec->nFramesPerPacket; i++ ) {\r
-                if( psDec->LBRR_flags[ i ] ) {\r
-                    SKP_Silk_decode_indices( psDec, psRangeDec, i, 1 );\r
-                    SKP_Silk_decode_pulses( psRangeDec, pulses, psDec->indices.signalType, \r
-                        psDec->indices.quantOffsetType, psDec->frame_length );\r
-                }\r
-            }\r
-        }\r
-\r
-    }\r
-\r
-    if( lostFlag == DECODE_LBRR && psDec->LBRR_flags[ psDec->nFramesDecoded ] == 0 ) {\r
-        /* Treat absent LBRR data as lost frame */\r
-        lostFlag = PACKET_LOST;\r
-        psDec->nFramesDecoded++;\r
-    }\r
-\r
-    if( lostFlag != PACKET_LOST ) {\r
+    if(   lostFlag == FLAG_DECODE_NORMAL || \r
+        ( lostFlag == FLAG_DECODE_LBRR && psDec->LBRR_flags[ psDec->nFramesDecoded ] == 1 ) ) \r
+    {\r
         /*********************************************/\r
         /* Decode quantization indices of side info  */\r
         /*********************************************/\r
@@ -151,7 +97,6 @@ TOC(decode_core)
 \r
         /* A frame has been decoded without errors */\r
         psDec->first_frame_after_reset = 0;\r
-        psDec->nFramesDecoded++;\r
     } else {\r
         /* Handle packet loss by extrapolation */\r
         SKP_Silk_PLC( psDec, &sDecCtrl, pOut, L, 1 );\r
@@ -175,20 +120,12 @@ TOC(decode_core)
     /************************************************/\r
     SKP_Silk_CNG( psDec, &sDecCtrl, pOut, L );\r
 \r
-    /********************************************/\r
-    /* HP filter output                            */\r
-    /********************************************/\r
-TIC(HP_out)\r
-    SKP_Silk_biquad_alt( pOut, psDec->HP_B, psDec->HP_A, psDec->HPState, pOut, L );\r
-TOC(HP_out)\r
-\r
     /* Update some decoder state variables */\r
     psDec->lagPrev = sDecCtrl.pitchL[ psDec->nb_subfr - 1 ];\r
+    psDec->nFramesDecoded++;\r
 \r
-    /********************************************/\r
-    /* set output frame length                    */\r
-    /********************************************/\r
-    *pN = ( SKP_int16 )L;\r
+    /* Set output frame length */\r
+    *pN = L;\r
 \r
 TOC(DECODE_FRAME)\r
 \r
index 488bbd2..9864eaf 100644 (file)
@@ -27,7 +27,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 \r
 #include "SKP_Silk_main.h"\r
 \r
-/* Decode indices from payload */\r
+/* Decode side-information parameters from payload */\r
 void SKP_Silk_decode_indices(\r
     SKP_Silk_decoder_state      *psDec,             /* I/O  State                                       */\r
     ec_dec                      *psRangeDec,        /* I/O  Compressor data structure                   */\r
@@ -40,6 +40,7 @@ void SKP_Silk_decode_indices(
     SKP_int16 ec_ix[ MAX_LPC_ORDER ];\r
     SKP_uint8 pred_Q8[ MAX_LPC_ORDER ];\r
 \r
+    /* Use conditional coding if previous frame available */\r
     if( FrameIndex > 0 && ( decode_LBRR == 0 || psDec->LBRR_flags[ FrameIndex - 1 ] == 1 ) ) {\r
         condCoding = 1;\r
     } else {\r
@@ -60,17 +61,17 @@ void SKP_Silk_decode_indices(
     /****************/\r
     /* Decode gains */\r
     /****************/\r
-    /* first subframe */    \r
+    /* First subframe */    \r
     if( condCoding ) {\r
-        /* conditional coding */\r
+        /* Conditional coding */\r
         psDec->indices.GainsIndices[ 0 ] = (SKP_int8)ec_dec_icdf( psRangeDec, SKP_Silk_delta_gain_iCDF, 8 );\r
     } else {\r
-        /* independent coding, in two stages: MSB bits followed by 3 LSBs */\r
+        /* Independent coding, in two stages: MSB bits followed by 3 LSBs */\r
         psDec->indices.GainsIndices[ 0 ]  = (SKP_int8)SKP_LSHIFT( ec_dec_icdf( psRangeDec, SKP_Silk_gain_iCDF[ psDec->indices.signalType ], 8 ), 3 );\r
         psDec->indices.GainsIndices[ 0 ] += (SKP_int8)ec_dec_icdf( psRangeDec, SKP_Silk_uniform8_iCDF, 8 );\r
     }\r
 \r
-    /* remaining subframes */\r
+    /* Remaining subframes */\r
     for( i = 1; i < psDec->nb_subfr; i++ ) {\r
         psDec->indices.GainsIndices[ i ] = (SKP_int8)ec_dec_icdf( psRangeDec, SKP_Silk_delta_gain_iCDF, 8 );\r
     }\r
index 7142efc..ea316fc 100644 (file)
@@ -76,16 +76,10 @@ void SKP_Silk_decoder_set_fs(
         psDec->first_frame_after_reset = 1;\r
 \r
         if( fs_kHz == 16 ) {\r
-            psDec->HP_A = SKP_Silk_Dec_A_HP_16;\r
-            psDec->HP_B = SKP_Silk_Dec_B_HP_16;\r
             psDec->pitch_lag_low_bits_iCDF = SKP_Silk_uniform8_iCDF;\r
         } else if( fs_kHz == 12 ) {\r
-            psDec->HP_A = SKP_Silk_Dec_A_HP_12;\r
-            psDec->HP_B = SKP_Silk_Dec_B_HP_12;\r
             psDec->pitch_lag_low_bits_iCDF = SKP_Silk_uniform6_iCDF;\r
         } else if( fs_kHz == 8 ) {\r
-            psDec->HP_A = SKP_Silk_Dec_A_HP_8;\r
-            psDec->HP_B = SKP_Silk_Dec_B_HP_8;\r
             psDec->pitch_lag_low_bits_iCDF = SKP_Silk_uniform4_iCDF;\r
         } else {\r
             /* unsupported sampling rate */\r
index 04b1b1f..adefef8 100644 (file)
@@ -40,6 +40,11 @@ extern "C"
 {\r
 #endif\r
 \r
+/* Max number of encoder channels (1/2) */\r
+#define ENCODER_NUM_CHANNELS                    2\r
+/* Number of decoder channels (1/2) */\r
+#define DECODER_NUM_CHANNELS                    2\r
+\r
 #define MAX_FRAMES_PER_PACKET                   3\r
 \r
 #ifndef FIXED_POINT\r
@@ -51,30 +56,36 @@ extern "C"
 #define MAX_TARGET_RATE_BPS                     80000\r
 #define TARGET_RATE_TAB_SZ                      8\r
 \r
+/* Decay time for bitreservoir */\r
+#define BITRESERVOIR_DECAY_TIME_MS              200\r
+\r
 /* LBRR thresholds */\r
 #define LBRR_NB_MIN_RATE_BPS                    9000\r
 #define LBRR_MB_MIN_RATE_BPS                    12000\r
 #define LBRR_WB_MIN_RATE_BPS                    15000\r
 \r
-/* DTX settings                                 */\r
-#define NO_SPEECH_FRAMES_BEFORE_DTX             5       /* eq 100 ms */\r
+/* DTX settings */\r
+#define NB_SPEECH_FRAMES_BEFORE_DTX             10      /* eq 200 ms */\r
 #define MAX_CONSECUTIVE_DTX                     20      /* eq 400 ms */\r
 \r
-/* Activate bandwidth transition filtering for mode switching */\r
-#define SWITCH_TRANSITION_FILTERING             1\r
-\r
-/* Decoder Parameters */\r
-#define DEC_HP_ORDER                            2\r
-\r
 /* Maximum sampling frequency, should be 16 for embedded */\r
 #define MAX_FS_KHZ                              16 \r
 #define MAX_API_FS_KHZ                          48\r
 \r
-/* Signal types used by silk */\r
+/* Signal types */\r
 #define TYPE_NO_VOICE_ACTIVITY                  0\r
 #define TYPE_UNVOICED                           1\r
 #define TYPE_VOICED                             2\r
 \r
+/* Setting for stereo processing */\r
+#define STEREO_QUANT_STEPS                      15\r
+#define STEREO_QUANT_HYSTERESIS                 0.25\r
+#define STEREO_INTERPOL_LENGTH_MS               10\r
+\r
+/* Range of pitch lag estimates */\r
+#define PITCH_EST_MIN_LAG_MS                    2           /* 2 ms -> 500 Hz */\r
+#define PITCH_EST_MAX_LAG_MS                    18          /* 18 ms -> 56 Hz */\r
+\r
 /* Number of subframes */\r
 #define MAX_NB_SUBFR                            4\r
 \r
@@ -147,20 +158,20 @@ extern "C"
 #define MAX_DEL_DEC_STATES                      4\r
 \r
 #define LTP_BUF_LENGTH                          512\r
-#define LTP_MASK                                (LTP_BUF_LENGTH - 1)\r
+#define LTP_MASK                                ( LTP_BUF_LENGTH - 1 )\r
 \r
 #define DECISION_DELAY                          32\r
-#define DECISION_DELAY_MASK                     (DECISION_DELAY - 1)\r
+#define DECISION_DELAY_MASK                     ( DECISION_DELAY - 1 )\r
 \r
-/* number of subframes for excitation entropy coding */\r
+/* Number of subframes for excitation entropy coding */\r
 #define SHELL_CODEC_FRAME_LENGTH                16\r
 #define LOG2_SHELL_CODEC_FRAME_LENGTH           4\r
-#define MAX_NB_SHELL_BLOCKS                     (MAX_FRAME_LENGTH / SHELL_CODEC_FRAME_LENGTH)\r
+#define MAX_NB_SHELL_BLOCKS                     ( MAX_FRAME_LENGTH / SHELL_CODEC_FRAME_LENGTH )\r
 \r
-/* number of rate levels, for entropy coding of excitation */\r
+/* Number of rate levels, for entropy coding of excitation */\r
 #define N_RATE_LEVELS                           10\r
 \r
-/* maximum sum of pulses per shell coding frame */\r
+/* Maximum sum of pulses per shell coding frame */\r
 #define MAX_PULSES                              16\r
 \r
 #define MAX_MATRIX_SIZE                         MAX_LPC_ORDER /* Max of LPC Order and LTP order */\r
@@ -206,16 +217,12 @@ extern "C"
 #define NLSF_QUANT_DEL_DEC_STATES               ( 1 << NLSF_QUANT_DEL_DEC_STATES_LOG2 )\r
 \r
 /* Transition filtering for mode switching */\r
-#if SWITCH_TRANSITION_FILTERING\r
 #  define TRANSITION_TIME_MS                    5120 // 5120 = 64 * FRAME_LENGTH_MS * ( TRANSITION_INT_NUM - 1 ) = 64*(20*4)\r
 #  define TRANSITION_NB                         3 /* Hardcoded in tables */\r
 #  define TRANSITION_NA                         2 /* Hardcoded in tables */\r
 #  define TRANSITION_INT_NUM                    5 /* Hardcoded in tables */\r
 #  define TRANSITION_FRAMES                     ( TRANSITION_TIME_MS / MAX_FRAME_LENGTH_MS ) // todo: needs to be made flexible for 10 ms frames\r
 #  define TRANSITION_INT_STEPS                  ( TRANSITION_FRAMES  / ( TRANSITION_INT_NUM - 1 ) )\r
-#else\r
-#  define TRANSITION_FRAMES                     0\r
-#endif\r
 \r
 /* BWE factors to apply after packet loss */\r
 #define BWE_AFTER_LOSS_Q16                      63570\r
index d0e86c0..71dd5e9 100644 (file)
@@ -34,86 +34,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #if FIXED_POINT\r
 #include "SKP_Silk_main_FIX.h"\r
 #define SKP_Silk_encoder_state_Fxx      SKP_Silk_encoder_state_FIX\r
-#define SKP_Silk_init_encoder_Fxx       SKP_Silk_init_encoder_FIX\r
-#define SKP_Silk_control_encoder_Fxx    SKP_Silk_control_encoder_FIX\r
 #define SKP_Silk_encode_frame_Fxx       SKP_Silk_encode_frame_FIX\r
 #else\r
 #include "SKP_Silk_main_FLP.h"\r
 #define SKP_Silk_encoder_state_Fxx      SKP_Silk_encoder_state_FLP\r
-#define SKP_Silk_init_encoder_Fxx       SKP_Silk_init_encoder_FLP\r
-#define SKP_Silk_control_encoder_Fxx    SKP_Silk_control_encoder_FLP\r
 #define SKP_Silk_encode_frame_Fxx       SKP_Silk_encode_frame_FLP\r
 #endif\r
-#define SKP_Silk_EncodeControlStruct    SKP_SILK_SDK_EncControlStruct\r
 \r
-/**************************/\r
-/* Encode frame with Silk */\r
-/**************************/\r
-static SKP_int process_enc_control_struct( \r
-    SKP_Silk_encoder_state_Fxx          *psEnc,         /* I/O: State                                           */\r
-    SKP_Silk_EncodeControlStruct        *encControl     /* I:   Control structure                               */\r
-)\r
-{\r
-    SKP_int   max_internal_fs_kHz, min_internal_fs_kHz, Complexity, PacketSize_ms, PacketLoss_perc, UseInBandFEC, ret = SKP_SILK_NO_ERROR;\r
-    SKP_int32 TargetRate_bps, API_fs_Hz;\r
-\r
-    SKP_assert( encControl != NULL );\r
-\r
-    /* Check sampling frequency first, to avoid divide by zero later */\r
-    if( ( ( encControl->API_sampleRate        !=  8000 ) &&\r
-          ( encControl->API_sampleRate        != 12000 ) &&\r
-          ( encControl->API_sampleRate        != 16000 ) &&\r
-          ( encControl->API_sampleRate        != 24000 ) && \r
-          ( encControl->API_sampleRate        != 32000 ) &&\r
-          ( encControl->API_sampleRate        != 44100 ) &&\r
-          ( encControl->API_sampleRate        != 48000 ) ) ||\r
-        ( ( encControl->maxInternalSampleRate !=  8000 ) &&\r
-          ( encControl->maxInternalSampleRate != 12000 ) &&\r
-          ( encControl->maxInternalSampleRate != 16000 ) ) ||\r
-        ( ( encControl->minInternalSampleRate !=  8000 ) &&\r
-          ( encControl->minInternalSampleRate != 12000 ) &&\r
-          ( encControl->minInternalSampleRate != 16000 ) ) ||\r
-          ( encControl->minInternalSampleRate > encControl->maxInternalSampleRate ) ) {\r
-        ret = SKP_SILK_ENC_FS_NOT_SUPPORTED;\r
-        SKP_assert( 0 );\r
-        return( ret );\r
-    }\r
-    if( encControl->useDTX < 0 || encControl->useDTX > 1 ) {\r
-        ret = SKP_SILK_ENC_INVALID_DTX_SETTING;\r
-    }\r
-       if( encControl->useCBR < 0 || encControl->useCBR > 1 ) {\r
-        ret = SKP_SILK_ENC_INVALID_CBR_SETTING;\r
-    }\r
-\r
-    /* Set encoder parameters from control structure */\r
-    API_fs_Hz           =            encControl->API_sampleRate;\r
-    max_internal_fs_kHz = (SKP_int)( encControl->maxInternalSampleRate >> 10 ) + 1;   /* convert Hz -> kHz */\r
-    min_internal_fs_kHz = (SKP_int)( encControl->minInternalSampleRate >> 10 ) + 1;   /* convert Hz -> kHz */\r
-    PacketSize_ms       =            encControl->payloadSize_ms;\r
-    TargetRate_bps      =            encControl->bitRate;\r
-    PacketLoss_perc     =            encControl->packetLossPercentage;\r
-    UseInBandFEC        =            encControl->useInBandFEC;\r
-    Complexity          =            encControl->complexity;\r
-    psEnc->sCmn.useDTX  =            encControl->useDTX;\r
-       psEnc->sCmn.useCBR  =                    encControl->useCBR;\r
-\r
-    /* Save values in state */\r
-    psEnc->sCmn.API_fs_Hz          = API_fs_Hz;\r
-    psEnc->sCmn.maxInternal_fs_kHz = max_internal_fs_kHz;\r
-    psEnc->sCmn.minInternal_fs_kHz = min_internal_fs_kHz;\r
-    psEnc->sCmn.useInBandFEC       = UseInBandFEC;\r
-\r
-    TargetRate_bps = SKP_LIMIT( TargetRate_bps, MIN_TARGET_RATE_BPS, MAX_TARGET_RATE_BPS );\r
-    if( ( ret = SKP_Silk_control_encoder_Fxx( psEnc, PacketSize_ms, TargetRate_bps, \r
-                        PacketLoss_perc, Complexity) ) != 0 ) {\r
-        SKP_assert( 0 );\r
-        return( ret );\r
-    }\r
-\r
-    encControl->internalSampleRate = SKP_SMULBB( psEnc->sCmn.fs_kHz, 1000 );\r
-    \r
-    return ret;\r
-}\r
+/* Encoder Super Struct */\r
+typedef struct {\r
+    SKP_Silk_encoder_state_Fxx          state_Fxx[ ENCODER_NUM_CHANNELS ];\r
+    stereo_state                        sStereo;\r
+    SKP_int32                           nBitsExceeded;\r
+    SKP_int                             nChannels;\r
+} SKP_Silk_encoder;\r
 \r
 /****************************************/\r
 /* Encoder functions                    */\r
@@ -123,7 +57,7 @@ SKP_int SKP_Silk_SDK_Get_Encoder_Size( SKP_int32 *encSizeBytes )
 {\r
     SKP_int ret = SKP_SILK_NO_ERROR;\r
     \r
-    *encSizeBytes = sizeof( SKP_Silk_encoder_state_Fxx );\r
+    *encSizeBytes = sizeof( SKP_Silk_encoder );\r
     \r
     return ret;\r
 }\r
@@ -133,26 +67,30 @@ SKP_int SKP_Silk_SDK_Get_Encoder_Size( SKP_int32 *encSizeBytes )
 /*************************/\r
 SKP_int SKP_Silk_SDK_InitEncoder(\r
     void                            *encState,          /* I/O: State                                           */\r
-    SKP_Silk_EncodeControlStruct    *encStatus          /* O:   Control structure                               */\r
+    SKP_SILK_SDK_EncControlStruct   *encStatus          /* O:   Control structure                               */\r
 )\r
 {\r
-    SKP_Silk_encoder_state_Fxx *psEnc;\r
-    SKP_int ret = SKP_SILK_NO_ERROR;\r
-\r
-        \r
-    psEnc = ( SKP_Silk_encoder_state_Fxx* )encState;\r
+    SKP_Silk_encoder *psEnc;\r
+    SKP_int n, ret = SKP_SILK_NO_ERROR;\r
 \r
-    /* Reset Encoder */\r
-    if( ret += SKP_Silk_init_encoder_Fxx( psEnc ) ) {\r
-        SKP_assert( 0 );\r
+    psEnc = (SKP_Silk_encoder *)encState;\r
+    \r
+    /* Reset encoder */\r
+    for( n = 0; n < ENCODER_NUM_CHANNELS; n++ ) {\r
+        if( ret += SKP_Silk_init_encoder( &psEnc->state_Fxx[ n ] ) ) {\r
+            SKP_assert( 0 );\r
+        }\r
     }\r
+    SKP_memset( &psEnc->sStereo, 0, sizeof( psEnc->sStereo ) );\r
+\r
+    psEnc->nBitsExceeded = 0;\r
+    psEnc->nChannels = 1;\r
 \r
     /* Read control structure */\r
     if( ret += SKP_Silk_SDK_QueryEncoder( encState, encStatus ) ) {\r
         SKP_assert( 0 );\r
     }\r
 \r
-\r
     return ret;\r
 }\r
 \r
@@ -161,25 +99,26 @@ SKP_int SKP_Silk_SDK_InitEncoder(
 /***************************************/\r
 SKP_int SKP_Silk_SDK_QueryEncoder(\r
     const void *encState,                       /* I:   State Vector                                    */\r
-    SKP_Silk_EncodeControlStruct *encStatus     /* O:   Control Structure                               */\r
+    SKP_SILK_SDK_EncControlStruct *encStatus    /* O:   Control Structure                               */\r
 )\r
 {\r
-    SKP_Silk_encoder_state_Fxx *psEnc;\r
+    SKP_Silk_encoder_state_Fxx *state_Fxx;\r
     SKP_int ret = SKP_SILK_NO_ERROR;\r
 \r
-    psEnc = ( SKP_Silk_encoder_state_Fxx* )encState;\r
-\r
-    encStatus->API_sampleRate        = psEnc->sCmn.API_fs_Hz;\r
-    encStatus->maxInternalSampleRate = SKP_SMULBB( psEnc->sCmn.maxInternal_fs_kHz, 1000 );\r
-    encStatus->minInternalSampleRate = SKP_SMULBB( psEnc->sCmn.minInternal_fs_kHz, 1000 );\r
-    encStatus->payloadSize_ms        = psEnc->sCmn.PacketSize_ms;\r
-    encStatus->bitRate               = psEnc->sCmn.TargetRate_bps;\r
-    encStatus->packetLossPercentage  = psEnc->sCmn.PacketLoss_perc;\r
-    encStatus->complexity            = psEnc->sCmn.Complexity;\r
-    encStatus->useInBandFEC          = psEnc->sCmn.useInBandFEC;\r
-    encStatus->useDTX                = psEnc->sCmn.useDTX;\r
-    encStatus->useCBR                = psEnc->sCmn.useCBR;\r
-    encStatus->internalSampleRate    = SKP_SMULBB( psEnc->sCmn.fs_kHz, 1000 );\r
+    state_Fxx = ((SKP_Silk_encoder *)encState)->state_Fxx;\r
+\r
+    encStatus->API_sampleRate        = state_Fxx->sCmn.API_fs_Hz;\r
+    encStatus->maxInternalSampleRate = state_Fxx->sCmn.maxInternal_fs_Hz;\r
+    encStatus->minInternalSampleRate = state_Fxx->sCmn.minInternal_fs_Hz;\r
+    encStatus->payloadSize_ms        = state_Fxx->sCmn.PacketSize_ms;\r
+    encStatus->bitRate               = state_Fxx->sCmn.TargetRate_bps;\r
+    encStatus->packetLossPercentage  = state_Fxx->sCmn.PacketLoss_perc;\r
+    encStatus->complexity            = state_Fxx->sCmn.Complexity;\r
+    encStatus->useInBandFEC          = state_Fxx->sCmn.useInBandFEC;\r
+    encStatus->useDTX                = state_Fxx->sCmn.useDTX;\r
+    encStatus->useCBR                = state_Fxx->sCmn.useCBR;\r
+    encStatus->internalSampleRate    = SKP_SMULBB( state_Fxx->sCmn.fs_kHz, 1000 );\r
+\r
     return ret;\r
 }\r
 \r
@@ -188,81 +127,219 @@ SKP_int SKP_Silk_SDK_QueryEncoder(
 /**************************/\r
 SKP_int SKP_Silk_SDK_Encode( \r
     void                                *encState,      /* I/O: State                                           */\r
-    SKP_Silk_EncodeControlStruct        *encControl,    /* I:   Control structure                               */\r
+    SKP_SILK_SDK_EncControlStruct       *encControl,    /* I:   Control structure                               */\r
     const SKP_int16                     *samplesIn,     /* I:   Speech sample input vector                      */\r
     SKP_int                             nSamplesIn,     /* I:   Number of samples in input vector               */\r
     ec_enc                              *psRangeEnc,    /* I/O  Compressor data structure                       */\r
     SKP_int32                           *nBytesOut,     /* I/O: Number of bytes in payload (input: Max bytes)   */\r
-    const SKP_int                       prefillFlag     /* I:   Flag to indicate prefilling buffers no coding   */\r
+    const SKP_int                       prefillFlag     /* I:   Flag to indicate prefilling buffers; no coding  */\r
 )\r
 {\r
-    SKP_int   tmp_payloadSize_ms, tmp_complexity, ret = 0;\r
+    SKP_int   n, i, nBits, flags, tmp_payloadSize_ms, tmp_complexity, MS_predictorIx = 0, ret = 0;\r
     SKP_int   nSamplesToBuffer, nBlocksOf10ms, nSamplesFromInput = 0;\r
-    SKP_Silk_encoder_state_Fxx *psEnc = ( SKP_Silk_encoder_state_Fxx* )encState;\r
+    SKP_int32 TargetRate_bps, channelRate_bps, LBRR_symbol;\r
+    SKP_Silk_encoder *psEnc = ( SKP_Silk_encoder * )encState;\r
+    SKP_int16 buf[ MAX_FRAME_LENGTH_MS * MAX_API_FS_KHZ ];\r
 \r
-    ret = process_enc_control_struct( psEnc, encControl );\r
+    /* Check values in encoder control structure */\r
+    if( ( ret = check_control_input( encControl ) != 0 ) ) {\r
+        SKP_assert( 0 );\r
+        return ret;\r
+    }\r
 \r
-    nBlocksOf10ms = SKP_DIV32( 100 * nSamplesIn, psEnc->sCmn.API_fs_Hz );\r
+    if( encControl->nChannels > psEnc->nChannels ) {\r
+        /* Mono -> Stereo transition: init state of second channel and stereo state */\r
+        SKP_memset( &psEnc->sStereo, 0, sizeof( psEnc->sStereo ) );\r
+        ret += SKP_Silk_init_encoder( &psEnc->state_Fxx[ 1 ] );\r
+    }\r
+    psEnc->nChannels = encControl->nChannels;\r
+\r
+    nBlocksOf10ms = SKP_DIV32( 100 * nSamplesIn, encControl->API_sampleRate );\r
     if( prefillFlag ) {\r
         /* Only accept input length of 10 ms */\r
         if( nBlocksOf10ms != 1 ) {\r
             ret = SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES;\r
             SKP_assert( 0 );\r
-            return( ret );\r
+            return ret;\r
         }\r
         /* Reset Encoder */\r
-        if( ret = SKP_Silk_init_encoder_Fxx( psEnc ) ) {\r
-            SKP_assert( 0 );\r
+        for( n = 0; n < encControl->nChannels; n++ ) {\r
+            if( ret = SKP_Silk_init_encoder( &psEnc->state_Fxx[ n ] ) ) {\r
+                SKP_assert( 0 );\r
+            }\r
         }\r
         tmp_payloadSize_ms = encControl->payloadSize_ms;\r
         encControl->payloadSize_ms = 10;\r
         tmp_complexity = encControl->complexity;\r
         encControl->complexity = 0;\r
-        ret = process_enc_control_struct( psEnc, encControl );\r
-        psEnc->sCmn.prefillFlag = 1;\r
+        for( n = 0; n < encControl->nChannels; n++ ) {\r
+            psEnc->state_Fxx[ n ].sCmn.controlled_since_last_payload = 0;\r
+            psEnc->state_Fxx[ n ].sCmn.prefillFlag = 1;\r
+        }\r
     } else {\r
         /* Only accept input lengths that are a multiple of 10 ms */\r
-        if( nBlocksOf10ms * psEnc->sCmn.API_fs_Hz != 100 * nSamplesIn || nSamplesIn < 0 ) {\r
+        if( nBlocksOf10ms * encControl->API_sampleRate != 100 * nSamplesIn || nSamplesIn < 0 ) {\r
             ret = SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES;\r
             SKP_assert( 0 );\r
-            return( ret );\r
+            return ret;\r
         }\r
         /* Make sure no more than one packet can be produced */\r
-        if( 1000 * (SKP_int32)nSamplesIn > psEnc->sCmn.PacketSize_ms * psEnc->sCmn.API_fs_Hz ) {\r
+        if( 1000 * (SKP_int32)nSamplesIn > encControl->payloadSize_ms * encControl->API_sampleRate ) {\r
             ret = SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES;\r
             SKP_assert( 0 );\r
-            return( ret );\r
+            return ret;\r
+        }\r
+    }\r
+\r
+    TargetRate_bps = SKP_RSHIFT32( encControl->bitRate, encControl->nChannels - 1 );\r
+    for( n = 0; n < encControl->nChannels; n++ ) {\r
+        if( ( ret = SKP_Silk_control_encoder( &psEnc->state_Fxx[ n ], encControl, TargetRate_bps ) ) != 0 ) {\r
+            SKP_assert( 0 );\r
+            return ret;\r
         }\r
     }\r
+    SKP_assert( encControl->nChannels == 1 || psEnc->state_Fxx[ 0 ].sCmn.fs_kHz == psEnc->state_Fxx[ 1 ].sCmn.fs_kHz );\r
 \r
     /* Input buffering/resampling and encoding */\r
     while( 1 ) {\r
-        nSamplesToBuffer = psEnc->sCmn.frame_length - psEnc->sCmn.inputBufIx;\r
-        if( psEnc->sCmn.API_fs_Hz == SKP_SMULBB( 1000, psEnc->sCmn.fs_kHz ) ) { \r
-            nSamplesToBuffer  = SKP_min_int( nSamplesToBuffer, nSamplesIn );\r
-            nSamplesFromInput = nSamplesToBuffer;\r
-            /* Copy to buffer */\r
-            SKP_memcpy( &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], samplesIn, nSamplesFromInput * sizeof( SKP_int16 ) );\r
-        } else {  \r
-            nSamplesToBuffer  = SKP_min( nSamplesToBuffer, 10 * nBlocksOf10ms * psEnc->sCmn.fs_kHz );\r
-            nSamplesFromInput = SKP_DIV32_16( nSamplesToBuffer * psEnc->sCmn.API_fs_Hz, psEnc->sCmn.fs_kHz * 1000 );\r
-            /* Resample and write to buffer */\r
-            ret += SKP_Silk_resampler( &psEnc->sCmn.resampler_state, &psEnc->sCmn.inputBuf[ psEnc->sCmn.inputBufIx ], samplesIn, nSamplesFromInput );\r
-        } \r
-        samplesIn              += nSamplesFromInput;\r
-        nSamplesIn             -= nSamplesFromInput;\r
-        psEnc->sCmn.inputBufIx += nSamplesToBuffer;\r
+        nSamplesToBuffer  = psEnc->state_Fxx[ 0 ].sCmn.frame_length - psEnc->state_Fxx[ 0 ].sCmn.inputBufIx;\r
+        nSamplesToBuffer  = SKP_min( nSamplesToBuffer, 10 * nBlocksOf10ms * psEnc->state_Fxx[ 0 ].sCmn.fs_kHz );\r
+        nSamplesFromInput = SKP_DIV32_16( nSamplesToBuffer * psEnc->state_Fxx[ 0 ].sCmn.API_fs_Hz, psEnc->state_Fxx[ 0 ].sCmn.fs_kHz * 1000 );\r
+        /* Resample and write to buffer */\r
+        if( encControl->nChannels == 2 ) {\r
+            for( n = 0; n < nSamplesFromInput; n++ ) {\r
+                buf[ n ] = samplesIn[ 2 * n ];\r
+            }\r
+            ret += SKP_Silk_resampler( &psEnc->state_Fxx[ 0 ].sCmn.resampler_state, \r
+                &psEnc->state_Fxx[ 0 ].sCmn.inputBuf[ psEnc->state_Fxx[ 0 ].sCmn.inputBufIx ], buf, nSamplesFromInput );\r
+            psEnc->state_Fxx[ 0 ].sCmn.inputBufIx += nSamplesToBuffer;\r
 \r
-        /* Silk encoder */\r
-        if( psEnc->sCmn.inputBufIx >= psEnc->sCmn.frame_length ) {\r
-            SKP_assert( psEnc->sCmn.inputBufIx == psEnc->sCmn.frame_length );\r
+            nSamplesToBuffer  = psEnc->state_Fxx[ 1 ].sCmn.frame_length - psEnc->state_Fxx[ 1 ].sCmn.inputBufIx;\r
+            nSamplesToBuffer  = SKP_min( nSamplesToBuffer, 10 * nBlocksOf10ms * psEnc->state_Fxx[ 1 ].sCmn.fs_kHz );\r
+            for( n = 0; n < nSamplesFromInput; n++ ) {\r
+                buf[ n ] = samplesIn[ 2 * n + 1 ];\r
+            }\r
+            ret += SKP_Silk_resampler( &psEnc->state_Fxx[ 1 ].sCmn.resampler_state, \r
+                &psEnc->state_Fxx[ 1 ].sCmn.inputBuf[ psEnc->state_Fxx[ 1 ].sCmn.inputBufIx ], buf, nSamplesFromInput );\r
+            psEnc->state_Fxx[ 1 ].sCmn.inputBufIx += nSamplesToBuffer;\r
+        } else {\r
+            SKP_assert( encControl->nChannels == 1 );\r
+            ret += SKP_Silk_resampler( &psEnc->state_Fxx[ 0 ].sCmn.resampler_state, \r
+                &psEnc->state_Fxx[ 0 ].sCmn.inputBuf[ psEnc->state_Fxx[ 0 ].sCmn.inputBufIx ], samplesIn, nSamplesFromInput );\r
+            psEnc->state_Fxx[ 0 ].sCmn.inputBufIx += nSamplesToBuffer;\r
+        }\r
+        samplesIn  += nSamplesFromInput * encControl->nChannels;\r
+        nSamplesIn -= nSamplesFromInput;\r
 \r
+        /* Silk encoder */\r
+        if( psEnc->state_Fxx[ 0 ].sCmn.inputBufIx >= psEnc->state_Fxx[ 0 ].sCmn.frame_length ) {\r
             /* Enough data in input buffer, so encode */\r
-            if( ( ret = SKP_Silk_encode_frame_Fxx( psEnc, nBytesOut, psRangeEnc ) ) != 0 ) {\r
-                SKP_assert( 0 );\r
+            SKP_assert( psEnc->state_Fxx[ 0 ].sCmn.inputBufIx == psEnc->state_Fxx[ 0 ].sCmn.frame_length );\r
+            SKP_assert( encControl->nChannels == 1 || psEnc->state_Fxx[ 1 ].sCmn.inputBufIx == psEnc->state_Fxx[ 1 ].sCmn.frame_length );\r
+\r
+            /* Deal with LBRR data */\r
+            if( psEnc->state_Fxx[ 0 ].sCmn.nFramesAnalyzed == 0 && !prefillFlag ) {\r
+                /* Create space at start of payload for VAD and FEC flags */\r
+                SKP_uint8 iCDF[ 2 ] = { 0, 0 };\r
+                iCDF[ 0 ] = 256 - SKP_RSHIFT( 256, ( psEnc->state_Fxx[ 0 ].sCmn.nFramesPerPacket + 1 ) * encControl->nChannels );\r
+                ec_enc_icdf( psRangeEnc, 0, iCDF, 8 );\r
+\r
+                /* Encode any LBRR data from previous packet */\r
+                /* Encode LBRR flags */\r
+                for( n = 0; n < encControl->nChannels; n++ ) {\r
+                    LBRR_symbol = 0;\r
+                    for( i = 0; i < psEnc->state_Fxx[ n ].sCmn.nFramesPerPacket; i++ ) {\r
+                        LBRR_symbol |= SKP_LSHIFT( psEnc->state_Fxx[ n ].sCmn.LBRR_flags[ i ], i );\r
+                    }\r
+                    psEnc->state_Fxx[ n ].sCmn.LBRR_flag = LBRR_symbol > 0 ? 1 : 0;\r
+                    if( LBRR_symbol && psEnc->state_Fxx[ n ].sCmn.nFramesPerPacket > 1 ) {\r
+                        ec_enc_icdf( psRangeEnc, LBRR_symbol - 1, SKP_Silk_LBRR_flags_iCDF_ptr[ psEnc->state_Fxx[ n ].sCmn.nFramesPerPacket - 2 ], 8 );\r
+                    }\r
+                }\r
+\r
+                /* Code LBRR indices and excitation signals */\r
+                for( i = 0; i < psEnc->state_Fxx[ 0 ].sCmn.nFramesPerPacket; i++ ) {\r
+                    for( n = 0; n < encControl->nChannels; n++ ) {                \r
+                        if( psEnc->state_Fxx[ n ].sCmn.LBRR_flags[ i ] ) {\r
+                            SKP_Silk_encode_indices( &psEnc->state_Fxx[ n ].sCmn, psRangeEnc, i, 1 );\r
+                            SKP_Silk_encode_pulses( psRangeEnc, psEnc->state_Fxx[ n ].sCmn.indices_LBRR[i].signalType, psEnc->state_Fxx[ n ].sCmn.indices_LBRR[i].quantOffsetType, \r
+                                psEnc->state_Fxx[ n ].sCmn.pulses_LBRR[ i ], psEnc->state_Fxx[ n ].sCmn.frame_length );\r
+                        }\r
+                    }\r
+                }\r
+\r
+                /* Reset LBRR flags */\r
+                for( n = 0; n < encControl->nChannels; n++ ) {                \r
+                    SKP_memset( psEnc->state_Fxx[ n ].sCmn.LBRR_flags, 0, sizeof( psEnc->state_Fxx[ n ].sCmn.LBRR_flags ) );\r
+                }\r
+            }\r
+\r
+            /* Convert Left/Right to Mid/Side */\r
+            if( encControl->nChannels == 2 ) {\r
+                SKP_Silk_stereo_LR_to_MS( &psEnc->sStereo, psEnc->state_Fxx[ 0 ].sCmn.inputBuf, psEnc->state_Fxx[ 1 ].sCmn.inputBuf, \r
+                    &MS_predictorIx, psEnc->state_Fxx[ 0 ].sCmn.fs_kHz, psEnc->state_Fxx[ 0 ].sCmn.frame_length );\r
+                ec_enc_icdf( psRangeEnc, MS_predictorIx, SKP_Silk_stereo_predictor_iCDF, 8 );\r
+            }\r
+\r
+\r
+            /* Total target bits for packet */\r
+            nBits = SKP_DIV32_16( SKP_MUL( encControl->bitRate, encControl->payloadSize_ms ), 1000 );\r
+            /* Subtract bits already used */\r
+            nBits -= ec_tell( psRangeEnc );\r
+            /* Divide by number of uncoded frames left in packet */\r
+            nBits = SKP_DIV32_16( nBits, psEnc->state_Fxx[ 0 ].sCmn.nFramesPerPacket - psEnc->state_Fxx[ 0 ].sCmn.nFramesAnalyzed );\r
+            /* Convert to bits/second */\r
+            if( encControl->payloadSize_ms == 10 ) {\r
+                TargetRate_bps = SKP_SMULBB( nBits, 100 );\r
+            } else {\r
+                TargetRate_bps = SKP_SMULBB( nBits, 50 );\r
+            }\r
+            /* Subtract fraction of bits in excess of target in previous packets */\r
+            TargetRate_bps -= SKP_DIV32_16( SKP_MUL( psEnc->nBitsExceeded, 1000 ), BITRESERVOIR_DECAY_TIME_MS );\r
+            /* Don't exceed input bitrate */\r
+            TargetRate_bps = SKP_min( TargetRate_bps, encControl->bitRate );\r
+\r
+            /* Encode */\r
+            for( n = 0; n < encControl->nChannels; n++ ) {\r
+                /* For stereo coding, allocate 60% of the bitrate to mid and 40% to side */\r
+                if( encControl->nChannels == 1 ) {\r
+                    channelRate_bps = TargetRate_bps;\r
+                } else if( n == 0 ) {\r
+                    channelRate_bps = SKP_SMULWW( TargetRate_bps, SKP_FIX_CONST( 0.6, 16 ) );\r
+                } else {\r
+                    channelRate_bps = SKP_SMULWB( TargetRate_bps, SKP_FIX_CONST( 0.4, 16 ) );\r
+                }\r
+                SKP_Silk_control_SNR( &psEnc->state_Fxx[ n ].sCmn, channelRate_bps );\r
+                //SKP_Silk_control_SNR( &psEnc->state_Fxx[ n ].sCmn, TargetRate_bps / 2 );\r
+                if( ( ret = SKP_Silk_encode_frame_Fxx( &psEnc->state_Fxx[ n ], nBytesOut, psRangeEnc ) ) != 0 ) {\r
+                    SKP_assert( 0 );\r
+                }\r
+                psEnc->state_Fxx[ n ].sCmn.controlled_since_last_payload = 0;\r
+                psEnc->state_Fxx[ n ].sCmn.inputBufIx = 0;\r
+            }\r
+\r
+            /* Insert VAD and FEC flags at beginning of bitstream */\r
+            if( *nBytesOut > 0 ) {\r
+                flags = 0;\r
+                for( n = 0; n < encControl->nChannels; n++ ) {\r
+                    for( i = 0; i < psEnc->state_Fxx[ n ].sCmn.nFramesPerPacket; i++ ) {\r
+                        flags  = SKP_LSHIFT( flags, 1 );\r
+                        flags |= psEnc->state_Fxx[ n ].sCmn.VAD_flags[ i ];\r
+                    }\r
+                    flags  = SKP_LSHIFT( flags, 1 );\r
+                    flags |= psEnc->state_Fxx[ n ].sCmn.LBRR_flag;\r
+                }\r
+                ec_enc_patch_initial_bits( psRangeEnc, flags, ( psEnc->state_Fxx[ 0 ].sCmn.nFramesPerPacket + 1 ) * encControl->nChannels );\r
+\r
+                /* Return zero bytes if DTXed */\r
+                if( psEnc->state_Fxx[ 0 ].sCmn.inDTX && ( encControl->nChannels == 1 || psEnc->state_Fxx[ 1 ].sCmn.inDTX ) ) {\r
+                    *nBytesOut = 0;\r
+                }\r
+\r
+                psEnc->nBitsExceeded += *nBytesOut * 8;\r
+                psEnc->nBitsExceeded -= SKP_DIV32_16( SKP_MUL( encControl->bitRate, encControl->payloadSize_ms ), 1000 );\r
+                psEnc->nBitsExceeded  = SKP_LIMIT( psEnc->nBitsExceeded, 0, 10000 );\r
             }\r
-            psEnc->sCmn.inputBufIx = 0;\r
-            psEnc->sCmn.controlled_since_last_payload = 0;\r
 \r
             if( nSamplesIn == 0 ) {\r
                 break;\r
@@ -272,11 +349,14 @@ SKP_int SKP_Silk_SDK_Encode(
         }\r
     }\r
 \r
+    encControl->internalSampleRate = SKP_SMULBB( psEnc->state_Fxx[ 0 ].sCmn.fs_kHz, 1000 );\r
     if( prefillFlag ) {\r
         encControl->payloadSize_ms = tmp_payloadSize_ms;\r
         encControl->complexity = tmp_complexity;\r
-        ret = process_enc_control_struct( psEnc, encControl );\r
-        psEnc->sCmn.prefillFlag = 0;\r
+        for( n = 0; n < encControl->nChannels; n++ ) {\r
+            psEnc->state_Fxx[ n ].sCmn.controlled_since_last_payload = 0;\r
+            psEnc->state_Fxx[ n ].sCmn.prefillFlag = 0;\r
+        }\r
     }\r
 \r
     return ret;\r
index 8962095..71fc766 100644 (file)
@@ -27,9 +27,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 \r
 #include "SKP_Silk_main.h"\r
 \r
-/*******************************************/\r
-/* Encode parameters to create the payload */\r
-/*******************************************/\r
+/* Encode side-information parameters to payload */\r
 void SKP_Silk_encode_indices(\r
     SKP_Silk_encoder_state      *psEncC,            /* I/O  Encoder state                               */\r
     ec_enc                      *psRangeEnc,        /* I/O  Compressor data structure                   */\r
@@ -47,6 +45,7 @@ void SKP_Silk_encode_indices(
     SKP_int nBytes_after, nBytes_before;\r
 #endif\r
 \r
+    /* Use conditional coding if previous frame available */\r
     if( FrameIndex > 0 && ( encode_LBRR == 0 || psEncC->LBRR_flags[ FrameIndex - 1 ] == 1 ) ) {\r
         condCoding = 1;\r
     } else {\r
similarity index 85%
rename from src_FIX/SKP_Silk_init_encoder_FIX.c
rename to src_common/SKP_Silk_init_encoder.c
index 601414b..7f2b7c3 100644 (file)
@@ -25,17 +25,24 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
 ***********************************************************************/\r
 \r
+#if FIXED_POINT\r
 #include "SKP_Silk_main_FIX.h"\r
+#define SKP_Silk_encoder_state_Fxx      SKP_Silk_encoder_state_FIX\r
+#else\r
+#include "SKP_Silk_main_FLP.h"\r
+#define SKP_Silk_encoder_state_Fxx      SKP_Silk_encoder_state_FLP\r
+#endif\r
 \r
 /*********************************/\r
 /* Initialize Silk Encoder state */\r
 /*********************************/\r
-SKP_int SKP_Silk_init_encoder_FIX(\r
-    SKP_Silk_encoder_state_FIX  *psEnc          /* I/O  Pointer to Silk encoder state               */\r
+SKP_int SKP_Silk_init_encoder(\r
+    SKP_Silk_encoder_state_Fxx  *psEnc          /* I/O  Pointer to Silk encoder state               */\r
 ) {\r
     SKP_int ret = 0;\r
+\r
     /* Clear the entire encoder state */\r
-    SKP_memset( psEnc, 0, sizeof( SKP_Silk_encoder_state_FIX ) );\r
+    SKP_memset( psEnc, 0, sizeof( SKP_Silk_encoder_state_Fxx ) );\r
 \r
     psEnc->sCmn.variable_HP_smth1_Q15 = 200844; /* = SKP_Silk_log2(70)_Q0; */\r
     psEnc->sCmn.variable_HP_smth2_Q15 = 200844; /* = SKP_Silk_log2(70)_Q0; */\r
index 9f1eee4..f8de3ea 100644 (file)
@@ -38,6 +38,7 @@ extern "C"
 #include "SKP_Silk_structs.h"\r
 #include "SKP_Silk_tables.h"\r
 #include "SKP_Silk_PLC.h"\r
+#include "SKP_Silk_control.h"\r
 #include "SKP_debug.h"\r
 #include "entenc.h"\r
 #include "entdec.h"\r
@@ -49,6 +50,26 @@ extern "C"
 //#define FORCE_INTERNAL_FS_KHZ       16\r
 \r
 \r
+/* Convert Left/Right stereo signal to adaptive Mid/Side representation */\r
+void SKP_Silk_stereo_LR_to_MS( \r
+    stereo_state        *state,                         /* I/O  State                                       */\r
+    SKP_int16           x1[],                           /* I/O  Left input signal, becomes mid signal       */\r
+    SKP_int16           x2[],                           /* I/O  Right input signal, becomes side signal     */\r
+    SKP_int             *predictorIx,                   /* O    Index for predictor filter                  */\r
+    SKP_int             fs_kHz,                         /* I    Samples rate (kHz)                          */\r
+    SKP_int             frame_length                    /* I    Number of samples                           */\r
+);\r
+\r
+/* Convert adaptive Mid/Side representation to Left/Right stereo signal */\r
+void SKP_Silk_stereo_MS_to_LR( \r
+    stereo_state        *state,                         /* I/O  State                                       */\r
+    SKP_int16           x1[],                           /* I/O  Left input signal, becomes mid signal       */\r
+    SKP_int16           x2[],                           /* I/O  Right input signal, becomes side signal     */\r
+    SKP_int             predictorIx,                    /* I    Index for predictor filter                  */\r
+    SKP_int             fs_kHz,                         /* I    Samples rate (kHz)                          */\r
+    SKP_int             frame_length                    /* I    Number of samples                           */\r
+);\r
+\r
 /* Encodes signs of excitation */\r
 void SKP_Silk_encode_signs(\r
     ec_enc                      *psRangeEnc,                        /* I/O  Compressor data structure                   */\r
@@ -69,12 +90,23 @@ void SKP_Silk_decode_signs(
     const SKP_int               sum_pulses[ MAX_NB_SHELL_BLOCKS ]   /* I    Sum of absolute pulses per block            */\r
 );\r
 \r
+/* Check encoder control struct */\r
+SKP_int check_control_input( \r
+    SKP_SILK_SDK_EncControlStruct        *encControl     /* I:   Control structure                               */\r
+);\r
+\r
 /* Control internal sampling rate */\r
 SKP_int SKP_Silk_control_audio_bandwidth(\r
     SKP_Silk_encoder_state      *psEncC,            /* I/O  Pointer to Silk encoder state               */\r
     SKP_int32                   TargetRate_bps      /* I    Target max bitrate (bps)                    */\r
 );\r
 \r
+/* Control SNR of redidual quantizer */\r
+SKP_int SKP_Silk_control_SNR(\r
+    SKP_Silk_encoder_state      *psEncC,            /* I/O  Pointer to Silk encoder state               */\r
+    SKP_int32                   TargetRate_bps      /* I    Target max bitrate (bps)                    */\r
+);\r
+\r
 /***************/\r
 /* Shell coder */\r
 /***************/\r
@@ -226,7 +258,6 @@ void SKP_Silk_HP_variable_cutoff(
     const SKP_int                   frame_length    /* I    length of input                             */\r
 );\r
 \r
-#if SWITCH_TRANSITION_FILTERING\r
 /* Low-pass filter with variable cutoff frequency based on  */\r
 /* piece-wise linear interpolation between elliptic filters */\r
 /* Start by setting transition_frame_no = 1;                */\r
@@ -235,13 +266,6 @@ void SKP_Silk_LP_variable_cutoff(
     SKP_int16                   *signal,            /* I/O  Low-pass filtered output signal             */\r
     const SKP_int               frame_length        /* I    Frame length                                */\r
 );\r
-#endif\r
-\r
-/* Encode LBRR side info and excitation */\r
-void SKP_Silk_LBRR_embed(\r
-    SKP_Silk_encoder_state      *psEncC,            /* I/O  Encoder state                               */\r
-    ec_enc                      *psRangeEnc         /* I/O  Compressor data structure                   */\r
-);\r
 \r
 /******************/\r
 /* NLSF Quantizer */\r
@@ -333,7 +357,6 @@ SKP_int SKP_Silk_decode_frame(
     ec_dec                      *psRangeDec,        /* I/O  Compressor data structure                   */\r
     SKP_int16                   pOut[],             /* O    Pointer to output speech frame              */\r
     SKP_int32                   *pN,                /* O    Pointer to size of output frame             */\r
-    const SKP_int               nBytes,             /* I    Payload length                              */\r
     SKP_int                     lostFlag            /* I    0: no loss, 1 loss, 2 decode fec            */\r
 );\r
 \r
index 229709f..f4da024 100644 (file)
@@ -50,9 +50,13 @@ void SKP_Silk_process_NLSFs(
     /***********************/\r
     /* NLSF_mu  = 0.003 - 0.0015 * psEnc->speech_activity; */\r
     NLSF_mu_Q20 = SKP_SMLAWB( SKP_FIX_CONST( 0.003, 20 ), SKP_FIX_CONST( -0.0015, 28 ), psEncC->speech_activity_Q8 );\r
+    if( psEncC->nb_subfr == 2 ) {\r
+        /* Multiply by 1.5 for 10 ms packets */\r
+        NLSF_mu_Q20 = SKP_ADD_RSHIFT( NLSF_mu_Q20, NLSF_mu_Q20, 1 );\r
+    }\r
 \r
     SKP_assert( NLSF_mu_Q20 >  0 );\r
-    SKP_assert( NLSF_mu_Q20 <= SKP_FIX_CONST( 0.003, 20 ) );\r
+    SKP_assert( NLSF_mu_Q20 <= SKP_FIX_CONST( 0.0045, 20 ) );\r
 \r
     /* Calculate NLSF weights */\r
     SKP_Silk_NLSF_VQ_weights_laroia( pNLSFW_Q5, pNLSF_Q15, psEncC->predictLPCOrder );\r
diff --git a/src_common/SKP_Silk_setup.h b/src_common/SKP_Silk_setup.h
deleted file mode 100644 (file)
index 4017e23..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-/***********************************************************************\r
-Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
-Redistribution and use in source and binary forms, with or without \r
-modification, (subject to the limitations in the disclaimer below) \r
-are permitted provided that the following conditions are met:\r
-- Redistributions of source code must retain the above copyright notice,\r
-this list of conditions and the following disclaimer.\r
-- Redistributions in binary form must reproduce the above copyright \r
-notice, this list of conditions and the following disclaimer in the \r
-documentation and/or other materials provided with the distribution.\r
-- Neither the name of Skype Limited, nor the names of specific \r
-contributors, may be used to endorse or promote products derived from \r
-this software without specific prior written permission.\r
-NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
-BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
-CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
-FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
-COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
-USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-***********************************************************************/\r
-\r
-#include "SKP_Silk_main.h"\r
-#include "SKP_Silk_tuning_parameters.h"\r
-\r
-SKP_INLINE SKP_int SKP_Silk_setup_complexity(\r
-    SKP_Silk_encoder_state          *psEncC,            /* I/O                      */\r
-    SKP_int                         Complexity          /* I                        */\r
-)\r
-{\r
-    SKP_int ret = 0;\r
-\r
-    /* Set encoding complexity */\r
-    if( Complexity < 2 ) {\r
-        psEncC->pitchEstimationComplexity       = SKP_Silk_PE_MIN_COMPLEX;\r
-        psEncC->pitchEstimationThreshold_Q16    = SKP_FIX_CONST( 0.8, 16 );\r
-        psEncC->pitchEstimationLPCOrder         = 6;\r
-        psEncC->shapingLPCOrder                 = 8;\r
-        psEncC->la_shape                        = 3 * psEncC->fs_kHz;\r
-        psEncC->nStatesDelayedDecision          = 1;\r
-        psEncC->useInterpolatedNLSFs            = 0;\r
-        psEncC->LTPQuantLowComplexity           = 1;\r
-        psEncC->NLSF_MSVQ_Survivors             = 2;\r
-        psEncC->warping_Q16                     = 0;\r
-    } else if( Complexity < 4 ) {\r
-        psEncC->pitchEstimationComplexity       = SKP_Silk_PE_MID_COMPLEX;\r
-        psEncC->pitchEstimationThreshold_Q16    = SKP_FIX_CONST( 0.76, 16 );\r
-        psEncC->pitchEstimationLPCOrder         = 8;\r
-        psEncC->shapingLPCOrder                 = 10;\r
-        psEncC->la_shape                        = 5 * psEncC->fs_kHz;\r
-        psEncC->nStatesDelayedDecision          = 1;\r
-        psEncC->useInterpolatedNLSFs            = 1;\r
-        psEncC->LTPQuantLowComplexity           = 0;\r
-        psEncC->NLSF_MSVQ_Survivors             = 4;\r
-        psEncC->warping_Q16                     = 0;\r
-    } else if( Complexity < 6 ) {\r
-        psEncC->pitchEstimationComplexity       = SKP_Silk_PE_MID_COMPLEX;\r
-        psEncC->pitchEstimationThreshold_Q16    = SKP_FIX_CONST( 0.74, 16 );\r
-        psEncC->pitchEstimationLPCOrder         = 10;\r
-        psEncC->shapingLPCOrder                 = 12;\r
-        psEncC->la_shape                        = 5 * psEncC->fs_kHz;\r
-        psEncC->nStatesDelayedDecision          = 2;\r
-        psEncC->useInterpolatedNLSFs            = 0;\r
-        psEncC->LTPQuantLowComplexity           = 0;\r
-        psEncC->NLSF_MSVQ_Survivors             = 6;\r
-        psEncC->warping_Q16                     = psEncC->fs_kHz * SKP_FIX_CONST( WARPING_MULTIPLIER, 16 );\r
-    } else if( Complexity < 8 ) {\r
-        psEncC->pitchEstimationComplexity       = SKP_Silk_PE_MID_COMPLEX;\r
-        psEncC->pitchEstimationThreshold_Q16    = SKP_FIX_CONST( 0.72, 16 );\r
-        psEncC->pitchEstimationLPCOrder         = 12;\r
-        psEncC->shapingLPCOrder                 = 14;\r
-        psEncC->la_shape                        = 5 * psEncC->fs_kHz;\r
-        psEncC->nStatesDelayedDecision          = 3;\r
-        psEncC->useInterpolatedNLSFs            = 0;\r
-        psEncC->LTPQuantLowComplexity           = 0;\r
-        psEncC->NLSF_MSVQ_Survivors             = 8;\r
-        psEncC->warping_Q16                     = psEncC->fs_kHz * SKP_FIX_CONST( WARPING_MULTIPLIER, 16 );\r
-    } else if( Complexity <= 10 ) {\r
-        psEncC->pitchEstimationComplexity       = SKP_Silk_PE_MAX_COMPLEX;\r
-        psEncC->pitchEstimationThreshold_Q16    = SKP_FIX_CONST( 0.7, 16 );\r
-        psEncC->pitchEstimationLPCOrder         = 16;\r
-        psEncC->shapingLPCOrder                 = 16;\r
-        psEncC->la_shape                        = 5 * psEncC->fs_kHz;\r
-        psEncC->nStatesDelayedDecision          = MAX_DEL_DEC_STATES;\r
-        psEncC->useInterpolatedNLSFs            = 1;\r
-        psEncC->LTPQuantLowComplexity           = 0;\r
-        psEncC->NLSF_MSVQ_Survivors             = 16;\r
-        psEncC->warping_Q16                     = psEncC->fs_kHz * SKP_FIX_CONST( WARPING_MULTIPLIER, 16 );\r
-    } else {\r
-        ret = SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING;\r
-    }\r
-\r
-    /* Do not allow higher pitch estimation LPC order than predict LPC order */\r
-    psEncC->pitchEstimationLPCOrder = SKP_min_int( psEncC->pitchEstimationLPCOrder, psEncC->predictLPCOrder );\r
-    psEncC->shapeWinLength          = SUB_FRAME_LENGTH_MS * psEncC->fs_kHz + 2 * psEncC->la_shape;\r
-\r
-    SKP_assert( psEncC->pitchEstimationLPCOrder <= MAX_FIND_PITCH_LPC_ORDER );\r
-    SKP_assert( psEncC->shapingLPCOrder         <= MAX_SHAPE_LPC_ORDER      );\r
-    SKP_assert( psEncC->nStatesDelayedDecision  <= MAX_DEL_DEC_STATES       );\r
-    SKP_assert( psEncC->warping_Q16             <= 32767                    );\r
-    SKP_assert( psEncC->la_shape                <= LA_SHAPE_MAX             );\r
-    SKP_assert( psEncC->shapeWinLength          <= SHAPE_LPC_WIN_MAX        );\r
-    SKP_assert( psEncC->NLSF_MSVQ_Survivors     <= NLSF_VQ_MAX_SURVIVORS    );\r
-\r
-    return( ret );\r
-}\r
-\r
-SKP_INLINE SKP_int SKP_Silk_setup_LBRR(\r
-    SKP_Silk_encoder_state          *psEncC            /* I/O                      */\r
-)\r
-{\r
-    SKP_int   ret = SKP_SILK_NO_ERROR;\r
-    SKP_int32 LBRRRate_thres_bps;\r
-\r
-    if( psEncC->useInBandFEC < 0 || psEncC->useInBandFEC > 1 ) {\r
-        ret = SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING;\r
-    }\r
-    \r
-    if( psEncC->fs_kHz == 8 ) {\r
-        LBRRRate_thres_bps = LBRR_NB_MIN_RATE_BPS;\r
-    } else if( psEncC->fs_kHz == 12 ) {\r
-        LBRRRate_thres_bps = LBRR_MB_MIN_RATE_BPS;\r
-    } else if( psEncC->fs_kHz == 16 ) {\r
-        LBRRRate_thres_bps = LBRR_WB_MIN_RATE_BPS;\r
-    } else {\r
-        SKP_assert( 0 );\r
-    }\r
-\r
-    LBRRRate_thres_bps = SKP_RSHIFT( SKP_SMULBB( LBRRRate_thres_bps, 7 - psEncC->PacketLoss_perc ), 2 );\r
-    if( psEncC->useInBandFEC && psEncC->TargetRate_bps >= LBRRRate_thres_bps && psEncC->PacketLoss_perc > 0 ) {\r
-        /* Set gain increase / rate reduction for LBRR usage */\r
-        psEncC->LBRR_GainIncreases = SKP_max_int( 6 - SKP_SMULWB( psEncC->PacketLoss_perc, SKP_FIX_CONST( 0.4, 16 ) ), 2 );\r
-        psEncC->LBRR_enabled = 1;\r
-    } else {\r
-        psEncC->LBRR_enabled = 0;\r
-    }\r
-    return ret;\r
-}\r
diff --git a/src_common/SKP_Silk_stereo_LR_to_MS.c b/src_common/SKP_Silk_stereo_LR_to_MS.c
new file mode 100644 (file)
index 0000000..e4a60ae
--- /dev/null
@@ -0,0 +1,94 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+#include "SKP_Silk_main.h"\r
+\r
+/* Convert Left/Right stereo signal to adaptive Mid/Side representation */\r
+void SKP_Silk_stereo_LR_to_MS( \r
+    stereo_state        *state,                         /* I/O  State                                       */\r
+    SKP_int16           x1[],                           /* I/O  Left input signal, becomes mid signal       */\r
+    SKP_int16           x2[],                           /* I/O  Right input signal, becomes side signal     */\r
+    SKP_int             *predictorIx,                   /* O    Index for predictor filter                  */\r
+    SKP_int             fs_kHz,                         /* I    Samples rate (kHz)                          */\r
+    SKP_int             frame_length                    /* I    Number of samples                           */\r
+)\r
+{\r
+    SKP_int   n, scale, scale1, scale2;\r
+    SKP_int32 sum, diff, nrg1, nrg2, corr, predictor_Q16, pred_Q16, delta_Q16;\r
+\r
+    /* Convert to basic mid/side signals */\r
+    for( n = 0; n < frame_length; n++ ) {\r
+        sum  = x1[ n ] + (SKP_int32)x2[ n ];\r
+        diff = x1[ n ] - (SKP_int32)x2[ n ];\r
+        x1[ n ] = (SKP_int16)SKP_RSHIFT32( sum + 1,  1 );\r
+        x2[ n ] = (SKP_int16)SKP_RSHIFT32( diff, 1 );\r
+    }\r
+\r
+    /* Find  predictor */\r
+    SKP_Silk_sum_sqr_shift( &nrg1, &scale1, x1, frame_length );\r
+    SKP_Silk_sum_sqr_shift( &nrg2, &scale2, x2, frame_length );\r
+    if( scale1 > scale2 ) {\r
+        scale = scale1;\r
+    } else {\r
+        scale = scale2;\r
+        nrg1 = SKP_RSHIFT32( nrg1, scale2 - scale1 );\r
+    }\r
+    corr = SKP_Silk_inner_prod_aligned_scale( x1, x2, scale, frame_length );\r
+    predictor_Q16 = SKP_DIV32_varQ( corr, nrg1 + 1, 16 );\r
+\r
+    /* Hysteresis */\r
+    if( predictor_Q16 > state->predictor_prev_Q16 ) {\r
+        predictor_Q16 -= SKP_FIX_CONST( STEREO_QUANT_HYSTERESIS / STEREO_QUANT_STEPS, 16 );\r
+    } else {\r
+        predictor_Q16 += SKP_FIX_CONST( STEREO_QUANT_HYSTERESIS / STEREO_QUANT_STEPS, 16 );\r
+    }\r
+\r
+    /* Quantize */\r
+    *predictorIx = SKP_RSHIFT_ROUND( SKP_MUL( predictor_Q16 + 65536, STEREO_QUANT_STEPS - 1 ), 17 );\r
+    *predictorIx = SKP_LIMIT( *predictorIx, 0, STEREO_QUANT_STEPS - 1 );\r
+\r
+    predictor_Q16 = SKP_SMLABB( -65536, *predictorIx, ( 1 << 17 ) / ( STEREO_QUANT_STEPS - 1 ) );\r
+\r
+    /* Subtract prediction from side channel */\r
+    if( predictor_Q16 != state->predictor_prev_Q16 ) {\r
+        /* Interpolate predictor */\r
+        pred_Q16 = -state->predictor_prev_Q16;\r
+        delta_Q16 = -SKP_DIV32_16( predictor_Q16 - state->predictor_prev_Q16, STEREO_INTERPOL_LENGTH_MS * fs_kHz );\r
+        for( n = 0; n < STEREO_INTERPOL_LENGTH_MS * fs_kHz; n++ ) {\r
+            pred_Q16 += delta_Q16;\r
+            x2[ n ] = (SKP_int16)SKP_SAT16( SKP_SMLAWB( x2[ n ], pred_Q16, x1[ n ] ) );\r
+        }\r
+    } else {\r
+        n = 0;\r
+    }\r
+    pred_Q16 = -predictor_Q16;\r
+    for( ; n < frame_length; n++ ) {\r
+        x2[ n ] = (SKP_int16)SKP_SAT16( SKP_SMLAWB( x2[ n ], pred_Q16, x1[ n ] ) );\r
+    }\r
+\r
+    state->predictor_prev_Q16 = predictor_Q16;\r
+}\r
diff --git a/src_common/SKP_Silk_stereo_MS_to_LR.c b/src_common/SKP_Silk_stereo_MS_to_LR.c
new file mode 100644 (file)
index 0000000..ad3ed14
--- /dev/null
@@ -0,0 +1,72 @@
+/***********************************************************************\r
+Copyright (c) 2006-2011, Skype Limited. All rights reserved. \r
+Redistribution and use in source and binary forms, with or without \r
+modification, (subject to the limitations in the disclaimer below) \r
+are permitted provided that the following conditions are met:\r
+- Redistributions of source code must retain the above copyright notice,\r
+this list of conditions and the following disclaimer.\r
+- Redistributions in binary form must reproduce the above copyright \r
+notice, this list of conditions and the following disclaimer in the \r
+documentation and/or other materials provided with the distribution.\r
+- Neither the name of Skype Limited, nor the names of specific \r
+contributors, may be used to endorse or promote products derived from \r
+this software without specific prior written permission.\r
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED \r
+BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+***********************************************************************/\r
+\r
+#include "SKP_Silk_main.h"\r
+\r
+/* Convert adaptive Mid/Side representation to Left/Right stereo signal */\r
+void SKP_Silk_stereo_MS_to_LR( \r
+    stereo_state        *state,                         /* I/O  State                                       */\r
+    SKP_int16           x1[],                           /* I/O  Left input signal, becomes mid signal       */\r
+    SKP_int16           x2[],                           /* I/O  Right input signal, becomes side signal     */\r
+    SKP_int             predictorIx,                    /* I    Index for predictor filter                  */\r
+    SKP_int             fs_kHz,                         /* I    Samples rate (kHz)                          */\r
+    SKP_int             frame_length                    /* I    Number of samples                           */\r
+)\r
+{\r
+    SKP_int   n;\r
+    SKP_int32 sum, diff, predictor_Q16, pred_Q16, delta_Q16;\r
+\r
+    /* Dequantize */\r
+    predictor_Q16 = SKP_SMLABB( -65536, predictorIx, ( 1 << 17 ) / ( STEREO_QUANT_STEPS - 1 ) );\r
+\r
+    /* Add prediction to side channel */\r
+    if( predictor_Q16 != state->predictor_prev_Q16 ) {\r
+        /* Interpolate predictor */\r
+        pred_Q16 = state->predictor_prev_Q16;\r
+        delta_Q16 = SKP_DIV32_16( predictor_Q16 - state->predictor_prev_Q16, STEREO_INTERPOL_LENGTH_MS * fs_kHz );\r
+        for( n = 0; n < STEREO_INTERPOL_LENGTH_MS * fs_kHz; n++ ) {\r
+            pred_Q16 += delta_Q16;\r
+            x2[ n ] = (SKP_int16)SKP_SAT16( SKP_SMLAWB( x2[ n ], pred_Q16, x1[ n ] ) );\r
+        }\r
+    } else {\r
+        n = 0;\r
+    }\r
+    pred_Q16 = predictor_Q16;\r
+    for( ; n < frame_length; n++ ) {\r
+        x2[ n ] = (SKP_int16)SKP_SAT16( SKP_SMLAWB( x2[ n ], pred_Q16, x1[ n ] ) );\r
+    }\r
+\r
+    state->predictor_prev_Q16 = predictor_Q16;\r
+\r
+    /* Convert to left/right signals */\r
+    for( n = 0; n < frame_length; n++ ) {\r
+        sum  = x1[ n ] + (SKP_int32)x2[ n ];\r
+        diff = x1[ n ] - (SKP_int32)x2[ n ];\r
+        x1[ n ] = (SKP_int16)SKP_SAT16( sum );\r
+        x2[ n ] = (SKP_int16)SKP_SAT16( diff );\r
+    }\r
+}\r
index 5fcde00..cbceaee 100644 (file)
@@ -28,6 +28,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #ifndef SKP_SILK_STRUCTS_H\r
 #define SKP_SILK_STRUCTS_H\r
 \r
+#ifdef HAVE_CONFIG_H\r
+#include "config.h"\r
+#endif\r
 \r
 #include "SKP_Silk_typedef.h"\r
 #include "SKP_Silk_SigProc_FIX.h"\r
@@ -96,6 +99,10 @@ typedef struct {
 } SKP_Silk_NLSF_CB_struct;\r
 \r
 typedef struct {\r
+    SKP_int32                   predictor_prev_Q16;\r
+} stereo_state;\r
+\r
+typedef struct {\r
     SKP_int8        GainsIndices[ MAX_NB_SUBFR ];\r
     SKP_int8        LTPIndex[ MAX_NB_SUBFR ];\r
     SKP_int8        NLSFIndices[ MAX_LPC_ORDER + 1 ];\r
@@ -128,8 +135,8 @@ typedef struct {
     SKP_int                         max_pitch_lag;                  /* Highest possible pitch lag (samples)                                 */\r
     SKP_int32                       API_fs_Hz;                      /* API sampling frequency (Hz)                                          */\r
     SKP_int32                       prev_API_fs_Hz;                 /* Previous API sampling frequency (Hz)                                 */\r
-    SKP_int                         maxInternal_fs_kHz;             /* Maximum internal sampling frequency (kHz)                            */\r
-    SKP_int                         minInternal_fs_kHz;             /* Minimum internal sampling frequency (kHz)                            */\r
+    SKP_int                         maxInternal_fs_Hz;              /* Maximum internal sampling frequency (Hz)                             */\r
+    SKP_int                         minInternal_fs_Hz;              /* Minimum internal sampling frequency (Hz)                             */\r
     SKP_int                         fs_kHz;                         /* Internal sampling frequency (kHz)                                    */\r
     SKP_int                         nb_subfr;                       /* Number of 5 ms subframes in a frame                                  */\r
     SKP_int                         frame_length;                   /* Frame length (samples)                                               */\r
@@ -157,13 +164,13 @@ typedef struct {
     SKP_int                         controlled_since_last_payload;  /* Flag for ensuring codec_control only runs once per packet            */\r
        SKP_int                         warping_Q16;                    /* Warping parameter for warped noise shaping                           */\r
     SKP_int             &nb